Alexander Nazarov (nfokz) wrote in changelog,
Alexander Nazarov
nfokz
changelog

[ljcom] r12419: LJSUP-13138: Fix _off method for basicWi...

Committer: anazarov
LJSUP-13138: Fix _off method for basicWidget pub/sub system
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-08-06 05:45:49 UTC (rev 12418)
+++ trunk/htdocs/js/jquery/jquery.lj.basicWidget.js	2012-08-06 06:35:49 UTC (rev 12419)
@@ -97,7 +97,7 @@
 		 * @param {Function} callback Function that should be fired on the event.
 		 */
 		_on: function( type, callback ) {
-			if( !( type in __callbacks ) ) {
+			if (!__callbacks.hasOwnProperty(type)) {
 				__callbacks[ type ] = [];
 			}
 
@@ -127,12 +127,15 @@
 		 *     callbacks of this instance from the subscription on this type of event.
 		 */
 		_off: function( type, callback ) {
-			if( !( type in __callbacks ) ) { return; }
+			if (!__callbacks.hasOwnProperty(type)) {
+				return;
+			}
 
 			var cbs = __callbacks[ type ];
-			for( var i = 0; i < cbs.length; ++i ) {
-				if( ( callback && cbs[ i ].fn === callback ) || ( cbs[i].owner === this ) ) {
-					cbs.splice( i, 1 );
+
+			for (var i = 0; i < cbs.length; ++i) {
+				if ((cbs[i].fn === callback) || (!callback && cbs[i].owner === this)) {
+					cbs.splice(i--, 1);
 				}
 			}
 		},
@@ -189,7 +192,7 @@
 				cbs = __callbacks[ type ];
 				for( var i = 0; i < cbs.length; ++i ) {
 					if( cbs[i].owner === this ) {
-						cbs.splice( i, 1 )
+						cbs.splice( i--, 1 )
 					}
 				}
 			}

Tags: anazarov, js, ljcom, nfokz
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