Media.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/App/Media", ["exports", "BaseApp"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(exports, require("BaseApp"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(mod.exports, global.BaseApp);
  11. global.AppMedia = mod.exports;
  12. }
  13. })(this, function (_exports, _BaseApp2) {
  14. "use strict";
  15. Object.defineProperty(_exports, "__esModule", {
  16. value: true
  17. });
  18. _exports.run = run;
  19. _exports.getInstance = getInstance;
  20. _exports.default = _exports.AppMedia = void 0;
  21. _BaseApp2 = babelHelpers.interopRequireDefault(_BaseApp2);
  22. var AppMedia =
  23. /*#__PURE__*/
  24. function (_BaseApp) {
  25. babelHelpers.inherits(AppMedia, _BaseApp);
  26. function AppMedia() {
  27. babelHelpers.classCallCheck(this, AppMedia);
  28. return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(AppMedia).apply(this, arguments));
  29. }
  30. babelHelpers.createClass(AppMedia, [{
  31. key: "initialize",
  32. value: function initialize() {
  33. babelHelpers.get(babelHelpers.getPrototypeOf(AppMedia.prototype), "initialize", this).call(this);
  34. this.$arrGrid = $('#arrangement-grid');
  35. this.$arrList = $('#arrangement-list');
  36. this.$actionBtn = $('.site-action');
  37. this.$actionToggleBtn = this.$actionBtn.find('.site-action-toggle');
  38. this.$content = $('#mediaContent');
  39. this.$fileupload = $('#fileupload'); // states
  40. this.states = {
  41. list: false,
  42. checked: false
  43. };
  44. }
  45. }, {
  46. key: "process",
  47. value: function process() {
  48. babelHelpers.get(babelHelpers.getPrototypeOf(AppMedia.prototype), "process", this).call(this);
  49. this.steupArrangement();
  50. this.setupActionBtn();
  51. this.bindListChecked();
  52. this.bindAction();
  53. this.bindDropdownAction();
  54. }
  55. }, {
  56. key: "list",
  57. value: function list(active) {
  58. if (active) {
  59. this.$arrGrid.removeClass('active');
  60. this.$arrList.addClass('active');
  61. $('.media-list').removeClass('is-grid').addClass('is-list');
  62. $('.media-list>ul>li').removeClass('animation-scale-up').addClass('animation-fade');
  63. } else {
  64. this.$arrList.removeClass('active');
  65. this.$arrGrid.addClass('active');
  66. $('.media-list').removeClass('is-list').addClass('is-grid');
  67. $('.media-list>ul>li').removeClass('animation-fade').addClass('animation-scale-up');
  68. }
  69. this.states.list = active;
  70. }
  71. }, {
  72. key: "checked",
  73. value: function checked(_checked) {
  74. var api = this.$actionBtn.actionBtn().data('actionBtn');
  75. if (_checked) {
  76. api.show();
  77. } else {
  78. api.hide();
  79. }
  80. this.states.checked = _checked;
  81. }
  82. }, {
  83. key: "steupArrangement",
  84. value: function steupArrangement() {
  85. var self = this;
  86. this.$arrGrid.on('click', function () {
  87. if ($(this).hasClass('active')) {
  88. return;
  89. }
  90. self.list(false);
  91. });
  92. this.$arrList.on('click', function () {
  93. if ($(this).hasClass('active')) {
  94. return;
  95. }
  96. self.list(true);
  97. });
  98. }
  99. }, {
  100. key: "setupActionBtn",
  101. value: function setupActionBtn() {
  102. var _this = this;
  103. this.$actionToggleBtn.on('click', function (e) {
  104. if (!_this.states.checked) {
  105. _this.$fileupload.trigger('click');
  106. e.stopPropagation();
  107. }
  108. });
  109. }
  110. }, {
  111. key: "bindListChecked",
  112. value: function bindListChecked() {
  113. var _this2 = this;
  114. this.$content.on('asSelectable::change', function (e, api, checked) {
  115. _this2.checked(checked);
  116. });
  117. }
  118. }, {
  119. key: "bindDropdownAction",
  120. value: function bindDropdownAction() {
  121. $('.info-wrap>.dropdown').on('show.bs.dropdown', function () {
  122. $(this).closest('.media-item').toggleClass('item-active');
  123. }).on('hidden.bs.dropdown', function () {
  124. $(this).closest('.media-item').toggleClass('item-active');
  125. });
  126. $('.info-wrap .dropdown-menu').on('`click', function (e) {
  127. e.stopPropagation();
  128. });
  129. }
  130. }, {
  131. key: "bindAction",
  132. value: function bindAction() {
  133. $('[data-action="trash"]', '.site-action').on('click', function () {
  134. console.log('trash');
  135. });
  136. $('[data-action="download"]', '.site-action').on('click', function () {
  137. console.log('download');
  138. });
  139. }
  140. }]);
  141. return AppMedia;
  142. }(_BaseApp2.default);
  143. _exports.AppMedia = AppMedia;
  144. var instance = null;
  145. function getInstance() {
  146. if (!instance) {
  147. instance = new AppMedia();
  148. }
  149. return instance;
  150. }
  151. function run() {
  152. var app = getInstance();
  153. app.run();
  154. }
  155. var _default = AppMedia;
  156. _exports.default = _default;
  157. });