Parcourir la source

Second commint

Support for divs and iframe
Inuyaksa il y a 13 ans
Parent
commit
be59cc1c2a
7 fichiers modifiés avec 958 ajouts et 69 suppressions
  1. 3 1
      README
  2. 185 0
      demo/iframe/lgpl-3.0-standalone.html
  3. 15 0
      demo/js/jquery.license.txt
  4. 15 0
      demo/js/jquery.min.js
  5. 415 0
      demo/js/jquery.nicescroll.js
  6. 110 0
      demo/test1.html
  7. 215 68
      jquery.nicescroll.js

+ 3 - 1
README

@@ -1,11 +1,13 @@
 jquery.nicescroll
+v. 1.5.0 10-30-2011
 copyright 2011 InuYaksa*2011
 licensed under the MIT
 https://github.com/inuyaksa/jquery.nicescroll
 
 
 A jquery (since 1.5) plugin for nice scrollbars as ios/mobile style.
-Compatible with Firefox 4+, Chrome 5+, Safari 5+, Opera 10+, IE 8+.
+It supports DIVs, IFrames and document page (body) scrollbars.
+Compatible with Firefox 4+, Chrome 5+, Safari 4+, Opera 10+, IE 8+.
 
 
 

+ 185 - 0
demo/iframe/lgpl-3.0-standalone.html

@@ -0,0 +1,185 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>GNU Lesser General Public License v3.0 - GNU Project - Free Software Foundation (FSF)</title>
+ <link rel="alternate" type="application/rdf+xml" href="http://www.gnu.org/licenses/lgpl-3.0.rdf"> 
+</head>
+<body>
+<h3 style="text-align: center;">GNU LESSER GENERAL PUBLIC LICENSE</h3>
+<p style="text-align: center;">Version 3, 29 June 2007</p>
+
+<p>Copyright © 2007 Free Software Foundation, Inc.
+ &lt;<a href="http://fsf.org/">http://fsf.org/</a>&gt;</p><p>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.</p>
+
+<p>This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.</p>
+
+<h4><a name="section0"></a>0. Additional Definitions.</h4>
+
+<p>As used herein, “this License” refers to version 3 of the GNU Lesser
+General Public License, and the “GNU GPL” refers to version 3 of the GNU
+General Public License.</p>
+
+<p>“The Library” refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.</p>
+
+<p>An “Application” is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.</p>
+
+<p>A “Combined Work” is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the “Linked
+Version”.</p>
+
+<p>The “Minimal Corresponding Source” for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.</p>
+
+<p>The “Corresponding Application Code” for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.</p>
+
+<h4><a name="section1"></a>1. Exception to Section 3 of the GNU GPL.</h4>
+
+<p>You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.</p>
+
+<h4><a name="section2"></a>2. Conveying Modified Versions.</h4>
+
+<p>If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:</p>
+
+<ul>
+<li>a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or</li>
+
+<li>b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.</li>
+</ul>
+
+<h4><a name="section3"></a>3. Object Code Incorporating Material from Library Header Files.</h4>
+
+<p>The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:</p>
+
+<ul>
+<li>a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.</li>
+
+<li>b) Accompany the object code with a copy of the GNU GPL and this license
+   document.</li>
+</ul>
+
+<h4><a name="section4"></a>4. Combined Works.</h4>
+
+<p>You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:</p>
+
+<ul>
+<li>a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.</li>
+
+<li>b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.</li>
+
+<li>c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.</li>
+
+<li>d) Do one of the following:
+
+<ul>
+<li>0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.</li>
+
+<li>1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.</li>
+</ul></li>
+
+<li>e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)</li>
+</ul>
+
+<h4><a name="section5"></a>5. Combined Libraries.</h4>
+
+<p>You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:</p>
+
+<ul>
+<li>a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.</li>
+
+<li>b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.</li>
+</ul>
+
+<h4><a name="section6"></a>6. Revised Versions of the GNU Lesser General Public License.</h4>
+
+<p>The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.</p>
+
+<p>Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License “or any later version”
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.</p>
+
+<p>If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.</p>
+
+
+</body></html>

+ 15 - 0
demo/js/jquery.license.txt

@@ -0,0 +1,15 @@
+Original web page: http://jquery.org/license/
+
+The MIT License is recommended for most projects. It is simple and easy to understand and it places almost no restrictions on what you can do with a jQuery project.
+
+If the GPL suits your project better you are also free to use a jQuery project under that license.
+
+You don’t have to do anything special to choose one license or the other and you don’t have to notify anyone which license you are using. You are free to use a jQuery project in commercial projects as long as the copyright header is left intact.
+Licenses
+
+    MIT License (More Information)
+    GPL (More Information)
+
+Sizzle
+
+The Sizzle selector engine (which is included inside the jQuery library) is held by the Dojo Foundation and is licensed under the MIT, GPL, and BSD licenses. 

Fichier diff supprimé car celui-ci est trop grand
+ 15 - 0
demo/js/jquery.min.js


+ 415 - 0
demo/js/jquery.nicescroll.js

