// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) // // MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // Navigation Object var nav_obj = {} nav_obj.observers = []; nav_obj.add_observer = function(o) { nav_obj.observers.push(o); } nav_obj.ol = []; // // notify my history so that it gets added to the back button history // nav_obj.open_notify = function(t, dt, dn, no_history) { // last should not be this (refresh) if(nav_obj.ol.length) { var tmp = nav_obj.ol[nav_obj.ol.length-1]; if(tmp && tmp[0]==t && tmp[1]==dt && tmp[2]==dn) return; } if(!no_history) { // remove from history (if exists so that we can put it back on top) var tmp = []; for(var i in nav_obj.ol) if(!(nav_obj.ol[i][0]==t && nav_obj.ol[i][1]==dt && nav_obj.ol[i][2]==dn)) tmp.push(nav_obj.ol[i]); nav_obj.ol = tmp; // add to top nav_obj.ol.push([t, dt, dn]) // encode en_t = encodeURIComponent(t); en_dt = encodeURIComponent(dt); en_dn = dn ? encodeURIComponent(dn) : ''; if(en_t=='Page') { var id = en_dt + (dn ? ('/'+en_dn): '') } else { var id = en_t+'/'+ en_dt + (dn ? ('/'+en_dn): '') } // option to add to analytics engine if(nav_obj.on_open) nav_obj.on_open(id); // add to "back" history // replace state (to url) if(window.location.hash!='!' + id) { window.location.hash = '!' + id; } } nav_obj.notify_observers(t, dt, dn); if(wn.boot.analytics_code) { try { eval(wn.boot.analytics_code); } catch (e) { console.log(e); } } } // Notify observers // ========================================= nav_obj.notify_observers = function(t, dt, dn) { // notify observers (for menu?) for(var i=0; i=3) { // combine all else for(var i=2; i