'use strict'; /* jshint quotmark: single, eqnull: true, eqeqeq: true, undef: true, unused: true, strict: true, curly: false, funcscope: true, globalstrict: true, shadow:false */ /* global MouseHelper, __METHOD__, __LINE__, AppStaticLib, jQuery, document, StaticLib, window, propName, console, DependencyLoader */ if (StaticLib.Empty(window.Framework)) throw new Error(__METHOD__ + ' reports that the Framework was not found on line ' + __LINE__); window.ContextMenuStruct = { create: function(obj, settings) { var struct = { Caption: new window.Framework.DataTypes.StringPropStruct ({name: propName({Caption:0})}), Icon: new window.Framework.DataTypes.StringPropStruct ({name: propName({Icon:0})}), Action: new window.Framework.DataTypes.ObjectPropStruct ({name: propName({Action:0})}), Args: new window.Framework.DataTypes.ObjectPropStruct ({name: propName({Args:0})}), Enabled: new window.Framework.DataTypes.BooleanPropStruct ({name: propName({Enabled:0}), defaultValue: true}) }; if (typeof(obj) !== 'undefined') StaticLib.SetProps(struct, obj, settings); return struct; } }; StaticLib.DeepSeal(window.ContextMenuStruct); StaticLib.DeepFreeze(window.ContextMenuStruct); window.ContextMenuControl = function (struct) { // **************************************************************** // // // props // // **************************************************************** // this.prop = window.ContextMenuStruct.create(struct, {autobind: true, parent: this}); // **************************************************************** // // // vars // // **************************************************************** // this.vars = { __Items: [], DIV_ZINDEX_BASE: 10000, CurrentMenu: null, ITEM_HEIGHT: 20, MIN_WIDTH: 150, _cover: false, div: null, ul: null }; this.Action = function(cmd) { cmd.Action.GetValue()(cmd.Args.GetValue()); }; this.AddItem = function(title, cmd, args, icon) { var o = title; if (typeof(o) !== 'object') { o = window.ContextMenuStruct.create(); o.Caption = title; o.Action = cmd; o.Args = args; o.Icon = icon; } this.vars.__Items.push(o); }; this.AddItems = function(json) { var items = json; if (typeof(items) === 'string') { items = JSON.parse(json); if ((typeof(items.length) !== 'undefined') && (items.length === 0)) return false; } var menuItem = null; for (var i = 0; i < items.length; i++) { menuItem = window.ContextMenuStruct.create(items[i]); this.AddItem(menuItem); } return true; }; this.RemoveCover = function() { this.vars._cover.removeEventListener('keydown', function() { this.EscapeMenu(); }); var li = null; for (var i = 0; i < this.vars.ul.length; i++) { li = this.vars.ul[i]; li.removeEventListener('click', this.OnClickEvent); } }; this.OnClickEvent = function() { if (window.Framework.prop.ContextMenu === null) return; window.Framework.prop.ContextMenu.doAction(this.id); }; this.InstallCover = function() { this.vars._cover = document.createElement('div'); this.vars._cover.className = 'p-menu-cover'; this.vars._cover.style.zIndex = (this.vars.div.style.zIndex - 1); this.vars._cover.style.visibility = 'hidden'; if (typeof(this.vars._cover) === 'undefined') throw new Error(__METHOD__ + ' reports that the cover was not provided on line ' + __LINE__); document.getElementById('dialogWindows').appendChild(this.vars._cover); this.vars._cover.addEventListener('mousedown', this.CloseContextMenu); this.vars._cover.addEventListener('keydown', function() { this.EscapeMenu(); }); }; this.EscapeMenu = function() { if (this.vars.CurrentMenu) { this.vars.CurrentMenu.Close(); } }; this.Show = function() { if (!this.vars._cover) this.InstallCover(); this.vars._cover.style.width = document.documentElement.clientWidth + 'px'; this.vars._cover.style.height = document.documentElement.clientHeight + 'px'; this.vars._cover.style.visibility = 'visible'; var loc = MouseHelper.currentMouseLoc(); loc[1] -= 65; this.vars.div.style.left = loc[0]+ 'px'; this.vars.div.style.top = loc[1]+ 'px'; this.vars.CurrentMenu = this; this.vars.div.style.visibility = 'visible'; var li; var sp; for (var i = 0; i < this.vars.__Items.length; i++) { li = document.createElement('li'); if (this.vars.__Items[i].Caption.GetValue() !== '-') { sp = document.createElement('div'); sp.innerHTML = this.vars.__Items[i].Caption.GetValue(); li.appendChild(sp); li.className = 'normal-item'; li.id = 'menu-cmd-' + i; } else { li.innerHTML = '
'; } this.vars.ul.appendChild(li); li.addEventListener('click', this.OnClickEvent); } if (this.vars.div.clientWidth < this.vars.MIN_WIDTH) { this.vars.div.style.width = this.vars.MIN_WIDTH+ 'px'; } }; this.FindMenuItem = function(index) { if (typeof(index) === 'string') index = parseInt(index); if ((typeof(index) !== 'number') || (index < 0)) return null; if (index >= this.vars.__Items.length) return null; return this.vars.__Items[index]; }; this.doAction = function(cmd) { if (!this.vars.CurrentMenu) return; if ((this.vars.CurrentMenu.Action) && (cmd !== '')) { try { var action = this.FindMenuItem(cmd.substr(9)); if (action === null) return; if (!action.Enabled) return; this.vars.CurrentMenu.Action(action); } catch(err) { if (window.Framework.prop.developer) console.log('ERROR: ' + err.message); } } this.vars.CurrentMenu.Close(); }; this.CloseContextMenu = jQuery.proxy(function(e) { if (window.Framework.prop.ContextMenu !== null) { if (jQuery(this.vars.div).has(e.target).length > 0) return true; window.Framework.prop.ContextMenu.Close(); } }, this); this.Close = function() { this.RemoveCover(); this.vars.div.parentElement.removeChild(this.vars._cover); this.vars.div.parentElement.removeChild(this.vars.div); this.vars._cover.removeEventListener('mousedown', this.CloseContextMenu); this.vars.CurrentMenu = null; window.Framework.prop.ContextMenu = null; }; // **************************************************************** // // // ctor // // **************************************************************** // this.ctor = function() { this.vars.div = document.createElement('div'); this.vars.div.className = 'p-menu'; this.vars.div.style.zIndex = (this.vars.DIV_ZINDEX_BASE + 1); this.vars.div.style.visibility = 'hidden'; this.vars.ul = document.createElement('ul'); this.vars.div.appendChild(this.vars.ul); if (typeof(this.vars.div) === 'undefined') throw new Error(__METHOD__ + ' reports that the div was not provided on line ' + __LINE__); document.getElementById('dialogWindows').appendChild(this.vars.div); }; // Execute struct = null; this.ctor(); return this; }; StaticLib.DeepSeal(window.ContextMenuControl); StaticLib.DeepFreeze(window.ContextMenuControl); window.ShowContextMenu = function(e) { if (typeof(window.Framework) === 'undefined') return; if (window.Framework.prop.ContextMenu !== null) return; if ((e.target.tagName === 'TEXTAREA') || ((e.target.tagName === 'INPUT') && (e.target.type !== 'button') && (e.target.type !== 'checkbox') && (e.target.type !== 'range') && (e.target.type !== 'radio') && (e.target.type !== 'color'))) return true; if (!window.Framework.prop.developer) e.preventDefault(); if (window.Framework.prop.developer) console.log('You are Developer!'); if (window.Framework.prop.screenLocked) return; var hasSelectedText = false; var copySelectedText = function(){}; if (window.getSelection().toString().length > 0) { hasSelectedText = true; var range = null; if (window.getSelection) { var sel = window.getSelection(); if (sel.getRangeAt && sel.rangeCount) range = sel.getRangeAt(0); } else if (document.selection && document.selection.createRange) { range = document.selection.createRange(); } copySelectedText = jQuery.proxy(function(){ if (window.getSelection) { var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(this); } else if (document.selection && range.select) { this.select(); } document.execCommand('copy'); }, range); } var thisApp = AppStaticLib.GetThisApp(e.target); if (AppStaticLib.IsAnApp(thisApp)) { // check app to see if it has context menu settings if (thisApp.hasContextMenu === true) { if (thisApp.contextMenuItems !== null) { window.Framework.prop.ContextMenu = new window.ContextMenuControl(); window.Framework.prop.ContextMenu.AddItems(thisApp.contextMenuItems); if (hasSelectedText) { window.Framework.prop.ContextMenu.AddItems([ {Caption: '-'}, {Caption: 'Copy Selected Text', Action: copySelectedText} ]); } window.Framework.prop.ContextMenu.Show(); } thisApp.AutoLoadMenu = true; return; } } window.Framework.prop.ContextMenu = new window.ContextMenuControl(); window.Framework.prop.ContextMenu.AddItems( [ {Caption: 'OnLoad.js: PlatformContextMenu', Action: window.Framework.UI.MsgBox, Args: {title: 'ContextMenu Details', message: 'This is the platform ContextMenu system. ', height: 200, width: 300}}, {Caption: '-'}, {Caption: 'About MobyLink', Action: window.Framework.UI.MsgBox, Args: {title: 'About MobyLink', message: 'Or should we boot an app to load some static content?. ', height: 200, width: 300}} ] ); if (hasSelectedText) { window.Framework.prop.ContextMenu.AddItems([ {Caption: '-'}, {Caption: 'Copy Selected Text', Action: copySelectedText} ]); } window.Framework.prop.ContextMenu.Show(); }; /*if ((typeof(window.Framework) !== 'undefined') && (!window.Framework.prop.developer)) { document.addEventListener('contextmenu', ShowContextMenu); }*/ var randomString = function(length) { var text = ''; var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; for(var i = 0; i < length; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } return text; }; window.DataSize = 0; window.FrameworkID = randomString(3); jQuery(document).ready(function() { // Supports IE Browser if (typeof(Object.values) === 'undefined') { Object.defineProperty(Object.prototype, 'values', { value: function(obj) { var returnVal = []; var keys = Object.keys(obj); for (var count = 0; count < keys.length; count++) { returnVal.push(obj[keys[count]]); } return returnVal; } }); } if (typeof(String.includes) === 'undefined') { Object.defineProperty(String.prototype, 'includes', { value: function(substring) { return (this.indexOf(substring) !== -1); } }); } if (typeof(String.endsWith) === 'undefined') { /*String.prototype.endsWith = function(str) { return (this.match(str + '$') === str); };*/ Object.defineProperty(String.prototype, 'endsWith', { value: function(search, this_len) { if ((this_len === undefined) || (this_len > this.length)) { this_len = this.length; } return this.substring((this_len - search.length), this_len) === search; } }); } if (typeof(String.startsWith) === 'undefined') { /*String.prototype.startsWith = function(str) { return (this.match('^' + str) === str); };*/ Object.defineProperty(String.prototype, 'startsWith', { value: function(search, rowPos) { var pos = ((typeof(rowPos) === 'integer') && (rowPos > 0)) ? rowPos | 0 : 0; return this.substring(pos, pos + search.length) === search; } }); } String.prototype.UCFirst = function(str) { if ((typeof(str) !== 'undefined') && (typeof(str) !== 'string')) return ''; if (typeof(str) === 'undefined') str = this; return str.charAt(0).toUpperCase() + str.slice(1); }; String.prototype.LeftTrim = function() { return this.replace(/^\s+/,''); }; String.prototype.RightTrim = function() { return this.replace(/\s+$/,''); }; if (typeof(String.repeat) === 'undefined') { Object.defineProperty(String.prototype, 'repeat', { value:function(count) { if (this === null) throw new TypeError('can\'t convert ' + this + ' to object'); var str = '' + this; // To convert string to integer. count = +count; // Check NaN if (count !== count) count = 0; if (count < 0) throw new RangeError('repeat count must be non-negative'); if (count === Infinity) throw new RangeError('repeat count must be less than infinity'); count = Math.floor(count); if ((str.length === 0) || (count === 0)) return ''; // Ensuring count is a 31-bit integer allows us to heavily optimize the // main part. But anyway, most current (August 2014) browsers can't handle // strings 1 << 28 chars or longer, so: if (str.length * count >= 1 << 28) throw new RangeError('repeat count must not overflow maximum string size'); var maxCount = (str.length * count); count = Math.floor(Math.log(count) / Math.log(2)); while (count) { str += str; count--; } str += str.substring(0, maxCount - str.length); return str; } }); } if (typeof(Array.prototype.includes) === 'undefined') { Object.defineProperty(Array.prototype, 'includes', { value: function(valueToFind, fromIndex) { if (this === null) { throw new TypeError('\'this\' is null or not defined'); } // 1. Let O be ? ToObject(this value). var o = Object(this); // 2. Let len be ? ToLength(? Get(O, 'length')). var len = o.length >>> 0; // 3. If len is 0, return false. if (len === 0) return false; // 4. Let n be ? ToInteger(fromIndex). // (If fromIndex is undefined, this step produces the value 0.) var n = fromIndex | 0; // 5. If n ≥ 0, then // a. Let k be n. // 6. Else n < 0, // a. Let k be len + n. // b. If k < 0, let k be 0. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); function sameValueZero(x, y) { return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); } // 7. Repeat, while k < len while (k < len) { // a. Let elementK be the result of ? Get(O, ! ToString(k)). // b. If SameValueZero(valueToFind, elementK) is true, return true. if (sameValueZero(o[k], valueToFind)) return true; // c. Increase k by 1. k++; } // 8. Return false return false; } }); } /*Number.isInteger = Number.isInteger || function(value) { return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; };*/ /* if (typeof(Array.includes) === 'undefined') { Object.defineProperty(Array.prototype, 'includes', { value: function(value) { return typeof value === 'number' && isFinite(value) && Math.floor(value) === value; } }); } */ var sizing = function(e) { if (window.Framework.prop.developer) console.log(e); }; var keys = ['', 'webkit', 'moz', 'ms']; for (var i = 0; i < keys.length; i++) { document.addEventListener(keys[i]+'fullscreenchange', sizing, false); } // setup emulation mode debugger; var url = window.location.href; window.emulationMode = 0; jQuery('body').addClass('HideFeedback'); // hides the visual border around the apps and controls which is a setting that can be overridden by visual=true in the get args of the url if ((url.indexOf('emulation=') !== -1) || (url.indexOf('visual=') !== -1)) { var getVars = url.split(/[?&]/); var length = getVars.length; var value = ''; for (var count = 0; count < length; count++) { if (getVars[count].indexOf('emulation=') === 0) { value = getVars[count].replace('emulation=', '').replace('#', ''); window.emulationMode = value; switch (window.emulationMode) { case 'web': { window.emulationMode = 1; break; } case 'ipadpro': case 'ipadair': case 'samsungtablet': case 'tablet': { window.emulationMode = 2; break; } case 'iphone10': case 'phone': { window.emulationMode = 6; break; } default: { window.emulationMode = 0; } } } else if (getVars[count].indexOf('visual=') === 0) { value = getVars[count].replace('visual=', '').replace('#', ''); if (StaticLib.ObjectToBoolean(value) === false) jQuery('body').addClass('HideFeedback'); } } } /*if ((StaticLib.IsMobile()) || (StaticLib.IsTablet())) { //Remove the vertical moving when its loaded from a mobile alert('found emulation'); var xStart, yStart = 0; if (window.emulationMode === 0) window.emulationMode = 6; // phone document.addEventListener('touchstart', function(e) { xStart = e.touches[0].screenX; yStart = e.touches[0].screenY; MouseHelper.SetMouseDown(true); if ((typeof(window.Framework.UI) !== undefined) && (window.Framework.UI.Notifications !== null)) window.Framework.UI.Notifications.Add('Mouse Notification', 'The pointer is down', 'sticky'); }); document.addEventListener('touchend', function() { MouseHelper.SetMouseDown(false); MouseHelper.SetMouseMoving(false); if ((typeof(window.Framework.UI) !== undefined) && (window.Framework.UI.Notifications !== null)) window.Framework.UI.Notifications.Add('Mouse Notification', 'The pointer is up', 'sticky'); }); document.addEventListener('touchmove', function(e) { MouseHelper.SetMouseMoving(true); var xMovement = Math.abs(e.touches[0].screenX - xStart); var yMovement = Math.abs(e.touches[0].screenY - yStart); if ((yMovement * 3) > xMovement) e.preventDefault(); if (e.touches[0].screenX > 0) {//|| (e.touches[0].screenX > $(window).width())) //e.preventDefault(); } }); }*/ }); // handler for other files we fetch that we don't find window.addEventListener('error', function(e) { /*debugger; var thisApp = AppStaticLib.GetThisApp(e.target); if (thisApp !== null) { jQuery.proxy(thisApp.AddAppError, thisApp)({Body: e.message}); } else { if (e.target instanceof window.HTMLImageElement) { if ((typeof(window.Framework) === 'object') && (StaticLib.Empty(window.Framework.UI) !== true) && (typeof(window.Framework.UI.MsgBox) === 'function')) { window.Framework.UI.MsgBox({title: 'Error loading image', message: 'Error loading image for ID: ' + e.target.td + ' URL: \'' + e.target.src + '\''}); } else { window.alert('Error loading image for ID: ' + e.target.td + ' URL: \'' + e.target.src + '\'' + additional); } } }*/ if ((e.target instanceof window.HTMLImageElement) || (e.target instanceof window.HTMLLinkElement)) { var type = 'Image'; var url = e.target.src; var additional = ''; if (e.target instanceof window.HTMLLinkElement) { type = 'Style-Sheet'; url = e.target.href; console.log('Style-Sheet'); console.log(e); } var ID = e.target.id; if ((typeof(ID) !== 'undefined') && (ID !== '')) { ID = ' for ID: ' + ID; } else { if ((typeof(e.target.name) !== 'undefined') && (e.target.name !== '')) { ID = ' for Name: ' + e.target.name; } } var thisApp = null; if (url.substr(0, 23) === 'data:image/png;base64, ') { thisApp = AppStaticLib.GetThisApp(e.target); if (thisApp !== null) { if (typeof(ID) === 'undefined') ID = ''; /* jshint debug: true */debugger; return thisApp.AddAppError({Body:'Invalid Base64 image data provided' + ID + '.'}); } } if (typeof(url) !== 'undefined') url = ' URL: \'' + url + '\''; thisApp = AppStaticLib.GetThisApp(e.target); if (thisApp !== null) { additional = ' in App [' + thisApp.AppDetails.GetAppPath('/') + ']'; } window.__handleConnectionError(e, 404, 'Error loading ' + type + ID + url + additional); } }, true); var _InvokeAPI = function(e, API, data, from) { return; //if (e.isTrusted !== true) throw new Error('Invalid request for API'); if ((typeof(window.Framework.V5) === 'undefined') && (window.Framework.V5 === null)) return; var hasBeacon = (typeof(navigator.sendBeacon) === 'function') ? true : false; //if ((API !== 'Reboot') && (API !== 'VisibleChanged')) hasBeacon = false; if ((hasBeacon === true) && (API !== 'Reboot')) hasBeacon = false; if (hasBeacon === false) { var o = new window.Framework.Methods.GetAPIV2( window.APIV2Struct.create({ from: window.Framework, proxyServlet: 'system', proxyView: 'default', proxyServletGroup: 'platform', api: API, callback: 'EmptyCallback', postData: JSON.stringify(data) }) ); o.invoke(); } else { alert('beacon'); navigator.sendBeacon('platform/system/default/' + API + '/?f=' + window.Framework.V5.RunningFrameworkID + '&a=1&b=10&' + from + '=true', JSON.stringify(data)); } }; var _EventTypesList = { VISIBLE: 0, HIDDEN: 1, FOCUS: 2, BLUR: 3 }; window.LastEvent = _EventTypesList.VISIBLE; window.HasFocus = false; window.addEventListener('focus', function (e) { if (window.Framework.teapot === true) return; /* developer code start */ console.log('focus hidden'); /* developer code end */ if ((window.HasFocus === false) && (window.LastEvent !== _EventTypesList.FOCUS)) { //window.HasFocus.delay(250).fadeOut(function() { //this.remove(); window.HasFocus = true; var data = {Orig: window.FrameworkID}; _InvokeAPI(e, 'GotFocus', data, 'focus'); window.LastEvent = _EventTypesList.FOCUS; //}); } }); window.addEventListener('blur', function (e) { if (window.Framework.teapot === true) return; /* developer code start */ console.log('lost focus not hidden'); /* developer code end */ if ((window.HasFocus === true) && (window.LastEvent !== _EventTypesList.BLUR)) { window.HasFocus = false; //window.HasFocus = jQuery('
'); //jQuery('body').append(window.HasFocus); var data = {Orig: window.FrameworkID}; _InvokeAPI(e, 'LostFocus', data, 'blur'); window.LastEvent = _EventTypesList.BLUR; } }); window.IsVisible = false; document.addEventListener('visibilitychange', function (e) { //debugger; if (window.Framework.teapot === true) return; if (document.visibilityState === 'hidden') { /* developer code start */ console.log('hidden'); /* developer code end */ if ((window.IsVisible === true) && (window.LastEvent !== _EventTypesList.HIDDEN)) { window.IsVisible = false; if (window.HasFocus === true) window.HasFocus = false; //window.IsVisible = jQuery('
'); //jQuery('body').append(window.IsVisible); var data = {Orig: window.FrameworkID, HasFocus: false}; _InvokeAPI(e, 'VisibleChanged', data, 'visibilitychange-hidden'); window.LastEvent = _EventTypesList.HIDDEN; } } else { /* developer code start */ console.log('not hidden'); /* developer code end */ if ((window.IsVisible === false) && (window.LastEvent !== _EventTypesList.VISIBLE)) { //window.IsVisible.delay(250).fadeOut(function() { //this.remove(); window.IsVisible = true; window.LastEvent = _EventTypesList.VISIBLE; var data = {Orig: window.FrameworkID, HasFocus: true}; _InvokeAPI(e, 'VisibleChanged', data, 'visibilitychange-not-hidden'); //}); } } }); window.addEventListener('beforeunload', function (e) { // Chrome requires returnValue to be set var _callback_s = jQuery.proxy(function(a, b, c) { /* jshint debug: true */debugger; }, this); /* jshint debug: true */debugger; if ((typeof(window.Framework) !== 'undefined') && (typeof(window.Framework.prop) !== 'undefined') && (!window.Framework.prop.forceRefresh)) { // Cancel the event e.preventDefault(); e.returnValue = 'You are about to leave Mobylink, are you sure you want to do this?'; return false; } /* jshint debug: true */debugger; if (window.Framework.teapot === false) { var data = {Orig: window.FrameworkID}; _InvokeAPI(e, 'Reboot', data, 'beforeunload'); //navigator.sendBeacon('platform/system/default/Reboot/?f=' + window.Framework.V5.RunningFrameworkID + '&a=1&b=10&beforeunload=true', {Orig: window.FrameworkID}); } }); // ENUM_DLLKEYS_COREFRAMEWORK = 1 jQuery( document ).ready(function() { jQuery('#DummyLoadingScreen').remove(); window.FrameworkID = randomString(3); new DependencyLoader(1, function(){}, true); } );