Browse Source

Icon select: load images when the control becomes visible

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2846 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 years ago
parent
commit
77007150eb
1 changed files with 21 additions and 5 deletions
  1. 21 5
      js/icon_select.js

+ 21 - 5
js/icon_select.js

@@ -46,6 +46,15 @@ $(function()
 				this.oUploadBtn.click( function() { me._upload_dlg(); } );
 				this.oButton.after(this.oUploadBtn);
 			}
+			var id = this.element.attr('id');
+			$('#event_bus').bind('tabshow.itop-icon-select'+id, function(event) {
+				// Compute the offsetX the first time the 'element' becomes visible...
+				var bVisible = me.element.parent().is(':visible');
+				if ((me.options.offsetX == null) && (bVisible))
+				{
+					me._refresh();
+				}
+			});
 			this.oUploadDlg = null;
 			this._refresh();
 		},
@@ -53,13 +62,20 @@ $(function()
 		// called when created, and later when changing options
 		_refresh: function()
 		{
-			if (this.options.items.length > 0)
+			if (!this.element.parent().is(':visible'))
 			{
-				this.element.val(this.options.items[this.options.current_idx].value);
-				this.oImg.attr('src', this.options.items[this.options.current_idx].icon);
-				this.oLabel.text(this.options.items[this.options.current_idx].label);
+				this.options.offsetX = null; // Menu needs to be reconstructed when the button becomes visible
+			}
+			else
+			{
+				if (this.options.items.length > 0)
+				{
+					this.element.val(this.options.items[this.options.current_idx].value);
+					this.oImg.attr('src', this.options.items[this.options.current_idx].icon);
+					this.oLabel.text(this.options.items[this.options.current_idx].label);
+				}
+				this._create_menu();
 			}
-			this._create_menu();
 		},
 		_create_menu: function()
 		{