@@ -0,0 +1,415 @@
+/* jquery.nicescroll
+-- versione 1.5.0
+-- copyright 2011 InuYaksa*2011
+-- licensed under the MIT
+--
+-- https://github.com/inuyaksa/jquery.nicescroll
+--
+*/
+
+(function($){
+
+  var domfocus = false;
+  var mousefocus = false;
+
+  var NiceScrollClass = function(myopt) {
+
+    var self = this;
+    
+    this.opt = {
+      doc:$("body"),
+      win:false,
+      zindex:9999,
+      cursoropacitymin:0,
+      cursoropacitymax:1,
+      cursorcolor:"#424242",
+      scrollspeed:60,
+      mousescrollstep:8*6,
+    };
+    
+    if (myopt) {
+      for(var a in self.opt) {
+        if (myopt[a]!==undefined) self.opt[a] = myopt[a];
+      }
+    }
+    
+    this.id = self.opt.doc[0].id||'';
+    this.doc = self.opt.doc;
+    this.ispage = (self.doc[0].nodeName=='BODY'||self.doc[0].nodeName=='HTML');    
+    this.docscroll = self.ispage?$(window):this.doc;
+    this.win = self.opt.win||this.docscroll;
+    
+    this.isiframe = (this.doc[0].nodeName == 'IFRAME');
+    
+    if (self.isiframe) {
+      this.docscroll = (this.doc[0].document)?$(this.doc[0].document.body):this.doc;
+      this.doc.load(function() {
+        var doc = 'contentDocument' in this? this.contentDocument : this.contentWindow.document;
+        self.docscroll = $(doc.body);
+        self.onResize();
+        $(doc.body).css({'overflow-y':'hidden'});
+        $(doc).scroll(self.onscroll);
+        self.bind(doc,"mousewheel",self.onmousewheel);
+        $(doc).keydown(self.onkeypress);
+      });
+    }
+    
+    this.view = false;
+    this.page = false;
+    
+    this.scroll = {x:0,y:0};
+    this.scrollratio = {x:0,y:0};    
+    this.cursorheight = 20;
+    this.scrollvaluemax = 0;
+    
+    do {
+      this.id = "ascrail"+Math.round(Math.random() * 99999);
+    } while (document.getElementById(this.id));
+    
+    this.rail = false;
+    this.cursor = false;
+    this.cursorfreezed = false;  
+    
+    this.hasfocus = false;
+    this.hasmousefocus = false;
+    
+    this.isie = (document.all && !document.opera);
+    
+    this.scrollTop = function(val) {
+      return (val === undefined) ? self.getScrollTop() : self.setScrollTop(val);
+    };
+    
+    this.getScrollTop = function() {
+      return self.docscroll.scrollTop();
+    };
+    this.setScrollTop = function(val) {
+      return self.docscroll.scrollTop(val);
+    };
+    
+    this.hasParent = function(e,id) {
+      var el = e.target||e||false;
+      while (el && el.id != id) {
+        el = el.parentNode||false;
+      }
+      return (el!==false);
+    };
+    
+    this.updateScrollBar = function() {
+      var pos = self.win.offset();
+      pos.top+=2;
+      pos.left+=self.win.outerWidth()-16;
+      self.rail.css({position:"absolute",top:pos.top,left:pos.left,height:self.win.outerHeight()});
+    };
+    
+    this.init = function() {
+      self.doc.css({'overflow-y':'hidden'});
+      var rail = $(document.createElement('div'));
+      rail.attr('id',self.id);
+      rail.css({"padding-left":"4px",width:"12px",'z-index':self.opt.zindex,opacity:self.cursoropacitymin});
+      self.rail = rail;
+      
+      if (self.ispage) {
+        rail.css({position:"fixed",top:"0px",right:"0px",height:"100%"});
+        self.doc.append(rail);
+      } else {
+        self.updateScrollBar();
+        $("body").append(rail);
+      }
+      
+      var cursor = $(document.createElement('div'));
+      cursor.css({
+        position:"relative",top:0,left:0,width:"8px",height:"0px",
+        'background-color':self.opt.cursorcolor,
+        border:"1px solid #fff",
+        '-webkit-border-radius':'4px',
+        '-moz-border-radius':'4px',
+        'border-radius':'4px'
+      });
+      self.cursor = cursor;
+      self.rail.append(cursor);
+      
+      self.win.resize(function(){self.onResize()});    
+      self.doc.resize(function(){self.onResize()});    
+      self.onResize();
+
+      self.rail.mousedown(function(e) {
+        self.rail.drag = {x:e.screenX,y:e.screenY,sx:self.scroll.x,sy:self.scroll.y};
+        return self.cancelEvent(e);
+      });
+      self.rail.mouseup(function() {
+        self.rail.drag = false;
+        return false;
+      });
+      
+      $(document).mouseup(function(e) {
+        self.rail.drag = false;      
+        self.hideCursor();
+      });
+      
+      $(document).mousemove(function(e) {
+        if (self.rail.drag) {
+          self.scroll.y = self.rail.drag.sy + (e.screenY-self.rail.drag.y);
+          if (self.scroll.y<0) self.scroll.y=0;
+          var my = self.scrollvaluemax;
+          if (self.scroll.y>my) self.scroll.y=my;
+          self.showCursor();
+          self.cursorfreezed = true;
+          self.doScroll(Math.round(self.scroll.y*self.scrollratio.y));          
+          return self.cancelEvent(e);
+        }
+      });
+      
+      self.rail.mouseenter(function() {
+        $(self.rail).animate({opacity:self.opt.cursoropacitymax});
+        self.rail.active = true;
+      });
+      self.rail.mouseleave(function() {
+        self.rail.active = false;
+        if (!self.rail.drag) self.hideCursor();
+      });
+      
+      if (!self.isiframe) self.bind(self.docscroll,"mousewheel",self.onmousewheel);
+      self.bind(self.rail,"mousewheel",self.onmousewheel);
+
+      if (!self.ispage) {
+        if (!self.win.attr("tabindex")) self.win.attr({"tabindex":(new Date()).getTime()});
+        self.win.focus(function(e) {          
+          domfocus = e.target.id||true;
+          self.hasfocus = true;
+          self.showCursor();
+          self.hideCursor();
+        });
+        self.win.blur(function(e) {
+          domfocus = false;
+          self.hasfocus = false;
+        });
+        self.win.mouseenter(function(e) {
+          mousefocus = e.target.id||true;
+          self.hasmousefocus = true;
+        });
+        self.win.mouseleave(function() {
+          mousefocus = false;
+          self.hasmousefocus = false;
+        });
+      };
+      
+      //Thanks to http://www.quirksmode.org !!
+      self.onkeypress = function(e) {
+        e = (e) ? e : window.e;
+        if (e.target&&/(INPUT|TEXTAREA|SELECT)/.test(e.target.nodeName)) return;
+        if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
+          var key = e.keyCode;     
+          var ret = true;
+          switch (key) {
+            case 38:
+            case 63233: //safari
+              self.doScrollBy(12);
+              ret = false;
+              break;
+            case 40:
+            case 63235: //safari
+              self.doScrollBy(-12);
+              ret = false;
+              break;
+            case 33:
+            case 63276: // safari
+              self.doScrollBy(self.view.h,true);
+              ret = false;
+              break;
+            case 34:
+            case 63277: // safari
+              self.doScrollBy(-self.view.h,true);
+              ret = false;
+              break;
+            case 36:
+            case 63273: // safari
+              self.doScrollTo(0,true);
+              ret = false;
+              break;
+            case 35:
+            case 63275: // safari
+              self.doScrollTo(self.page.h,true);
+              ret = false;
+              break;
+          }
+          if (!ret) return self.cancelEvent(e);
+        }
+      };
+      self.bind(document,"keydown",self.onkeypress);
+      
+    };
+    
+    this.showCursor = function() {
+      if (self.cursortimeout) {
+        clearTimeout(self.cursortimeout);
+        self.cursortimeout = 0;
+      }
+      self.rail.clearQueue().css({opacity:self.opt.cursoropacitymax});
+      self.cursor.css({height:self.cursorheight,top:self.scroll.y});
+    };
+    
+    this.hideCursor = function(tm) {
+      if (self.cursortimeout) return;
+      self.cursortimeout = setTimeout(function() {
+         if (self.rail.active) return;
+         $(self.rail).animate({opacity:self.opt.cursoropacitymin});
+         self.cursortimeout = 0;
+      },tm||800);
+    };
+    
+    this.getContentSize = function() {
+      var pg = (self.ispage) ?
+        {
+          w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
+          h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
+        } : 
+        {
+          w:self.docscroll[0].scrollWidth,
+          h:self.docscroll[0].scrollHeight
+        };
+
+      pg.w-=1;
+      pg.h-=1;
+
+      return pg;
+    };
+    
+    this.onResize = function() {
+      if (!self.ispage) self.updateScrollBar();
+    
+      self.view = {
+        w:(self.ispage) ? self.win.width() : self.win.innerWidth(),
+        h:(self.ispage) ? self.win.height() : self.win.innerHeight()
+      };
+      self.page = self.getContentSize();
+      
+      self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
+      
+      self.scrollvaluemax = self.view.h-self.cursorheight-2;
+      
+      self.scrollratio = {
+        x:0,
+        y:((self.page.h - self.view.h)/self.scrollvaluemax)
+      };
+      
+      self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
+      
+      self.showCursor();
+      self.hideCursor();
+    };
+   
+    this.bind = function(dom,name,fn,bubble) {  // fixing jquery bind
+      var el = (dom.length) ? dom[0] : dom;
+      if (el.addEventListener) {
+        el.addEventListener(name,fn,bubble||false);
+        if (name=='mousewheel') el.addEventListener("DOMMouseScroll",fn,bubble||false);
+      } 
+      else if (el.attachEvent) {
+        el.attachEvent(name,fn);
+      } 
+      else {
+        el["on"+name] = fn;
+      }
+    };
+    
+    // Thanks to http://www.switchonthecode.com !!
+    this.cancelEvent = function(e) {
+      e = e ? e : window.event;
+      if(e.stopPropagation) e.stopPropagation();
+      if(e.preventDefault) e.preventDefault();
+      e.cancelBubble = true;
+      e.cancel = true;
+      e.returnValue = false;
+      return false;
+    };
+   
+    this.onmousewheel = function(e) {
+      var delta = 0;
+      e = e ? e : window.event;
+      var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
+      if (delta) {
+        self.doScrollBy(delta*self.opt.mousescrollstep,true);
+      }
+      return self.cancelEvent(e);
+    };
+    
+    this.mousewheel = function(fn) {
+      if (!self.isie) self.bind(self.docscroll,'DOMMouseScroll',self.onmousewheel,false);      
+      self.bind(self.docscroll,'mousewheel',self.onmousewheel,false);
+      if (!self.ispage) {
+        if (!self.isie) self.bind(self.rail,'DOMMouseScroll',self.onmousewheel,false);      
+        self.bind(self.rail,'mousewheel',self.onmousewheel,false);
+      }
+    };
+    
+    this.doScroll = function(y) {
+      self.newscrolly = y;
+      if (self.timer) return;
+      self.timer = setInterval(function() {
+        var gp = self.newscrolly - self.getScrollTop();
+        var df = (gp>0) ? Math.ceil(gp/4) : Math.floor(gp/4);
+        var sc = self.getScrollTop()+df;
+        self.setScrollTop(sc);     
+        if (sc == self.newscrolly) {
+          clearInterval(self.timer);
+          self.timer = 0;        
+          self.cursorfreezed = false;
+        }
+      },self.opt.scrollspeed);
+      self.showCursor();
+      self.hideCursor();
+    };
+    
+    this.doScrollBy = function(stp,absolute) {
+      if (absolute) stp = Math.round(stp * 1/self.scrollratio.y);
+      var ny = self.scroll.y-stp;
+      if (ny<0) ny=0;
+      var my = self.scrollvaluemax;
+      if (ny>my) ny=my;
+      self.cursorfreezed = false;
+      self.doScroll(Math.floor(ny*self.scrollratio.y));
+    };
+
+    this.doScrollTo = function(pos,absolute) {
+      if (absolute) pos = Math.round(pos * 1/self.scrollratio.y);
+      ny=pos;
+      if (ny<0) ny=0;
+      var my = self.scrollvaluemax;
+      if (ny>my) ny=my;
+      self.cursorfreezed = false;
+      self.doScroll(Math.floor(ny*self.scrollratio.y));
+    };
+    
+    self.onscroll = function(e) {    
+      var tm = (new Date()).getTime();
+      if (!self.lastcontentcheck || self.lastcontentcheck<tm) {
+        self.lastcontentcheck=tm+500;
+        var pg = self.getContentSize();
+        if (pg.h!=self.page.h) self.onResize();        
+      }    
+      if (self.rail.drag) return;
+      if (!self.cursorfreezed) self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
+      self.showCursor();
+      self.hideCursor();
+    };
+    self.docscroll.scroll(function(e) {
+      self.onscroll(e);
+    });
+   
+    this.init();
+
+  };
+  
+  $.fn.niceScroll = function(opt) {
+    var ret = [];
+    if (opt===undefined) opt = {};
+    var docundef = (opt.doc===undefined);
+    this.each(function() {      
+      opt.doc = (docundef) ? $(this) : opt.doc;
+      ret.push(new NiceScrollClass(opt));
+    });
+    return (ret.length==1) ? ret[0] : ret;
+  };
+  
+})( jQuery );
+  

