You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

  1. /*!
  2. * jQuery Viewer v1.0.0
  3. * https://github.com/fengyuanchen/jquery-viewer
  4. *
  5. * Copyright (c) 2018 Chen Fengyuan
  6. * Released under the MIT license
  7. *
  8. * Date: 2018-04-01T05:58:29.617Z
  9. */
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery'), require('viewerjs')) :
  12. typeof define === 'function' && define.amd ? define(['jquery', 'viewerjs'], factory) :
  13. (factory(global.jQuery,global.Viewer));
  14. }(this, (function ($,Viewer) { 'use strict';
  15. $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  16. Viewer = Viewer && Viewer.hasOwnProperty('default') ? Viewer['default'] : Viewer;
  17. if ($.fn) {
  18. var AnotherViewer = $.fn.viewer;
  19. var NAMESPACE = 'viewer';
  20. $.fn.viewer = function jQueryViewer(option) {
  21. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  22. args[_key - 1] = arguments[_key];
  23. }
  24. var result = void 0;
  25. this.each(function (i, element) {
  26. var $element = $(element);
  27. var isDestroy = option === 'destroy';
  28. var viewer = $element.data(NAMESPACE);
  29. if (!viewer) {
  30. if (isDestroy) {
  31. return;
  32. }
  33. var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
  34. viewer = new Viewer(element, options);
  35. $element.data(NAMESPACE, viewer);
  36. }
  37. if (typeof option === 'string') {
  38. var fn = viewer[option];
  39. if ($.isFunction(fn)) {
  40. result = fn.apply(viewer, args);
  41. if (result === viewer) {
  42. result = undefined;
  43. }
  44. if (isDestroy) {
  45. $element.removeData(NAMESPACE);
  46. }
  47. }
  48. }
  49. });
  50. return result !== undefined ? result : this;
  51. };
  52. $.fn.viewer.Constructor = Viewer;
  53. $.fn.viewer.setDefaults = Viewer.setDefaults;
  54. $.fn.viewer.noConflict = function noConflict() {
  55. $.fn.viewer = AnotherViewer;
  56. return this;
  57. };
  58. }
  59. })));