js/comm/comm/urlresponder/urlresponder.js in rsence-2.0.0.0.pre vs js/comm/comm/urlresponder/urlresponder.js in rsence-2.0.0.pre
- old
+ new
@@ -18,55 +18,46 @@
**
***/
COMM.URLResponder = HApplication.extend({
constructor: function(){
this.urlMatchers = [];
- this.urlCallBacks = [];
- this.defaultCallBacks = [];
- this.prevCallBacks = [];
- this.prevMatchStrs = [];
+ this.urlCallBack = [];
+ this.defaultCallBack = null;
+ this.prevCallBack = false;
+ this.prevMatchStr = '';
this.base(1, 'URLResponder');
this.value = 0;
+ this.clientValue = HValue.nu( false, '' );
+ this.clientValue.bind( this );
+ this.serverValue = false;
},
// sets the view to show when there is
// no matches (like a virtual 404)
setDefaultResponder: function(_callBack){
- this.defaultCallBacks = [ _callBack ];
- this.refresh();
+ this.defaultCallBack = _callBack;
},
- addDefaultResponder: function(_callBack){
- this.defaultCallBacks.push( _callBack );
- this.refresh();
- },
-
- delDefaultResponder: function(_callBack){
- this.defaultCallBacks.splice(this.defaultCallbacks.indexOf(_callBack),1);
- this.refresh();
- },
-
// Removes responder
// - matchStr is an url that the callBack will
// respond to
// - callBack is the component registered
delResponder: function(_matchStr,_callBack){
_callBack.hide();
- if(this.prevCallBacks.indexOf(_callBack) !== -1){
- this.prevCallBacks.splice(this.prevCallBacks.indexOf(_callBack),1);
- this.prevMatchStrs.splice(this.prevMatchStrs.indexOf(_matchStr),1);
+ if(_callBack === this.prevCallBack){
+ this.prevCallBack = false;
+ this.prevMatchStr = '';
}
var i=0, _urlMatch, _urlCallBack;
for(;i<this.urlMatchers.length;i++){
_urlMatch = this.urlMatchers[i].test(_matchStr);
if(_urlMatch){
this.urlMatchers.splice(i,1);
- this.urlCallBacks.splice(i,1);
+ this.urlCallBack.splice(i,1);
return 1;
}
}
- this.refresh();
return 0;
},
// Adds responder
// - matchRegExp is the regular expression
@@ -74,75 +65,61 @@
// - callBack is the component that will receive hide/show calls
// - activate is a flag that tells the view to be immediately
// activate (and the previous one to deactivate)
addResponder: function(_matchRegExp,_callBack,_activate){
this.urlMatchers.push(new RegExp(_matchRegExp));
- this.urlCallBacks.push(_callBack);
+ this.urlCallBack.push(_callBack);
this.checkMatch(this.value);
if(_activate!==undefined){
- window.location.href=_activate;
+ location.href=_activate;
}
- this.refresh();
},
// Checks the matchStr agains regular expressions
checkMatch: function(_matchStr){
- if(this.prevMatchStrs.indexOf( _matchStr ) !== -1 ){
+ if(_matchStr === this.prevMatchStr){
return 0;
}
- var i=0, _urlMatch, _urlCallBacks=[], _urlCallBack;
+ var i=0, _urlMatch, _urlCallBack;
for(;i<this.urlMatchers.length;i++){
_urlMatch = this.urlMatchers[i].test(_matchStr);
if(_urlMatch){
- _urlCallBacks.push(this.urlCallBacks[i]);
- }
- }
- if(_urlCallBacks.length !== 0){
- for(i=0;i<_urlCallBacks.length;i++){
- _urlCallBack = _urlCallBacks[i];
- _urlCallBack.show();
- if(this.prevMatchStrs.indexOf(_matchStr)!==-1){
- this.prevMatchStrs.push( _matchStr );
+ _urlCallBack = this.urlCallBack[i];
+ if(this.prevCallBack){
+ this.prevCallBack.hide();
}
+ _urlCallBack.show();
+ this.prevCallBack = _urlCallBack;
+ this.prevmatchStr = _matchStr;
+ return 1;
}
- var _prevCallBack;
- for(i=0;i<this.prevCallBacks.length;i++){
- _prevCallBack = this.prevCallBacks[i];
- if(_urlCallBacks.indexOf(_prevCallBack) === -1){
- this.prevCallBacks[i].hide();
- }
- }
- this.prevCallBacks = _urlCallBacks;
- return 1;
}
- if(this.defaultCallBacks.length !== 0){
- if(this.prevCallBacks.length !== 0){
- for(i=0;i<this.prevCallBacks.length;i++){
- this.prevCallBacks[i].hide();
- }
+ if(this.defaultCallBack){
+ if(this.prevCallBack){
+ this.prevCallBack.hide();
}
- this.prevCallBacks = [];
- for(i=0;i<this.defaultCallBacks.length;i++){
- this.defaultCallBacks[i].show();
- this.prevCallBacks.push( this.defaultCallBacks[i] );
- }
+ this.defaultCallBack.show();
+ this.prevCallBack = this.defaultCallBack;
}
return -1;
},
refresh: function(){
var _value = this.value;
if(_value.length === 0){ return; }
- if(window.location.href !== _value){
- window.location.href = _value;
+ if (!this.serverValue && this.valueObj.id !== this.clientValue.id) {
+ this.clientValue.die();
}
+ if(location.href !== _value){
+ location.href = _value;
+ }
this.checkMatch( _value );
},
onIdle: function(){
if(!this['valueObj']){return;}
- var _href = window.location.href;
- if(_href!==this.value){
+ var _href = location.href;
+ if(_href!==this.valueObj.value){
this.setValue(_href);
}
}
});