Permalink
Browse files

Updated this.on() method to take target even dispatcher.

  • Loading branch information...
Alex Gorbatchev
Alex Gorbatchev committed Dec 29, 2011
1 parent 723e635 commit b4eb663b21b49444847dac193ac24a770d31b154
Showing with 31 additions and 20 deletions.
  1. +16 −7 src/js/textext.core.js
  2. +2 −1 src/js/textext.plugin.arrow.js
  3. +6 −5 src/js/textext.plugin.autocomplete.js
  4. +7 −7 src/js/textext.plugin.tags.js
View
@@ -500,22 +500,27 @@
* @author agorbatchev
* @date 2011/08/09
*/
- function hookupEvents(args)
+ function hookupEvents()
{
- var self = this,
+ var args = slice.apply(arguments),
+ self = this,
+ target = args.length === 1 ? self : args.shift(),
event
;
- function bind(self, event, handler)
+ args = args[0] || {};
+
+ function bind(event, handler)
{
- self.bind(event, function()
+ target.bind(event, function()
{
+ // apply handler to our PLUGIN object, not the target
return handler.apply(self, arguments);
});
}
for(event in args)
- bind(self, event, args[event]);
+ bind(event, args[event]);
};
function formDataObject(input, form)
@@ -833,8 +838,10 @@
/**
* Allows to add multiple event handlers which will be execued in the scope of the current object.
*
- * @signature TextExt.on(handlers)
+ * @signature TextExt.on([target], handlers)
*
+ * @param target {Object} **Optional**. Target object which has traditional `bind(event, handler)` method.
+ * Handler function will still be executed in the current object's scope.
* @param handlers {Object} Key/value pairs of event names and handlers, eg `{ event: handler }`.
*
* @author agorbatchev
@@ -1215,8 +1222,10 @@
/**
* Allows to add multiple event handlers which will be execued in the scope of the current object.
*
- * @signature TextExtPlugin.on(handlers)
+ * @signature TextExt.on([target], handlers)
*
+ * @param target {Object} **Optional**. Target object which has traditional `bind(event, handler)` method.
+ * Handler function will still be executed in the current object's scope.
* @param handlers {Object} Key/value pairs of event names and handlers, eg `{ event: handler }`.
*
* @author agorbatchev
@@ -68,7 +68,8 @@
self.baseInit(core, DEFAULT_OPTS);
- self.core().wrapElement().append(self._arrow = arrow = $(self.opts(OPT_HTML_ARROW)));
+ self._arrow = arrow = $(self.opts(OPT_HTML_ARROW));
+ self.core().wrapElement().append(arrow);
arrow.bind('click', function(e) { self.onArrowClick(e); });
};
@@ -265,11 +265,12 @@
container = $(self.opts(OPT_HTML_DROPDOWN));
container.insertAfter(input);
- container
- .bind('mouseover', function(e) { self.onMouseOver(e); })
- .bind('click', function(e) { self.onClick(e); })
- .addClass('text-position-' + self.opts(OPT_POSITION))
- ;
+ self.on(container, {
+ mouseover : self.onMouseOver,
+ click : self.onClick
+ });
+
+ container.addClass('text-position-' + self.opts(OPT_POSITION));
$(self).data('container', container);
@@ -164,14 +164,14 @@
getFormData : self.onGetFormData
});
- container
- .click(function(e) { self.onClick(e) })
- .mousemove(function(e) { self.onContainerMouseMove(e) })
- ;
+ self.on(container, {
+ click : self.onClick,
+ mousemove : self.onContainerMouseMove
+ });
- input
- .mousemove(function(e) { self.onInputMouseMove(e) })
- ;
+ self.on(input, {
+ mousemove : self.onInputMouseMove
+ });
}
self._originalPadding = {

0 comments on commit b4eb663

Please sign in to comment.