From c9bd4b7c650948cdded9397f7ec4ac8a3e97b021 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 24 Nov 2014 23:07:30 +0100 Subject: [PATCH] LSform : preserve current tab between view, modify and create pages --- public_html/includes/js/LSform.js | 43 +++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/public_html/includes/js/LSform.js b/public_html/includes/js/LSform.js index 03c2b004..34b49588 100644 --- a/public_html/includes/js/LSform.js +++ b/public_html/includes/js/LSform.js @@ -97,6 +97,33 @@ var LSform = new Class({ 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) { @@ -108,13 +135,21 @@ var LSform = new Class({ return $('LSform_layout_btn_'+name[1]); }, - getLayout: function(btn) { + getLayoutNameFromBtn: function(btn) { var getName = new RegExp('LSform_layout_btn_(.*)'); var name = getName.exec(btn.id); if (!name) { 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) { @@ -137,6 +172,10 @@ var LSform = new Class({ this._currentTab = li; li.addClass('LSform_layout_current'); + var a=li.getElement('a'); + if ($type(a)) { + location.hash='#'+this.getLayoutNameFromBtn(li); + } var div = this.getLayout(li); if ($type(div)) { div.addClass('LSform_layout_current');