From b1f48200e61b7c76a1e3ef5507467776a42534e3 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 17 Oct 2014 12:14:44 +0000 Subject: [PATCH] fixed color-picker shown twice if used in a tab-widget after apply, backport of r48992: disabling immediate direct call to loadingFinished() for selected tab seems to have no recognisable impact and some widgets, eg. color-picker have problems with calling doLoadingFinished twice r49047: change tab loading again to initialise visible tab immediatly and gard et2_color / jPicker against being initialised twice --- etemplate/js/et2_widget_color.js | 21 ++++++++++++++------- etemplate/js/et2_widget_tabs.js | 5 +++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/etemplate/js/et2_widget_color.js b/etemplate/js/et2_widget_color.js index 5be9c5cc63..9a1fde48b5 100644 --- a/etemplate/js/et2_widget_color.js +++ b/etemplate/js/et2_widget_color.js @@ -99,7 +99,11 @@ var et2_color = et2_inputWidget.extend( this._super.call(this, arguments); }, - doLoadingFinished: function() { + doLoadingFinished: function() + { + // as tabs can cause a double loading, we check here if jPicker is already initialised + if (this.get_jPicker()) return; + this._super.apply(this, arguments); var self = this; @@ -130,7 +134,7 @@ var et2_color = et2_inputWidget.extend( setTimeout(function() { //Regex to exclude invalid charachters from class identifier name, to be able to address the class name with jquery selector later. var regExClassName = /[\[\]']+/g; - + // Make the buttons look like all the others jQuery("div.jPicker :button").addClass("et2_button et2_button_text"); @@ -163,14 +167,17 @@ var et2_color = et2_inputWidget.extend( /** * Get the jPicker object for this widget, so further things can be done to it + * + * Id of jPicker node is either our id+'_jPicker' or our dom_id (no idea why). */ get_jPicker: function() { - if(jQuery.jPicker.List.length) + for(var i=0; i < jQuery.jPicker.List.length; ++i) { - var self = this; - return jQuery(jQuery.jPicker.List.filter(function(elem,index) { - return (elem && elem.id == self.id + "_jPicker"); - }))[0]; + var node = jQuery.jPicker.List[i]; + if (node && (node.id == this.id+'_jPicker' || node.id == this.dom_id)) + { + return node; + } } return null; }, diff --git a/etemplate/js/et2_widget_tabs.js b/etemplate/js/et2_widget_tabs.js index 407fd8e342..30fa61c882 100644 --- a/etemplate/js/et2_widget_tabs.js +++ b/etemplate/js/et2_widget_tabs.js @@ -242,6 +242,7 @@ var et2_tabbox = et2_valueWidget.extend([et2_IInput], window.setTimeout(function() { for (var i = 0; i < tabs.tabData.length; i++) { + if (i == tabs.selected_index) continue; tabs._loadTab(i,promises); } jQuery.when.apply(jQuery,promises).then(function() { @@ -343,7 +344,7 @@ var et2_tabbox = et2_valueWidget.extend([et2_IInput], /** * Gets the index of the currently active tab - * + * * @returns {number} */ get_active_tab: function() { @@ -352,7 +353,7 @@ var et2_tabbox = et2_valueWidget.extend([et2_IInput], /** * Sets the currently active tab by index - * + * * @param {number} _idx */ setActiveTab: function(_idx) {