소스 검색

Added Node/CommonJS support.

Bruno Nadeau 9 년 전
부모
커밋
4342054d4c
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      jquery.nicescroll.js

+ 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 style for Browserify
+    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('/') + '/' : '';
   }