Separate initialize, update and destroy functions.

This commit is contained in:
Hyunje Alex Jun
2015-01-25 18:24:28 +00:00
parent 7ab6c5e5ef
commit fa7e169b9f
9 changed files with 888 additions and 795 deletions

View File

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