jquery.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. var ps = require('../main')
  3. , psInstances = require('../plugin/instances');
  4. function mountJQuery(jQuery) {
  5. jQuery.fn.perfectScrollbar = function (settingOrCommand, updateSettings) {
  6. return this.each(function () {
  7. if (typeof settingOrCommand === 'object' ||
  8. typeof settingOrCommand === 'undefined') {
  9. // If it's an object or none, initialize.
  10. var settings = settingOrCommand;
  11. if (!psInstances.get(this)) {
  12. ps.initialize(this, settings);
  13. }
  14. } else {
  15. // Unless, it may be a command.
  16. var command = settingOrCommand;
  17. if (command === 'update') {
  18. ps.update(this, updateSettings);
  19. } else if (command === 'destroy') {
  20. ps.destroy(this);
  21. }
  22. }
  23. return jQuery(this);
  24. });
  25. };
  26. }
  27. if (typeof define === 'function' && define.amd) {
  28. // AMD. Register as an anonymous module.
  29. define(['jquery'], mountJQuery);
  30. } else {
  31. var jq = window.jQuery ? window.jQuery : window.$;
  32. if (typeof jq !== 'undefined') {
  33. mountJQuery(jq);
  34. }
  35. }
  36. module.exports = mountJQuery;