+ 110 - 0
demo/test1.html

@@ -0,0 +1,110 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>jQuery NiceScroll Test</title>
+<style type="text/css">
+#boxscroll {
+	padding: 40px;
+	height: 300px;
+	width: 300px;
+	border: 2px solid #00F;
+	overflow: auto;
+}
+#boxscroll2 {
+	padding: 40px;
+	height: 120px;
+	width: 500px;
+	border: 2px solid #F00;
+	overflow: auto;
+}
+#boxframe {
+  position:absolute;
+  top:8px;
+  left:420px;
+	border: 2px solid #0F0;
+}
+</style>
+
+<script src="js/jquery.min.js"></script>
+<script src="js/jquery.nicescroll.js"></script>
+
+<script>
+  $(document).ready(function() {
+    $("body").niceScroll();  // The document page (body)
+    $("#boxscroll").niceScroll({cursorcolor:"#00F",cursoropacitymax:0.7});  // First scrollable DIV
+    $("#boxscroll2").niceScroll({cursorcolor:"#F00",cursoropacitymax:0.7});  // Second scrollable DIV
+    $("#boxscroll3").niceScroll({cursorcolor:"#0F0",cursoropacitymax:0.7});  // Thi is an IFrame
+  });
+</script>
+
+</head>
+
+<body>
+<div id="boxscroll">
+  <h2> Package Description </h2>
+  <p>Release Date: August 10, 2010</p>
+  <p>The <a title="http://www.openprinting.org/show_driver.cgi?driver=hpijs" rel="nofollow" href="http://www.openprinting.org/show_driver.cgi?driver=hpijs">HPIJS</a> driver is the free, <a title="http://hplipopensource.com/hplip-web/index.html" rel="nofollow" href="http://hplipopensource.com/hplip-web/index.html">open-source driver</a> issued by HP for their DeskJet and LaserJet printers. For most <a title="" href="http://www.linuxfoundation.org/collaborate/workgroups/openprinting/macosx/hpijs#Printers">supported printers</a>,   this driver produces output quality equivalent to the proprietary HP   drivers. In photo mode, with photo paper, the output quality is very   high, especially for the HP DeskJet 990C and later models, which   auto-detect the paper type in hardware. Photo printing is fully   supported in the newer 6- and 7-ink models.</p>
+  <p>A major advantage of using this driver over those supplied by HP is   the direct interface between HPIJS and the native CUPS spooler, which   allows printing from any printer over any available connection such as   USB, AppleTalk, TCP/IP (via LPD and IPP), HP JetDirect, and shared   windows printers via SAMBA. Additionally, this driver utilizes the   existing Mac OS X USB &quot;backend&quot; and thus does not install any software   that might interfere with standard USB operation.</p>
+  <p>Please note:</p>
+  <ul>
+    <li>HP does not provide any support for HPLIP or HPIJS on the Mac OS X platform.</li>
+    <li><a href="http://www.linuxfoundation.org/en/OpenPrinting/MacOSX/hpijs-USB">Several HP USB devices</a> may not print successfully over the standard Mac OS X USB &quot;backend&quot;. Please <a href="http://www.linuxfoundation.org/en/OpenPrinting/MacOSX/hpijs-USB">see this note</a> for more information.</li>
+  </ul>
+  <h2>Release Notes</h2>
+  <ul>
+    <li>This release fixes a problem with the PPDs that caused many job   options such as page orientation, color/grayscale mode, duplex printing,   etc. to fail.</li>
+    <li>HPIJS is HP's universal printer driver for most of their   non-PostScript printers. It comes as a part of HPLIP, HP Linux Imaging   and Printing.</li>
+    <li>The PPDs for HP printers are now sourced from the HPLIP package rather than the OpenPrinting.org database.</li>
+    <li>PPDs for printers from other manufacturers are provided by OpenPrinting.org.</li>
+    <li>Some printers are only partially supported.  Printers such as<br />
+      HP LaserJet 1022<br />
+      HP LaserJet p1505n<br />
+      HP LaserJet p12014<br />
+      HP LaserJet p2035<br />
+      require a proprietary plug-in for full support.  This package does not contain or support such plug-ins.</li>
+  </ul>
+  <p><a name="Printer_Set_Up_Instructions" id="Printer_Set_Up_Instructions"></a></p>
+  <h2> Printer Set Up Instructions </h2>
+  <p>To add a printer queue, Leopard (Mac OS X 10.5.x) users should use   the Print &amp; Fax from System Preferences. Click on the + (plus) icon   at the lower left. A new window will open. In that window, click the   Default Browser icon at the top left. Highlight your printer in the   section below. Use the &quot;Print Using&quot; pop-up menu near the bottom of the   window to select the correct PPD for your printer and click Add.</p>
+  <p>Tiger users should open the Printer Setup Utility and click on the   Add icon at the top of the Printer List window. A new window will open.   In that window, click the Default Browser icon at the top left.   Highlight your printer in the section below. Use the &quot;Print Using&quot;   pop-up menu near the bottom of the window to select the correct PPD for   your printer and click Add.</p>
+  <p>Jaguar (OS X 10.2.x) and Panther (OS X 10.3.x) users should open   Print Center (Jaguar) or Printer Setup Utility (Panther), hold down the   Option key, and click the Add Printer button in the Print Center   toolbar. Within the setup sheet, choose Advanced from the top popup   menu; then in the &quot;Device:&quot; popup menu select your printer by name (it   should be the last item in the menu list). Finally, select the correct   PPD from the model browser and click Add.</p>
+</div>
+
+<div id="boxscroll2">
+  <h2> Package Description </h2>
+  <p>Release Date: August 10, 2010</p>
+  <p>The <a title="http://www.openprinting.org/show_driver.cgi?driver=hpijs" rel="nofollow" href="http://www.openprinting.org/show_driver.cgi?driver=hpijs">HPIJS</a> driver is the free, <a title="http://hplipopensource.com/hplip-web/index.html" rel="nofollow" href="http://hplipopensource.com/hplip-web/index.html">open-source driver</a> issued by HP for their DeskJet and LaserJet printers. For most <a title="" href="http://www.linuxfoundation.org/collaborate/workgroups/openprinting/macosx/hpijs#Printers">supported printers</a>,   this driver produces output quality equivalent to the proprietary HP   drivers. In photo mode, with photo paper, the output quality is very   high, especially for the HP DeskJet 990C and later models, which   auto-detect the paper type in hardware. Photo printing is fully   supported in the newer 6- and 7-ink models.</p>
+  <p>A major advantage of using this driver over those supplied by HP is   the direct interface between HPIJS and the native CUPS spooler, which   allows printing from any printer over any available connection such as   USB, AppleTalk, TCP/IP (via LPD and IPP), HP JetDirect, and shared   windows printers via SAMBA. Additionally, this driver utilizes the   existing Mac OS X USB &quot;backend&quot; and thus does not install any software   that might interfere with standard USB operation.</p>
+  <p>Please note:</p>
+  <ul>
+    <li>HP does not provide any support for HPLIP or HPIJS on the Mac OS X platform.</li>
+    <li><a href="http://www.linuxfoundation.org/en/OpenPrinting/MacOSX/hpijs-USB">Several HP USB devices</a> may not print successfully over the standard Mac OS X USB &quot;backend&quot;. Please <a href="http://www.linuxfoundation.org/en/OpenPrinting/MacOSX/hpijs-USB">see this note</a> for more information.</li>
+  </ul>
+  <h2>Release Notes</h2>
+  <ul>
+    <li>This release fixes a problem with the PPDs that caused many job   options such as page orientation, color/grayscale mode, duplex printing,   etc. to fail.</li>
+    <li>HPIJS is HP's universal printer driver for most of their   non-PostScript printers. It comes as a part of HPLIP, HP Linux Imaging   and Printing.</li>
+    <li>The PPDs for HP printers are now sourced from the HPLIP package rather than the OpenPrinting.org database.</li>
+    <li>PPDs for printers from other manufacturers are provided by OpenPrinting.org.</li>
+    <li>Some printers are only partially supported.  Printers such as<br />
+      HP LaserJet 1022<br />
+      HP LaserJet p1505n<br />
+      HP LaserJet p12014<br />
+      HP LaserJet p2035<br />
+      require a proprietary plug-in for full support.  This package does not contain or support such plug-ins.</li>
+  </ul>
+  <p><a name="Printer_Set_Up_Instructions" id="Printer_Set_Up_Instructions"></a></p>
+  <h2> Printer Set Up Instructions </h2>
+  <p>To add a printer queue, Leopard (Mac OS X 10.5.x) users should use   the Print &amp; Fax from System Preferences. Click on the + (plus) icon   at the lower left. A new window will open. In that window, click the   Default Browser icon at the top left. Highlight your printer in the   section below. Use the &quot;Print Using&quot; pop-up menu near the bottom of the   window to select the correct PPD for your printer and click Add.</p>
+  <p>Tiger users should open the Printer Setup Utility and click on the   Add icon at the top of the Printer List window. A new window will open.   In that window, click the Default Browser icon at the top left.   Highlight your printer in the section below. Use the &quot;Print Using&quot;   pop-up menu near the bottom of the window to select the correct PPD for   your printer and click Add.</p>
+  <p>Jaguar (OS X 10.2.x) and Panther (OS X 10.3.x) users should open   Print Center (Jaguar) or Printer Setup Utility (Panther), hold down the   Option key, and click the Add Printer button in the Print Center   toolbar. Within the setup sheet, choose Advanced from the top popup   menu; then in the &quot;Device:&quot; popup menu select your printer by name (it   should be the last item in the menu list). Finally, select the correct   PPD from the model browser and click Add.</p>
+</div>
+
+<div id="boxframe">
+<iframe id="boxscroll3" src="iframe/lgpl-3.0-standalone.html" height="380px" width="400px" frameborder="0"></iframe>
+</div>
+
+
+</body>
+</html>

