From 098c14bb3e871feed5a323122df3cd568dfe196d Mon Sep 17 00:00:00 2001 From: robrobbins Date: Tue, 26 Mar 2013 09:26:06 -0700 Subject: [PATCH] data delegate updates --- build/debug/sudo-x.js | 52 +++++++++++++++++++++++++---------- extras/delegates/data/data.js | 19 +++++++++++++ 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/build/debug/sudo-x.js b/build/debug/sudo-x.js index 4c339dc..ebc4ef8 100644 --- a/build/debug/sudo-x.js +++ b/build/debug/sudo-x.js @@ -1021,7 +1021,7 @@ sudo.Navigator.prototype.setData = function setData() { // Gather the necessary information about the current environment and // bind to either (push|pop)state or hashchange. // Also, if given an imcorrect URL for the current environment (hashchange -// vs pushState) normalize it and set accordingly. +// vs pushState) normalize it and set accordingly (or don't). // // `returns` {object} `this` sudo.Navigator.prototype.start = function start() { @@ -1043,26 +1043,31 @@ sudo.Navigator.prototype.start = function start() { } else if (this.isHashChange) { $(window).on('hashchange', this.handleChange.bind(this)); } else return; - // Does the current URL need to changed? (hashchange vs popstate) atRoot = window.location.pathname.replace(/[^\/]$/, '$&/') === this.data['root']; - // somehow a pushstate URL got here (and here is hashchange) - if(this.isHashChange && !atRoot) { - window.location.replace(this.data['root'] + window.location.search + '#' + - this.data.fragment); - // return early as browser will redirect - return true; - // the converse of the above - } else if(this.isPushState && atRoot && window.location.hash) { - tmp = this.getHash().replace(this.leadingStripper, ''); - window.history.replaceState({}, document.title, this.data['root'] + - tmp + window.location.search); + // somehow a URL got here not in my 'format', unless explicitly told not too, correct this + if(!this.data.stay) { + if(this.isHashChange && !atRoot) { + window.location.replace(this.data['root'] + window.location.search + '#' + + this.data.fragment); + // return early as browser will redirect + return true; + // the converse of the above + } else if(this.isPushState && atRoot && window.location.hash) { + tmp = this.getHash().replace(this.leadingStripper, ''); + window.history.replaceState({}, document.title, this.data['root'] + + tmp + window.location.search); + } } // TODO provide option to `go` from inital `start` state? return this; }; -// Is a passed in fragment different from the currently set one? +// ###urlChanged +// Is a passed in fragment different from the one currently set at `this.get('fragment')`? +// If so set the fragment to the passed fragment passed in (as well as any 'query' data), else +// simply return false // // `param` {String} `fragment` +// `returns` {bool} sudo.Navigator.prototype.urlChanged = function urlChanged(fragment) { var current = this.getFragment(fragment); // nothing has changed @@ -1728,6 +1733,16 @@ sudo.delegates.Data = function(data) { }; // inherits from Model sudo.delegates.Data.prototype = Object.create(sudo.Model.prototype); +// ###addFilter +// Place an entry into this object's hash of filters +// +// `param` {string} `key` +// `param` {string} `val` +// `returns` {object} this +sudo.delegates.Data.prototype.addFilter = function addFilter(key, val) { + this.data.filters[key] = val; + return this; +}; // ###filter // iterates over a given object literal and returns a value (if present) // located at a given key or path @@ -1752,6 +1767,15 @@ sudo.delegates.Data.prototype.filter = function(obj) { } } }; +// ###removeFilter +// Remove an entry from this object's hash of filters +// +// `param` {string} `key` +// `returns` {object} this +sudo.delegates.Data.prototype.removeFilter = function removeFilter(key) { + delete this.data.filters[key]; + return this; +}; // `private` sudo.delegates.Data.prototype.role = 'data'; diff --git a/extras/delegates/data/data.js b/extras/delegates/data/data.js index d4f433b..2b09940 100644 --- a/extras/delegates/data/data.js +++ b/extras/delegates/data/data.js @@ -13,6 +13,16 @@ sudo.delegates.Data = function(data) { }; // inherits from Model sudo.delegates.Data.prototype = Object.create(sudo.Model.prototype); +// ###addFilter +// Place an entry into this object's hash of filters +// +// `param` {string} `key` +// `param` {string} `val` +// `returns` {object} this +sudo.delegates.Data.prototype.addFilter = function addFilter(key, val) { + this.data.filters[key] = val; + return this; +}; // ###filter // iterates over a given object literal and returns a value (if present) // located at a given key or path @@ -37,6 +47,15 @@ sudo.delegates.Data.prototype.filter = function(obj) { } } }; +// ###removeFilter +// Remove an entry from this object's hash of filters +// +// `param` {string} `key` +// `returns` {object} this +sudo.delegates.Data.prototype.removeFilter = function removeFilter(key) { + delete this.data.filters[key]; + return this; +}; // `private` sudo.delegates.Data.prototype.role = 'data';