/****************************************************************************************************** * XPRS HELPER - SHARED FUNCTIONS ******************************************************************************************************/ var XPRSHelper = {}; XPRSHelper.currentUser = {}; XPRSHelper.LOCAL_SERVER_PATH = "http://localhost:7000"; XPRSHelper.PRODUCTION_SERVER_PATH = "/"; XPRSHelper.RELATIVE_SERVER_PATH = ""; //XPRSHelper.devMode = "LOCAL"; XPRSHelper.devMode = "PRODUCTION"; XPRSHelper.saveQueue = {"PENDING":{},"ERRED":{},"COMPLETED":{},"FUTURE":{}}; XPRSHelper.presetTypes = { "APPS":{"TYPE":"PROMO","NAME":"Widgets","GROUP":"SLIDESHOWS","PAGE":1}, "FEATURES":{"TYPE":"FEATURES","NAME":"Features","GROUP":"FEATURES","PAGE":1}, "TEAM":{"TYPE":"TEAM","NAME":"Team","GROUP":"FEATURES","PAGE":1}, "LOGOS":{"TYPE":"LOGOS","NAME":"Logos","GROUP":"FEATURES","PAGE":1}, "TESTIMONIALS":{"TYPE":"TESTIMONIALS","NAME":"Testimonials","GROUP":"SLIDESHOWS","PAGE":1}, "PROJECTS":{"TYPE":"PROJECTS","NAME":"Projects","GROUP":"FEATURES","PAGE":1}, "GALLERIES":{"TYPE":"GALLERIES","NAME":"Gallery","GROUP":"GALLERIES","PAGE":1}, "BLOG":{"TYPE":"BLOG","NAME":"Blog","GROUP":"GALLERIES","PAGE":1}, "STORE":{"TYPE":"STORE","NAME":"Store","GROUP":"GALLERIES","PAGE":1}, "TEXT_BLOCK":{"TYPE":"TEXT_BLOCK","NAME":"Text Block","GROUP":"ITEMS","PAGE":1}, "ARTICLE":{"TYPE":"ARTICLE","NAME":"Article","GROUP":"ITEMS","PAGE":1}, "HEADER":{"TYPE":"HEADER","NAME":"Header","GROUP":"ITEMS","PAGE":1}, "CALL_TO_ACTION":{"TYPE":"CALL_TO_ACTION","NAME":"Call to action","GROUP":"ITEMS","PAGE":1}, "ITEMS":{"TYPE":"ITEMS","NAME":"Item","GROUP":"ITEMS","PAGE":1}, "PROMO":{"TYPE":"PROMO","NAME":"Header","GROUP":"SLIDESHOWS","PAGE":1}, "FORM":{"TYPE":"FORM","NAME":"Forms","GROUP":"ITEMS","PAGE":1}, "SLIDESHOWS":{"TYPE":"SLIDESHOWS","NAME":"Slideshow","GROUP":"SLIDESHOWS","PAGE":1}, "FOOD_MENU":{"TYPE":"FOOD_MENU","NAME":"Food Menu","GROUP":"FEATURES","PAGE":1}, "MAPS":{"TYPE":"MAPS","NAME":"Maps","GROUP":"SLIDESHOWS","PAGE":1}, "VIDEOS":{"TYPE":"VIDEOS","NAME":"Videos","GROUP":"SLIDESHOWS","PAGE":1}, "RESERVATION":{"TYPE":"RESERVATION","NAME":"Reservations","GROUP":"ITEMS","PAGE":1}, "STORIES":{"TYPE":"STORIES","NAME":"Stories","GROUP":"FEATURES","PAGE":1}, "PRICING":{"TYPE":"PRICING","NAME":"Pricing","GROUP":"FEATURES","PAGE":1}, "SERVICES":{"TYPE":"SERVICES","NAME":"Services","GROUP":"FEATURES","PAGE":1}, "SOCIAL_ICONS":{"TYPE":"SOCIAL_ICONS","NAME":"Social","GROUP":"FEATURES","PAGE":1}, "BIO_CV":{"TYPE":"BIO_CV","NAME":"Bio / Cv","GROUP":"ITEMS","PAGE":1}, "TABLES":{"TYPE":"TABLES","NAME":"Tables","GROUP":"FEATURES","PAGE":1}, "MENUS":{"TYPE":"MENUS","NAME":"Menu","GROUP":"MENUS","COLOR":"#6666FF"}, "FOOTERS":{"TYPE":"FOOTERS","NAME":"Footer","GROUP":"FOOTERS","PAGE":1}, "SELF":{"TYPE":"SELF","NAME":"Self","GROUP":"WIDGETS","PAGE":1,"COLOR":"#5D99C2"}, //ELEMENT "TITLE":{"TYPE":"TITLE","NAME":"Title","GROUP":"ELEMENTS","COLOR":"#0f95ee","PAGE":2}, "PIC":{"TYPE":"PIC","NAME":"Pic","GROUP":"ELEMENTS","COLOR":"#00cc99","PAGE":2}, "DRAGGABLE_PIC":{"TYPE":"DRAGGABLE_PIC","NAME":"Draggable image","GROUP":"ELEMENTS","COLOR":"#00cc99","PAGE":2}, "SUBTITLE":{"TYPE":"SUBTITLE","NAME":"Subtitle","GROUP":"ELEMENTS","COLOR":"#336667","PAGE":2}, "VIDEO":{"TYPE":"VIDEO","NAME":"Video","GROUP":"ELEMENTS","COLOR":"#6766cc","PAGE":2}, "BODY":{"TYPE":"BODY","NAME":"Body","GROUP":"ELEMENTS","COLOR":"#ff679a","PAGE":2}, "QUOTE":{"TYPE":"QUOTE","NAME":"Quote","GROUP":"ELEMENTS","COLOR":"#FF9933","PAGE":2}, "LINK":{"TYPE":"LINK","NAME":"Link","GROUP":"ELEMENTS","COLOR":"#663398","PAGE":2}, "ICON":{"TYPE":"ICON","NAME":"Icon","GROUP":"ELEMENTS","COLOR":"#996533","PAGE":2}, "MAP":{"TYPE":"MAP","NAME":"Map","GROUP":"ELEMENTS","COLOR":"#0099cb","PAGE":2}, "HTML":{"TYPE":"HTML","NAME":"HTML","GROUP":"UNRESOLVED","COLOR":"#999999","PAGE":0}, "DIVIDER":{"TYPE":"DIVIDER","NAME":"Divider","GROUP":"UNRESOLVED","COLOR":"#BDB76B","PAGE":0}, "RAW":{"TYPE":"RAW","NAME":"Raw","GROUP":"ELEMENTS","COLOR":"#5a5a5a","PAGE":2}, //UNRESOLVED "UNRESOLVED":{"TYPE":"UNRESOLVED","NAME":"","GROUP":"UNRESOLVED","COLOR":"","PAGE":0}, "SOCIAL":{"TYPE":"SOCIAL","NAME":"","GROUP":"UNRESOLVED","COLOR":"#333","PAGE":0}, "IMAGE":{"TYPE":"IMAGE","NAME":"Pic","GROUP":"UNRESOLVED","COLOR":"#00cc99","PAGE":0}, "LABEL":{"TYPE":"LABEL","NAME":"Label","GROUP":"UNRESOLVED","COLOR":"#663398","PAGE":0}, "FIELD":{"TYPE":"FIELD","NAME":"Field","GROUP":"UNRESOLVED","COLOR":"#FF9900","PAGE":0}, "PRICE":{"TYPE":"PRICE","NAME":"PRICE","GROUP":"UNRESOLVED","COLOR":"#339966","PAGE":0}, // ECOMMERCE "CART":{"TYPE":"CART","NAME":"Cart","GROUP":"UNRESOLVED","COLOR":"#00CC99","PAGE":0}, // ECOMMERCE "QUOTE_AUTHOR":{"TYPE":"QUOTE_AUTHOR","NAME":"Quote Author","GROUP":"UNRESOLVED","COLOR":"#FF9933","PAGE":0}, "INLINE_PIC":{"TYPE":"INLINE_PIC","NAME":"Image","GROUP":"UNRESOLVED","COLOR":"#00CC99","PAGE":0}, "INLINE_RAW":{"TYPE":"INLINE_RAW","NAME":"HTML Box","GROUP":"UNRESOLVED","COLOR":"#3411CC","PAGE":0} }; XPRSHelper.inPresetGroup = function(presetId,presetGroup){ if (presetId in XPRSHelper.presetTypes){ return (XPRSHelper.presetTypes[presetId]["GROUP"] == presetGroup); } return false; }; XPRSHelper.getServerPath = function(){ if ($("body").attr("data-server")){ return $("body").attr("data-server"); }else{ return XPRSHelper.RELATIVE_SERVER_PATH; } }; XPRSHelper.getStaticServerPath = function(){ return $("body").attr("data-static-server"); }; XPRSHelper.getXprsCookie = function(cookieName){ cookieName = cookieName.replace("xprs","imxprs"); try { return $.cookie(cookieName); } catch(err) { var name = cookieName + "="; var ca = document.cookie.split(';'); for(var i = 0; i 0){ if (XPRSHelper.pendingActionExists(saveKey)){ }else if (XPRSHelper.futureQueueSize(saveKey) > 0){ } XPRSHelper.addToFutureQueue(saveKey,url,saveName,params,callbackFunc); return; }else{ XPRSHelper.markAsPending(saveKey); } if (typeof EditorHelper != "undefined"){ params["root_id"] = EditorHelper.getRootId(); params["page_id"] = EditorHelper.getPageId(); }else if (typeof SpimeDualView != "undefined"){ params["root_id"] = SpimeDualView.getRootId(); } $.ajax({ type: "POST", url: XPRSHelper.getServerPath() + url, data: params, success: function(result) { if (result.response == "SUCCESS"){ XPRSHelper.updateSaveQueue(saveKey,"PENDING","COMPLETED",result); XPRSHelper.updateParent({"deliver_to":"parent","action":"saved"}); if (typeof callbackFunc != "undefined"){ callbackFunc(result); } if (typeof XPRSUndo != "undefined"){ XPRSUndo.pushHistoryEntry({"key":saveKey,"url":url,"name":saveName,"params":params}); } }else{ //handle error!! console.log("got error for key " + saveKey + " with result " + JSON.stringify(result)); XPRSHelper.updateSaveQueue(saveKey,"PENDING","ERRED",result); } }, dataType: "json" }).fail(function(xhr, textStatus, errorThrown) { try{ XPRSHelper.reportError("something went wrong... " + textStatus + " " + errorThrown,{"ajax_url":url,"ajax_params":JSON.stringify(params)}); window.console.error(text); }catch (ex) {} }).always(function(){ if (XPRSHelper.futureQueueSize(saveKey) > 0){ var nextAction = XPRSHelper.getNextSaveAction(saveKey); if (nextAction != null){ console.log("found a new action, for key " + saveKey + " calling future action") setTimeout(function(){ XPRSHelper.SAFEPOST(nextAction.url,nextAction.params,nextAction.saveKey,nextAction.saveName,nextAction.callback); },1000) } } }); }; XPRSHelper.pendingActionExists = function(saveKey){ return (saveKey in XPRSHelper.saveQueue["PENDING"]); }; XPRSHelper.markAsPending = function(saveKey){ XPRSHelper.saveQueue["PENDING"][saveKey] = true; }; XPRSHelper.addToFutureQueue = function(saveKey,url,saveName,params,callback){ var action = {}; action.url = url; action.params = params; action.saveKey = saveKey; action.saveName = saveName; action.callback = callback; if (!(saveKey in XPRSHelper.saveQueue["FUTURE"])){ XPRSHelper.saveQueue["FUTURE"][saveKey] = []; } XPRSHelper.saveQueue["FUTURE"][saveKey].push(action); }; XPRSHelper.futureQueueSize = function(saveKey){ var size = 0; if (saveKey in XPRSHelper.saveQueue["FUTURE"]){ size = XPRSHelper.saveQueue["FUTURE"][saveKey].length } return size; }; XPRSHelper.updateSaveQueue = function(saveKey,fromState,toState,result){ XPRSHelper.saveQueue[toState][saveKey] = true; delete XPRSHelper.saveQueue[fromState][saveKey]; }; XPRSHelper.getNextSaveAction = function(saveKey){ var nextAction = null; if (saveKey in XPRSHelper.saveQueue["FUTURE"]){ var nextAction = XPRSHelper.saveQueue["FUTURE"][saveKey].pop(); if (XPRSHelper.saveQueue["FUTURE"][saveKey].length == 0){ delete XPRSHelper.saveQueue["FUTURE"][saveKey]; } } return nextAction; }; XPRSHelper.localServer = function(){ try{ return (XPRSHelper.getParentWindow().location.href.indexOf("localhost") != -1); }catch(err){}; }; XPRSHelper.clonePrefix = function() { return 'xxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); }; XPRSHelper.onCssTransitionFinish = function(obj,callbackFunc){ if (typeof callbackFunc != "undefined"){ callbackFunc(); } }; XPRSHelper.signout = function(labelName){ XPRSHelper.removeXprsCookie("xprs_user"); XPRSHelper.removeXprsCookie("xprs_root"); XPRSHelper.removeXprsCookie("xprs_session"); XPRSHelper.removeXprsCookie("xprs_email"); if (typeof labelName != "undefined" && labelName == "bricksite"){ XPRSHelper.updateParent({"deliver_to":"parent","action":"remove_navigation_confirmation"}); XPRSHelper.getParentWindow().location.href = "https://admin.bricksite.net/logout.php"; }else{ XPRSHelper.getParentWindow().location.href = "/"; } }; XPRSHelper.getCurrentUser = function(callbackFunc){ XPRSHelper.GET("/get_loggedin_user",{},function(userObj){ XPRSHelper.currentUser = userObj; if (typeof callbackFunc != "undefined"){ callbackFunc(); } },"json"); }; XPRSHelper.trackEvent = function(eventName, category, label, eventValue, skipBi){ if (typeof YSBApp == "undefined"){ // analytics.track(eventName,{label:label}); // analytics.page(eventName,{title:eventName, url:"/" + eventName, path: "/" + eventName}); if (typeof eventValue == "undefined"){ eventValue = 0; } if (typeof ga != "undefined"){ if (typeof ANALYTICS_CODES != "undefined"){ for (i in ANALYTICS_CODES){ var analyticsName = ANALYTICS_CODES[i]["name"]; ga('send', { 'hitType': 'event', // Required. 'eventCategory': category, // Required. 'eventAction': eventName, // Required. 'eventLabel': label, 'eventValue':eventValue }); ga('send', 'pageview', { 'page': eventName, 'title':eventName }); } } } try{ if (typeof IMOS != "undefined"){ var ourGoals = {"Registration":true,"Premium":true,"Whitelabel Premium":true}; if (eventName in ourGoals){ //will be tracked from the goal function //IMOS.trackGoal(eventName); }else{ IMOS.trackEvent(eventName); } } if (typeof Intercom != "undefined"){ if (eventName.indexOf("-Publish") == -1 && eventName.indexOf("-Pay") == -1 && eventName.indexOf("-Select") == -1){ Intercom('trackEvent', eventName, {value:label}); } if (eventName == "clicked become a reseller"){ if (typeof Intercom != "undefined"){ Intercom('update', {"visited whitelabel form": true}); } } } if (typeof imosSdk != "undefined"){ imosSdk.customEvent(eventName); } } catch (err){ console.log("failed to track imos"); } } if (!skipBi){ XPRSHelper.POST("/track_user_action", {"event_name":eventName,"url":window.location.href,"extra_data":label}); } }; XPRSHelper.getParentWindow = function(){ if (typeof SpimeDualView != "undefined"){ return window.self } try { if (window.parent.location.href){ return window.parent; } }catch (err){ return window.self; } }; XPRSHelper.changeHash = function(newHash){ XPRSHelper.getParentWindow().location.hash = newHash; }; XPRSHelper.getHash = function(){ return XPRSHelper.getParentWindow().location.hash; }; XPRSHelper.imagePreloader = function(arrayOfImages,containingFolder,suffix) { $(arrayOfImages).each(function(){ $('')[0].src = containingFolder + "/" + this + "." + suffix; }); }; XPRSHelper.renderTip = function(tipIndex){ tooltTips = [ { "category":"Adding Sections", "title":"Add a new section to your page", "content":"Click to add text, pictures, gallery, slideshow, contact form and more.", "direction":"bottom-left", "selector":"#add-stripe", "container_selector":".master.item-box:visible:not(.force-transparency):not(.element-box):not(.header-box) + .control-handle:eq(0) .add-stripe-holder", "frame":"viewer", "circle_offset_left":38, "circle_offset_top":40//, //"generate_click":true }, { "category":"Editing Content", "title":"Click & edit any element", "content":"Click any element and insert your own content: text, pictures and more.", "direction":"bottom-right", "selector":".text-element", "container_selector":".master.item-box:not(.header-box)", "frame":"viewer", "circle_offset_left":0, "circle_offset_top":37 }, { "category":"Adding Pages", "title":"Add a new page to your site", "content":"Click to add a new page: about, blog, gallery, contact and more", "direction":"top-right", "selector":"#pages-menu-btn", "container_selector":"#control-panel-left", "frame":"dual", "circle_offset_left":15, "circle_offset_top":29 }, { "category":"Responsive", "title":"Preview on all devices", "content":"See how your website looks on tablets and mobile phones", "direction":"top-right", "selector":"#preview-menu-btn", "container_selector":"#control-panel-right", "frame":"dual", "circle_offset_left":8, "circle_offset_top":27 }, { "category":"Publish", "title":"Publish your site", "content":"When you finish editing your site, click Publish to connect to a domain and share your site with the world.", "direction":"top-right", "selector":"#publish-btn", "container_selector":"body", "frame":"dual", "circle_offset_left":-19, "circle_offset_top":28 }, { "category":"History", "title":"Undo certain actions", "content":"Undo 'delete', 'add' and 'order' actions", "direction":"bottom-left", "selector":"#undo-btn", "container_selector":"body", "frame":"dual", "circle_offset_left":40, "circle_offset_top":28 } ]; tipObj = tooltTips[tipIndex]; if (tipObj.frame == "dual"){ if (typeof SpimeDualView == "undefined"){ XPRSHelper.updateParent({"deliver_to":"parent","action":"show-tooltip","tip":tipIndex}); return; } } if (tipObj.frame == "viewer"){ if (typeof EditorHelper == "undefined"){ XPRSHelper.updateParent({"deliver_to":"viewer","action":"show-tooltip","tip":tipIndex}); return; } } var tooltipWrapper = $("
"); var tooltipHolder = $("
"); var availableContainers = $(tipObj.container_selector); var tooltipRefrenceContainer = availableContainers.first(); var tooltipRefrenceElement = tooltipRefrenceContainer.find(tipObj.selector).first(); if (tooltipRefrenceElement.length == 0){ if (availableContainers.length > 1){ tooltipRefrenceContainer = availableContainers.eq(1); tooltipRefrenceElement = tooltipRefrenceContainer.find(tipObj.selector); } } var lastTip = false; var nextTipIndex = tipIndex + 1; if (nextTipIndex == tooltTips.length){ lastTip = true; } //console.log(tooltipRefrenceContainer.attr("class") + " ---- " + tooltipRefrenceElement.attr("class")) //No such reference element, skip if (tooltipRefrenceElement.length == 0){ XPRSHelper.renderTip(nextTipIndex); console.log("didn't find") return; } var tooltipcategory = $("
").text(tipObj.category); var tooltipTitle = $("
").text(tipObj.title); var tooltipContent = $("
").html(tipObj.content); nextBtnText = (lastTip) ? "got it" : "next"; var tooltipNextTip = $("
").text(nextBtnText); var tooltipHideTip = $("
").text("hide"); tooltipNextTip.unbind("click").bind("click",function(e){ e.stopPropagation(); $(".tooltip-ui" + tipIndex).remove(); if (tipObj.generate_click){ tooltipRefrenceElement.trigger("click"); } XPRSHelper.updateParent({"deliver_to":"viewer","action":"remove-tooltips", "tooltip_index":tipIndex}); if ( !lastTip ){ XPRSHelper.renderTip(nextTipIndex); }else{ XPRSHelper.updateParent({"deliver_to":"parent","action":"remove-tooltips", "tooltip_index":tipIndex}); } }); var tooltipCircle = $("
"); tooltipCircle.unbind("click").bind("click",function(event) { event.stopPropagation(); XPRSHelper.updateParent({"deliver_to":"parent","action":"remove-tooltips"}); tooltipRefrenceElement.click(); }); if (tipObj.generate_click){ setTimeout(function(){ tooltipRefrenceElement.trigger("click"); },1500) } tooltipHideTip.unbind("click").bind("click",function(e){ e.stopPropagation(); XPRSHelper.updateParent({"deliver_to":"viewer","action":"remove-tooltips", "tooltip_index":tipIndex}); XPRSHelper.updateParent({"deliver_to":"parent","action":"remove-tooltips", "tooltip_index":tipIndex}); }); tooltipHolder.append(tooltipcategory).append(tooltipTitle).append(tooltipContent).append(tooltipHideTip).append(tooltipNextTip); tooltipWrapper.append(tooltipHolder); tooltipRefrenceContainer.append(tooltipCircle); tooltipRefrenceContainer.append(tooltipWrapper); var scrollOffset = 0; if (tipObj.frame == "viewer"){ scrollOffset = $('.main-page').scrollTop(); } tooltipCircle.offset({ top: tooltipRefrenceElement.offset().top - tipObj.circle_offset_top, left: tooltipRefrenceElement.offset().left - tipObj.circle_offset_left}); var preferredDirection = tipObj.direction; var calculatedLeft = 0; var calculatedTop = 0; if (preferredDirection.indexOf("bottom") != -1){ calculatedTop = tooltipCircle.position().top - tooltipWrapper.innerHeight() + 40; // console.log("we prefer bottom " + calculatedTop) }else{ calculatedTop = tooltipCircle.position().top + tooltipCircle.innerHeight() - 40; } if (preferredDirection.indexOf("left") != -1){ calculatedLeft = tooltipCircle.position().left + tooltipCircle.innerWidth() - 40; }else{ calculatedLeft = tooltipCircle.position().left - tooltipWrapper.innerHeight(); } if (calculatedTop < 0 && preferredDirection.indexOf("bottom") != -1 && tipObj.selector != "#add-stripe"){ //console.log("we prefer bottom but there is no place " + calculatedTop + " < 0 " ) preferredDirection = preferredDirection.replace("bottom","top"); calculatedTop = tooltipCircle.position().top + tooltipCircle.innerHeight() - 40; } if (calculatedLeft < 0 && preferredDirection.indexOf("right") != -1 ){ preferredDirection = preferredDirection.replace("right","left"); calculatedLeft = tooltipCircle.position().left + tooltipCircle.innerWidth() - 40; }else if(calculatedLeft + tooltipWrapper.width() > parseInt($("document").width()) && preferredDirection.indexOf("left") != -1){ preferredDirection = preferredDirection.replace("right","left"); calculatedLeft = tooltipCircle.position().left - tooltipWrapper.innerHeight(); } tooltipWrapper.css("left",calculatedLeft); tooltipWrapper.css("top",calculatedTop ); tooltipWrapper.addClass(preferredDirection); if (tipObj.frame == "viewer"){ var topmostComponent = Math.min(tooltipCircle.offset().top,tooltipWrapper.offset().top); var scrollto = topmostComponent - $('.main-page').offset().top + $('.main-page').scrollTop(); var offset = tooltipCircle.offset().top; var visibleAreaStart = $(window).scrollTop(); var visibleAreaEnd = visibleAreaStart + window.innerHeight; if(offset < visibleAreaStart || offset > visibleAreaEnd){ // Not in view so scroll to it $('body,html').animate({scrollTop:scrollto},2000,'easeOutQuart'); } } XPRSTranslator.translateDom(tooltipWrapper); setTimeout(function(){ tooltipRefrenceContainer.addClass("tip-highlight"); },500); }; XPRSHelper.xprsAlert = function(msg,params){ if (typeof swal == "undefined"){ console.error("XPRS Error: " + msg + " " + JSON.stringify(params)); return; } if (typeof params == "undefined"){ params = {}; params["title"] = "_"; } params["confirmButtonColor"]="#0099CC"; params["customClass"] = "xprs-alert"; if (params && !params["do_not_translate"]){ msg = XPRSTranslator.translateText(msg); params["title"] = XPRSTranslator.translateText(params["title"]); } params["confirmButtonText"] = XPRSTranslator.translateText(params["confirmButtonText"]); params["cancelButtonText"] = XPRSTranslator.translateText(params["cancelButtonText"]); params["text"] = msg; var existingAlert = ($(".sweet-alert.visible").length == 1); if (existingAlert){ //params["closeOnConfirm"] = false; //params["closeOnCancel"] = false; } swal(params,params["callbackfunc"]); if (typeof params.report_error != "undefined"){ XPRSHelper.reportError(msg,params); } $(".sweet-overlay").unbind("click").bind("click",function(e){ e.stopPropagation(); if (params && params["cancelFunc"]){ params["cancelFunc"](); } swal.close(); }); }; XPRSHelper.reportError = function(errorMsg,params){ try{ $.ajax({ type: "POST", url: XPRSHelper.getServerPath() + "/log", data: {"log_info":errorMsg,"stack_trace":Error().stack,"url":window.location.href,"ajax_url":params["ajax_url"],"ajax_params":params["ajax_params"]} }); }catch (ex) {} }; XPRSHelper.invokeLogin = function(callbackFunc, form, cancelCallback, options){ XPRSHelper.getCurrentUser(function(){ var nextUrl = XPRSHelper.getUrlParameterByName("requested_url"); var forceDialog = false; if (form && form.indexOf("force-") != -1){ form = form.replace("force-",""); forceDialog = true; } if (XPRSHelper.currentUser["type"] == "GUEST" || nextUrl != "" || forceDialog){ if (typeof YSBApp != "undefined"){ YSBApp.send({"action": "session-expired", "appid": "ywebsite"}); return; } if (typeof ExternalLogin != "undefined"){ if (typeof SpimeDualView != "undefined"){ SpimeDualView.handleNavigationConfirmation = false; } if (form == "login"){ window.location.href = ExternalLogin.loginUrl; }else{ window.location.href = ExternalLogin.registerUrl; } return } if (typeof LoginModule == "undefined"){ var login_css = $(""); login_css.attr({ rel: "stylesheet", type: "text/css", href: XPRSHelper.getServerPath() + "/css/login.css?v=147" }); $("head").append(login_css); $.ajax({ url: XPRSHelper.getServerPath() + "/js/login.js?v=147", dataType: 'script', success: function(){ setTimeout(function(){ LoginModule.popLogin(callbackFunc, form, cancelCallback, options); },250); }, cache: true //async: false }); }else{ LoginModule.popLogin(callbackFunc, form, cancelCallback, options); } }else{ if (typeof callbackFunc != "undefined"){ callbackFunc(); } } }); }; XPRSHelper.md5 = function(str){ var xl; var rotateLeft = function(lValue, iShiftBits) { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); }; var addUnsigned = function(lX, lY) { var lX4, lY4, lX8, lY8, lResult; lX8 = (lX & 0x80000000); lY8 = (lY & 0x80000000); lX4 = (lX & 0x40000000); lY4 = (lY & 0x40000000); lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); if (lX4 & lY4) { return (lResult ^ 0x80000000 ^ lX8 ^ lY8); } if (lX4 | lY4) { if (lResult & 0x40000000) { return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); } else { return (lResult ^ 0x40000000 ^ lX8 ^ lY8); } } else { return (lResult ^ lX8 ^ lY8); } }; var _F = function(x, y, z) { return (x & y) | ((~x) & z); }; var _G = function(x, y, z) { return (x & z) | (y & (~z)); }; var _H = function(x, y, z) { return (x ^ y ^ z); }; var _I = function(x, y, z) { return (y ^ (x | (~z))); }; var _FF = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var _GG = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var _HH = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var _II = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var convertToWordArray = function(str) { var lWordCount; var lMessageLength = str.length; var lNumberOfWords_temp1 = lMessageLength + 8; var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64; var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; var lWordArray = new Array(lNumberOfWords - 1); var lBytePosition = 0; var lByteCount = 0; while (lByteCount < lMessageLength) { lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount) << lBytePosition)); lByteCount++; } lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); lWordArray[lNumberOfWords - 2] = lMessageLength << 3; lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; return lWordArray; }; var wordToHex = function(lValue) { var wordToHexValue = '', wordToHexValue_temp = '', lByte, lCount; for (lCount = 0; lCount <= 3; lCount++) { lByte = (lValue >>> (lCount * 8)) & 255; wordToHexValue_temp = '0' + lByte.toString(16); wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); } return wordToHexValue; }; var x = [], k, AA, BB, CC, DD, a, b, c, d, S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20, S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21; str = XPRSHelper.utf8_encode(str); x = convertToWordArray(str); a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; xl = x.length; for (k = 0; k < xl; k += 16) { AA = a; BB = b; CC = c; DD = d; a = _FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); d = _FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); c = _FF(c, d, a, b, x[k + 2], S13, 0x242070DB); b = _FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); a = _FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); d = _FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); c = _FF(c, d, a, b, x[k + 6], S13, 0xA8304613); b = _FF(b, c, d, a, x[k + 7], S14, 0xFD469501); a = _FF(a, b, c, d, x[k + 8], S11, 0x698098D8); d = _FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); c = _FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); b = _FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); a = _FF(a, b, c, d, x[k + 12], S11, 0x6B901122); d = _FF(d, a, b, c, x[k + 13], S12, 0xFD987193); c = _FF(c, d, a, b, x[k + 14], S13, 0xA679438E); b = _FF(b, c, d, a, x[k + 15], S14, 0x49B40821); a = _GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); d = _GG(d, a, b, c, x[k + 6], S22, 0xC040B340); c = _GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); b = _GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); a = _GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); d = _GG(d, a, b, c, x[k + 10], S22, 0x2441453); c = _GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); b = _GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); a = _GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); d = _GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); c = _GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); b = _GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); a = _GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); d = _GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); c = _GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); b = _GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); a = _HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); d = _HH(d, a, b, c, x[k + 8], S32, 0x8771F681); c = _HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); b = _HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); a = _HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); d = _HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); c = _HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); b = _HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); a = _HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); d = _HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); c = _HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); b = _HH(b, c, d, a, x[k + 6], S34, 0x4881D05); a = _HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); d = _HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); c = _HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); b = _HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); a = _II(a, b, c, d, x[k + 0], S41, 0xF4292244); d = _II(d, a, b, c, x[k + 7], S42, 0x432AFF97); c = _II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); b = _II(b, c, d, a, x[k + 5], S44, 0xFC93A039); a = _II(a, b, c, d, x[k + 12], S41, 0x655B59C3); d = _II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); c = _II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); b = _II(b, c, d, a, x[k + 1], S44, 0x85845DD1); a = _II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); d = _II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); c = _II(c, d, a, b, x[k + 6], S43, 0xA3014314); b = _II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); a = _II(a, b, c, d, x[k + 4], S41, 0xF7537E82); d = _II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); c = _II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); b = _II(b, c, d, a, x[k + 9], S44, 0xEB86D391); a = addUnsigned(a, AA); b = addUnsigned(b, BB); c = addUnsigned(c, CC); d = addUnsigned(d, DD); } var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); return temp.toLowerCase(); }; XPRSHelper.isTransparentColor = function(color){ if (color === undefined){ return false; } var isTransparent = color == "rgba(0, 0, 0, 0)" || color == "transparent"; if (color.indexOf("rgba") != -1 && color.indexOf(", 0)") != -1){ isTransparent = true; } return isTransparent }; XPRSHelper.checkBrowserSupport = function(){ var currentBrowser = XPRSHelper.getBrowser(); if (currentBrowser.toLowerCase().indexOf("chrome") == -1){ //We does not support your browser for the time being please download chrome } }; XPRSHelper.getBrowser = function(){ var ua= navigator.userAgent, tem, M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; if(/trident/i.test(M[1])){ tem= /\brv[ :]+(\d+)/g.exec(ua) || []; return 'IE '+(tem[1] || ''); } if(M[1]=== 'Chrome'){ tem= ua.match(/\bOPR\/(\d+)/); if(tem!= null) return 'Opera '+tem[1]; } M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]); return M.join(' '); }; XPRSHelper.slugify = function(text){ return text.toString().toLowerCase() .replace(/\s+/g, '-') // Replace spaces with - .replace(/[^\w\-]+/g, '') // Remove all non-word chars .replace(/\-\-+/g, '-') // Replace multiple - with single - .replace(/^-+/, '') // Trim - from start of text .replace(/-+$/, ''); // Trim - from end of text } XPRSHelper.isChrome = function(){ var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; var isChrome = !!window.chrome && !isOpera; // Chrome 1+ return isChrome; } XPRSHelper.utf8_encode = function (argString) { if (argString === null || typeof argString === 'undefined') { return ''; } var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n"); var utftext = '', start, end, stringl = 0; start = end = 0; stringl = string.length; for (var n = 0; n < stringl; n++) { var c1 = string.charCodeAt(n); var enc = null; if (c1 < 128) { end++; } else if (c1 > 127 && c1 < 2048) { enc = String.fromCharCode( (c1 >> 6) | 192, (c1 & 63) | 128 ); } else if (c1 & 0xF800 != 0xD800) { enc = String.fromCharCode( (c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128 ); } else { // surrogate pairs if (c1 & 0xFC00 != 0xD800) { throw new RangeError('Unmatched trail surrogate at ' + n); } var c2 = string.charCodeAt(++n); if (c2 & 0xFC00 != 0xDC00) { throw new RangeError('Unmatched lead surrogate at ' + (n - 1)); } c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000; enc = String.fromCharCode( (c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (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; }; var dateFormat = function () { var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g, timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g, timezoneClip = /[^-+\dA-Z]/g, pad = function (val, len) { val = String(val); len = len || 2; while (val.length < len) val = "0" + val; return val; }; // Regexes and supporting functions are cached through closure return function (date, mask, utc) { var dF = dateFormat; // You can't provide utc if you skip other args (use the "UTC:" mask prefix) if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) { mask = date; date = undefined; } // Passing date through Date applies Date.parse, if necessary date = date ? new Date(date) : new Date; if (isNaN(date)) throw SyntaxError("invalid date"); mask = String(dF.masks[mask] || mask || dF.masks["default"]); // Allow setting the utc argument via the mask if (mask.slice(0, 4) == "UTC:") { mask = mask.slice(4); utc = true; } var _ = utc ? "getUTC" : "get", d = date[_ + "Date"](), D = date[_ + "Day"](), m = date[_ + "Month"](), y = date[_ + "FullYear"](), H = date[_ + "Hours"](), M = date[_ + "Minutes"](), s = date[_ + "Seconds"](), L = date[_ + "Milliseconds"](), o = utc ? 0 : date.getTimezoneOffset(), flags = { d: d, dd: pad(d), ddd: dF.i18n.dayNames[D], dddd: dF.i18n.dayNames[D + 7], m: m + 1, mm: pad(m + 1), mmm: dF.i18n.monthNames[m], mmmm: dF.i18n.monthNames[m + 12], yy: String(y).slice(2), yyyy: y, h: H % 12 || 12, hh: pad(H % 12 || 12), H: H, HH: pad(H), M: M, MM: pad(M), s: s, ss: pad(s), l: pad(L, 3), L: pad(L > 99 ? Math.round(L / 10) : L), t: H < 12 ? "a" : "p", tt: H < 12 ? "am" : "pm", T: H < 12 ? "A" : "P", TT: H < 12 ? "AM" : "PM", Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""), o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4), S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10] }; return mask.replace(token, function ($0) { return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1); }); }; }(); // Some common format strings dateFormat.masks = { "default": "ddd mmm dd yyyy HH:MM:ss", shortDate: "m/d/yy", mediumDate: "mmm d, yyyy", longDate: "mmmm d, yyyy", fullDate: "dddd, mmmm d, yyyy", shortTime: "h:MM TT", mediumTime: "h:MM:ss TT", longTime: "h:MM:ss TT Z", isoDate: "yyyy-mm-dd", isoTime: "HH:MM:ss", isoDateTime: "yyyy-mm-dd'T'HH:MM:ss", isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" }; // Internationalization strings dateFormat.i18n = { dayNames: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ], monthNames: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] }; // For convenience... Date.prototype.format = function (mask, utc) { return dateFormat(this, mask, utc); }; XPRSHelper.shortUuid = function(prefix) { if (typeof prefix == "undefined"){ prefix = "element"; } return prefix + '-xxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); };