1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
var ua=navigator.userAgent.toLowerCase();
|
|
|
|
function getJsonMachineData() {
|
|
|
|
}
|
|
|
|
if(ua.indexOf('msie') != -1 && ua.indexOf('opera') == -1 && ua.indexOf('webtv') == -1)
|
|
{
|
|
if (document.addEventListener){
|
|
window.addEventListener("message", function(e){
|
|
var query = e.data;
|
|
if (query.indexOf('epwidget=set')>-1) {
|
|
document.location.hash = query;
|
|
}
|
|
//document.location.hash = e.data;
|
|
}, false);
|
|
} else {
|
|
window.attachEvent('onmessage', function(e){
|
|
var query = e.data;
|
|
if (query.indexOf('epwidget=set')>-1) {
|
|
document.location.hash = query;
|
|
}
|
|
//document.location.hash = e.data;
|
|
});
|
|
}
|
|
}
|
|
var InpostEPWidget = {
|
|
isIE: (ua.indexOf('msie') != -1 && ua.indexOf('opera') == -1 && ua.indexOf('webtv') == -1),
|
|
isOPERA: navigator.userAgent.toLowerCase().indexOf('opera') != -1 ? true : false,
|
|
url: 'https://geowidget.inpost.pl/',
|
|
isIframe: false,
|
|
hash: '',
|
|
interval: null,
|
|
ref: '',
|
|
scrollTo: '',
|
|
inpost: '',
|
|
//machinesData: getJsonMachineData(),
|
|
selectedMachine: null,
|
|
getOptions: function (selectedName) {
|
|
|
|
//InpostEPWidget.machinesData = getJsonMachineData();
|
|
var options = '<option value="">Please select your nearest terminal</option>';
|
|
|
|
var tempObjMachines = [];
|
|
var lengthOfObjects = 0;
|
|
for (var i in InpostEPWidget.machinesData) {
|
|
|
|
if ('PL' == 'RU') {
|
|
|
|
options += '<optgroup label="' + i + '">';
|
|
|
|
for (var j in InpostEPWidget.machinesData[i]) {
|
|
options += InpostEPWidget.drawHTMLOptionSelect(InpostEPWidget.machinesData[i][j], selectedName);
|
|
tempObjMachines[j] = InpostEPWidget.machinesData[i][j];
|
|
lengthOfObjects++;
|
|
}
|
|
|
|
options += '</optgroup>';
|
|
|
|
} else {
|
|
|
|
options += InpostEPWidget.drawHTMLOptionSelect(InpostEPWidget.machinesData[i], selectedName);
|
|
}
|
|
}
|
|
if (lengthOfObjects) {
|
|
InpostEPWidget.machinesData = tempObjMachines;
|
|
}
|
|
return options;
|
|
},
|
|
drawHTMLOptionSelect: function (machine, selectedName) {
|
|
|
|
var results = '';
|
|
|
|
results += '<option data-address="' + machine.town + ';' + machine.street + ';' + machine.buildingNumber + '" value="' + machine.name + '"' + (machine.name == selectedName ? ' selected' : '') + '>'
|
|
+ machine.name + ', '
|
|
+ machine.town + ', '
|
|
+ machine.street + ' '
|
|
+ machine.buildingNumber + '</option>';
|
|
|
|
return results;
|
|
|
|
},
|
|
getDropdown: function (selectedName) {
|
|
return '<select class="" name="" id="" onchange="InpostEPWidget.updateFromDropdown(this)">' + InpostEPWidget.getOptions(selectedName) + '</select>';
|
|
},
|
|
callback: function (data) {
|
|
var openerSelect = document.getElementsByName("")[0];
|
|
|
|
hash = data['data'];
|
|
var hashArray = hash.split('|');
|
|
var machineName = hashArray[0];
|
|
var address = unescape(hashArray[1]);
|
|
var openIndex = hashArray[2];
|
|
|
|
paczkomatyinpostMachineSelected(machineName, null, openIndex, this.inpost);
|
|
},
|
|
open: function (options) {
|
|
if (ie_ver() || this.isOPERA)
|
|
this.createIframe();
|
|
if (typeof (callback) == 'function')
|
|
this.callback = callback;
|
|
|
|
var opt = options.split('&');
|
|
var idpo = opt[1];
|
|
var inpost = idpo.split('=');
|
|
this.inpost = inpost[1];
|
|
|
|
var settings = {
|
|
openIndex: false,
|
|
town: '',
|
|
cod: 'FALSE',
|
|
selected: ''
|
|
};
|
|
|
|
if (InpostEPWidget.selectedMachine != null) {
|
|
settings.selected = InpostEPWidget.selectedMachine.name;
|
|
}
|
|
|
|
switch (typeof (options)) {
|
|
case 'string':
|
|
case 'number':
|
|
settings.openIndex = options;
|
|
options = {};
|
|
break;
|
|
case 'object':
|
|
for (var i in options) {
|
|
if (options.hasOwnProperty(i)) {
|
|
settings[i] = options[i]
|
|
}
|
|
}
|
|
;
|
|
break;
|
|
case undefined:
|
|
break;
|
|
}
|
|
;
|
|
|
|
this.ref = encodeURIComponent(document.location.toString());
|
|
if (this.ref.indexOf('#') > 0)
|
|
this.ref = this.ref.substr(0, this.ref.indexOf('#'));
|
|
|
|
this.scrollTo = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
|
|
|
|
var height = 760;
|
|
var width = 1000;
|
|
|
|
var top = 0;
|
|
var left = 0;
|
|
if (typeof (screen) != 'undefined') {
|
|
top = Math.round(screen.height / 2 - height / 2);
|
|
left = Math.round(screen.width / 2 - width / 2);
|
|
}
|
|
|
|
if (ie_ver() || this.isOPERA) {
|
|
epwidget_iframe.location = this.url + '/iframe.html#epwidget=open&width=' + width + '&height=' + height + '&top=' + top + '&left=' + left + '&ref=' + encodeURIComponent(this.ref) + '&cod=' + settings.cod + '&openIndex=' + settings.openIndex + '&scrollTo=' + this.scrollTo + '&town=' + settings.town + '&selected=' + settings.selected;
|
|
} else {
|
|
window.open(this.url + '?ref=' + encodeURIComponent(this.ref) + '&cod=' + settings.cod + '&town=' + settings.town + '&selected=' + settings.selected + '&openIndex=' + settings.openIndex + '&scrollTo=' + this.scrollTo, 'InpostEPWidget', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',location=no,toolbar=no,directories=no,scrollbars=yes');
|
|
}
|
|
},
|
|
openCod: function (openIndex) {
|
|
if (this.isIE || this.isOPERA)
|
|
this.createIframe();
|
|
if (typeof (callback) == 'function')
|
|
this.callback = callback;
|
|
|
|
if (openIndex === undefined)
|
|
openIndex = false;
|
|
|
|
this.ref = encodeURIComponent(document.location.toString());
|
|
if (this.ref.indexOf('#') > 0)
|
|
this.ref = this.ref.substr(0, this.ref.indexOf('#'));
|
|
|
|
this.scrollTo = self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
|
|
|
|
var height = 760;
|
|
var width = 1000;
|
|
|
|
var top = 0;
|
|
var left = 0;
|
|
if (typeof (screen) != 'undefined') {
|
|
top = Math.round(screen.height / 2 - height / 2);
|
|
left = Math.round(screen.width / 2 - width / 2);
|
|
}
|
|
|
|
if (this.isIE || this.isOPERA) {
|
|
epwidget_iframe.location = this.url + '/iframe.html#epwidget=open&width=' + width + '&height=' + height + '&top=' + top + '&left=' + left + '&ref=' + encodeURIComponent(this.ref) + '&cod=TRUE&openIndex=' + openIndex + '&scrollTo=' + this.scrollTo;
|
|
} else {
|
|
window.open(this.url + '?ref=' + encodeURIComponent(this.ref) + '&cod=TRUE&openIndex=' + openIndex + '&scrollTo=' + this.scrollTo, 'InpostEPWidget', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',location=no,toolbar=no,directories=no,scrollbars=yes');
|
|
}
|
|
},
|
|
createIframe: function () {
|
|
if (this.isIframe || (!ie_ver() && !this.isOPERA))
|
|
return false;
|
|
if (document.body != null) {
|
|
var iframe = document.createElement('iframe');
|
|
iframe.setAttribute('name', 'epwidget_iframe');
|
|
iframe.setAttribute('id', 'epwidget_iframe');
|
|
iframe.setAttribute('src', this.url + '/iframe.html');
|
|
iframe.style.display = 'none';
|
|
document.body.appendChild(iframe);
|
|
this.isIframe = true;
|
|
} else {
|
|
window.setTimeout("InpostEPWidget.createIframe()", 500);
|
|
}
|
|
},
|
|
getSetting: function (hash) {
|
|
var setting = new Array();
|
|
var fields = hash.split('&');
|
|
for (var i = 0; i < fields.length; i++) {
|
|
var value = fields[i].split('=');
|
|
setting[value[0]] = decodeURIComponent(value[1]);
|
|
}
|
|
return setting;
|
|
},
|
|
checkHash: function () {
|
|
var hash = document.location.hash.toString();
|
|
|
|
if (hash.indexOf('#') == 0)
|
|
hash = hash.substr(1);
|
|
|
|
if (hash != '') {
|
|
|
|
if (hash.indexOf('epwidget') > -1)
|
|
document.location.hash = this.hash;
|
|
else
|
|
this.hash = hash;
|
|
|
|
var splitHash = hash.split("#");
|
|
|
|
var request = this.getSetting(splitHash[splitHash.length - 1]);
|
|
switch (request['epwidget']) {
|
|
case 'set':
|
|
this.scroll(parseInt(request['scrollTo']));
|
|
this.callback(request);
|
|
break;
|
|
}
|
|
}
|
|
|
|
},
|
|
setMachine: function (objRef) {
|
|
var data = objRef.getAttribute('machine') + '|' + objRef.getAttribute('address') + '|' + objRef.getAttribute('openIndex');
|
|
var query = 'epwidget=set&data=' + encodeURIComponent(data) + '&scrollTo=' + encodeURIComponent(objRef.getAttribute('scroll'));
|
|
|
|
if (ie_ver() || this.isOPERA) {
|
|
//window.opener.location.hash=query+'&ref='+encodeURIComponent( objRef.getAttribute( 'ref' ) );
|
|
window.opener.postMessage(query, "*");
|
|
window.opener.location.hash = query;
|
|
} else {
|
|
window.opener.location.replace(objRef.getAttribute('ref') + '#' + query);
|
|
}
|
|
// window.close();
|
|
// paczkomatyinpostMachineSelected(objRef.getAttribute('machine'), null, objSelect.name);
|
|
},
|
|
setSelectedIndex: function (s, v) {
|
|
for (var i = 0; i < s.options.length; i++) {
|
|
if (s.options[i].value == v) {
|
|
s.options[i].selected = true;
|
|
return;
|
|
}
|
|
}
|
|
},
|
|
stop: function () {
|
|
window.clearInterval(this.interval);
|
|
},
|
|
scroll: function (scrollTo) {
|
|
if (!scrollTo > 0)
|
|
return;
|
|
if (document.documentElement)
|
|
document.documentElement.scrollTop = scrollTo;
|
|
if (document.body)
|
|
document.body.scrollTop = scrollTo;
|
|
},
|
|
updateFromDropdown: function (objSelect) {
|
|
var options = objSelect.getElementsByTagName("option");
|
|
var optionHTML = options[ objSelect.selectedIndex ].innerHTML;
|
|
var address = optionHTML.split(',');
|
|
|
|
var objMachine = InpostEPWidget.machinesData[objSelect.value];
|
|
InpostEPWidget.selectedMachine = objMachine;
|
|
|
|
paczkomatyinpostMachineSelected(objSelect.value, InpostEPWidget.machinesData[objSelect.value], objSelect.name);
|
|
}
|
|
}
|
|
|
|
function openMap(options) {
|
|
InpostEPWidget.interval = window.setInterval("InpostEPWidget.checkHash()", 500);
|
|
InpostEPWidget.createIframe();
|
|
InpostEPWidget.open(options);
|
|
}
|
|
|
|
function openMapCod(openIndex) {
|
|
InpostEPWidget.interval = window.setInterval("InpostEPWidget.checkHash()", 500);
|
|
InpostEPWidget.createIframe();
|
|
InpostEPWidget.openCod(openIndex);
|
|
}
|
|
|
|
function epwidgetGetDropdown(selectedName) {
|
|
if (selectedName == undefined || selectedName == 'machine_id' || selectedName == '')
|
|
selectedName = '';
|
|
|
|
document.write(InpostEPWidget.getDropdown(selectedName));
|
|
}
|
|
|
|
function inpost_machines_dropdown(selectedName) {
|
|
epwidgetGetDropdown(selectedName);
|
|
}
|
|
function ie_ver() {
|
|
var iev = 0;
|
|
var ieold = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
|
|
var trident = !!navigator.userAgent.match(/Trident\/7.0/);
|
|
var rv = navigator.userAgent.indexOf("rv:11.0");
|
|
|
|
if (ieold)
|
|
iev = new Number(RegExp.$1);
|
|
if (navigator.appVersion.indexOf("MSIE 10") != -1)
|
|
iev = 10;
|
|
if (trident && rv != -1)
|
|
iev = 11;
|
|
|
|
return iev;
|
|
} |