'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){this.prop=window.ContextMenuStruct.create(struct,{autobind:true,parent:this});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';}this.vars.ul.appendChild(li);li.addEventListener('click',this.OnClickEvent);}if(this.vars.div.clientWidth=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;};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);};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)){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();};var randomString=function(length){var text='';var possible='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';for(var i=0;ithis.length)){this_len=this.length;}return this.substring((this_len-search.length),this_len)===search;}});}if(typeof(String.startsWith)==='undefined'){Object.defineProperty(String.prototype,'startsWith',{value:function(search,rowPos){var pos=((typeof(rowPos)==='number')&&(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;count=+count;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'';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');}var o=Object(this);var len=o.length>>>0;if(len===0)return false;var n=fromIndex|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));}while(k