+ 215 - 68
jquery.nicescroll.js

@@ -1,5 +1,5 @@
 /* jquery.nicescroll
--- versione 1.0.0
+-- versione 1.5.0
 -- copyright 2011 InuYaksa*2011
 -- licensed under the MIT
 --
@@ -9,36 +9,56 @@
 
 (function($){
 
-  var AScrollClass = function(myopt) {
+  var domfocus = false;
+  var mousefocus = false;
+
+  var NiceScrollClass = function(myopt) {
 
     var self = this;
     
-    var opt = {
+    this.opt = {
       doc:$("body"),
-      win:$(window),
+      win:false,
       zindex:9999,
       cursoropacitymin:0,
-      scrollspeed:60
+      cursoropacitymax:1,
+      cursorcolor:"#424242",
+      scrollspeed:60,
+      mousescrollstep:8*6,
     };
     
     if (myopt) {
-      for(var a in opt) {
-        if (myopt[a]!==undefined) opt[a] = myopt[a];
+      for(var a in self.opt) {
+        if (myopt[a]!==undefined) self.opt[a] = myopt[a];
       }
     }
     
-    this.zindex = opt.zindex;
-    this.cursoropacitymin = opt.cursoropacitymin;
+    this.id = self.opt.doc[0].id||'';
+    this.doc = self.opt.doc;
+    this.ispage = (self.doc[0].nodeName=='BODY'||self.doc[0].nodeName=='HTML');    
+    this.docscroll = self.ispage?$(window):this.doc;
+    this.win = self.opt.win||this.docscroll;
+    
+    this.isiframe = (this.doc[0].nodeName == 'IFRAME');
     
-    this.doc = opt.doc;
-    this.win = opt.win;
-    this.docscroll = (self.doc[0].nodeName=='BODY'||self.doc[0].nodeName=='HTML')?$(window):this.doc;
+    if (self.isiframe) {
+      this.docscroll = (this.doc[0].document)?$(this.doc[0].document.body):this.doc;
+      this.doc.load(function() {
+        var doc = 'contentDocument' in this? this.contentDocument : this.contentWindow.document;
+        self.docscroll = $(doc.body);
+        self.onResize();
+        $(doc.body).css({'overflow-y':'hidden'});
+        $(doc).scroll(self.onscroll);
+        self.bind(doc,"mousewheel",self.onmousewheel);
+        $(doc).keydown(self.onkeypress);
+      });
+    }
     
-    this.screen = false;
+    this.view = false;
     this.page = false;
     
     this.scroll = {x:0,y:0};
-    this.scrollratio = {x:0,y:0};
+    this.scrollratio = {x:0,y:0};    
     this.cursorheight = 20;
     this.scrollvaluemax = 0;
     
@@ -48,7 +68,10 @@
     
     this.rail = false;
     this.cursor = false;
-    this.cursorfreezed = false;
+    this.cursorfreezed = false;  
+    
+    this.hasfocus = false;
+    this.hasmousefocus = false;
     
     this.isie = (document.all && !document.opera);
     
@@ -71,16 +94,32 @@
       return (el!==false);
     };
     
+    this.updateScrollBar = function() {
+      var pos = self.win.offset();
+      pos.top+=2;
+      pos.left+=self.win.outerWidth()-16;
+      self.rail.css({position:"absolute",top:pos.top,left:pos.left,height:self.win.outerHeight()});
+    };
+    
     this.init = function() {
       self.doc.css({'overflow-y':'hidden'});
       var rail = $(document.createElement('div'));
       rail.attr('id',self.id);
-      rail.css({position:"fixed",top:0,right:0,"padding-left":"4px",width:"12px",height:"100%",'z-index':self.zindex,opacity:self.cursoropacitymin});
+      rail.css({"padding-left":"4px",width:"12px",'z-index':self.opt.zindex,opacity:self.cursoropacitymin});
       self.rail = rail;
-      self.doc.append(rail);
+      
+      if (self.ispage) {
+        rail.css({position:"fixed",top:"0px",right:"0px",height:"100%"});
+        self.doc.append(rail);
+      } else {
+        self.updateScrollBar();
+        $("body").append(rail);
+      }
+      
       var cursor = $(document.createElement('div'));
       cursor.css({
-        position:"relative",top:0,right:0,width:"8px",height:"0px",'background-color':"#424242",
+        position:"relative",top:0,left:0,width:"8px",height:"0px",
+        'background-color':self.opt.cursorcolor,
         border:"1px solid #fff",
         '-webkit-border-radius':'4px',
         '-moz-border-radius':'4px',
@@ -93,12 +132,11 @@
       self.doc.resize(function(){self.onResize()});    
       self.onResize();
 
-      $(self.rail).mousedown(function(e) {
+      self.rail.mousedown(function(e) {
         self.rail.drag = {x:e.screenX,y:e.screenY,sx:self.scroll.x,sy:self.scroll.y};
-        e.preventDefault();
-        return false;
+        return self.cancelEvent(e);
       });
-      $(self.rail).mouseup(function() {
+      self.rail.mouseup(function() {
         self.rail.drag = false;
         return false;
       });
@@ -116,30 +154,89 @@
           if (self.scroll.y>my) self.scroll.y=my;
           self.showCursor();
           self.cursorfreezed = true;
-          self.doScroll(Math.round(self.scroll.y*self.scrollratio.y));
-          e.preventDefault();
-          return false;
+          self.doScroll(Math.round(self.scroll.y*self.scrollratio.y));          
+          return self.cancelEvent(e);
         }
       });
       
-      $(self.rail).mouseenter(function() {
-        $(self.rail).animate({opacity:1});
+      self.rail.mouseenter(function() {
+        $(self.rail).animate({opacity:self.opt.cursoropacitymax});
         self.rail.active = true;
       });
-      $(self.rail).mouseleave(function() {
+      self.rail.mouseleave(function() {
         self.rail.active = false;
         if (!self.rail.drag) self.hideCursor();
       });
       
-      self.mousewheel(function(delta){
-        self.scroll.y+=(-delta)*12;
-        if (self.scroll.y<0) self.scroll.y=0;
-        var my = self.scrollvaluemax;
-        if (self.scroll.y>my) self.scroll.y=my;
-        self.cursorfreezed = false;
-        self.doScroll(Math.round(self.scroll.y*self.scrollratio.y));
-      });
-    
+      if (!self.isiframe) self.bind(self.docscroll,"mousewheel",self.onmousewheel);
+      self.bind(self.rail,"mousewheel",self.onmousewheel);
+
+      if (!self.ispage) {
+        if (!self.win.attr("tabindex")) self.win.attr({"tabindex":(new Date()).getTime()});
+        self.win.focus(function(e) {          
+          domfocus = e.target.id||true;
+          self.hasfocus = true;
+          self.showCursor();
+          self.hideCursor();
+        });
+        self.win.blur(function(e) {
+          domfocus = false;
+          self.hasfocus = false;
+        });
+        self.win.mouseenter(function(e) {
+          mousefocus = e.target.id||true;
+          self.hasmousefocus = true;
+        });
+        self.win.mouseleave(function() {
+          mousefocus = false;
+          self.hasmousefocus = false;
+        });
+      };
+      
+      //Thanks to http://www.quirksmode.org !!
+      self.onkeypress = function(e) {
+        e = (e) ? e : window.e;
+        if (e.target&&/(INPUT|TEXTAREA|SELECT)/.test(e.target.nodeName)) return;
+        if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
+          var key = e.keyCode;     
+          var ret = true;
+          switch (key) {
+            case 38:
+            case 63233: //safari
+              self.doScrollBy(12);
+              ret = false;
+              break;
+            case 40:
+            case 63235: //safari
+              self.doScrollBy(-12);
+              ret = false;
+              break;
+            case 33:
+            case 63276: // safari
+              self.doScrollBy(self.view.h,true);
+              ret = false;
+              break;
+            case 34:
+            case 63277: // safari
+              self.doScrollBy(-self.view.h,true);
+              ret = false;
+              break;
+            case 36:
+            case 63273: // safari
+              self.doScrollTo(0,true);
+              ret = false;
+              break;
+            case 35:
+            case 63275: // safari
+              self.doScrollTo(self.page.h,true);
+              ret = false;
+              break;
+          }
+          if (!ret) return self.cancelEvent(e);
+        }
+      };
+      self.bind(document,"keydown",self.onkeypress);
+      
     };
     
     this.showCursor = function() {
@@ -147,41 +244,48 @@
         clearTimeout(self.cursortimeout);
         self.cursortimeout = 0;
       }
-      self.rail.clearQueue().css({opacity:1});
+      self.rail.clearQueue().css({opacity:self.opt.cursoropacitymax});
       self.cursor.css({height:self.cursorheight,top:self.scroll.y});
-    }
+    };
     
     this.hideCursor = function(tm) {
       if (self.cursortimeout) return;
       self.cursortimeout = setTimeout(function() {
          if (self.rail.active) return;
-         $(self.rail).animate({opacity:self.cursoropacitymin});
+         $(self.rail).animate({opacity:self.opt.cursoropacitymin});
          self.cursortimeout = 0;
       },tm||800);
     };
     
     this.getContentSize = function() {
-      return (self.doc[0].nodeName=='BODY') ?
+      var pg = (self.ispage) ?
         {
           w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
           h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
         } : 
         {
-          w:self.doc[0].scrollWidth,
-          h:self.doc[0].scrollHeight
+          w:self.docscroll[0].scrollWidth,
+          h:self.docscroll[0].scrollHeight
         };
+
+      pg.w-=1;
+      pg.h-=1;
+
+      return pg;
     };
     
     this.onResize = function() {
+      if (!self.ispage) self.updateScrollBar();
+    
       self.view = {
-        w:self.win.width(),
-        h:self.win.height()
+        w:(self.ispage) ? self.win.width() : self.win.innerWidth(),
+        h:(self.ispage) ? self.win.height() : self.win.innerHeight()
       };
       self.page = self.getContentSize();
       
-      self.cursorheight = Math.round(self.view.h * (self.view.h / self.page.h));
+      self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
       
-      self.scrollvaluemax = self.view.h-self.cursorheight-1;
+      self.scrollvaluemax = self.view.h-self.cursorheight-2;
       
       self.scrollratio = {
         x:0,
@@ -195,9 +299,10 @@
     };
    
     this.bind = function(dom,name,fn,bubble) {  // fixing jquery bind
-      var el = dom[0];
+      var el = (dom.length) ? dom[0] : dom;
       if (el.addEventListener) {
         el.addEventListener(name,fn,bubble||false);
+        if (name=='mousewheel') el.addEventListener("DOMMouseScroll",fn,bubble||false);
       } 
       else if (el.attachEvent) {
         el.attachEvent(name,fn);
@@ -206,18 +311,35 @@
         el["on"+name] = fn;
       }
     };
+    
+    // Thanks to http://www.switchonthecode.com !!
+    this.cancelEvent = function(e) {
+      e = e ? e : window.event;
+      if(e.stopPropagation) e.stopPropagation();
+      if(e.preventDefault) e.preventDefault();
+      e.cancelBubble = true;
+      e.cancel = true;
+      e.returnValue = false;
+      return false;
+    };
    
+    this.onmousewheel = function(e) {
+      var delta = 0;
+      e = e ? e : window.event;
+      var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
+      if (delta) {
+        self.doScrollBy(delta*self.opt.mousescrollstep,true);
+      }
+      return self.cancelEvent(e);
+    };
+    
     this.mousewheel = function(fn) {
-      function wheel(e){
-        var delta = 0;
-        e = e ? e : window.event;
-        var delta = e.detail ? e.detail * -1 : e.wheelDelta / 40;
-        if (fn&&delta) fn(delta);
-        if (e.preventDefault) e.preventDefault();
-        e.returnValue = false;
+      if (!self.isie) self.bind(self.docscroll,'DOMMouseScroll',self.onmousewheel,false);      
+      self.bind(self.docscroll,'mousewheel',self.onmousewheel,false);
+      if (!self.ispage) {
+        if (!self.isie) self.bind(self.rail,'DOMMouseScroll',self.onmousewheel,false);      
+        self.bind(self.rail,'mousewheel',self.onmousewheel,false);
       }
-      if (!self.isie) self.bind(self.docscroll,'DOMMouseScroll',wheel,false);
-      self.bind(self.docscroll,'mousewheel',wheel,false);
     };
     
     this.doScroll = function(y) {
@@ -227,39 +349,64 @@
         var gp = self.newscrolly - self.getScrollTop();
         var df = (gp>0) ? Math.ceil(gp/4) : Math.floor(gp/4);
         var sc = self.getScrollTop()+df;
-        self.setScrollTop(sc);
+        self.setScrollTop(sc);     
         if (sc == self.newscrolly) {
           clearInterval(self.timer);
           self.timer = 0;        
           self.cursorfreezed = false;
         }
-      },opt.scrollspeed);
-    }
+      },self.opt.scrollspeed);
+      self.showCursor();
+      self.hideCursor();
+    };
+    
+    this.doScrollBy = function(stp,absolute) {
+      if (absolute) stp = Math.round(stp * 1/self.scrollratio.y);
+      var ny = self.scroll.y-stp;
+      if (ny<0) ny=0;
+      var my = self.scrollvaluemax;
+      if (ny>my) ny=my;
+      self.cursorfreezed = false;
+      self.doScroll(Math.floor(ny*self.scrollratio.y));
+    };
 
-    self.win.scroll(function(e) {
+    this.doScrollTo = function(pos,absolute) {
+      if (absolute) pos = Math.round(pos * 1/self.scrollratio.y);
+      ny=pos;
+      if (ny<0) ny=0;
+      var my = self.scrollvaluemax;
+      if (ny>my) ny=my;
+      self.cursorfreezed = false;
+      self.doScroll(Math.floor(ny*self.scrollratio.y));
+    };
+    
+    self.onscroll = function(e) {    
       var tm = (new Date()).getTime();
       if (!self.lastcontentcheck || self.lastcontentcheck<tm) {
         self.lastcontentcheck=tm+500;
         var pg = self.getContentSize();
         if (pg.h!=self.page.h) self.onResize();        
-      }
-    
+      }    
       if (self.rail.drag) return;
       if (!self.cursorfreezed) self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
       self.showCursor();
       self.hideCursor();
+    };
+    self.docscroll.scroll(function(e) {
+      self.onscroll(e);
     });
    
     this.init();
 
-  }
+  };
   
   $.fn.niceScroll = function(opt) {
     var ret = [];
-    if (!opt) opt = {};
-    this.each(function() {
-      opt.doc = (opt.doc===undefined) ? $(this) : opt.doc;
-      ret.push(new AScrollClass(opt));
+    if (opt===undefined) opt = {};
+    var docundef = (opt.doc===undefined);
+    this.each(function() {      
+      opt.doc = (docundef) ? $(this) : opt.doc;
+      ret.push(new NiceScrollClass(opt));
     });
     return (ret.length==1) ? ret[0] : ret;
   };

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff