浏览代码

Merge pull request #534 from bnadeau/browserify

Browserify and Node/CommonJS support.
Inuyaksa 9 年之前
父节点
当前提交
3c7e6c13c5
共有 2 个文件被更改,包括 5 次插入1 次删除
  1. 4 1
      jquery.nicescroll.js
  2. 1 0
      package.json

+ 4 - 1
jquery.nicescroll.js

@@ -12,6 +12,9 @@
   if (typeof define === 'function' && define.amd) {
     // AMD. Register as anonymous module.
     define(['jquery'], factory);
+  } else if (typeof exports === 'object') {
+    // Node/CommonJS.
+    module.exports = factory(require('jquery'));
   } else {
     // Browser globals.
     factory(jQuery);
@@ -31,7 +34,7 @@
   // http://stackoverflow.com/questions/2161159/get-script-path
   function getScriptPath() {
     var scripts = document.getElementsByTagName('script');
-    var path = scripts[scripts.length - 1].src.split('?')[0];
+    var path = scripts.length ? scripts[scripts.length - 1].src.split('?')[0] : '';
     return (path.split('/').length > 0) ? path.split('/').slice(0, -1).join('/') + '/' : '';
   }
 

+ 1 - 0
package.json

@@ -54,6 +54,7 @@
     "jquery.nicescroll.min.js",
     "zoomico.png"
   ],
+  "main": "jquery.nicescroll.js",
   "dependencies": {
     "jquery": ">=1.8.3"
   },