diff --git a/examples/historyState/.meteor/.finished-upgraders b/examples/historyState/.meteor/.finished-upgraders new file mode 100644 index 0000000..ee0ed5a --- /dev/null +++ b/examples/historyState/.meteor/.finished-upgraders @@ -0,0 +1,6 @@ +# This file contains information which helps Meteor properly upgrade your +# app when you run 'meteor update'. You should check it into version control +# with your project. + +notices-for-0.9.0 +notices-for-0.9.1 diff --git a/examples/historyState/.meteor/.gitignore b/examples/historyState/.meteor/.gitignore new file mode 100644 index 0000000..4083037 --- /dev/null +++ b/examples/historyState/.meteor/.gitignore @@ -0,0 +1 @@ +local diff --git a/examples/historyState/.meteor/.id b/examples/historyState/.meteor/.id new file mode 100644 index 0000000..67e846a --- /dev/null +++ b/examples/historyState/.meteor/.id @@ -0,0 +1,7 @@ +# This file contains a token that is unique to your project. +# Check it into your repository along with the rest of this directory. +# It can be used for purposes such as: +# - ensuring you don't accidentally deploy one app on top of another +# - providing package authors with aggregated statistics + +r44vi31sejv9otpmybw diff --git a/examples/historyState/.meteor/cordova-plugins b/examples/historyState/.meteor/cordova-plugins new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/historyState/.meteor/cordova-plugins @@ -0,0 +1 @@ + diff --git a/examples/historyState/.meteor/packages b/examples/historyState/.meteor/packages new file mode 100644 index 0000000..3352778 --- /dev/null +++ b/examples/historyState/.meteor/packages @@ -0,0 +1,10 @@ +# Meteor packages used by this project, one per line. +# +# 'meteor add' and 'meteor remove' will edit this file for you, +# but you can also edit it by hand. + +meteor-platform +autopublish +insecure +iron:location + diff --git a/examples/historyState/.meteor/release b/examples/historyState/.meteor/release new file mode 100644 index 0000000..8738ff2 --- /dev/null +++ b/examples/historyState/.meteor/release @@ -0,0 +1 @@ +METEOR@0.9.2 diff --git a/examples/historyState/.meteor/versions b/examples/historyState/.meteor/versions new file mode 100644 index 0000000..62856fd --- /dev/null +++ b/examples/historyState/.meteor/versions @@ -0,0 +1,54 @@ +application-configuration@1.0.2 +autopublish@1.0.0 +autoupdate@1.1.0 +base64@1.0.0 +binary-heap@1.0.0 +blaze-tools@1.0.0 +blaze@2.0.0 +boilerplate-generator@1.0.0 +callback-hook@1.0.0 +check@1.0.0 +ctl-helper@1.0.3 +ctl@1.0.1 +ddp@1.0.8 +deps@1.0.3 +ejson@1.0.2 +fastclick@1.0.0-cordova1 +follower-livedata@1.0.1 +geojson-utils@1.0.0 +html-tools@1.0.0 +htmljs@1.0.0-cordova1 +http@1.0.5 +id-map@1.0.0 +insecure@1.0.0 +iron:core@1.0.0-pre1 +iron:location@1.0.0-pre1 +iron:url@1.0.0-pre1 +jquery@1.0.0 +json@1.0.0 +livedata@1.0.9 +logging@1.0.2-cordova2 +meteor-platform@1.1.0 +meteor@1.1.0 +minifiers@1.1.0 +minimongo@1.0.3 +mobile-status-bar@1.0.0-cordova3 +mongo@1.0.5 +observe-sequence@1.0.2 +ordered-dict@1.0.0 +random@1.0.0 +reactive-dict@1.0.2 +reactive-var@1.0.1 +reload@1.1.0 +retry@1.0.0 +routepolicy@1.0.0-cordova1 +session@1.0.1 +spacebars-compiler@1.0.2 +spacebars@1.0.1 +templating@1.0.6 +tracker@1.0.2 +ui@1.0.2 +underscore@1.0.0 +url@1.0.0 +webapp-hashing@1.0.0-cordova1 +webapp@1.1.1 diff --git a/examples/historyState/historyState.html b/examples/historyState/historyState.html new file mode 100644 index 0000000..c4ad8f2 --- /dev/null +++ b/examples/historyState/historyState.html @@ -0,0 +1,25 @@ +
+{{historyState}}+ + + + diff --git a/examples/historyState/historyState.js b/examples/historyState/historyState.js new file mode 100644 index 0000000..04b2816 --- /dev/null +++ b/examples/historyState/historyState.js @@ -0,0 +1,19 @@ +if (Meteor.isClient) { + Template.hello.helpers({ + historyState: function() { + return Iron.Location.get().options && + Iron.Location.get().options.historyState; + } + }); + + Template.hello.events({ + 'submit #push': function(e, t) { + e.preventDefault(); + Iron.Location.go('/' + Random.id(), {historyState: t.$('input').val()}); + }, + 'submit #replace': function(e, t) { + e.preventDefault(); + console.log("Can't do this yet"); + } + }) +} diff --git a/lib/location.js b/lib/location.js index 7b2f7d7..048afc4 100644 --- a/lib/location.js +++ b/lib/location.js @@ -43,14 +43,15 @@ var set = function (state) { var setStateFromEventHandler = function () { var href = location.href; - + var state; + if (isUsingHashPaths()) { - var state = new State(urlFromHashStyle(href)); - set(state); + state = new State(urlFromHashStyle(href)); } else { - var state = new State(href); - set(state); + state = new State(href, {historyState: history.state}); } + + set(state); }; var fireOnClick = function (e) { @@ -61,27 +62,21 @@ var fireOnClick = function (e) { /** * Go to a url. */ -var go = function (url) { - if (isUsingHashPaths()) { - var state = new State(url); - - if (set(state)) { +var go = function (url, options) { + var state = new State(url, options); + + if (set(state)) { + Deps.afterFlush(function () { // if after we've flushed if nobody has cancelled the state then change // the url. - Deps.afterFlush(function () { - if (!state.isCancelled()) + if (!state.isCancelled()) { + if (isUsingHashPaths()) { location.hash = fixHashPath(url); - }); - } - } else { - var state = new State(url); - - if (set(state)) { - Deps.afterFlush(function () { - if (!state.isCancelled()) - history.pushState(null, null, url); - }); - } + } else { + history.pushState(state.options.historyState, null, url); + } + } + }); } }; @@ -229,8 +224,8 @@ Location.onClick = function (fn) { /** * Go to a new url. */ -Location.go = function (url) { - return go(url); +Location.go = function (url, options) { + return go(url, options); }; /** diff --git a/lib/state.js b/lib/state.js index 05c3f3a..270c838 100644 --- a/lib/state.js +++ b/lib/state.js @@ -1,9 +1,10 @@ var Url = Iron.Url; -State = function (url) { - _.extend(this, Url.parse(url)); +State = function (url, options) { + _.extend(this, Url.parse(url), {options: options || {}}); }; +// XXX: should this compare options (e.g. history.state?) State.prototype.equals = function (other) { if (!other) return false; diff --git a/versions.json b/versions.json index 81baf7a..f145958 100644 --- a/versions.json +++ b/versions.json @@ -38,6 +38,6 @@ ] ], "pluginDependencies": [], - "toolVersion": "meteor-tool@1.0.30", + "toolVersion": "meteor-tool@1.0.29", "format": "1.0" } \ No newline at end of file