if (window.location.search.indexOf("client=ios") !== -1) { console.log('=> Using iOSClient.js'); var Client = Class.extend({ initialize: function() { this.commands = []; this.timer = new Timer($.proxy(this._sendNotifications, this), 133); this.timer.start(); }, // Called by the web application to send values to the client. // // @param {Object} obj - a set of key/value parameters to send to client notify: function(obj) { if (top.location === self.location) { this.commands.push(obj); } }, // Called by the client to set a value or trigger an action in the web page. // // @param {String} name // @param {Object} value (optional) callback: function(name, value) { Application.onClientCallback(name, value); }, _sendNotifications: function() { // Do nothing if array is empty. if (this.commands.length === 0) return; // Send the first command in the array. this._createUrlForClientInterception("client_notify", this.commands[0]); this.commands.shift(); }, _createUrlForClientInterception: function(prefix, obj) { this._initClientTransportIfNecessary(prefix); for (var prop in obj) { if (typeof obj[prop] !== 'function') { var input = document.createElement("input"); input.type = "hidden"; input.name = prop; // these do not need to be encoded, because the form does this for us. input.value = obj[prop]; this.form.appendChild(input); } } // prevent embedded iframe from being source of further events. if (top.location === self.location) { this.form.submit(); } }, _initClientTransportIfNecessary: function(prefix) { if (this.iframe === null || this.iframe === undefined) { this.iframe = document.createElement("iframe"); this.iframe.name = "postit"; this.iframe.setAttribute("style", "position:absolute; left:-1000px; top:-100px;"); this.iframe.width = this.iframe.height = 10; document.body.appendChild(this.iframe); this.form = document.createElement("form"); this.form.target = "postit"; this.form.style.visibility = "hidden"; this.form.style.position = "absolute"; document.body.appendChild(this.form); } this.form.action = prefix; this.form.innerHTML = ""; } }); // Singleton Client = new Client(); }