Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

locationRouter navigate doesnt trigger a route two times

  • Loading branch information...
commit 89e92cfc7e957870935483a3dc808fea43b37015 1 parent a5be213
@podefr podefr authored
View
384 build/Olives-map
@@ -1,7 +1,7 @@
{
"version":2,
"file":"build/Olives.min.js",
-"lineCount":33,
+"lineCount":34,
"lineMaps":["",
"",
"",
@@ -33,8 +33,9 @@
"qAmyE+EJU/Q/A/AFo/A8c/A/cIABABA/ACMEM/A/ADA9E/AHs/A/ADA9A6A1MVArA/MZo/A/ADA9EmQeAgRAjI/A/cDABABA/ACIBMDM/A/ADA9A/AFMBEBMDs/A/ADA9QGQ/A/ADA9AEA8AFA7YGEBAyM7YUUBAqQZQ/A/cDABABA/ACIBMDM/A/ADA9A/AFMBEBMDs/A/ADA9QGQ/A/ADA9AEA8AFA7YGEBAyM7YUUBAqQZQ/A/cDABABA/ACA+ADIBMDM/A/ADA9A/AFMBEBADc/A/ADA9EGY/A/ADA9AEA8EFABA/ADA/ACA+E+AHw/A/ADA9AEA8A7AMs/A/ADA9EGY/A/ADA9AEA8AFA7YGEBB/fM7ZAnUBB/X",
"OAo8Y/A/cDABABA/ACA+ADUBACMDM/A/ADA9E+AGo6sHE5AMY/A/ADA9AEA8AFA7A/AJw/A/ADA9AGo/A/ADA9A8A4AQEoQZAlQes/A/cDABABA/ACUBEDc/A/ADA9A+QIU/A/cDEBABUBEDo/Y/A+QHM/A/cDABABA/ACUBQDs/A/ADA9E/AFA6QJQ/A/cDABABA/ACUBQEM/A/ADA9E/AIs/A/ADA9A/MFE2QLAzQQQ/A/cDABABA/ACUBQEM/A/ADA9E/AGo/I7AHE5MLQ/A/ADA9AGc/A/ADA9A8A/MJEvQSAsQXc/A/cDEBABADc/A/MEQ/A9MFA7A/",
"OAq9c/A/cDEBABADc/A/MEQ/A9MFA7A/QJk/A/cDEBABUBEBA+QFo/A/cDABABA/ACUBECo/sCA+ADA9AEA8QFA5QKw/A/cDEBABUBEBA+QFw/A/cDABABA/ACUBECo/sCE+AEA/ACA+MDE6QHA3QMo/A/ADA9B5JA2A5",
-"WAr6A/8CA+ADcBA/YCA+A9cGABABA/ACA+ADcBEBEBABMBABQDU/A/cDABABA/ACUBEHU/A/IDA9M/E/U/A/IIA4A+QNU/A/cDABABA/ACUBEDQ/A/IDA9A+QIU/A/cDEBABMDw/E/QGg/U/A/MEA8MHU/A/UFg/Q/A9A7QN!AQ/E/QF!AR/E/AuQXc/A/cDEBABMDc/A/ADA9YG!AT/A/sDA9MF!AR/A8MGA6A7QOw/A/cDABABA/ACMEg/U/A/MEA8MHU/A/AIY/U/A/IEA8M/E/A9A7A/",
-"OAtq!AR/A/MGw/Q/A/MEA8QH!AQ/A/cDEBABUD!AQ/A/sDA9MF!AR/A8MGA6A/QK!AR/A/cDEBABACA/MEU/A/ME0/A9MFA7A9QL0/A/cDEBABUEg/Q/A/MGU/A/AFc/A/gDA9A9A7B93VCVgBEBABADk/A/MDABYBQBABA4B9kA2"],
+"WAr6A/8CA+ADcBA/YCA+A9cGABABA/ACA+ADcBEBEBABcBEBEBABUEg/Q/A/MHg/U/A/MEA8MHU/A/UFg/Q/A9A7A8MRg/A/ADA9AwM8AYAoEZEBAmEbUDg/Q/QF8/A/cDABABA/ACUBECE/UCEBE9cEE8AGA/ACA+MDE4QJA1QO8/A/cDEBABUBEBA+QFU/A/cDABABA/ACUBEHU/A/IDA9M/E/U/A/IIA4A+QNU/A/cDABABA/ACUBEDQ/A/IDA9A+QIU/A/cDABABA/ACMD8/A/ADA9EGQ/A/MDA9QG!AQ/E/",
+"OAtx!AR/E/A0QRc/A/cDEBABMDc/A/ADA9YG!AT/A/sDA9MF!AR/A8MGA6A7QOw/A/cDEBABUEg/Q/E/AEE8AHQ/A/MDA9A6QM!AR/A/MGw/Q/A/MEA8QH!AQ/A/cDEBABUD!AQ/A/sDA9MF!AR/A8MGA6A/QK!AR/A/cDEBABACA/MEU/A/ME0/A9MFA7A9QL0/A/cDEBABUEg/Q/A/MGU/A/AFc/A/gDA9A9",
+"CAvHA/UEg/Q/AyQTw/A/cDEBABUBEBA+B83VDMgBEBABADk/A/MDABYBQBABA4B8tA2"],
"mappings":[[0,13,6],
[0,13,0,0],
[0,13,7],
@@ -2859,167 +2860,222 @@
[0,1940,13,360],
[0,1940,38],
[0,1940,41],
-[0,1946,8],
-[0,1946,12,361],
-[0,1959,8],
-[0,1959,8,226],
-[0,1959,8],
-[0,1959,21,362],
-[0,1959,35],
-[0,1959,36,363],
-[0,1959,42],
-[0,1960,12],
-[0,1960,46],
-[0,1960,19,15],
-[0,1960,38],
-[0,1960,19,364],
-[0,1960,29],
-[0,1960,19,15],
-[0,1960,19,363],
-[0,1960,30],
-[0,1960,47],
-[0,1974,8],
-[0,1974,8,365],
-[0,1974,8],
-[0,1974,21,366],
-[0,1974,35],
-[0,1974,36,367],
-[0,1974,42],
-[0,1975,12],
-[0,1975,28],
-[0,1975,19,16],
-[0,1975,19,367],
-[0,1975,29],
-[0,1984,8],
-[0,1984,8,86],
-[0,1984,8],
-[0,1984,21,368],
-[0,1984,35],
-[0,1984,38],
-[0,1985,29],
-[0,1985,12,369],
-[0,1985,12],
-[0,1987,31],
-[0,1987,12,119],
-[0,1987,12,370],
-[0,1987,12],
-[0,1987,32],
-[0,1986,39,371],
-[0,1986,29,226],
-[0,1986,29],
-[0,1986,40,363],
-[0,1986,40,372],
-[0,1986,40,373],
-[0,1988,33],
-[0,1988,12,374],
-[0,1988,12],
-[0,1989,34],
-[0,1989,12,375],
-[0,1989,12],
-[0,1995,8],
-[0,1995,8,376],
-[0,1995,8],
-[0,1995,23,377],
-[0,1995,39],
-[0,1995,42],
-[0,1996,24],
-[0,1996,12,378],
-[0,1996,12],
-[0,1996,25,361],
-[0,1997,38],
-[0,1997,12,379],
-[0,1997,12,373],
-[0,1997,39],
-[0,1997,53,380],
-[0,1997,53],
-[0,1997,77],
-[0,2004,8],
-[0,2004,8,381],
-[0,2004,8],
-[0,2004,29,382],
-[0,2004,50],
-[0,2004,51,170],
-[0,2004,58],
-[0,2006,31],
-[0,2006,12,119],
-[0,2006,12,370],
-[0,2006,12],
-[0,2006,32],
-[0,2005,39,371],
-[0,2005,29,226],
-[0,2005,29],
-[0,2005,67],
-[0,2005,40,364],
-[0,2005,58],
-[0,2005,40,15],
-[0,2005,40,383],
-[0,2005,40,170],
-[0,2005,59],
-[0,2013,8],
-[0,2013,8,380],
-[0,2013,8],
-[0,2013,55],
-[0,2013,33,146],
-[0,2013,33,381],
-[0,2013,33],
-[0,2013,56],
-[0,2020,8],
-[0,2020,8,374],
-[0,2020,8],
-[0,2020,32,384],
-[0,2020,57],
-[0,2020,60],
-[0,2021,35],
-[0,2021,12,158],
-[0,2021,12,373],
-[0,2021,36],
-[0,2021,50,380],
-[0,2021,50],
-[0,2021,74],
-[0,2028,8],
-[0,2028,8,375],
-[0,2028,8],
-[0,2028,33,385],
-[0,2028,59],
-[0,2028,62],
-[0,2029,12],
-[0,2029,12,361],
-[0,2029,37],
-[0,2029,27,139],
-[0,2029,27],
-[0,2029,38,386],
-[0,2029,38],
-[0,2029,58],
-[0,2037,8],
-[0,2037,8,386],
-[0,2037,8],
-[0,2037,29,387],
-[0,2037,51],
-[0,2037,54],
-[0,2038,12],
-[0,2038,12,363],
-[0,2038,12,372],
-[0,2038,12,373],
-[0,2038,45],
-[0,2038,35,365],
-[0,2038,35],
-[0,2038,59],
-[0,2038,46,34],
-[0,2038,46,1],
-[0,2038,60,154],
-[0,2043,4],
-[0,2043,11,388],
-[0,2043,41],
-[0,2043,44],
-[0,2044,8],
-[0,2044,8,177],
-[0,2044,8,360],
-[0,2044,56],
-[0,2044,50,359],
-[0,2045,8],
-[0,2045,44],
-[0,2045,19,360],
+[0,1965,8,361],
+[0,1965,17,361],
+[0,1965,27],
+[0,1965,30],
+[0,1966,12],
+[0,1966,16,362],
+[0,1966,16,363],
+[0,1966,16,364],
+[0,1968,35],
+[0,1968,16,119],
+[0,1968,16,365],
+[0,1968,16],
+[0,1968,36],
+[0,1967,43,366],
+[0,1967,33,226],
+[0,1967,33],
+[0,1967,44,362],
+[0,1967,44,363],
+[0,1967,44,364],
+[0,1970,29],
+[0,1970,16,365],
+[0,1970,16],
+[0,1970,30,367],
+[0,1946,12,368],
+[0,1952,8,367],
+[0,1952,24],
+[0,1958,8,369],
+[0,1958,21,362],
+[0,1958,21,363],
+[0,1958,21,364],
+[0,1979,8],
+[0,1979,8,370],
+[0,1979,8],
+[0,1979,31,371],
+[0,1979,55],
+[0,1979,56,372],
+[0,1979,70],
+[0,1980,12],
+[0,1980,12],
+[0,1980,16,372],
+[0,1980,32],
+[0,1980,39,372],
+[0,1980,55],
+[0,1982,23],
+[0,1981,16,367],
+[0,1981,32,372],
+[0,1982,23],
+[0,1984,23],
+[0,1992,8],
+[0,1992,8,373],
+[0,1992,8],
+[0,1992,31,374],
+[0,1992,55],
+[0,1992,58],
+[0,1993,12],
+[0,1993,19,367],
+[0,2007,8],
+[0,2007,8,226],
+[0,2007,8],
+[0,2007,21,375],
+[0,2007,35],
+[0,2007,36,362],
+[0,2007,42],
+[0,2008,12],
+[0,2008,46],
+[0,2008,19,15],
+[0,2008,38],
+[0,2008,19,376],
+[0,2008,29],
+[0,2008,19,15],
+[0,2008,19,362],
+[0,2008,30],
+[0,2008,47],
+[0,2022,8],
+[0,2022,8,377],
+[0,2022,8],
+[0,2022,21,378],
+[0,2022,35],
+[0,2022,36,379],
+[0,2022,42],
+[0,2023,12],
+[0,2023,28],
+[0,2023,19,16],
+[0,2023,19,379],
+[0,2023,29],
+[0,2032,8],
+[0,2032,8,86],
+[0,2032,8],
+[0,2032,21,380],
+[0,2032,35],
+[0,2032,36,372],
+[0,2032,50],
+[0,2033,32],
+[0,2033,12,370],
+[0,2033,12],
+[0,2033,33,372],
+[0,2034,27],
+[0,2034,12,176],
+[0,2034,12,361],
+[0,2034,28],
+[0,2035,33],
+[0,2035,12,381],
+[0,2035,12],
+[0,2036,34],
+[0,2036,12,382],
+[0,2036,12],
+[0,2042,8],
+[0,2042,8,383],
+[0,2042,8],
+[0,2042,23,384],
+[0,2042,39],
+[0,2042,42],
+[0,2043,24],
+[0,2043,12,385],
+[0,2043,12],
+[0,2043,25,368],
+[0,2044,38],
+[0,2044,12,386],
+[0,2044,12,364],
+[0,2044,39],
+[0,2044,53,387],
+[0,2044,53],
+[0,2044,77],
+[0,2051,8],
+[0,2051,8,388],
+[0,2051,8],
+[0,2051,29,389],
+[0,2051,50],
+[0,2051,53],
+[0,2052,12],
+[0,2052,16,362],
+[0,2052,16,363],
+[0,2052,16,364],
+[0,2052,40,369],
+[0,2053,31],
+[0,2053,16,176],
+[0,2053,16,361],
+[0,2053,32],
+[0,2061,8],
+[0,2061,8,387],
+[0,2061,8],
+[0,2061,55],
+[0,2061,33,146],
+[0,2061,33,388],
+[0,2061,33],
+[0,2061,56],
+[0,2068,8],
+[0,2068,8,381],
+[0,2068,8],
+[0,2068,32,390],
+[0,2068,57],
+[0,2068,60],
+[0,2069,35],
+[0,2069,12,158],
+[0,2069,12,364],
+[0,2069,36],
+[0,2069,50,387],
+[0,2069,50],
+[0,2069,74],
+[0,2076,8],
+[0,2076,8,382],
+[0,2076,8],
+[0,2076,33,391],
+[0,2076,59],
+[0,2076,62],
+[0,2077,12],
+[0,2077,12,368],
+[0,2077,37],
+[0,2077,27,139],
+[0,2077,27],
+[0,2077,38,392],
+[0,2077,38],
+[0,2077,58],
+[0,2085,8],
+[0,2085,8,392],
+[0,2085,8],
+[0,2085,29,393],
+[0,2085,51],
+[0,2085,54],
+[0,2086,12],
+[0,2086,12,362],
+[0,2086,12,363],
+[0,2086,12,364],
+[0,2086,45],
+[0,2086,35,377],
+[0,2086,35],
+[0,2086,59],
+[0,2086,46,34],
+[0,2086,46,1],
+[0,2086,60,154],
+[0,2087,12],
+[0,2087,12,369],
+[0,2087,25,362],
+[0,2087,25,363],
+[0,2087,25,364],
+[0,2090,8],
+[0,2090,8,394],
+[0,2090,8],
+[0,2090,28,395],
+[0,2090,49],
+[0,2090,52],
+[0,2091,12],
+[0,2091,19,369],
+[0,2096,4],
+[0,2096,11,396],
+[0,2096,41],
+[0,2096,44],
+[0,2097,8],
+[0,2097,8,177],
+[0,2097,8,360],
+[0,2097,56],
+[0,2097,50,359],
+[0,2098,8],
+[0,2098,44],
+[0,2098,19,360],
],
"sources":["build/Olives.js"],
-"names":["define","Tools","getNodes","dom","query","isAcceptedType","parentNode","appendChild","createDocumentFragment","document","querySelectorAll","getDataset","i","l","dataset","split","join","hasOwnProperty","length","attributes","name","shift","getAttribute","type","HTMLElement","SVGElement","setAttribute","node","property","value","matches","parent","selector","indexOf","toArray","BindPlugin","Store","Observable","DomUtils","BindPluginConstructor","$model","$bindings","_removeObserversForId","id","_observers","forEach","handler","unwatchValue","_model","_bindings","_itemRenderers","observers","setModel","this.setModel","model","getModel","this.getModel","ItemRenderer","this.ItemRenderer","$plugins","$rootNode","_node","_plugins","_rootNode","_start","_nb","setRenderer","this.setRenderer","getRenderer","this.getRenderer","setRootNode","this.setRootNode","rootNode","renderer","querySelector","removeChild","getRootNode","this.getRootNode","setPlugins","this.setPlugins","plugins","getPlugins","this.getPlugins","items","setStart","this.setStart","start","parseInt","getStart","this.getStart","setNb","this.setNb","nb","getNb","this.getNb","addItem","this.addItem","next","getNextItem","create","insertBefore","this.getNextItem","keys","map","Object","string","Number","closest","closestGreater","closestId","removeItem","this.removeItem","item","this.create","has","newNode","cloneNode","nodes","child","apply","render","this.render","_tmpNb","getNbItems","marked","loop","idx","push","reverse","sort","compareNumbers","setItemRenderer","this.setItemRenderer","itemRenderer","getItemRenderer","this.getItemRenderer","foreach","this.foreach","idItemRenderer","watch","updateStart","this.updateStart","updateNb","this.updateNb","refresh","this.refresh","bind","this.bind","modelIdx","prop","get","getNestedProperty","extraParam","slice","arguments","execBinding","concat","hasBinding","addEventListener","update","set","watchValue","this.set","getItemIndex","this.getItemIndex","form","this.form","DOMform","nodeName","that","event","preventDefault","addBinding","this.addBinding","binding","this.execBinding","call","prototype","Array","this.hasBinding","getBinding","this.getBinding","addBindings","this.addBindings","list","EventPlugin","Utils","EventPluginConstructor","$parent","$isMobile","_parent","_map","_isMobile","this.addEventListener","callback","useCapture","listen","this.listen","listener","e","delegate","this.delegate","target","getParent","this.getParent","setParent","this.setParent","this.map","setMap","this.setMap","LocalStore","LocalStoreConstructor","_name","_localStorage","localStorage","setLocalStorage","setItem","toJSON","this.setLocalStorage","local$torage","Function","getLocalStorage","this.getLocalStorage","sync","this.sync","json","parse","JSON","getItem","LocalStoreFactory","init","Plugins","PluginsConstructor","trim","applyPlugin","phrase","plugin","couple","method","params","unshift","add","this.add","addAll","this.addAll","this.get","del","this.del","this.apply","OObject","StateMachine","OObjectConstructor","otherStore","UI","baseNode","_currentPlace","createElement","template","innerHTML","childNodes","Error","place","DOMplace","beforeNode","_stateMachine","renderNPlace","this.place","setTemplateFromDom","this.setTemplateFromDom","alive","this.alive","nextElementSibling","getCurrentPlace","this.getCurrentPlace","PlacePlugin","PlacePluginConstructor","$uis","_uis","ui","setAll","this.setAll","uis","SocketIOTransport","SocketIOTransportConstructor","$socket","_socket","setSocket","this.setSocket","socket","emit","getSocket","this.getSocket","on","this.on","func","once","this.once","this.emit","data","removeListener","this.removeListener","request","this.request","channel","scope","reqData","now","Date","floor","Math","random","eventId","boundCallback","stop","Stack","require","StackConstructor","getNextElementInDom","position","_childNodes","nextElement","_hidePlace","remove","this.remove","index","splice","newParentDom","childDom","_setParent","up","this.up","domPosition","getPosition","move","down","this.down","this.move","domIndex","insert","this.insert","this.getPosition","count","this.count","this.has","hide","this.hide","show","this.show","hideAll","this.hideAll","showAll","this.showAll","this._setParent","getHidePlace","this.getHidePlace","setHidePlace","this.setHidePlace","hidePlace","LocationRouter","Router","LocationRouterConstructor","_watchHandle","this.parse","hash","pop","toUrl","this.toUrl","args","this.start","clearHistory","navigate","parsedHash","location","window","bindOnHashChange","bindOnRouteChange","destroy","this.destroy","unwatch","removeEventListener","boundOnHashChange","onHashChange","this.onHashChange","newURL","this.bindOnHashChange","this.bindOnRouteChange","onRouteChange","this.onRouteChange","LocationRouterFactory"]
+"names":["define","Tools","getNodes","dom","query","isAcceptedType","parentNode","appendChild","createDocumentFragment","document","querySelectorAll","getDataset","i","l","dataset","split","join","hasOwnProperty","length","attributes","name","shift","getAttribute","type","HTMLElement","SVGElement","setAttribute","node","property","value","matches","parent","selector","indexOf","toArray","BindPlugin","Store","Observable","DomUtils","BindPluginConstructor","$model","$bindings","_removeObserversForId","id","_observers","forEach","handler","unwatchValue","_model","_bindings","_itemRenderers","observers","setModel","this.setModel","model","getModel","this.getModel","ItemRenderer","this.ItemRenderer","$plugins","$rootNode","_node","_plugins","_rootNode","_start","_nb","setRenderer","this.setRenderer","getRenderer","this.getRenderer","setRootNode","this.setRootNode","rootNode","renderer","querySelector","removeChild","getRootNode","this.getRootNode","setPlugins","this.setPlugins","plugins","getPlugins","this.getPlugins","items","setStart","this.setStart","start","parseInt","getStart","this.getStart","setNb","this.setNb","nb","getNb","this.getNb","addItem","this.addItem","next","getNextItem","create","insertBefore","this.getNextItem","keys","map","Object","string","Number","closest","closestGreater","closestId","removeItem","this.removeItem","item","this.create","has","newNode","cloneNode","nodes","child","apply","render","this.render","_tmpNb","getNbItems","marked","loop","idx","push","reverse","sort","compareNumbers","setItemRenderer","this.setItemRenderer","itemRenderer","getItemRenderer","this.getItemRenderer","foreach","this.foreach","idItemRenderer","watch","updateStart","this.updateStart","updateNb","this.updateNb","refresh","this.refresh","bind","this.bind","modelIdx","prop","get","getNestedProperty","extraParam","slice","arguments","execBinding","concat","hasBinding","addEventListener","update","set","watchValue","this.set","getItemIndex","this.getItemIndex","form","this.form","DOMform","nodeName","that","event","preventDefault","addBinding","this.addBinding","binding","this.execBinding","call","prototype","Array","this.hasBinding","getBinding","this.getBinding","addBindings","this.addBindings","list","EventPlugin","Utils","EventPluginConstructor","$parent","$isMobile","_parent","_map","_isMobile","this.addEventListener","callback","useCapture","listen","this.listen","listener","e","delegate","this.delegate","target","getParent","this.getParent","setParent","this.setParent","this.map","setMap","this.setMap","LocalStore","LocalStoreConstructor","_name","_localStorage","localStorage","setLocalStorage","setItem","toJSON","this.setLocalStorage","local$torage","Function","getLocalStorage","this.getLocalStorage","sync","this.sync","json","parse","JSON","getItem","LocalStoreFactory","init","Plugins","PluginsConstructor","trim","applyPlugin","phrase","plugin","couple","method","params","unshift","add","this.add","addAll","this.addAll","this.get","del","this.del","this.apply","OObject","StateMachine","OObjectConstructor","otherStore","UI","baseNode","_currentPlace","createElement","template","innerHTML","childNodes","Error","place","DOMplace","beforeNode","_stateMachine","renderNPlace","this.place","setTemplateFromDom","this.setTemplateFromDom","alive","this.alive","nextElementSibling","getCurrentPlace","this.getCurrentPlace","PlacePlugin","PlacePluginConstructor","$uis","_uis","ui","setAll","this.setAll","uis","SocketIOTransport","SocketIOTransportConstructor","$socket","_socket","setSocket","this.setSocket","socket","emit","getSocket","this.getSocket","on","this.on","func","once","this.once","this.emit","data","removeListener","this.removeListener","request","this.request","channel","scope","reqData","now","Date","floor","Math","random","eventId","boundCallback","stop","Stack","require","StackConstructor","getNextElementInDom","position","_childNodes","nextElement","_hidePlace","remove","this.remove","index","splice","newParentDom","childDom","_setParent","up","this.up","domPosition","getPosition","move","down","this.down","this.move","domIndex","insert","this.insert","this.getPosition","count","this.count","this.has","hide","this.hide","show","this.show","hideAll","this.hideAll","showAll","this.showAll","this._setParent","getHidePlace","this.getHidePlace","setHidePlace","this.setHidePlace","hidePlace","LocationRouter","Router","LocationRouterConstructor","doNavigate","hash","location","window","navigate","parsedHash","_defaultRoute","_watchHandle","_lastRoute","setDefaultRoute","this.setDefaultRoute","defaultRoute","getDefaultRoute","this.getDefaultRoute","this.parse","pop","toUrl","this.toUrl","args","this.start","bindOnHashChange","bindOnRouteChange","destroy","this.destroy","unwatch","removeEventListener","boundOnHashChange","onHashChange","this.onHashChange","this.bindOnHashChange","this.bindOnRouteChange","onRouteChange","this.onRouteChange","getLastRoute","this.getLastRoute","LocationRouterFactory"]
}
View
69 build/Olives.js
@@ -1943,7 +1943,55 @@ function LocationRouter(Router, Tools) {
* The handle on the watch
* @private
*/
- var _watchHandle;
+ var _watchHandle,
+
+ /**
+ * The default route to navigate to when nothing is supplied in the url
+ * @private
+ */
+ _defaultRoute = "",
+
+ /**
+ * The last route that was navigated to
+ * @private
+ */
+ _lastRoute = window.location.hash;
+
+ /**
+ * Navigates to the current hash or to the default route if none is supplied in the url
+ * @private
+ */
+ /*jshint validthis:true*/
+ function doNavigate() {
+ if (window.location.hash) {
+ var parsedHash = this.parse(window.location.hash);
+ this.navigate.apply(this, parsedHash);
+ } else {
+ this.navigate(_defaultRoute);
+ }
+ }
+
+ /**
+ * Set the default route to navigate to when nothing is defined in the url
+ * @param {String} defaultRoute the defaultRoute to navigate to
+ * @returns {Boolean} true if it's not an empty string
+ */
+ this.setDefaultRoute = function setDefaultRoute(defaultRoute) {
+ if (defaultRoute && typeof defaultRoute == "string") {
+ _defaultRoute = defaultRoute;
+ return true;
+ } else {
+ return false;
+ }
+ };
+
+ /**
+ * Get the currently set default route
+ * @returns {String} the default route
+ */
+ this.getDefaultRoute = function getDefaultRoute() {
+ return _defaultRoute;
+ };
/**
* The function that parses the url to determine the route to navigate to.
@@ -1981,10 +2029,9 @@ function LocationRouter(Router, Tools) {
* It will also start listening to route changes and hashmark changes to navigate.
* While navigating, the hashmark itself will also change to reflect the current route state
*/
- this.start = function start() {
- this.clearHistory();
- var parsedHash = this.parse(window.location.hash);
- this.navigate.apply(this, parsedHash);
+ this.start = function start(defaultRoute) {
+ this.setDefaultRoute(defaultRoute);
+ doNavigate.call(this);
this.bindOnHashChange();
this.bindOnRouteChange();
};
@@ -2001,9 +2048,10 @@ function LocationRouter(Router, Tools) {
* Parse the hash and navigate to the corresponding url
* @private
*/
- this.onHashChange = function onHashChange(event) {
- var parsedHash = this.parse(event.newURL.split("#").pop());
- this.navigate.apply(this, parsedHash);
+ this.onHashChange = function onHashChange() {
+ if (window.location.hash != _lastRoute) {
+ doNavigate.call(this);
+ }
};
/**
@@ -2036,6 +2084,11 @@ function LocationRouter(Router, Tools) {
*/
this.onRouteChange = function onRouteChange() {
window.location.hash = this.toUrl(Tools.toArray(arguments));
+ _lastRoute = window.location.hash;
+ };
+
+ this.getLastRoute = function getLastRoute() {
+ return _lastRoute;
};
}
View
53 build/Olives.min.js
@@ -3,31 +3,32 @@
The MIT License (MIT)
Copyright (c) 2012-2013 Olivier Scherrer <pode.fr@gmail.com> - Olivier Wietrich <olivier.wietrich@gmail.com>
*/
-define("DomUtils",["Tools"],function(g){return{getNodes:function(d,c){return this.isAcceptedType(d)?(d.parentNode||document.createDocumentFragment().appendChild(d),d.parentNode.querySelectorAll(c||"*")):false},getDataset:function(d){var c=0,b,e={},f,a;if(this.isAcceptedType(d))if(d.hasOwnProperty("dataset"))return d.dataset;else{for(b=d.attributes.length;c<b;c++)f=d.attributes[c].name.split("-"),f.shift()=="data"&&(e[a=f.join("-")]=d.getAttribute("data-"+a));return e}else return false},isAcceptedType:function(d){return d instanceof
+define("DomUtils",["Tools"],function(g){return{getNodes:function(d,c){return this.isAcceptedType(d)?(d.parentNode||document.createDocumentFragment().appendChild(d),d.parentNode.querySelectorAll(c||"*")):false},getDataset:function(d){var c=0,b,h={},e,a;if(this.isAcceptedType(d))if(d.hasOwnProperty("dataset"))return d.dataset;else{for(b=d.attributes.length;c<b;c++)e=d.attributes[c].name.split("-"),e.shift()=="data"&&(h[a=e.join("-")]=d.getAttribute("data-"+a));return h}else return false},isAcceptedType:function(d){return d instanceof
HTMLElement||d instanceof SVGElement?true:false},setAttribute:function(d,c,b){return d instanceof HTMLElement?(d[c]=b,true):d instanceof SVGElement?(d.setAttribute(c,b),true):false},matches:function(d,c,b){return g.toArray(this.getNodes(d,c)).indexOf(b)>-1}}});
-define("Bind.plugin",["Store","Observable","Tools","DomUtils"],function(g,d,c,b){return function(e,d){function a(a){h[a]&&(h[a].forEach(function(a){j.unwatchValue(a)}),delete h[a])}var j=null,i={},l={},h={};this.observers=h;this.setModel=function(a){return a instanceof g?(j=a,true):false};this.getModel=function(){return j};this.ItemRenderer=function(k,d){var e=null,f=null,h=null,i=null,g=null;this.setRenderer=function(a){e=a;return true};this.getRenderer=function(){return e};this.setRootNode=function(a){return b.isAcceptedType(a)?
-(h=a,a=h.querySelector("*"),this.setRenderer(a),a&&h.removeChild(a),true):false};this.getRootNode=function(){return h};this.setPlugins=function(a){f=a;return true};this.getPlugins=function(){return f};this.items={};this.setStart=function(a){return i=parseInt(a,10)};this.getStart=function(){return i};this.setNb=function(a){return g=a=="*"?a:parseInt(a,10)};this.getNb=function(){return g};this.addItem=function(a){var b;return typeof a=="number"&&!this.items[a]?(b=this.getNextItem(a),(a=this.create(a))?
-(b?h.insertBefore(a,b):h.appendChild(a),true):false):false};this.getNextItem=function(a){var b=Object.keys(this.items).map(function(a){return Number(a)}),k=c.closestGreater(a,b),b=b[k];if(b!=a)return this.items[b]};this.removeItem=function(b){var k=this.items[b];return k?(h.removeChild(k),delete this.items[b],a(b),true):false};this.create=function(a){if(j.has(a)){var k=e.cloneNode(true),d=b.getNodes(k);c.toArray(d).forEach(function(b){b.setAttribute("data-"+f.name+"_id",a)});this.items[a]=k;f.apply(k);
-return k}};this.render=function(){var a=g=="*"?j.getNbItems():g,b=[];if(g!==null&&i!==null){c.loop(this.items,function(k,c){c=Number(c);(c<i||c>=i+a||!j.has(c))&&b.push(c)},this);b.sort(c.compareNumbers).reverse().forEach(this.removeItem,this);for(var k=i,d=a+i;k<d;k++)this.addItem(k);return true}else return false};this.setPlugins(k);this.setRootNode(d)};this.setItemRenderer=function(a,b){l[a||"default"]=b};this.getItemRenderer=function(a){return l[a]};this.foreach=function(b,c,d,e){var h=new this.ItemRenderer(this.plugins,
-b);h.setStart(d||0);h.setNb(e||"*");h.render();j.watch("added",h.render,h);j.watch("deleted",function(b){h.render();a(b)},this);this.setItemRenderer(c,h)};this.updateStart=function(a,b){var c=this.getItemRenderer(a);return c?(c.setStart(b),true):false};this.updateNb=function(a,b){var c=this.getItemRenderer(a);return c?(c.setNb(b),true):false};this.refresh=function(a){return(a=this.getItemRenderer(a))?(a.render(),true):false};this.bind=function(a,h,d){var d=d||"",e=a.getAttribute("data-"+this.plugins.name+
-"_id"),f=d.split("."),i=e||f.shift(),g=e?d:f.join("."),e=c.getNestedProperty(j.get(i),g),l=c.toArray(arguments).slice(3);if(e||e===0||e===false)this.execBinding.apply(this,[a,h,e].concat(l))||b.setAttribute(a,h,e);this.hasBinding(h)||a.addEventListener("change",function(){j.has(i)&&(g?j.update(i,d,a[h]):j.set(i,a[h]))},true);this.observers[i]=this.observers[i]||[];this.observers[i].push(j.watchValue(i,function(d){this.execBinding.apply(this,[a,h,c.getNestedProperty(d,g)].concat(l))||b.setAttribute(a,
-h,c.getNestedProperty(d,g))},this))};this.set=function(a){return b.isAcceptedType(a)&&a.name?(j.set(a.name,a.value),true):false};this.getItemIndex=function(a){return(a=b.getDataset(a))&&typeof a[this.plugins.name+"_id"]!="undefined"?+a[this.plugins.name+"_id"]:false};this.form=function(a){if(a&&a.nodeName=="FORM"){var b=this;a.addEventListener("submit",function(d){c.toArray(a.querySelectorAll("[name]")).forEach(b.set,b);d.preventDefault()},true);return true}else return false};this.addBinding=function(a,
-b){return a&&typeof a=="string"&&typeof b=="function"?(i[a]=b,true):false};this.execBinding=function(a,b){return this.hasBinding(b)?(i[b].apply(a,Array.prototype.slice.call(arguments,2)),true):false};this.hasBinding=function(a){return i.hasOwnProperty(a)};this.getBinding=function(a){return i[a]};this.addBindings=function(a){return c.loop(a,function(a,b){this.addBinding(b,a)},this)};this.setModel(e);this.addBindings(d)}});
-define("Event.plugin",["DomUtils"],function(g){return function(d,c){var b=null,e={mousedown:"touchstart",mouseup:"touchend",mousemove:"touchmove"},f=!!c;this.addEventListener=function(a,b,c,d){a.addEventListener(this.map(b),c,!!d)};this.listen=function(a,c,d,e){this.addEventListener(a,c,function(c){b[d].call(b,c,a)},!!e)};this.delegate=function(a,c,d,e,h){this.addEventListener(a,d,function(d){g.matches(a,c,d.target)&&b[e].call(b,d,a)},!!h)};this.getParent=function(){return b};this.setParent=function(a){return a instanceof
-Object?(b=a,true):false};this.map=function(a){return f?e[a]||a:a};this.setMap=function(a,b){return typeof a=="string"&&typeof b=="string"?(e[a]=b,true):false};this.setParent(d)}});
-define("LocalStore",["Store","Tools"],function(g,d){function c(){var b=null,c=localStorage,f=function(){c.setItem(b,this.toJSON())};this.setLocalStorage=function(a){return a&&a.setItem instanceof Function?(c=a,true):false};this.getLocalStorage=function(){return c};this.sync=function(a){return typeof a=="string"?(b=a,a=JSON.parse(c.getItem(a)),d.loop(a,function(a,b){this.has(b)||this.set(b,a)},this),f.call(this),this.watch("added",f,this),this.watch("updated",f,this),this.watch("deleted",f,this),true):
+define("Bind.plugin",["Store","Observable","Tools","DomUtils"],function(g,d,c,b){return function(d,e){function a(a){i[a]&&(i[a].forEach(function(a){f.unwatchValue(a)}),delete i[a])}var f=null,j={},l={},i={};this.observers=i;this.setModel=function(a){return a instanceof g?(f=a,true):false};this.getModel=function(){return f};this.ItemRenderer=function(k,e){var d=null,h=null,i=null,j=null,g=null;this.setRenderer=function(a){d=a;return true};this.getRenderer=function(){return d};this.setRootNode=function(a){return b.isAcceptedType(a)?
+(i=a,a=i.querySelector("*"),this.setRenderer(a),a&&i.removeChild(a),true):false};this.getRootNode=function(){return i};this.setPlugins=function(a){h=a;return true};this.getPlugins=function(){return h};this.items={};this.setStart=function(a){return j=parseInt(a,10)};this.getStart=function(){return j};this.setNb=function(a){return g=a=="*"?a:parseInt(a,10)};this.getNb=function(){return g};this.addItem=function(a){var b;return typeof a=="number"&&!this.items[a]?(b=this.getNextItem(a),(a=this.create(a))?
+(b?i.insertBefore(a,b):i.appendChild(a),true):false):false};this.getNextItem=function(a){var b=Object.keys(this.items).map(function(a){return Number(a)}),f=c.closestGreater(a,b),b=b[f];if(b!=a)return this.items[b]};this.removeItem=function(b){var f=this.items[b];return f?(i.removeChild(f),delete this.items[b],a(b),true):false};this.create=function(a){if(f.has(a)){var k=d.cloneNode(true),e=b.getNodes(k);c.toArray(e).forEach(function(b){b.setAttribute("data-"+h.name+"_id",a)});this.items[a]=k;h.apply(k);
+return k}};this.render=function(){var a=g=="*"?f.getNbItems():g,b=[];if(g!==null&&j!==null){c.loop(this.items,function(k,c){c=Number(c);(c<j||c>=j+a||!f.has(c))&&b.push(c)},this);b.sort(c.compareNumbers).reverse().forEach(this.removeItem,this);for(var k=j,e=a+j;k<e;k++)this.addItem(k);return true}else return false};this.setPlugins(k);this.setRootNode(e)};this.setItemRenderer=function(a,b){l[a||"default"]=b};this.getItemRenderer=function(a){return l[a]};this.foreach=function(b,c,e,d){var i=new this.ItemRenderer(this.plugins,
+b);i.setStart(e||0);i.setNb(d||"*");i.render();f.watch("added",i.render,i);f.watch("deleted",function(b){i.render();a(b)},this);this.setItemRenderer(c,i)};this.updateStart=function(a,b){var f=this.getItemRenderer(a);return f?(f.setStart(b),true):false};this.updateNb=function(a,b){var f=this.getItemRenderer(a);return f?(f.setNb(b),true):false};this.refresh=function(a){return(a=this.getItemRenderer(a))?(a.render(),true):false};this.bind=function(a,e,i){var i=i||"",d=a.getAttribute("data-"+this.plugins.name+
+"_id"),h=i.split("."),j=d||h.shift(),g=d?i:h.join("."),d=c.getNestedProperty(f.get(j),g),l=c.toArray(arguments).slice(3);if(d||d===0||d===false)this.execBinding.apply(this,[a,e,d].concat(l))||b.setAttribute(a,e,d);this.hasBinding(e)||a.addEventListener("change",function(){f.has(j)&&(g?f.update(j,i,a[e]):f.set(j,a[e]))},true);this.observers[j]=this.observers[j]||[];this.observers[j].push(f.watchValue(j,function(f){this.execBinding.apply(this,[a,e,c.getNestedProperty(f,g)].concat(l))||b.setAttribute(a,
+e,c.getNestedProperty(f,g))},this))};this.set=function(a){return b.isAcceptedType(a)&&a.name?(f.set(a.name,a.value),true):false};this.getItemIndex=function(a){return(a=b.getDataset(a))&&typeof a[this.plugins.name+"_id"]!="undefined"?+a[this.plugins.name+"_id"]:false};this.form=function(a){if(a&&a.nodeName=="FORM"){var b=this;a.addEventListener("submit",function(f){c.toArray(a.querySelectorAll("[name]")).forEach(b.set,b);f.preventDefault()},true);return true}else return false};this.addBinding=function(a,
+b){return a&&typeof a=="string"&&typeof b=="function"?(j[a]=b,true):false};this.execBinding=function(a,b){return this.hasBinding(b)?(j[b].apply(a,Array.prototype.slice.call(arguments,2)),true):false};this.hasBinding=function(a){return j.hasOwnProperty(a)};this.getBinding=function(a){return j[a]};this.addBindings=function(a){return c.loop(a,function(a,b){this.addBinding(b,a)},this)};this.setModel(d);this.addBindings(e)}});
+define("Event.plugin",["DomUtils"],function(g){return function(d,c){var b=null,h={mousedown:"touchstart",mouseup:"touchend",mousemove:"touchmove"},e=!!c;this.addEventListener=function(a,b,c,e){a.addEventListener(this.map(b),c,!!e)};this.listen=function(a,f,c,e){this.addEventListener(a,f,function(f){b[c].call(b,f,a)},!!e)};this.delegate=function(a,f,c,e,d){this.addEventListener(a,c,function(c){g.matches(a,f,c.target)&&b[e].call(b,c,a)},!!d)};this.getParent=function(){return b};this.setParent=function(a){return a instanceof
+Object?(b=a,true):false};this.map=function(a){return e?h[a]||a:a};this.setMap=function(a,b){return typeof a=="string"&&typeof b=="string"?(h[a]=b,true):false};this.setParent(d)}});
+define("LocalStore",["Store","Tools"],function(g,d){function c(){var b=null,c=localStorage,e=function(){c.setItem(b,this.toJSON())};this.setLocalStorage=function(a){return a&&a.setItem instanceof Function?(c=a,true):false};this.getLocalStorage=function(){return c};this.sync=function(a){return typeof a=="string"?(b=a,a=JSON.parse(c.getItem(a)),d.loop(a,function(a,b){this.has(b)||this.set(b,a)},this),e.call(this),this.watch("added",e,this),this.watch("updated",e,this),this.watch("deleted",e,this),true):
false}}return function(b){c.prototype=new g(b);return new c}});
-define("Plugins",["Tools","DomUtils"],function(g,d){return function(c){var b={},e=function(a){return a.trim()},f=function(a,c,d){c.split(";").forEach(function(c){var h=c.split(":"),c=h[0].trim(),h=h[1]?h[1].split(",").map(e):[];h.unshift(a);b[d]&&b[d][c]&&b[d][c].apply(b[d],h)})};this.add=function(a,c){var d=this;return typeof a=="string"&&typeof c=="object"&&c?(b[a]=c,c.plugins={name:a,apply:function(){return d.apply.apply(d,arguments)}},true):false};this.addAll=function(a){return g.loop(a,function(a,
-b){this.add(b,a)},this)};this.get=function(a){return b[a]};this.del=function(a){return delete b[a]};this.apply=function(a){var b;return d.isAcceptedType(a)?(b=d.getNodes(a),g.loop(g.toArray(b),function(a){g.loop(d.getDataset(a),function(b,c){f(a,b,c)})}),a):false};this.addAll(c)}});
-define("OObject",["StateMachine","Store","Plugins","DomUtils","Tools"],function(g,d,c,b,e){return function(f){var a=function(a){var c=i||document.createElement("div");if(a.template){typeof a.template=="string"?c.innerHTML=a.template.trim():b.isAcceptedType(a.template)&&c.appendChild(a.template);if(c.childNodes.length>1)throw Error("UI.template should have only one parent node");else a.dom=c.childNodes[0];a.plugins.apply(a.dom)}else throw Error("UI.template must be set prior to render");},j=function(a,
-b,c){b&&(c?b.insertBefore(a.dom,c):b.appendChild(a.dom),i=b)},i=null,l=new g("Init",{Init:[["render",a,this,"Rendered"],["place",function(b,c){a(b);j.apply(null,e.toArray(arguments))},this,"Rendered"]],Rendered:[["place",j,this],["render",a,this]]});this.model=f instanceof d?f:new d;this.plugins=new c;this.dom=this.template=null;this.place=function(a,b){l.event("place",this,a,b)};this.render=function(){l.event("render",this)};this.setTemplateFromDom=function(a){return b.isAcceptedType(a)?(this.template=
-a,true):false};this.alive=function(a){return b.isAcceptedType(a)?(this.setTemplateFromDom(a),this.place(a.parentNode,a.nextElementSibling),true):false};this.getCurrentPlace=function(){return i}}});
-define("Place.plugin",["OObject","Tools"],function(g,d){return function(c){var b={};this.place=function(c,d){if(b[d]instanceof g)b[d].place(c);else throw Error(d+" is not an OObject UI in place:"+d);};this.set=function(c,d){return typeof c=="string"&&d instanceof g?(b[c]=d,true):false};this.setAll=function(b){d.loop(b,function(b,a){this.set(a,b)},this)};this.get=function(c){return b[c]};this.setAll(c)}});
-define("SocketIOTransport",["Observable","Tools"],function(){return function(g){var d=null;this.setSocket=function(c){return c&&typeof c.emit=="function"?(d=c,true):false};this.getSocket=function(){return d};this.on=function(c,b){return d.on(c,b)};this.once=function(c,b){return d.once(c,b)};this.emit=function(c,b,e){return d.emit(c,b,e)};this.removeListener=function(c,b,e){return d.removeListener(c,b,e)};this.request=function(c,b,d,f){return typeof c=="string"&&typeof b!="undefined"?(b={eventId:Date.now()+
-Math.floor(Math.random()*1E6),data:b},this.once(b.eventId,function(){d&&d.apply(f||null,arguments)}),this.emit(c,b),true):false};this.listen=function(c,b,d,f){if(typeof c=="string"&&typeof b!="undefined"&&typeof d=="function"){var a={eventId:Date.now()+Math.floor(Math.random()*1E6),data:b,keepAlive:true},j=function(){d&&d.apply(f||null,arguments)},g=this;this.on(a.eventId,j);this.emit(c,a);return function(){g.emit("disconnect-"+a.eventId);g.removeListener(a.eventId,j)}}else return false};this.setSocket(g)}});
-define("Stack",["Tools"],function(){var g=require("Tools");return function(d){function c(a){if(!(a>=f.length)){var d=f[a];return g.toArray(b.childNodes).indexOf(d)==-1?c(a+1):d}}var b=document.createDocumentFragment(),e=document.createElement("div"),f=[];this.add=function(a){return!this.has(a)&&a instanceof HTMLElement?(b.appendChild(a),f.push(a),a):false};this.remove=function(a){var c;return this.has(a)?(c=f.indexOf(a),b.removeChild(a),f.splice(c,1),a):false};this.place=function(a){return a instanceof
-HTMLElement?([].slice.call(b.childNodes).forEach(function(b){this.has(b)&&a.appendChild(b)},this),this._setParent(a)):false};this.up=function(a){if(this.has(a)){var b=this.getPosition(a);this.move(a,b+1);return a}else return false};this.down=function(a){if(this.has(a)){var b=this.getPosition(a);this.move(a,b-1);return a}else return false};this.move=function(a,d){if(this.has(a)){var e=f.indexOf(a);f.splice(e,1);(e=c(d))?b.insertBefore(a,e):b.appendChild(a);f.splice(d,0,a);return a}else return false};
-this.insert=function(a,c){return!this.has(a)&&a instanceof HTMLElement?(f.splice(c,0,a),b.insertBefore(a,b.childNodes[c]),a):false};this.getPosition=function(a){return f.indexOf(a)};this.count=function(){return b.childNodes.length};this.has=function(a){return this.getPosition(a)>=0};this.hide=function(a){return this.has(a)?(e.appendChild(a),true):false};this.show=function(a){return this.has(a)&&a.parentNode===e?(this.move(a,f.indexOf(a)),true):false};this.hideAll=function(){f.forEach(this.hide,this)};
-this.showAll=function(){f.forEach(this.show,this)};this.getParent=function(){return b};this._setParent=function(a){return a instanceof HTMLElement?b=a:false};this.getHidePlace=function(){return e};this.setHidePlace=function(a){return a instanceof HTMLElement?(e=a,true):false};this._setParent(d)}});
-define("LocationRouter",["Router","Tools"],function(g,d){function c(){var b;this.parse=function(b){return b.split("#").pop().split("/")};this.toUrl=function(b){return b.join("/")};this.start=function(){this.clearHistory();this.navigate.apply(this,this.parse(window.location.hash));this.bindOnHashChange();this.bindOnRouteChange()};this.destroy=function(){this.unwatch(b);window.removeEventListener("hashchange",this.boundOnHashChange,true)};this.onHashChange=function(b){this.navigate.apply(this,this.parse(b.newURL.split("#").pop()))};
-this.boundOnHashChange=this.onHashChange.bind(this);this.bindOnHashChange=function(){window.addEventListener("hashchange",this.boundOnHashChange,true)};this.bindOnRouteChange=function(){b=this.watch(this.onRouteChange,this)};this.onRouteChange=function(){window.location.hash=this.toUrl(d.toArray(arguments))}}return function(){c.prototype=new g;return new c}});
+define("Plugins",["Tools","DomUtils"],function(g,d){return function(c){var b={},h=function(a){return a.trim()},e=function(a,f,c){f.split(";").forEach(function(f){var e=f.split(":"),f=e[0].trim(),e=e[1]?e[1].split(",").map(h):[];e.unshift(a);b[c]&&b[c][f]&&b[c][f].apply(b[c],e)})};this.add=function(a,f){var c=this;return typeof a=="string"&&typeof f=="object"&&f?(b[a]=f,f.plugins={name:a,apply:function(){return c.apply.apply(c,arguments)}},true):false};this.addAll=function(a){return g.loop(a,function(a,
+b){this.add(b,a)},this)};this.get=function(a){return b[a]};this.del=function(a){return delete b[a]};this.apply=function(a){var b;return d.isAcceptedType(a)?(b=d.getNodes(a),g.loop(g.toArray(b),function(a){g.loop(d.getDataset(a),function(b,c){e(a,b,c)})}),a):false};this.addAll(c)}});
+define("OObject",["StateMachine","Store","Plugins","DomUtils","Tools"],function(g,d,c,b,h){return function(e){var a=function(a){var c=j||document.createElement("div");if(a.template){typeof a.template=="string"?c.innerHTML=a.template.trim():b.isAcceptedType(a.template)&&c.appendChild(a.template);if(c.childNodes.length>1)throw Error("UI.template should have only one parent node");else a.dom=c.childNodes[0];a.plugins.apply(a.dom)}else throw Error("UI.template must be set prior to render");},f=function(a,
+b,c){b&&(c?b.insertBefore(a.dom,c):b.appendChild(a.dom),j=b)},j=null,l=new g("Init",{Init:[["render",a,this,"Rendered"],["place",function(b,c){a(b);f.apply(null,h.toArray(arguments))},this,"Rendered"]],Rendered:[["place",f,this],["render",a,this]]});this.model=e instanceof d?e:new d;this.plugins=new c;this.dom=this.template=null;this.place=function(a,b){l.event("place",this,a,b)};this.render=function(){l.event("render",this)};this.setTemplateFromDom=function(a){return b.isAcceptedType(a)?(this.template=
+a,true):false};this.alive=function(a){return b.isAcceptedType(a)?(this.setTemplateFromDom(a),this.place(a.parentNode,a.nextElementSibling),true):false};this.getCurrentPlace=function(){return j}}});
+define("Place.plugin",["OObject","Tools"],function(g,d){return function(c){var b={};this.place=function(c,e){if(b[e]instanceof g)b[e].place(c);else throw Error(e+" is not an OObject UI in place:"+e);};this.set=function(c,e){return typeof c=="string"&&e instanceof g?(b[c]=e,true):false};this.setAll=function(b){d.loop(b,function(b,a){this.set(a,b)},this)};this.get=function(c){return b[c]};this.setAll(c)}});
+define("SocketIOTransport",["Observable","Tools"],function(){return function(g){var d=null;this.setSocket=function(c){return c&&typeof c.emit=="function"?(d=c,true):false};this.getSocket=function(){return d};this.on=function(c,b){return d.on(c,b)};this.once=function(c,b){return d.once(c,b)};this.emit=function(c,b,h){return d.emit(c,b,h)};this.removeListener=function(c,b,h){return d.removeListener(c,b,h)};this.request=function(c,b,d,e){return typeof c=="string"&&typeof b!="undefined"?(b={eventId:Date.now()+
+Math.floor(Math.random()*1E6),data:b},this.once(b.eventId,function(){d&&d.apply(e||null,arguments)}),this.emit(c,b),true):false};this.listen=function(c,b,d,e){if(typeof c=="string"&&typeof b!="undefined"&&typeof d=="function"){var a={eventId:Date.now()+Math.floor(Math.random()*1E6),data:b,keepAlive:true},f=function(){d&&d.apply(e||null,arguments)},g=this;this.on(a.eventId,f);this.emit(c,a);return function(){g.emit("disconnect-"+a.eventId);g.removeListener(a.eventId,f)}}else return false};this.setSocket(g)}});
+define("Stack",["Tools"],function(){var g=require("Tools");return function(d){function c(a){if(!(a>=e.length)){var f=e[a];return g.toArray(b.childNodes).indexOf(f)==-1?c(a+1):f}}var b=document.createDocumentFragment(),h=document.createElement("div"),e=[];this.add=function(a){return!this.has(a)&&a instanceof HTMLElement?(b.appendChild(a),e.push(a),a):false};this.remove=function(a){var c;return this.has(a)?(c=e.indexOf(a),b.removeChild(a),e.splice(c,1),a):false};this.place=function(a){return a instanceof
+HTMLElement?([].slice.call(b.childNodes).forEach(function(b){this.has(b)&&a.appendChild(b)},this),this._setParent(a)):false};this.up=function(a){if(this.has(a)){var b=this.getPosition(a);this.move(a,b+1);return a}else return false};this.down=function(a){if(this.has(a)){var b=this.getPosition(a);this.move(a,b-1);return a}else return false};this.move=function(a,f){if(this.has(a)){var d=e.indexOf(a);e.splice(d,1);(d=c(f))?b.insertBefore(a,d):b.appendChild(a);e.splice(f,0,a);return a}else return false};
+this.insert=function(a,c){return!this.has(a)&&a instanceof HTMLElement?(e.splice(c,0,a),b.insertBefore(a,b.childNodes[c]),a):false};this.getPosition=function(a){return e.indexOf(a)};this.count=function(){return b.childNodes.length};this.has=function(a){return this.getPosition(a)>=0};this.hide=function(a){return this.has(a)?(h.appendChild(a),true):false};this.show=function(a){return this.has(a)&&a.parentNode===h?(this.move(a,e.indexOf(a)),true):false};this.hideAll=function(){e.forEach(this.hide,this)};
+this.showAll=function(){e.forEach(this.show,this)};this.getParent=function(){return b};this._setParent=function(a){return a instanceof HTMLElement?b=a:false};this.getHidePlace=function(){return h};this.setHidePlace=function(a){return a instanceof HTMLElement?(h=a,true):false};this._setParent(d)}});
+define("LocationRouter",["Router","Tools"],function(g,d){function c(){function b(){window.location.hash?this.navigate.apply(this,this.parse(window.location.hash)):this.navigate(e)}var c,e="",a=window.location.hash;this.setDefaultRoute=function(a){return a&&typeof a=="string"?(e=a,true):false};this.getDefaultRoute=function(){return e};this.parse=function(a){return a.split("#").pop().split("/")};this.toUrl=function(a){return a.join("/")};this.start=function(a){this.setDefaultRoute(a);b.call(this);this.bindOnHashChange();
+this.bindOnRouteChange()};this.destroy=function(){this.unwatch(c);window.removeEventListener("hashchange",this.boundOnHashChange,true)};this.onHashChange=function(){window.location.hash!=a&&b.call(this)};this.boundOnHashChange=this.onHashChange.bind(this);this.bindOnHashChange=function(){window.addEventListener("hashchange",this.boundOnHashChange,true)};this.bindOnRouteChange=function(){c=this.watch(this.onRouteChange,this)};this.onRouteChange=function(){window.location.hash=this.toUrl(d.toArray(arguments));
+a=window.location.hash};this.getLastRoute=function(){return a}}return function(){c.prototype=new g;return new c}});
View
69 build/src/LocationRouter.js
@@ -21,7 +21,55 @@ function LocationRouter(Router, Tools) {
* The handle on the watch
* @private
*/
- var _watchHandle;
+ var _watchHandle,
+
+ /**
+ * The default route to navigate to when nothing is supplied in the url
+ * @private
+ */
+ _defaultRoute = "",
+
+ /**
+ * The last route that was navigated to
+ * @private
+ */
+ _lastRoute = window.location.hash;
+
+ /**
+ * Navigates to the current hash or to the default route if none is supplied in the url
+ * @private
+ */
+ /*jshint validthis:true*/
+ function doNavigate() {
+ if (window.location.hash) {
+ var parsedHash = this.parse(window.location.hash);
+ this.navigate.apply(this, parsedHash);
+ } else {
+ this.navigate(_defaultRoute);
+ }
+ }
+
+ /**
+ * Set the default route to navigate to when nothing is defined in the url
+ * @param {String} defaultRoute the defaultRoute to navigate to
+ * @returns {Boolean} true if it's not an empty string
+ */
+ this.setDefaultRoute = function setDefaultRoute(defaultRoute) {
+ if (defaultRoute && typeof defaultRoute == "string") {
+ _defaultRoute = defaultRoute;
+ return true;
+ } else {
+ return false;
+ }
+ };
+
+ /**
+ * Get the currently set default route
+ * @returns {String} the default route
+ */
+ this.getDefaultRoute = function getDefaultRoute() {
+ return _defaultRoute;
+ };
/**
* The function that parses the url to determine the route to navigate to.
@@ -59,10 +107,9 @@ function LocationRouter(Router, Tools) {
* It will also start listening to route changes and hashmark changes to navigate.
* While navigating, the hashmark itself will also change to reflect the current route state
*/
- this.start = function start() {
- this.clearHistory();
- var parsedHash = this.parse(window.location.hash);
- this.navigate.apply(this, parsedHash);
+ this.start = function start(defaultRoute) {
+ this.setDefaultRoute(defaultRoute);
+ doNavigate.call(this);
this.bindOnHashChange();
this.bindOnRouteChange();
};
@@ -79,9 +126,10 @@ function LocationRouter(Router, Tools) {
* Parse the hash and navigate to the corresponding url
* @private
*/
- this.onHashChange = function onHashChange(event) {
- var parsedHash = this.parse(event.newURL.split("#").pop());
- this.navigate.apply(this, parsedHash);
+ this.onHashChange = function onHashChange() {
+ if (window.location.hash != _lastRoute) {
+ doNavigate.call(this);
+ }
};
/**
@@ -114,6 +162,11 @@ function LocationRouter(Router, Tools) {
*/
this.onRouteChange = function onRouteChange() {
window.location.hash = this.toUrl(Tools.toArray(arguments));
+ _lastRoute = window.location.hash;
+ };
+
+ this.getLastRoute = function getLastRoute() {
+ return _lastRoute;
};
}
View
21 specs/LocationRouter.spec.js
@@ -122,6 +122,15 @@ require(["LocationRouter", "Router"], function (LocationRouter, Router) {
expect(locationRouter.navigate).toHaveBeenCalledWith("default");
});
+ it("doesn't navigate on hash change when the route in the url has been set by a route change event", function () {
+ locationRouter.onRouteChange("my", "route");
+ spyOn(locationRouter, "navigate");
+
+ locationRouter.onHashChange();
+
+ expect(locationRouter.navigate).not.toHaveBeenCalled();
+ });
+
});
describe("LocationRouter updates the URL when navigating", function () {
@@ -163,6 +172,18 @@ require(["LocationRouter", "Router"], function (LocationRouter, Router) {
expect(window.location.hash).toBe("#hello/im/the/router");
});
+ it("remembers the last route that has been navigated to", function () {
+ window.location.hash = "my/route";
+
+ locationRouter = new LocationRouter();
+
+ expect(locationRouter.getLastRoute()).toBe(window.location.hash);
+
+ locationRouter.onRouteChange("my", "route");
+
+ expect(locationRouter.getLastRoute()).toBe(window.location.hash);
+ });
+
});
describe("LocationRouter can be destroyed", function () {
View
17 src/LocationRouter.js
@@ -27,7 +27,13 @@ function LocationRouter(Router, Tools) {
* The default route to navigate to when nothing is supplied in the url
* @private
*/
- _defaultRoute = "";
+ _defaultRoute = "",
+
+ /**
+ * The last route that was navigated to
+ * @private
+ */
+ _lastRoute = window.location.hash;
/**
* Navigates to the current hash or to the default route if none is supplied in the url
@@ -121,7 +127,9 @@ function LocationRouter(Router, Tools) {
* @private
*/
this.onHashChange = function onHashChange() {
- doNavigate.call(this);
+ if (window.location.hash != _lastRoute) {
+ doNavigate.call(this);
+ }
};
/**
@@ -154,6 +162,11 @@ function LocationRouter(Router, Tools) {
*/
this.onRouteChange = function onRouteChange() {
window.location.hash = this.toUrl(Tools.toArray(arguments));
+ _lastRoute = window.location.hash;
+ };
+
+ this.getLastRoute = function getLastRoute() {
+ return _lastRoute;
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.