Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. function bubble(content, triggerElm){
  2. this.element = $('<div class="bubble" />').html(content);
  3. this.element.css(.....) // here is positioned based on triggerElm
  4. }
  5.  
  6. bubble.prototype.show = function(){
  7. $(document).on('click', this._click.bind(this));
  8. this.element.css(....)
  9. };
  10.  
  11. bubble.prototype.hide = function(){
  12. $(document).off('click', this._click.bind(this));
  13. this.element.css(....)
  14. };
  15.  
  16. bubble.prototype._click = function(event){
  17. console.log('click', this);
  18.  
  19. if(this.element.is(event.target) || (this.element.has(event.target).length > 0))
  20. return true;
  21.  
  22. this.hide();
  23. };
  24.  
  25. var b = new bubble();
  26. b.show();
  27. b.hide();
  28.  
  29. function bubble(content, tiggerElm) {
  30. var element = $('<div class="bubble" />').html(content);
  31. element.css(.....); // here is positioned based on triggerElm
  32.  
  33. function click(event) {
  34. console.log('click', element);
  35. if (element.is(event.target) ||
  36. element.has(event.target).length > 0) {
  37. return true;
  38. }
  39. hide();
  40. }
  41.  
  42. function show() {
  43. $(document).on('click', click);
  44. element.css(....);
  45. }
  46.  
  47. function hide() {
  48. $(document).off('click', click);
  49. element.css(....);
  50. }
  51.  
  52. return {
  53. show: show,
  54. hide: hide
  55. };
  56. }
  57.  
  58. var b1 = bubble(..., ...);
  59. b1.show();
  60.  
  61. var b2 = bubble(..., ...);
  62. b2.show();
  63.  
  64. $(document).on('click.name', test.bind(this));
  65. $(document).off('click.name');
  66.  
  67. var test = function(){
  68. console.log('click');
  69. };
  70.  
  71. $(document).on('click', $.proxy(test, this));
  72. $(document).off('click', $.proxy(test, this));
  73.  
  74. var test = function(){
  75. console.log('click');
  76. };
  77.  
  78. var newFunct = test.bind(this);
  79. $(document).on('click', newFunct );
  80. $(document).off('click', newFunct );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement