----------------------------------------------------------------------------------------------
if (typeof String.prototype.trim !== "function") { String.prototype.trim = function() { return this.replace(/^s+|s+$/g, "") } } FiAPTLocation = function(a) { this.init(a) }; FiAPTLocation.prototype = { defaultSettings: { target_id: "smartpost_widget_target", placeid_name: "smartpost_terminal_id", placename_name: "smartpost_terminal_name", selected_id: false, default_id: "-", show_infotext: true, show_logo: true, show_city: true, show_address: true, show_opened: true, text_infotext: "Tellimus viiakse kaubanduskeskuses asuvasse iseteeninduslikku pakiautomaati." + '<br/>Vaata lأ¤hemalt: <a href="https://uus.smartpost.ee/mis-on-pakiautomaat" target="_blank">' + '<b>Mis on pakiautomaat?</b></a> Vaata ka pakiautomaatide asukohtasid <a href="http://www.smartpost.ee/eteenindus/kiosks" target="_blank"><b>kaardil</b></a>.', text_place: "Pakiautomaadi asukoht:", text_city: "Pakiautomaadi linn:", text_address: "Pakiautomaadi aadress:", text_opened: "Pakiautomaadi lahtiolekuaeg:", text_default_item: "-- Vali Pakiautomaat --" }, ensureDefaultSettings: function() { for (var a in this.defaultSettings) { if (!this.defaultSettings.hasOwnProperty(a)) continue; if (typeof this.settings[a] == "undefined") this.settings[a] = this.defaultSettings[a] } this.settings.idHash = Math.round(Math.random() * 98765432123456780); delete this.defaultSettings; delete this.ensureDefaultSettings }, init: function(a) { if (!this.settings) { this.settings = new Object } if (typeof a !== "undefined" && typeof a == "object") for (var b in a) if (a.hasOwnProperty(b)) this.settings[b] = a[b]; this.ensureDefaultSettings(); this.downloadPlaces() }, downloadPlaces: function() { url = document.location.protocol + "//uus.smartpost.ee/fi_apt.js"; console.log('url is: ' + url); //url = "https://smartpost.ee/fi_apt.js"; var a = document.getElementsByTagName("head")[0]; if (!a) return; ppScript = document.createElement("SCRIPT"); ppScript.setAttribute("src", url); ppScript.setAttribute("type", "text/javascript"); a.appendChild(ppScript); var b = this; var c = setInterval(function() { if (typeof pickupapts == "undefined") return; clearInterval(c); b.makeHTML() }, 100) }, makeHTML: function() { var a = document.getElementById(this.settings.target_id); if (!a) { throw new Error('There is no target element "' + this.settings.target_id + '" for FiAPTLocation widget!'); return } this.pickuppoints = new Object; this.ppByCode = new Object; this.curSelected = new Object({ code: "", city: "", address: "", availability: "", postoffice: "" }); for (var b = 0; b < pickupapts.length; b++) { if (!pickupapts[b]) continue; if (!this.pickuppoints[pickupapts[b].city]) this.pickuppoints[pickupapts[b].city] = [pickupapts[b]]; else this.pickuppoints[pickupapts[b].city].push(pickupapts[b]) } delete pickupapts; a.innerHTML = '<div id="fiaptlocationHolder' + this.settings.idHash + '"></div>'; var a = document.getElementById("fiaptlocationHolder" + this.settings.idHash); var c = this.settings.show_infotext ? '<p class="fiaptlocationInfo">' + this.settings.text_infotext + "</p>" : ""; var d = '<tr><td class="label">' + (this.settings.text_place ? this.settings.text_place : "") + "</td>"; d += '<td class="input"><select id="fiaptlocationSelect' + this.settings.idHash + '" name="' + this.settings.placeid_name + '">'; d += '<option value="' + this.settings.default_id + '">' + this.settings.text_default_item + "</option>"; for (var e in this.pickuppoints) { if (!this.pickuppoints.hasOwnProperty(e)) continue; d += '<optgroup label="' + e + '">'; for (var b = 0; b < this.pickuppoints[e].length; b++) { for (var f in this.pickuppoints[e][b]) { if (!this.pickuppoints[e][b][f]) continue; this.pickuppoints[e][b][f] = this.pickuppoints[e][b][f].trim() } this.ppByCode[this.pickuppoints[e][b].code] = this.pickuppoints[e][b]; if (this.settings.selected_id == this.pickuppoints[e][b].code) this.curSelected = this.pickuppoints[e][b]; d += "<option " + (this.settings.selected_id == this.pickuppoints[e][b].code ? 'selected="selected"' : "") + ' value="' + this.pickuppoints[e][b].code + '">' + this.pickuppoints[e][b].postoffice + "</option>" } d += "</optgroup>" } d += "</select></td></tr>"; var e = '<tr style="' + (this.settings.show_city ? "" : "display:none") + '"><td class="label">' + this.settings.text_city + '</td><td class="input"><input id="fiaptlocationCity' + this.settings.idHash + '" type="text" readonly="yes" value="' + this.curSelected.city + '"/></td></tr>'; var g = '<tr style="' + (this.settings.show_address ? "" : "display:none") + '"><td class="label">' + this.settings.text_address + '</td><td class="input"><input id="fiaptlocationAddress' + this.settings.idHash + '" type="text" readonly="yes" value="' + this.curSelected.address + '"/></td></tr>'; var h = '<tr style="' + (this.settings.show_opened ? "" : "display:none") + '"><td class="label">' + this.settings.text_opened + '</td><td class="input"><input id="fiaptlocationAvailability' + this.settings.idHash + '" type="text" readonly="yes" value="' + this.curSelected.availability + '"/></td></tr>'; var i = this.settings.show_logo ? '<img alt="SmartPOST" class="fiaptlocationLogo" src="https://uus.smartpost.ee/images/posti_orange.png" height="100" width="200"/>' : ""; a.innerHTML = c; a.innerHTML += i; a.innerHTML += '<table class="fiaptlocationTable">' + d + e + g + h + "</table>"; a.innerHTML += '<input type="hidden" name="' + this.settings.placename_name + '" value="' + this.curSelected.postoffice + '" id="fiaptlocationName' + this.settings.idHash + '" />'; a.innerHTML += '<div style="clear:both"></div>'; var j = this; document.getElementById("fiaptlocationSelect" + this.settings.idHash).onchange = function() { if (this.value == j.settings.default_id) { document.getElementById("fiaptlocationCity" + j.settings.idHash).value = ""; document.getElementById("fiaptlocationAddress" + j.settings.idHash).value = ""; document.getElementById("fiaptlocationAvailability" + j.settings.idHash).value = ""; document.getElementById("fiaptlocationName" + j.settings.idHash).value = "" } else { document.getElementById("fiaptlocationCity" + j.settings.idHash).value = j.ppByCode[this.value].city; document.getElementById("fiaptlocationAddress" + j.settings.idHash).value = j.ppByCode[this.value].address; document.getElementById("fiaptlocationAvailability" + j.settings.idHash).value = j.ppByCode[this.value].availability; document.getElementById("fiaptlocationName" + j.settings.idHash).value = j.ppByCode[this.value].postoffice } } } }
----------------------------------------------------------------------------------------------
.fiaptlocationInfo { text-align: right; } .fiaptlocationLogo { border: none; float:left; } .fiaptlocationTable { float: right; } .fiaptlocationTable td.label { text-align: right; } .fiaptlocationTable td.input { text-align: right; } .fiaptlocationTable td.input input,.fiaptlocationTable td.input select { width: 180px; box-sizing: border-box; } .fiaptlocationSelect { width: 200px; }
----------------------------------------------------------------------------------------------