document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <script src="../main.js" type="text/javascript"></script>
  2. <script>
  3. JPLT.Class.create("JPLT.Object", Object,
  4.     function() {},
  5.  
  6.     {
  7.         listeners: {},
  8.        
  9.         addEventListener:function(eventName, func) {
  10.             if (this.listeners[eventName]) {
  11.                 this.listeners[eventName].push(func);
  12.             }
  13.             else {
  14.                 this.listeners[eventName] = [func];
  15.             }
  16.         },
  17.        
  18.         fireEvent:function(eventName, args) {
  19.             var handlers = this.listeners[eventName];
  20.            
  21.             if (handlers) {
  22.                 for (var i=0; i<handlers.length; i++) {
  23.                     handlers[i](args);
  24.                 }
  25.             }
  26.         },
  27.        
  28.         log:function() {
  29.             try {
  30.                 console.log.apply( console, arguments );
  31.             }
  32.             catch(e) {
  33.                 try {
  34.                     opera.postError.apply( opera, arguments );
  35.                 } catch(e){}
  36.             }
  37.         },
  38.  
  39.         superCall:function(functionName, args) {
  40.             return this.superClass.prototype[functionName].call(this,args);
  41.         },
  42.  
  43.         superConstruct:function(args) {
  44.             this.superClass.call(this,args);
  45.         },
  46.  
  47.         concatArgs: function(args,dargs) {
  48.             var result = [];
  49.            
  50.             for (var i=0; i<args.length; i++) {
  51.                 result.push(args[i]);
  52.             }
  53.             for (var i=1; i<dargs.length; i++) {
  54.                 result.push(dargs[i]);
  55.             }
  56.            
  57.             return result;
  58.         },
  59.  
  60.         delegate: function(func) {
  61.             var self = this;
  62.             var dargs = arguments;
  63.  
  64.             var f = function() { func.apply(self,self.concatArgs(arguments,dargs)); }
  65.             return f;
  66.         }
  67.     }
  68. );
  69.  
  70. JPLT.Class.create("JPLT.ImageLens",JPLT.Object,
  71.     function() {
  72.         this.createElement();
  73.         this.loadImage();
  74.         this.paint();
  75.     },
  76.  
  77.     {
  78.         loadImage: function() {
  79.             this.log("Loading image...");
  80.             this.image = new Image();
  81.             this.image.addEventListener("load", this.delegate(this.imageLoaded), true);
  82.             this.image.src = "image.jpg";
  83.         },
  84.        
  85.         imageLoaded: function() {
  86.             this.log("Image loaded.");
  87.             this.copyImageToCanvas();
  88.            
  89.             this.element.addEventListener("mousemove", this.delegate(this.mouseMoved), true);
  90.         },
  91.        
  92.         context: function() {
  93.             return this.element.getContext("2d");
  94.         },
  95.        
  96.         copyImageToCanvas: function() {
  97.             var ctx = this.context();
  98.             ctx.drawImage(this.image,0,0,640,640); 
  99.         },
  100.        
  101.         zoom: function(x,y,w,h) {
  102.             var ctx = this.context();
  103.             ctx.drawImage(this.image,x*3.65,y*3.65,w,h,x,y,w*3.65,h*3.65);
  104.         },
  105.        
  106.         constrain: function(n,min,max) {
  107.             if (n<min)
  108.                 n = min;
  109.             else if (n>max)
  110.                 n = max;
  111.                
  112.             return n;
  113.         },
  114.        
  115.         mouseMoved: function(e) {
  116.             var x = this.constrain(e.clientX - 25, 1, 640);
  117.             var y = this.constrain(e.clientY - 25, 1, 640);
  118.                        
  119.             this.copyImageToCanvas();
  120.             this.zoom(x,y,50,50);
  121.         },
  122.        
  123.         createElement: function() {
  124.             this.element = document.createElement("canvas");
  125.  
  126.             this.element.width = "640";
  127.             this.element.height = "640";
  128.             this.element.style.border = "1px solid #ccc";
  129.             this.element.src = "image.jpg";
  130.            
  131.             return this.element;
  132.         },
  133.  
  134.         paint: function() {
  135.             var body = document.documentElement || document.body;
  136.             body.appendChild(this.element);
  137.         }
  138.     }
  139. );
  140.  
  141.     var logo = new JPLT.ImageLens();
  142. </script>
  143. <h2>Wait for the big ass image to load and then mouse over to zoom.  Not IE friendly.</h2>
');