LSform : preserve current tab between view, modify and create pages

This commit is contained in:
Benjamin Renard 2014-11-24 23:07:30 +01:00
parent bb09c81243
commit c9bd4b7c65

View file

@ -97,6 +97,33 @@ var LSform = new Class({
document.getElement('li.LSform_layout').getFirst('a').fireEvent('click'); document.getElement('li.LSform_layout').getFirst('a').fireEvent('click');
} }
} }
var checkUrl = new RegExp('^(modify|create|view).php');
document.getElements('a.LSview-actions').each(function(a) {
if (checkUrl.exec(a.get('href'))) {
a.addEvent('click',this.onActionBtnClick.bindWithEvent(this,a));
}
},this);
},
onActionBtnClick: function(event,a) {
if (!location.hash) {
return true;
}
if ($type(event)) {
event = new Event(event);
event.stop();
}
var href=a.href;
var checkExistingHash=new RegExp('^([^#]+)#[^#]+$');
var cur = checkExistingHash.exec(href);
if (cur) {
href=cur[1]+location.hash;
}
else {
href=href+location.hash;
}
window.location=href;
}, },
getLayoutBtn: function(div) { getLayoutBtn: function(div) {
@ -108,13 +135,21 @@ var LSform = new Class({
return $('LSform_layout_btn_'+name[1]); return $('LSform_layout_btn_'+name[1]);
}, },
getLayout: function(btn) { getLayoutNameFromBtn: function(btn) {
var getName = new RegExp('LSform_layout_btn_(.*)'); var getName = new RegExp('LSform_layout_btn_(.*)');
var name = getName.exec(btn.id); var name = getName.exec(btn.id);
if (!name) { if (!name) {
return; return;
} }
return $('LSform_layout_div_'+name[1]); return name[1];
},
getLayout: function(btn) {
var name = this.getLayoutNameFromBtn(btn);
if (!name) {
return;
}
return $('LSform_layout_div_'+name);
}, },
onTabBtnClick: function(event,li) { onTabBtnClick: function(event,li) {
@ -137,6 +172,10 @@ var LSform = new Class({
this._currentTab = li; this._currentTab = li;
li.addClass('LSform_layout_current'); li.addClass('LSform_layout_current');
var a=li.getElement('a');
if ($type(a)) {
location.hash='#'+this.getLayoutNameFromBtn(li);
}
var div = this.getLayout(li); var div = this.getLayout(li);
if ($type(div)) { if ($type(div)) {
div.addClass('LSform_layout_current'); div.addClass('LSform_layout_current');