/[drupal]/contributions/modules/ui/javascript/ui.magnifier.js
ViewVC logotype

Diff of /contributions/modules/ui/javascript/ui.magnifier.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Sun Sep 2 20:21:42 2007 UTC revision 1.2, Mon Sep 17 03:42:34 2007 UTC
# Line 3  Line 3 
3          //If the UI scope is not availalable, add it          //If the UI scope is not availalable, add it
4          $.ui = $.ui || {};          $.ui = $.ui || {};
5    
6          $.fn.magnify = function(options) {          //Make nodes selectable by expression
7            $.extend($.expr[':'], { magnifier: "(' '+a.className+' ').indexOf(' ui-magnifier ')" });
8    
9            //Macros for external methods that support chaining
10            var methods = "destroy,enable,disable,reset".split(",");
11            for(var i=0;i<methods.length;i++) {
12                    var cur = methods[i], f;
13                    eval('f = function() { var a = arguments; return this.each(function() { if(jQuery(this).is(".ui-magnifier")) jQuery.data(this, "ui-magnifier")["'+cur+'"](a); }); }');
14                    $.fn["magnifier"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f;
15            };
16    
17            //get instance method
18            $.fn.magnifierInstance = function() {
19                    if($(this[0]).is(".ui-magnifier")) return $.data(this[0], "ui-magnifier");
20                    return false;
21            };
22    
23            $.fn.magnifier = function(options) {
24                  return this.each(function() {                  return this.each(function() {
25                          new $.ui.magnifier(this,options);                          new $.ui.magnifier(this,options);
26                  });                  });
27          };          };
28    
   
29          $.ui.magnifier = function(el,options) {          $.ui.magnifier = function(el,options) {
30    
31                  var self = this; this.items = []; this.element = el;                  var self = this; this.items = []; this.element = el;
32                  this.options = options || {}; var o = this.options;                  this.options = options || {}; var o = this.options;
33                    $.data(el, "ui-magnifier", this);
34                    $(el).addClass("ui-magnifier");
35    
36                  o.distance = o.distance || 150;                  o.distance = o.distance || 150;
37                  o.magnification = o.magnification || 2;                  o.magnification = o.magnification || 2;
# Line 42  Line 60 
60                          };                          };
61                  }                  }
62    
63                  $(document).bind("mousemove", function(e) {                  this.moveEvent = function(e) { if(!self.disabled) self.magnify.apply(self, [e]); }
64                          self.magnify.apply(self, [e]);                  $(document).bind("mousemove", this.moveEvent);
                 });  
65    
66                  if(o.click) { //If onclick callback is available                  if(o.click) { //If onclick callback is available
67    
68                          $(el).bind('click', function(e) {                          this.clickEvent = function(e) { if(!self.disabled) o.click.apply(this, [e, { options: self.options, current: self.current[0], currentOffset: self.current[1] }]); }
69                                  o.click.apply(this, [e, { options: self.options, current: self.current[0], currentOffset: self.current[1] }]);                          $(el).bind('click', this.clickEvent);
                         })  
70                  }                  }
71    
72          }          }
73    
74          $.extend($.ui.magnifier.prototype, {          $.extend($.ui.magnifier.prototype, {
75                    destroy: function() {
76                            $(this.element).removeClass("ui-magnifier").removeClass("ui-magnifier-disabled");
77                            $(document).unbind("mousemove", this.moveEvent);
78                            if(this.clickEvent) $(this.element).unbind("click", this.clickEvent);
79                    },
80                    enable: function() {
81                            $(this.element).removeClass("ui-magnifier-disabled");
82                            this.disabled = false;
83                    },
84                    disable: function() {
85                            $(this.element).addClass("ui-magnifier-disabled");
86                            this.reset();
87                            this.disabled = true;
88                    },
89                  reset: function(e) {                  reset: function(e) {
90    
91                          var o = this.options;                          var o = this.options;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2