Guest User

Untitled

a guest
Jun 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. (function($, window, document, undefined){
  2. //handy log function
  3. window.log = function(){
  4. log.history = log.history || [];
  5. log.history.push(arguments);
  6. if(this.console)
  7. console.log( Array.prototype.slice.call(arguments) );
  8. };
  9.  
  10. $.extend($.expr[':'], {
  11. lookup: function(a){return a.getAttribute('t2-ui-role') === 'lookup';}
  12. });
  13.  
  14. var Lookup = {
  15. options: {
  16. version: '0',
  17. icon: 'search'
  18. },
  19. currentlyActiveLookup: null,
  20. _create: function(){
  21. var self = this,
  22. el = self.element;
  23. self.options.icons.primary = self.icon;
  24. //log('element IS'+(el.jquery?'':' NOT')+' jQuery object');
  25.  
  26. $.ui.button.prototype._create.apply(self);
  27.  
  28. self._setOption('icons', {
  29. primary:'ui-icon-'+self.options.icon,
  30. secondary:null
  31. });
  32.  
  33. el.bind('click', function(e){
  34. e.preventDefault();
  35. e.stopPropagation();
  36. $(e.target).trigger('lookup.t2', {lookup:this});
  37. self._trigger('activated', null, {lookup:this});
  38. return false;
  39. });
  40. },
  41. _init: function(){ log('_init'); },
  42. boom: function(){ log('nice, you boom me!'); }
  43. };
  44.  
  45. $.widget('t2.lookup', $.ui.button, Lookup);//NS doesn't mean something yet
  46.  
  47. //====================== RUN CODE HERE ======================
  48. $('#id_ref_button').button({icons:{primary: "ui-icon-search"}});
  49.  
  50. var l1 = $(':lookup').lookup({
  51. activated: function(e, data){ //tightly coupled
  52. log('activated callback fired');
  53. log(' '+data, data.lookup);
  54. }
  55. });
  56. // a-la Observer Pattern
  57. $('body').bind('lookup.t2', function(e, data){ //loosely coupled v.1
  58. log('lookup.t2 event catched');
  59. log(' '+data, data ? data.lookup : 'nope');
  60. });
  61. $('body').bind('lookupactivated', function(e, data){ //loosely coupled v.2
  62. log('lookupactivated event catched'); //why not activated.lookup?
  63. log(' '+data, data.lookup);
  64. });
  65.  
  66. l1.lookup('boom');
  67.  
  68. })(jQuery, window, window.document)
Add Comment
Please, Sign In to add comment