can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[ljcom] r11920: LJSUP-12136: Implement mixins for jquery...

Committer: dpetrov
LJSUP-12136: Implement mixins for jquery ui widgets
U   trunk/htdocs/js/jquery/jquery.lj.basicWidget.js
Modified: trunk/htdocs/js/jquery/jquery.lj.basicWidget.js
===================================================================
--- trunk/htdocs/js/jquery/jquery.lj.basicWidget.js	2012-05-11 10:58:42 UTC (rev 11919)
+++ trunk/htdocs/js/jquery/jquery.lj.basicWidget.js	2012-05-11 11:52:00 UTC (rev 11920)
@@ -54,6 +54,8 @@
 			 * @type Object
 			 */
 			this.__suppressedEvents = {};
+			this.__modules = {};
+			this._locked = false;
 		},
 
 		/**
@@ -220,6 +222,57 @@
 		 */
 		_tmpl: function(name, data) {
 			return LJ.UI.template(this.options.templates[name], data);
-		}
+		},
+
+		/**
+		 * Use a mixin with the widget instance.
+		 *
+		 * @param {string} name Mixin name. A Mixin should be registered with LJ.UI.mixin.
+		 * @param {Object=} options Options to pass to the mixin.
+		 */
+		_use: function(name, options) {
+			var module;
+
+			if (module = LJ.UI.mixin(name)) {
+				if (this.__modules.hasOwnProperty(name)) {
+					LJ.console.log('Warn: Module ', name, ' has already been registered for ', this.widgetName);
+					return;
+				}
+
+				this.__modules[name] = module.call(this, jQuery, options);
+			} else {
+				LJ.console.log('Warn: Module ', name, ' has not been loaded yet');
+			}
+		},
+
+		/**
+		 * Return mixin object. Object should contain public api provided with this mixin.
+		 *
+		 * @param {string} name Mixin name.
+		 */
+		_: function(name) {
+			if (this.__modules.hasOwnProperty(name)) {
+				return this.__modules[name];
+			} else {
+				return null;
+			}
+		},
+
+		/**
+		 * Lock the widget. The method should be used to block widget UI during long operations, e.g. ajax requests.
+		 */
+		_lock: function() { this._locked = true; },
+
+		/**
+		 * Unlock the widget.
+		 */
+		_unlock: function() { this._locked = false; },
+
+		/**
+		 * Check whether widget is locked now.
+		 *
+		 * @return {boolean} The lock state
+		 */
+		locked: function() { return this._locked; }
 	} );
 } )( jQuery );

Tags: can3p, dpetrov, js, ljcom
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments