(function ($) {
function JQperfectScrollbar(element, options) {
this.element = $(element).get(0);
+ if(options===undefined || options==null){
+ options={};
+ }
this.ps = new PerfectScrollbar(this.element, options);
}
- JQperfectScrollbar.prototype = {};
+ JQperfectScrollbar.prototype = {
+ update: function () {
+ this.ps.update();
+ },
+ destroy: function () {
+ this.ps.destroy();
+ this.ps = null;
+ }
+ };
jQuery.fn.perfectScrollbar = function (options) {
return this.each(function () {
var $this = $(this);
- if ($(this).data('perfectScrollbar') === undefined) {
- $(this).data('perfectScrollbar', new JQperfectScrollbar($this, options));
+ var jps = $(this).data('perfectScrollbar');
+ var create = false;
+ if (jps === undefined) {
+ jps = new JQperfectScrollbar($this, options);
+ $(this).data('perfectScrollbar', jps);
+ create = true;
+ }
+ if (options === 'update') {
+ jps.update();
+ } else if (!create) {
+ console.log('destroy');
+ jps.destroy();
+ jps = new JQperfectScrollbar($this, options);
+ $(this).data('perfectScrollbar', jps);
}
})
};