Browse Source

Added Node/CommonJS support.

Bruno Nadeau 9 years ago
parent
commit
4342054d4c
1 changed files with 4 additions and 1 deletions
  1. 4 1
      jquery.nicescroll.js

+ 4 - 1
jquery.nicescroll.js

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