"use strict"; (function($){ $.mlp = {x:0,y:0}; // Mouse Last Position function documentHandler(){ var $current = this === document ? $(this) : $(this).contents(); $current.mousemove(function(e){jQuery.mlp = {x:e.pageX,y:e.pageY}}); //$current.find("iframe").load(documentHandler); } $(documentHandler); $.fn.ismouseover = function(overThis) { var result = false; this.eq(0).each(function() { var $current = $(this).is("iframe") ? $(this).contents().find("body") : $(this); var offset = $current.offset(); result = offset.left<=$.mlp.x && offset.left + $current.outerWidth() > $.mlp.x && offset.top<=$.mlp.y && offset.top + $current.outerHeight() > $.mlp.y; }); return result; }; //set do on enter on inputs event $.fn.doOnEnter = function(func){ var object = jQuery(this); if(object.is("input") == false) throw new Error("The do on enter event allowed only on inputs"); if(typeof func != "function") throw new Error("wrong function:"+func); object.keyup(function(event){ if(event.keyCode == 13) func(); }); }; })(jQuery); if(typeof window.addEvent == "undefined") window.addEvent = function(){}; function UniteAdminUC(){ var t = this; var g_errorMessageID = null, g_hideMessageCounter = 0, g_errorMessageHideFunc = null; var g_ajaxLoaderID = null, g_ajaxLoadingButtonID = null, g_ajaxHideButtonID = null, g_successMessageID = null; var g_colorPickerCallback = null; var g_providerAdmin = new UniteProviderAdminUC(), g_dialogActivation, g_generalSettings; g_providerAdmin.setParent(this); var g_temp = { timer: null, trasholdHandle: null, trasholdDelay: 500, debounceDelay: 500, throttleDelay: 50, }; this.getvalopt = { FORCE_BOOLEAN: "force_boolean", FORCE_NUMERIC: "force_numeric", TRIM: "trim" }; this.__________GENERAL_FUNCTIONS_____ = function(){}; /** * check if debug mode */ this.isDebugMode = function(){ var debugMode = false; if(typeof g_ucDebugMode != "undefined" && g_ucDebugMode === true) debugMode = true; return(debugMode); } /** * debug html on the top of the page (from the master view) */ this.debug = function(html){ html += "X"; jQuery("#div_debug").show().html(html); }; /** * output data to console */ this.trace = function(data,clear){ if(clear && clear == true) console.clear(); //console.trace(); console.log(data); }; /** * get general setting */ this.getGeneralSetting = function(name){ if(!g_generalSettings) g_generalSettings = jQuery.parseJSON(g_ucGeneralSettings); var value = t.getVal(g_generalSettings, name); return(value); }; /** * check if was pressed right mouse button */ this.isRightButtonPressed = function(event){ if(event.buttons == 2 || event.button == 2) return(true); return(false); }; /** * insert to CodeMirror editor * @param data */ this.insertToCodeMirror = function(cm, text){ var doc = cm.getDoc(); var cursor = doc.getCursor(); doc.replaceSelection(text); /* //set marked var to = { line: cursor.line, ch: cursor.ch+text.length } var options = { className:"uc-cm-mark-key" }; doc.markText(cursor, to, options); */ }; /** * get random number */ this.getRandomNumber = function(){ var min = 1; var max = 1000000; return Math.floor(Math.random() * (max - min + 1) + min); }; /** * get object property */ this.getVal = function(obj, name, defaultValue, opt){ if(!defaultValue) var defaultValue = ""; var val = ""; if(!obj || typeof obj != "object") val = defaultValue; else if(obj.hasOwnProperty(name) == false){ val = defaultValue; }else{ val = obj[name]; } //sanitize switch(opt){ case t.getvalopt.FORCE_BOOLEAN: val = t.strToBool(val); break; case t.getvalopt.TRIM: val = String(val); val = jQuery.trim(val); break; case t.getvalopt.FORCE_NUMERIC: val = jQuery.trim(val); if(typeof val == "string"){ val.replace("px",""); val = Number(val); } break; } return(val); } /** * add css setting to object */ this.addCssSetting = function(objSettings, objCss, name, cssName, suffix){ if(!suffix) var suffix = ""; var value = t.getVal(objSettings, name, null); if(value) objCss[cssName] = value + suffix; return(objCss); }; /** * get simple object size */ this.objSize = function(obj) { var count = 0; if (typeof obj == "object") { if (Object.keys) { count = Object.keys(obj).length; } else if (window._) { count = _.keys(obj).length; } else if (window.jQuery) { count = jQuery.map(obj, function() { return 1; }).length; } else { for (var key in obj) if (obj.hasOwnProperty(key)) count++; } } return count; }; /** * check if property object exists */ this.isObjPropertyExists = function(object, name){ if(typeof object != "object") return(false); return object.hasOwnProperty(name); } this.__________ARRAYS_____ = function(){}; /** * return if source array includes any of the second array values */ this.isArrIncludesAnotherArrItem = function(source, second){ var isContains = second.some(function(value){ return source.includes(value); }); return(isContains); } this.__________STRINGS_____ = function(){}; /** * get text diff */ this.getTextDiff = function(first, second) { var start = 0; while (start < first.length && first[start] == second[start]) { ++start; } var end = 0; while (first.length - end > start && first[first.length - end - 1] == second[second.length - end - 1]) { ++end; } end = second.length - end; return second.substr(start, end - start); } /** * raw url decode */ function rawurldecode(str){return decodeURIComponent(str+'');} /** * raw url encode */ function rawurlencode(str){str=(str+'').toString();return encodeURIComponent(str).replace(/!/g,'%21').replace(/'/g,'%27').replace(/\(/g,'%28').replace(/\)/g,'%29').replace(/\*/g,'%2A');} /** * utf8 decode */ function utf8_decode(str_data){var tmp_arr=[],i=0,ac=0,c1=0,c2=0,c3=0;str_data+='';while(i191&&c1<224){c2=str_data.charCodeAt(i+1);tmp_arr[ac++]=String.fromCharCode(((c1&31)<<6)|(c2&63));i+=2;}else{c2=str_data.charCodeAt(i+1);c3=str_data.charCodeAt(i+2);tmp_arr[ac++]=String.fromCharCode(((c1&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}} return tmp_arr.join('');} /** * base 64 decode */ this.base64_decode = function(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,dec="",tmp_arr=[];if(!data){return data;} data+='';do{h1=b64.indexOf(data.charAt(i++));h2=b64.indexOf(data.charAt(i++));h3=b64.indexOf(data.charAt(i++));h4=b64.indexOf(data.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;o1=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){tmp_arr[ac++]=String.fromCharCode(o1);}else if(h4==64){tmp_arr[ac++]=String.fromCharCode(o1,o2);}else{tmp_arr[ac++]=String.fromCharCode(o1,o2,o3);}}while(i127&&c1<2048){enc=String.fromCharCode((c1>>6)|192)+String.fromCharCode((c1&63)|128);}else{enc=String.fromCharCode((c1>>12)|224)+String.fromCharCode(((c1>>6)&63)|128)+String.fromCharCode((c1&63)|128);} if(enc!==null){if(end>start){utftext+=string.slice(start,end);} utftext+=enc;start=end=n+1;}} if(end>start){utftext+=string.slice(start,stringl);} return utftext;} /** * base 64 encode */ this.base64_encode = function(data){ var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc="",tmp_arr=[];if(!data){return data;} data=utf8_encode(data+'');do{o1=data.charCodeAt(i++);o2=data.charCodeAt(i++);o3=data.charCodeAt(i++);bits=o1<<16|o2<<8|o3;h1=bits>>18&0x3f;h2=bits>>12&0x3f;h3=bits>>6&0x3f;h4=bits&0x3f;tmp_arr[ac++]=b64.charAt(h1)+b64.charAt(h2)+b64.charAt(h3)+b64.charAt(h4);}while(i>> 0).toString(16)).substr(-8); } return hval >>> 0; /* return s.split("").reduce(function(a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a }, 0); /* var hash = 0, i, char; if (s.length == 0) return hash; for (i = 0, l = s.length; i < l; i++) { char = s.charCodeAt(i); hash = ((hash << 5) - hash) + char; hash |= 0; // Convert to 32bit integer } return hash; */ }; /** * encode object for save */ this.encodeObjectForSave = function(objData){ var jsonData = JSON.stringify(objData); var strEncodedData = t.encodeContent(jsonData); return(strEncodedData); }; /** * decode some content */ this.decodeContent = function(value){ return rawurldecode(t.base64_decode(value)); }; /** * get random string */ this.getRandomString = function(numChars) { if(!numChars) var numChars = 8; var text = ""; var possible = "abcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < numChars; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; }; /** * return true if some string has english chars only (not latin etc) */ this.isStringAscii = function(str){ var isAscii = /^[ -~\t\n\r]+$/.test(str); return(isAscii); } /** * get name from some title */ this.getNameFromTitle = function(title){ var name = title.trim(); // trim. replace spaces. lowercase name = name.replace( /\W+/g, '_' ); name = name.toLowerCase(); return(name); } this.__________EVENTS_____ = function(){}; /** * trigger some event */ this.triggerEvent = function(eventName, opt1){ eventName = "unite_" + eventName; jQuery("body").trigger(eventName, opt1); }; /** * on some event */ this.onEvent = function(eventName, func, objBody){ eventName = "unite_" + eventName; if(!objBody) var objBody = jQuery("body"); objBody.on(eventName, func); }; /** * destroy some event */ this.offEvent = function(eventName){ jQuery("body").off(eventName); }; /** * create function with debounce */ this.debounce = function (func, delay) { var handle = null; return function () { var args = arguments; clearTimeout(handle); handle = setTimeout(() => { func.apply(null, args); }, delay || g_temp.debounceDelay); }; }; /** * create function with throttle */ this.throttle = function (func, delay) { var handle = null; return function () { if (handle === null) { func.apply(null, arguments); handle = setTimeout(function () { handle = null; }, delay || g_temp.throttleDelay); } }; }; /** * run function with trashold */ this.runWithTrashold = function (func, event, objInput) { clearTimeout(g_temp.trasholdHandle); g_temp.trasholdHandle = setTimeout(function () { func(event, objInput); }, g_temp.trasholdDelay); }; /** * run on change input value with trashold */ this.onChangeInputValue = function(objInput, func){ objInput.keyup(function(){ t.runWithTrashold(function(event){ var value = objInput.val(); var oldValue = objInput.data("uc_old_val"); if(value !== oldValue) func(event, objInput); objInput.data("uc_old_val",value); }); }); }; this.__________HTML_RELATED_____ = function(){}; /** * add some option to select */ this.addOptionToSelect = function(objSelect, value, text, addDataName, addDataValue){ var option = jQuery('