diff --git a/build/appframework.ui.js b/build/appframework.ui.js index 34ab8207c..551e2b706 100644 --- a/build/appframework.ui.js +++ b/build/appframework.ui.js @@ -1,3009 +1,3010 @@ -/*! intel-appframework - v3.0.0 - 2016-03-26 */ - -/** - * af.shim.js - * @copyright Intel 2014 - * @author Ian Maffett - * @description jQuery helper functions for App Framework - */ -/* jshint eqeqeq:false */ -(function($,window){ - "use strict"; - jQuery.event.props.push("touches"); - jQuery.event.props.push("originalTouches"); - jQuery.event.props.push("changedTouches"); - var nundefined, document = window.document,classCache = {},isWin8=(typeof(MSApp)==="object"); - - function classRE(name) { - return name in classCache ? classCache[name] : (classCache[name] = new RegExp("(^|\\s)" + name + "(\\s|$)")); - } - function _shimNodes(nodes, obj) { - if (!nodes) - return; - if (nodes.nodeType) { - obj[obj.length++] = nodes; - return; - } - for (var i = 0, iz = nodes.length; i < iz; i++) - obj[obj.length++] = nodes[i]; - } - $.extend($.fn,{ - /** - * Get/Set vendor specific CSS - * Also set the vendor neutral version - * @param {String} attribute to get - * @param {String} value to set as - * @return {Object} an appframework object - * @title $().css(attribute,[value]) - */ - vendorCss: function (attribute, value, obj) { - this.css(attribute.toLowerCase(),value,obj); - return this.css($.feat.cssPrefix + attribute, value, obj); - }, - /** - * Performs a css vendor specific transform:translate operation on the collection. - * - ``` - $("#main").cssTranslate('200px,0,0'); - ``` - * @param {String} Transform values - * @return {Object} an appframework object - * @title $().vendorCss(value) - */ - cssTranslate: function (val) { - this.vendorCss("Transform", "translate" + $.feat.cssTransformStart + val + $.feat.cssTransformEnd); - }, - /** - * Gets the computed style of CSS values - * - ``` - $("#main").computedStyle('display'); - ``` - * @param {String} css property - * @return {Int|String|Float|} css vlaue - * @title $().computedStyle() - */ - computedStyle:function(val){ - if(this.length===0||val==nundefined) return; - return window.getComputedStyle(this[0],"")[val]; - }, - replaceClass: function(name, newName) { - if (name == nundefined || newName == nundefined) return this; - var replaceClassFn=function(cname) { - classList = classList.replace(classRE(cname), " "); - }; - for (var i = 0; i < this.length; i++) { - var classList = this[i].className; - - name.split(/\s+/g).concat(newName.split(/\s+/g)).forEach(replaceClassFn); - classList = classList.trim(); - if (classList.length > 0) { - this[i].className = (classList + " " + newName).trim(); - } else - this[i].className = newName; - } - return this; - } - }); - function detectUA($, userAgent) { - $.os = {}; - - $.os.webkit = userAgent.match(/WebKit\/([\d.]+)/) ? true : false; - $.os.android = userAgent.match(/(Android)\s+([\d.]+)/) || userAgent.match(/Silk-Accelerated/) ? true : false; - $.os.androidICS = $.os.android && userAgent.match(/(Android)\s4/) ? true : false; - $.os.ipad = userAgent.match(/(iPad).*OS\s([\d_]+)/) ? true : false; - $.os.iphone = !$.os.ipad && userAgent.match(/(iPhone\sOS)\s([\d_]+)/) ? true : false; - $.os.ios7 = ($.os.ipad||$.os.iphone); - $.os.webos = userAgent.match(/(webOS|hpwOS)[\s\/]([\d.]+)/) ? true : false; - $.os.touchpad = $.os.webos && userAgent.match(/TouchPad/) ? true : false; - $.os.ios = $.os.ipad || $.os.iphone; - $.os.playbook = userAgent.match(/PlayBook/) ? true : false; - $.os.blackberry10 = userAgent.match(/BB10/) ? true : false; - $.os.blackberry = $.os.playbook || $.os.blackberry10|| userAgent.match(/BlackBerry/) ? true : false; - $.os.chrome = userAgent.match(/Chrome/) ? true : false; - $.os.opera = userAgent.match(/Opera/) ? true : false; - $.os.fennec = userAgent.match(/fennec/i) ? true : userAgent.match(/Firefox/) ? true : false; - $.os.ie = userAgent.match(/MSIE 10.0/i)||userAgent.match(/Trident\/7/i) ? true : false; - $.os.ieTouch = $.os.ie && userAgent.toLowerCase().match(/touch/i) ? true : false; - $.os.tizen = userAgent.match(/Tizen/i)?true:false; - $.os.supportsTouch = ((window.DocumentTouch && document instanceof window.DocumentTouch) || "ontouchstart" in window); - $.os.kindle=userAgent.match(/Silk-Accelerated/)?true:false; - //features - $.feat = {}; - - $.feat.cssTransformStart = !$.os.opera ? "3d(" : "("; - $.feat.cssTransformEnd = !$.os.opera ? ",0)" : ")"; - if ($.os.android && !$.os.webkit) - $.os.android = false; - - - //IE tries to be webkit - if(userAgent.match(/IEMobile/i)){ - $.each($.os,function(ind){ - $.os[ind]=false; - }); - $.os.ie=true; - $.os.ieTouch=true; - } - var items=["Webkit","Moz","ms","O"]; - for(var j=0;jthis is some text"); - ``` - $.create("div",{id:'main',innerHTML:'this is some text'}); - $.create("
this is some text
"); - ``` - * @param {String} DOM Element type or html - * @param [{Object}] properties to apply to the element - * @return {Object} Returns an appframework object - * @title $.create(type,[params]) - */ - $.create = function(type, props) { - var elem; - var f = new $(); - if (props || type[0] !== "<") { - if (props.html){ - props.innerHTML = props.html; - delete props.html; - } - - elem = document.createElement(type); - for (var j in props) { - elem[j] = props[j]; - } - f[f.length++] = elem; - } else { - elem = document.createElement("div"); - if (isWin8) { - MSApp.execUnsafeLocalFunction(function() { - elem.innerHTML = type.trim(); - }); - } else - elem.innerHTML = type; - _shimNodes(elem.childNodes, f); - } - return f; - }; - /** - * $.query - a no longer faster alertnative to $("div") (App Framework was faster) - ``` - $.query(".panel"); - ``` - * @param {String} selector - * @param {Object} [context] - * @return {Object} Returns an appframework object - * @title $.query(selector,[context]) - */ - $.query = function (sel, what) { - try { - return $(sel,what); - } - catch(e) { - return $(); - } - }; - - $.isObject = function (obj) { - return typeof obj === "object"; - }; - - - $.is$ = function (obj) { - return obj instanceof $; - }; - //Shim to put touch events on the jQuery special event - - window.$afm=$; - - $.feat.TouchList=function(){ - this.length=0; - }; - - $.feat.TouchList.prototype = { - item:function(ind){ - return this[ind]; - }, - _add:function(touch){ - this[this.length]=touch; - this.length++; - } - }; - var identifier=1000; - $.feat.Touch = function() { - this.identifier=identifier++; - }; - - $.feat.Touch.prototype = { - "clientX":0, - "clientY":0, - "screenX":0, - "screenY":0, - "pageX":0, - "pageY":0, - "identifier":0 - }; - -})(jQuery,window); - -window.af=window.jq=jQuery; - -/** - * appframework.ui - A User Interface library for App Framework applications - * - * @copyright 2011-2014 Intel - * @author Intel - * @version 3.0 - */ -/* global FastClick*/ - - /* jshint camelcase:false*/ - - -(function($) { - "use strict"; - var startPath = window.location.pathname + window.location.search; - var defaultHash = window.location.hash; - var previousTarget = defaultHash; - var AFUi = function() { - // Init the page - var that = this; - - - if (typeof define === "function" && define.amd) { - that.autoLaunch=false; - define("appframeworkui", [], function() { - return $.afui; - }); - } else if (typeof module !== "undefined" && module.exports) { - that.autoLaunch=false; - $.afui = that; - } - - var setupAFDom = function() { - setupCustomTheme(); - if(window.FastClick) - FastClick.attach(document.documentElement); - }; - - if (document.readyState === "complete" || document.readyState === "loaded") { - setupAFDom(); - if(that.init) - that.autoBoot(); - else{ - $(window).one("afui:init", function() { - that.autoBoot(); - }); - } - } else $(document).ready( - function() { - setupAFDom(); - if(that.init) - that.autoBoot(); - else{ - $(window).one("afui:init", function() { - that.autoBoot(); - }); - } - }, - false); - - //click back event - window.addEventListener("popstate", function() { - - if(!that.useInternalRouting) return; - var id = that.getPanelId(document.location.hash); - var hashChecker = document.location.href.replace(document.location.origin + "/", ""); - //make sure we allow hash changes outside afui - - if (hashChecker === "#") return; - if (id === "" && that.history.length === 1) //Fix going back to first panel and an empty hash - id = "#" + that.firstPanel.id; - if (id === "") return; - if ($(id).filter(".panel").length === 0) return; - if (id !== "#" + that.activeDiv.id) { - //Make a custom event object for goBack - var evt = { - "target" : $(id) - }; - that.goBack(evt); - } - - }, false); - - - window.addEventListener("orientationchange",function(){ - window.scrollTo(0, 0); - }); - - function setupCustomTheme() { - - if (that.useOSThemes) { - - var $el=$(document.body); - $el.removeClass("ios ios7 win8 tizen bb android light dark firefox"); - if ($.os.android) - $el.addClass("android"); - else if ($.os.ie) { - $el.addClass("win8"); - } else if ($.os.blackberry||$.os.blackberry10||$.os.playbook) { - $el.addClass("bb"); - that.backButtonText = "Back"; - } else if ($.os.ios7){ - $el.addClass("ios7"); - } else if ($.os.ios) - $el.addClass("ios7"); - else if($.os.tizen) - $el.addClass("tizen"); - else if($.os.fennec) - $el.addClass("firefox"); - } - if($.os.ios7&&that.overlayStatusbar){ - that.ready(function(){ - $(document.body).addClass("overlayStatusbar"); - }); - } - } - }; - - - var clickHandlers=[]; - AFUi.prototype = { - init:false, - showLoading: true, - showingMask: false, - loadingText: "Loading Content", - remotePages: {}, - history: [], - views:{}, - _readyFunc: null, - doingTransition: false, - ajaxUrl: "", - transitionType: "slide", - firstPanel: "", - hasLaunched: false, - isLaunching:false, - launchCompleted: false, - activeDiv: "", - customClickHandler: "", - useOSThemes: true, - overlayStatusbar: false, - useAutoPressed: true, - useInternalRouting:true, - backButtonText: "Back", - autoBoot: function() { - this.hasLaunched = true; - if (this.autoLaunch) { - this.launch(); - } - }, - /** - * This blocks the page from bouncing on iOS - * @api private - */ - blockPageBounce:function(enable){ - if(!$.os.ios) return; - if(enable===false){ - window.removeEventListener("touchmove",this.handlePageBounce,false); - window.removeEventListener("touchstart",this.handlePageBounce,false); - return; - } - - window.addEventListener("touchmove",this.handlePageBounce,false); - window.addEventListener("touchstart",this.handlePageBounce,false); - - }, - /** - * Handle touch events for scrolling divs - * @api private - */ - handlePageBounce:function(evt){ - if(evt.type==="touchstart"){ - this._startTouchY=evt.touches[0].screenY; - return; - } - var panel=$(evt.target).closest(".panel"); - if(panel.length===0) return evt.preventDefault(); - var el=panel.get(0); - - var canScroll=el.scrollHeight>el.clientHeight; - var hasTouchOverflow=$(el).computedStyle("-webkit-overflow-scrolling")==="touch"; - var hasOverflow=$(el).computedStyle("overflowY")!=="hidden"; - var height=parseInt($(el).computedStyle("height"),10); - if(canScroll&&hasTouchOverflow&&hasOverflow){ - - var currY=evt.touches[0].screenY; - var scrollAtTop=((this._startTouchY<=currY)&&(el.scrollTop===0)); - var scrollAtBottom=((this._startTouchY>=currY)&&((el.scrollHeight-el.scrollTop)===height)); - if(scrollAtTop||scrollAtBottom) - evt.preventDefault(); - return; - } - - }, - /** - * Register a data directive for a click event. Plugins use this to allow - * html based execution (see af.popup.js) - ``` - $.afui.registerDataDirective("[data-foo]",function(){ - console.log("foo was clicked"); - }) - ``` - * @param {string} selector - * @param {function} callback to execute - * @title $.afui.registerDataDirective - */ - registerDataDirective:function(selector,cb){ - clickHandlers.push({sel:selector,cb:cb}); - }, - /** - * This enables the tab bar ability to keep pressed states on elements - ``` - $.afui.enableTabBar(); - ``` - @title $.afui.enableTabBar - */ - enableTabBar:function(){ - $(document).on("click",".button-grouped.tabbed",function(e){ - var $el=$(e.target); - $el.closest(".tabbed").find(".button").data("ignore-pressed","true").removeClass("pressed"); - //this is a hack, but the touchEvents plugin will remove pressed - $el.closest(".button").addClass("pressed"); - setTimeout(function(){ - $el.closest(".button").addClass("pressed"); - }); - }); - }, - /** - * This disables the tab bar ability to keep pressed states on elements - ``` - $.afui.disableTabBar(); - ``` - * @title $.afui.disableTabBar - */ - disableTabBar:function(){ - $(document).off("click",".button-grouped.tabbed"); - $(".button-grouped.tabbed .button").removeAttr("data-ignore-pressed"); - }, - - /** - * This is a boolean property. When set to true, we manage history and update the hash - ``` - $.afui.manageHistory=false;//Don't manage for apps using Backbone - ``` - *@title $.afui.manageHistory - */ - manageHistory: true, - - /** - * This is a boolean property. When set to true (default) it will load that panel when the app is started - ``` - $.afui.loadDefaultHash=false; //Never load the page from the hash when the app is started - $.afui.loadDefaultHash=true; //Default - ``` - *@title $.afui.loadDefaultHash - */ - loadDefaultHash: true, - /** - * This is a shorthand call to the $.actionsheet plugin. We wire it to the afui div automatically - ``` - $.afui.actionsheet("Settings Logout") - $.afui.actionsheet("[{ - text: 'back', - cssClasses: 'red', - handler: function () { $.afui.goBack(); ; } - }, { - text: 'show alert 5', - cssClasses: 'blue', - handler: function () { alert("hi"); } - }, { - text: 'show alert 6', - cssClasses: '', - handler: function () { alert("goodbye"); } - }]"); - ``` - * @param {(string|Array.)} links - * @title $.afui.actionsheet() - */ - actionsheet: function(opts) { - return $.query(document.body).actionsheet(opts); - }, - /** - * This is a wrapper to $.popup.js plugin. If you pass in a text string, it acts like an alert box and just gives a message - ``` - $.afui.popup(opts); - $.afui.popup( { - title:"Alert! Alert!", - message:"This is a test of the emergency alert system!! Don't PANIC!", - cancelText:"Cancel me", - cancelCallback: function(){console.log("cancelled");}, - doneText:"I'm done!", - doneCallback: function(){console.log("Done for!");}, - cancelOnly:false - }); - $.afui.popup('Hi there'); - ``` - * @param {(object|string)} options - * @title $.afui.popup(opts) - */ - popup: function(opts) { - return $.query(document.body).popup(opts); - }, - - /** - * This is a reference to the drawer plugin. - ``` - $.afui.drawer.show('#left','left','reveal') - ``` - * @param {string} id of drawer - * @param {string} position (left|right) - * @param {string} transition (push, cover, reveal) - * @title $.afui.drawer.show - */ - - /** - * This is a reference to the drawer plugin. - ``` - $.afui.drawer.hide('#left','left') - ``` - * @param {string} id of drawer - * @param {string} position (left|right) - * @title $.afui.drawer.hide - */ - - - /** - *This will throw up a mask and block the UI - ``` - $.afui.blockUI(.9) - ```` - * @param {number} opacity - * @title $.afui.blockUI(opacity) - */ - blockUI: function(opacity) { - $.blockUI(opacity); - }, - /** - *This will remove the UI mask - ``` - $.afui.unblockUI() - ```` - * @title $.afui.unblockUI() - */ - unblockUI: function() { - $.unblockUI(); - }, - - /** - * Boolean if you want to auto launch afui - ``` - $.afui.autoLaunch = false; // - ``` - * @title $.afui.autoLaunch - */ - autoLaunch: true, - /** - * function to fire when afui is ready and completed launch - ``` - $.afui.ready(function(){console.log('afui is ready');}); - ``` - * @param {function} param function to execute - * @title $.afui.ready - */ - ready: function(param) { - if (this.launchCompleted) - param(); - else { - $(document).one("afui:ready", function() { - param(); - }); - } - }, - - /** - * Initiate a back transition - ``` - $.afui.goBack() - ``` - - * @title $.afui.goBack() - * @param {number=} delta relative position from the last element (> 0) - */ - goBack: function(e) { - //find the view - var isSameView = true; - var currentView=$(this.activeDiv).closest(".view"); - var targetView=currentView; - if(e&&e.target) { - targetView=$(e.target).closest(".view"); - isSameView = targetView.prop("id") === (currentView.prop("id")); - } - - if(targetView.length===0) return; - - //history entry - if(!this.views[targetView.prop("id")]) return; - var hist=this.views[targetView.prop("id")]; - - if(hist.length===0) return; - var item=hist.pop(); - //If not in same view, just push back to keep last states - if (!isSameView) { - hist.push(item); - } - if(item.length===0) return; - if(hist.length>0){ - var toTarget = hist[hist.length-1].target; - if(!toTarget) return; - if(isSameView && (item.target===toTarget)) return; - if (!isSameView) { - this.clearHistory(); //Clear current view history - this.runViewTransition(this.transitionType, targetView, currentView, item.target, true); - } - else { - this.runTransition(item.transition, item.target, toTarget, true); - } - this.loadContentData(toTarget, targetView, true); - this.updateHash(toTarget.id); - } - else { - //try to dismiss the view - try{ - this.dismissView(item.target,item.transition); - } - catch(ex){ - } - - } - }, - /** - * Clear the history queue for the current view based off the active div - ``` - $.afui.clearHistory() - ``` - - * @title $.afui.clearHistory() - */ - clearHistory: function() { - //find the view - var view=this.findViewTarget(this.activeDiv); - this.views[view.prop("id")]=[]; - this.setBackButtonVisibility(false); - }, - - /** - * PushHistory - ``` - $.afui.pushHistory(previousPage, newPage, transition, hashExtras) - ``` - * @api private - * @title $.afui.pushHistory() - */ - pushHistory: function(previousPage, newPage, transition, hashExtras) { - //push into local history - - - //push into the browser history - try { - if (!this.manageHistory) return; - window.history.pushState(newPage, newPage, startPath + "#" + newPage + hashExtras); - $(window).trigger("hashchange", null, { - newUrl: startPath + "#" + newPage + hashExtras, - oldUrl: startPath + previousPage - }); - } catch (e) {} - }, - - - /** - * Updates the current window hash - * - * @param {string} newHash New Hash value - * @title $.afui.updateHash(newHash) - * @api private - */ - updateHash: function(newHash) { - if (!this.manageHistory) return; - newHash = newHash.indexOf("#") === -1 ? "#" + newHash : newHash; //force having the # in the begginning as a standard - previousTarget = newHash; - - var previousHash = window.location.hash; - var panelName = this.getPanelId(newHash).substring(1); //remove the # - try { - window.history.replaceState(panelName, panelName, startPath + newHash); - $(window).trigger("hashchange", null, { - newUrl: startPath + newHash, - oldUrl: startPath + previousHash - }); - } catch (e) {} - }, - /** - * gets the panel name from an hash - * @api private - */ - getPanelId: function(hash) { - var firstSlash = hash.indexOf("/"); - return firstSlash === -1 ? hash : hash.substring(0, firstSlash); - }, - - /** - * set the back button text - ``` - $.afui.setBackButtonText("about"); - ``` - * @param {string} text - * @title $.afui.setBackButtonText(title) - */ - setBackButtonText:function(text){ - $(this.activeDiv).closest(".view").find("header .backButton").html(text); - }, - /** - * Set the title of the active header from - ``` - $.afui.setTitle("New Title") - ``` - * @param {string|object} String or DOM node to get the title from - * @title $.afui.setTitle - */ - setTitle:function(item){ - //find the header - var title=""; - if(typeof(item)==="string"){ - title=item; - item=$(this.activeDiv).closest(".view"); - } - else if($(item).attr("data-title")) - title=$(item).attr("data-title"); - else if($(item).attr("title")) - title=$(item).attr("title"); - - if(title) - $(item).closest(".view").children("header").find("h1").html(title); - - }, - /** - * Get the title of the active header - ``` - $.afui.getTitle() - ``` - * @title $.afui.getTitle - */ - getTitle:function(){ - return $(this.activeDiv).closest(".view").children("header").find("h1").html(); - }, - /** - * Set the visibility of the back button for the current header - ``` - $.afui.setBackButtonVisibility(true) - ``` - * @param {boolean} Boolean to set the visibility. true show, false hide - * @title $.afui.setBackButtonVisibility - */ - setBackButtonVisibility:function(what){ - var visibility=what?"visible":"hidden"; - $(this.activeDiv).closest(".view").children("header").find(".backButton").css("visibility",visibility); - }, - - /** - * Update a badge on the selected target. Position can be - bl = bottom left - tl = top left - br = bottom right - tr = top right (default) - ``` - $.afui.updateBadge("#mydiv","3","bl","green"); - ``` - * @param {string} target - * @param {string} value - * @param {string=} position - * @param {string=} color Color or CSS hash - * @title $.afui.updateBadge(target,value,[position],[color]) - */ - updateBadge: function(target, value, position, color) { - if (position === undefined) position = ""; - - var $target = $(target); - var badge = $target.find("span.af-badge"); - - if (badge.length === 0) { - if ($target.css("position") !== "absolute") $target.css("position", "relative"); - badge = $.create("span", { - className: "af-badge " + position, - html: value - }); - $target.append(badge); - } else badge.html(value); - badge.removeClass("tl bl br tr"); - badge.addClass(position); - if (color === undefined) - color = "red"; - if ($.isObject(color)) { - badge.css(color); - } else if (color) { - badge.css("background", color); - } - badge.data("ignore-pressed", "true"); - - - }, - /** - * Removes a badge from the selected target. - ``` - $.afui.removeBadge("#mydiv"); - ``` - * @param {string} target - * @title $.afui.removeBadge(target) - */ - removeBadge: function(target) { - $(target).find("span.af-badge").remove(); - }, - /** - * Show the loading mask with specificed text - ``` - $.afui.showMask() - $.afui.showMask('Fetching data...') - ``` - - * @param {string=} text - * @title $.afui.showMask(text); - */ - showMask: function(text, value) { - if (!text) text = this.loadingText || ""; - if (!value || typeof value !== "number") timeout = 15000; - $.query("#afui_mask>h1").html(text); - $.query("#afui_mask").show(); - this.showingMask = true; - - var self = this; - //set another timeout to auto-hide the mask if something goes wrong, default is 15 sec - setTimeout(function() { - if(self.showingMask) { - self.hideMask(); - } - }, value); - }, - /** - * Hide the loading mask - ``` - $.afui.hideMask(); - ``` - * @title $.afui.hideMask(); - */ - hideMask: function() { - $.query("#afui_mask").hide(); - this.showingMask = false; - }, - /** - * @api private - */ - - dismissView:function(target,transition){ - transition=transition.replace(":dismiss",""); - var theView=$(target).closest(".view"); - this.runTransition(transition,theView,null,true,$(target.hash).addClass("active").closest(".view")); - //this.activeDiv=target; - this.activeDiv=$(".view").not(theView).find(".panel.active").get(0); - this.updateHash(this.activeDiv.id); - }, - /** - * This is called to initiate a transition or load content via ajax. - * We can pass in a hash+id or URL. - ``` - $.afui.loadContent("#main",false,false,"up"); - ``` - * @param {string} target - * @param {boolean=} newtab (resets history) - * @param {boolean=} go back (initiate the back click) - * @param {string=} transition - * @param {object=} anchor - * @title $.afui.loadContent(target, newTab, goBack, transition, anchor); - * @api public - */ - loadContent: function(target, newView, back, transition, anchor) { - - if (this.doingTransition) { - return; - } - anchor = anchor || document.createElement("a"); //Hack to allow passing in no anchor - if (target.length === 0) return; - if(target.indexOf("#")!==-1){ - this.loadDiv(target, newView, back, transition,anchor); - } - else{ - this.loadAjax(target, newView, back, transition,anchor); - } - }, - /** - * This is called internally by loadContent. Here we are loading a div instead of an Ajax link - ``` - $.afui.loadDiv("#main",false,false,"up"); - ``` - * @param {string} target - * @param {boolean=} newview (resets history) - * @param {boolean=} back Go back (initiate the back click) - * @param {string=} transition - * @title $.afui.loadDiv(target,newTab,goBack,transition); - * @api private - */ - loadDiv: function(target, newView, back, transition,anchor) { - // load a div - var newDiv = target; - - var hashIndex = newDiv.indexOf("#"); - var slashIndex = newDiv.indexOf("/"); - if ((slashIndex !== -1)&&(hashIndex !== -1)) { - //Ignore everything after the slash in the hash part of a URL - //For example: app.com/#panelid/option1/option2 will become -> app.com/#panelid - //For example: app.com/path/path2/path3 will still be -> app.com/path/path2/path3 - if (slashIndex > hashIndex) { - newDiv = newDiv.substr(0, slashIndex); - } - } - newDiv = newDiv.replace("#", ""); - - newDiv = $.query("#" + newDiv).get(0); - if (!newDiv) { - $(document).trigger("missingpanel", null, {missingTarget: target}); - this.doingTransition=false; - return; - } - - if (newDiv === this.activeDiv && !back) { - //toggle the menu if applicable - this.doingTransition=false; - return; - } - - this.transitionType = transition; - - var view=this.findViewTarget(newDiv); - var previous=this.findPreviousPanel(newDiv,view); - - - - //check current view - var currentView; - if(anchor){ - currentView=this.findViewTarget(anchor); - } - else - currentView=this.findViewTarget(this.activeDiv); - - //Check if we are dealing with the same view - - var isSplitViewParent=(currentView&¤tView.get(0)!==view.get(0)&¤tView.closest(".splitview").get(0)===view.closest(".splitview").get(0)&¤tView.closest(".splitview").length!==0); - if(isSplitViewParent){ - newView=false; - } - $(newDiv).trigger("panelbeforeload"); - $(previous).trigger("panelbeforeunload"); - var isNewView=false; - //check nested views - if(!isSplitViewParent) - isSplitViewParent=currentView.parent().closest(".view").length===1; - - if(isSplitViewParent&¤tView&¤tView.get(0)!==view.get(0)) - $(currentView).trigger("nestedviewunload"); - - - if(!isSplitViewParent&&(newView||currentView&¤tView.get(0)!==view.get(0))){ - //Need to transition the view - newView=currentView||newView; - this.runViewTransition(transition,view,newView,newDiv,back); - - this.updateViewHistory(view,newDiv,transition,target); - isNewView=true; - } - else{ - this.runTransition(transition,previous, newDiv, back); - this.updateViewHistory(view,newDiv,transition,target); - } - - //Let's check if it has a function to run to update the data - //Need to call after parsePanelFunctions, since new headers can override - this.loadContentData(newDiv,view,false,isNewView); - - }, - /** - * @api private - */ - findViewTarget:function(panel){ - var view=$(panel).closest(".view"); - if(!view) return false; - if(!this.views[view.prop("id")]) - this.views[view.prop("id")]=[]; - return view; - }, - /** - * @api private - */ - findPreviousPanel:function(div,view){ - var item=$(view).find(">.pages .panel.active").not(div); - if(item.length===0) - item=$(view).find(">.pages .panel:first-of-type"); - return item.get(0); - }, - /** - * This is called internally by loadDiv. This sets up the back button in the header and scroller for the panel - ``` - $.afui.loadContentData("#main",false,false,"up"); - ``` - * @param {string} target - * @param {boolean=} newtab (resets history) - * @param {boolean=} go back (initiate the back click) - * @title $.afui.loadContentData(target,newTab,goBack); - * @api private - */ - loadContentData: function(what,view,back,isNewView) { - this.activeDiv = what; - this.setTitle(what,view,back,isNewView); - this.showBackButton(view,isNewView); - this.setActiveTab(what,view); - }, - - /** - * Set the active tab in the footer - ``` - $.afui.setActiveTab("main",currView) - ``` - @param {string|Node} id or DOM node for footer tab - @param {Node} DOM node of the current view to set the footer - @title $.afui.setActiveTab - */ - setActiveTab:function(ele,view){ - var elementId; - if(typeof(ele)!=="string") - elementId=$(ele).prop("id"); - /* - Check if an item exists: - Note that footer hrefs' may point to elements preceded by a # when trying to load a div (f.ex.: