Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($, window, document, undefined){
- //handy log function
- window.log = function(){
- log.history = log.history || [];
- log.history.push(arguments);
- if(this.console)
- console.log( Array.prototype.slice.call(arguments) );
- };
- $.extend($.expr[':'], {
- lookup: function(a){return a.getAttribute('t2-ui-role') === 'lookup';}
- });
- var Lookup = {
- options: {
- version: '0',
- icon: 'search'
- },
- currentlyActiveLookup: null,
- _create: function(){
- var self = this,
- el = self.element;
- self.options.icons.primary = self.icon;
- //log('element IS'+(el.jquery?'':' NOT')+' jQuery object');
- $.ui.button.prototype._create.apply(self);
- self._setOption('icons', {
- primary:'ui-icon-'+self.options.icon,
- secondary:null
- });
- el.bind('click', function(e){
- e.preventDefault();
- e.stopPropagation();
- $(e.target).trigger('lookup.t2', {lookup:this});
- self._trigger('activated', null, {lookup:this});
- return false;
- });
- },
- _init: function(){ log('_init'); },
- boom: function(){ log('nice, you boom me!'); }
- };
- $.widget('t2.lookup', $.ui.button, Lookup);//NS doesn't mean something yet
- //====================== RUN CODE HERE ======================
- $('#id_ref_button').button({icons:{primary: "ui-icon-search"}});
- var l1 = $(':lookup').lookup({
- activated: function(e, data){ //tightly coupled
- log('activated callback fired');
- log(' '+data, data.lookup);
- }
- });
- // a-la Observer Pattern
- $('body').bind('lookup.t2', function(e, data){ //loosely coupled v.1
- log('lookup.t2 event catched');
- log(' '+data, data ? data.lookup : 'nope');
- });
- $('body').bind('lookupactivated', function(e, data){ //loosely coupled v.2
- log('lookupactivated event catched'); //why not activated.lookup?
- log(' '+data, data.lookup);
- });
- l1.lookup('boom');
- })(jQuery, window, window.document)
Add Comment
Please, Sign In to add comment