{ /** * Internal state vars. */ var config; var geoWindow; /** * Main, public API function. */ function myGeoPositionGeoPicker(configObj) { /** * Check for config data and store in specific var */ if (typeof configObj != 'object') { return; } config = configObj; /** * Get page META information */ var metaWindowTitle = ''; var metaTitle = ''; var metaDescription = ''; var metaKeywords = ''; if (document.getElementsByTagName) { var metatags = document.getElementsByTagName("meta"); for (var i = 0; i < metatags.length; i++) { if (metatags[i].getAttribute('name') && metatags[i].getAttribute('name').toLowerCase() == 'title') { metaTitle = metatags[i].getAttribute('content'); } if (metatags[i].getAttribute('name') && metatags[i].getAttribute('name').toLowerCase() == 'description') { metaDescription = metatags[i].getAttribute('content'); } if (metatags[i].getAttribute('name') && metatags[i].getAttribute('name').toLowerCase() == 'keywords') { metaKeywords = metatags[i].getAttribute('content'); } } if (document.getElementsByTagName("title").length > 0 && document.getElementsByTagName("title")[0].innerHTML) { metaWindowTitle = document.getElementsByTagName("title")[0].innerHTML } } /** * Prepare some vars */ var id = mgpGenerateId(document.location.hostname + document.location.pathname); if (typeof config.startPositionInputFieldIds == 'object' && config.startPositionInputFieldIds.length > 0) { config.startAddress = ''; for (var i = 0; i < config.startPositionInputFieldIds.length; i++) { if (document.getElementById(config.startPositionInputFieldIds[i])) { config.startAddress += document.getElementById(config.startPositionInputFieldIds[i]).value + ', '; } } } /** * Create iframe URL */ var iframeUrl = 'http://api.mygeoposition.com/api/geopicker/id-' + id + '/?'; function addToUrl(name, value) { if (value) { iframeUrl = iframeUrl + "&" + name + "=" + escape(value); } } addToUrl('startAddress', config.startAddress); addToUrl('startPositionLat', config.startPositionLat); addToUrl('startPositionLng', config.startPositionLng); addToUrl('autolocate', config.autolocate); addToUrl('locateme',config.locateme); addToUrl('zoomLevel', config.zoomLevel); addToUrl('mapType', config.mapType); addToUrl('showStartupInfoWindow', config.showStartupInfoWindow); addToUrl('showResultInfoWindow', config.showResultInfoWindow); addToUrl('returnUrl', document.location.href); addToUrl('langCode', config.langCode); addToUrl('langButtonSearch', config.langButtonSearch); addToUrl('langButtonReturn', config.langButtonReturn); addToUrl('langMarkerInfo', config.langMarkerInfo); addToUrl('langSearchField', config.langSearchField); addToUrl('langLookupFailed', config.langLookupFailed); addToUrl('langLookupNoResults', config.langLookupNoResults); addToUrl('backgroundColor', config.backgroundColor); addToUrl('windowTitle', config.windowTitle); addToUrl('metaWindowTitle', metaWindowTitle); addToUrl('metaTitle', metaTitle); addToUrl('metaDescription', metaDescription); addToUrl('metaKeywords', metaKeywords); /** * Open external window and connect to API server via iframe */ geoWindow = window.open("", "MGPGeoPickerWindow", "width=488,height=518,location=no,menubar=no,resizable=no,status=no,toolbar=no"); geoWindow.focus(); geoWindow.document.write(""); geoWindow.document.write(config.windowTitle ? config.windowTitle : (metaWindowTitle ? metaWindowTitle : 'MygeoPosition.com GeoPicker')); geoWindow.document.write(""); geoWindow.document.write(""); geoWindow.document.write(""); geoWindow.document.write(""); } /** * Process result data as configured by user. */ function mgpReturnResult(data) { // Create object from string result var resultObj = JSON.parse(data); // Return data in case of one field only if (config.returnFieldId && config.returnValueTemplate && document.getElementById(config.returnFieldId)) { document.getElementById(config.returnFieldId).value = mgpFillTemplate(config.returnValueTemplate, resultObj); } // Return data in case field mapping exists else if(config.returnFieldMap && typeof config.returnFieldMap == 'object') { for(var key in config.returnFieldMap) { var documentId = key; var template = config.returnFieldMap[key]; if (document.getElementById(documentId)) { document.getElementById(documentId).value = mgpFillTemplate(template, resultObj); } } } // Return data in case callback exists else if(config.returnCallback) { window[config.returnCallback](resultObj); } else { alert("No return field(s) specified!"); } } /** * Parse and process a result template. */ function mgpFillTemplate(template, resultObj) { var result = template; result = result.replace(//gi, resultObj.lat); result = result.replace(//gi, resultObj.lng); result = result.replace(//gi, resultObj.latMin); result = result.replace(//gi, resultObj.lngMin); result = result.replace(/
/gi, resultObj.address); result = result.replace(//gi, resultObj.country.short); result = result.replace(//gi, resultObj.country.long); result = result.replace(//gi, resultObj.state.short); result = result.replace(//gi, resultObj.state.long); result = result.replace(//gi, resultObj.district.short); result = result.replace(//gi, resultObj.district.long); result = result.replace(//gi, resultObj.city.short); result = result.replace(//gi, resultObj.city.long); result = result.replace(//gi, resultObj.suburb.short); result = result.replace(//gi, resultObj.suburb.long); result = result.replace(//gi, resultObj.postalCode.short); result = result.replace(//gi, resultObj.postalCode.long); result = result.replace(//gi, resultObj.postalCode.short); result = result.replace(//gi, resultObj.postalCode.long); result = result.replace(//gi, resultObj.street.short) result = result.replace(//gi, resultObj.street.long); result = result.replace(//gi, resultObj.streetNumber.short); result = result.replace(//gi, resultObj.streetNumber.long); result = result.replace(//gi, resultObj.streetNumber.short); result = result.replace(//gi, resultObj.streetNumber.long); return result; } /** * Generate quite unique app user id */ function mgpGenerateId(data) { data = data.replace(/http:\/\//g, ""); data = data.replace(/www/g, ""); data = data.replace(/\//g, ""); data = data.replace(/\./g, ""); data = data.replace(/\?/g, ""); data = data.replace(/_/g, ""); data = data.replace(/-/g, ""); data = data.replace(/&/g, ""); data = data.replace(/=/g, ""); data = data.replace(/a/g, "v"); data = data.replace(/e/g, "x"); data = data.replace(/i/g, "y"); data = data.replace(/o/g, "z"); data = data.replace(/u/g, "q"); data = data.replace(/#/g, ""); result = ''; result += data.substr(0, 15); result += data.substr(data.length - 13, 10); return result; } /** * JSON2.js */ if(!this.JSON){this.JSON={};} (function(){function f(n){return n<10?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';} function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} if(typeof rep==='function'){value=rep.call(holder,key,value);} switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i