Add CommonJS support for the jQuery adaptor.

master
Hyunje Alex Jun 10 years ago
parent 64ea58514b
commit ab40b55c8f

@ -177,10 +177,21 @@ As you may already know, perfect-scrollbar was a jQuery plugin.
And it *is* as well. There's a jQuery adaptor and the plugin can And it *is* as well. There's a jQuery adaptor and the plugin can
be used in the same way it used to be used before. be used in the same way it used to be used before.
I also recommend using NPM and CommonJS here, but it's not mandatory.
```javascript
var $ = require('jquery');
require('perfect-scrollbar/jquery')($);
```
For sure, you can just import a built script.
```html ```html
<script src='out/js/perfect-scrollbar.jquery.js'></script> <script src='out/js/perfect-scrollbar.jquery.js'></script>
``` ```
After importing it, you can use the plugin in the usual way.
```javascript ```javascript
$('#container').perfectScrollbar(); // Initialize $('#container').perfectScrollbar(); // Initialize
$('#container').perfectScrollbar({ ... }); // with options $('#container').perfectScrollbar({ ... }); // with options

@ -0,0 +1,6 @@
/* Copyright (c) 2015 Hyunje Alex Jun and other contributors
* Licensed under the MIT License
*/
'use strict';
module.exports = require('./src/js/main');

6
jquery.js vendored

@ -0,0 +1,6 @@
/* Copyright (c) 2015 Hyunje Alex Jun and other contributors
* Licensed under the MIT License
*/
'use strict';
module.exports = require('./src/js/adaptor/jquery');

@ -9,7 +9,7 @@
"email": "me@noraesae.net" "email": "me@noraesae.net"
} }
], ],
"main": "src/js/main.js", "main": "./index.js",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/noraesae/perfect-scrollbar" "url": "https://github.com/noraesae/perfect-scrollbar"

@ -3,7 +3,7 @@
*/ */
'use strict'; 'use strict';
var ps = require('../plugin/ps'); var ps = require('../main');
window.PerfectScrollbar = ps; window.PerfectScrollbar = ps;
if (typeof window.Ps === 'undefined') { if (typeof window.Ps === 'undefined') {

@ -3,30 +3,39 @@
*/ */
'use strict'; 'use strict';
var ps = require('../plugin/ps') var ps = require('../main')
, psInstances = require('../plugin/instances'); , psInstances = require('../plugin/instances');
$.fn.perfectScrollbar = function (settingOrCommand) { function mountJQuery(jQuery) {
return this.each(function () { jQuery.fn.perfectScrollbar = function (settingOrCommand) {
if (typeof settingOrCommand === 'object' || return this.each(function () {
typeof settingOrCommand === 'undefined') { if (typeof settingOrCommand === 'object' ||
// If it's an object or none, initialize. typeof settingOrCommand === 'undefined') {
var settings = settingOrCommand; // If it's an object or none, initialize.
var settings = settingOrCommand;
if (!psInstances.get(this)) { if (!psInstances.get(this)) {
ps.initialize(this, settings); ps.initialize(this, settings);
} }
} else { } else {
// Unless, it may be a command. // Unless, it may be a command.
var command = settingOrCommand; var command = settingOrCommand;
if (command === 'update') { if (command === 'update') {
ps.update(this); ps.update(this);
} else if (command === 'destroy') { } else if (command === 'destroy') {
ps.destroy(this); ps.destroy(this);
}
} }
}
return $(this); return $(this);
}); });
}; };
}
var jq = window.jQuery ? window.jQuery : window.$;
if (typeof jq !== 'undefined') {
mountJQuery(jq);
}
module.exports = mountJQuery;

@ -3,4 +3,12 @@
*/ */
'use strict'; 'use strict';
module.exports = require('./plugin/ps'); var destroy = require('./plugin/destroy')
, initialize = require('./plugin/initialize')
, update = require('./plugin/update');
module.exports = {
initialize: initialize,
update: update,
destroy: destroy
};

@ -1,14 +0,0 @@
/* Copyright (c) 2015 Hyunje Alex Jun and other contributors
* Licensed under the MIT License
*/
'use strict';
var destroy = require('./destroy')
, initialize = require('./initialize')
, update = require('./update');
module.exports = {
initialize: initialize,
update: update,
destroy: destroy
};
Loading…
Cancel
Save