iwb2.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. 
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined'
  4. ? factory(exports)
  5. : typeof define === 'function' && define.amd
  6. ? define(['exports'], factory)
  7. : (global = global || self, factory(global.adminlte = {}));
  8. // ReSharper disable once ThisInGlobalContext
  9. }(this,
  10. (function (exports) {
  11. 'use strict';
  12. var abp = window.abp || {};
  13. var SeparateBar;
  14. SeparateBar = function ($) {
  15. var NAME = 'SeparateBar';
  16. var DATA_KEY = 'iwb.separate_bar';
  17. var EVENT_KEY = "." + DATA_KEY;
  18. var JQUERY_NO_CONFLICT = $.fn[NAME];
  19. var ClassNames =
  20. {
  21. VerticalLine: 'VerticalLine',
  22. HorizontalLine: 'HorizontalLine'
  23. }
  24. var ALLOW_METHOD = [
  25. 'isShow'
  26. ];
  27. var Default = {
  28. direction: 'V',
  29. //moveDom: "",
  30. move2Dom: "",
  31. borderStyle: "",
  32. mouseMoveDom: "body",
  33. moveEvent: function (moveDom, mouseMoveDom, move2Dom) { }
  34. }
  35. var SeparateBar = function () {
  36. function SeparateBar(element, config) {
  37. this._element = element;
  38. this._config = config;
  39. this.isMouseDown = false;
  40. this.createDom = null;
  41. $.metPageCss("/Content/css/separateBar.css", "separateBar-css");
  42. this._init();
  43. }
  44. var _proto = SeparateBar.prototype;
  45. _proto._init = function () {
  46. var _this = this, $this = $(_this._element);
  47. this._create();
  48. }
  49. _proto._create = function () {
  50. var option = this._config;
  51. var direction = option.direction;
  52. let $moveDom =
  53. $(this._element); //typeof (option.moveDom) === 'string' ? $('#' + option.moveDom) : $(option.moveDom);
  54. let $move2Dom = typeof (option.move2Dom) === 'string'
  55. ? $('#' + option.move2Dom)
  56. : $(option.move2Dom);
  57. var $mouseMoveDom = typeof (option.mouseMoveDom) === 'string'
  58. ? (option.mouseMoveDom === 'body' ? $('' + option.mouseMoveDom) : $('#' + option.mouseMoveDom))
  59. : $(option.mouseMoveDom);
  60. if ($moveDom.css("position") !== "relative") {
  61. $moveDom.css("position", "relative");
  62. }
  63. var $reDiv = $('<div>');
  64. if (direction === 'V') {
  65. $reDiv.addClass(ClassNames.VerticalLine);
  66. $moveDom.append($reDiv);
  67. this.BindEvent($moveDom, $mouseMoveDom, $move2Dom);
  68. }
  69. if (direction === 'H') {
  70. $reDiv.addClass(ClassNames.HorizontalLine);
  71. $moveDom.append($reDiv);
  72. this.BindEvent($moveDom, $mouseMoveDom, $move2Dom);
  73. }
  74. this.createDom = $reDiv;
  75. }
  76. _proto.isShow = function (b) {
  77. var _this = this;
  78. var $dom = $(_this.createDom);
  79. b ? $dom.show() : $dom.hide();
  80. }
  81. _proto.BindEvent = function ($moveDom, $mouseMoveDom, $move2Dom) {
  82. var isMouseDown = this.isMouseDown;
  83. var option = this._config;
  84. $moveDom.find('.' + ClassNames.VerticalLine).off('mousedown' + EVENT_KEY).on(
  85. 'mousedown' + EVENT_KEY,
  86. function () {
  87. isMouseDown = true;
  88. $moveDom.css('cursor', 'n-resize');
  89. });
  90. $mouseMoveDom.off('mousemove' + EVENT_KEY).on(
  91. 'mousemove' + EVENT_KEY,
  92. function (e) {
  93. if (isMouseDown) {
  94. let offset = $moveDom.offset();
  95. //let offset2 = $move2Dom.offset();
  96. //let upPreHeight = $moveDom.height();
  97. //let downPreHeight = $move2Dom.height();
  98. if (option.direction === 'V') {
  99. var upNewHeight = e.pageY - offset.top;
  100. $moveDom.height(upNewHeight + 'px');
  101. }
  102. if (option.direction === 'H') {
  103. var upNewWidth = e.pageX - offset.left;
  104. $moveDom.width(upNewWidth + 'px');
  105. }
  106. //var downNewHeight = downPreHeight + (upPreHeight - upNewHeight);
  107. //$move2Dom.height(downNewHeight + 'px');
  108. //upPreHeight = upNewHeight;
  109. //downPreHeight = downNewHeight;
  110. option.moveEvent($moveDom, $mouseMoveDom, $move2Dom);
  111. }
  112. });
  113. $mouseMoveDom.off('mouseup' + EVENT_KEY).on(
  114. 'mouseup' + EVENT_KEY,
  115. function () {
  116. isMouseDown = false;
  117. $moveDom.css('cursor', 'auto');
  118. });
  119. }
  120. SeparateBar._jQueryInterface = function _jQueryInterface(option) {
  121. var value, args = Array.prototype.slice.call(arguments, 1);
  122. this.each(function () {
  123. var $this = $(this);
  124. var data = $this.data(DATA_KEY);
  125. if (typeof option === 'string') {
  126. if ($.inArray(option, ALLOW_METHOD) < 0) {
  127. throw new Error("Unknown method: " + option);
  128. }
  129. if (!data) {
  130. return;
  131. }
  132. value = data[option].apply(data, args);
  133. }
  134. if (!data) {
  135. var options = $.extend({}, Default, $(this).data(), typeof option === 'object' && option);
  136. data = new SeparateBar(this, options);
  137. $this.data(DATA_KEY, data);
  138. }
  139. });
  140. return typeof value === 'undefined' ? this : value;
  141. };
  142. return SeparateBar;
  143. }();
  144. /**
  145. * jQuery API
  146. * ====================================================
  147. */
  148. $.fn[NAME] = SeparateBar._jQueryInterface;
  149. $.fn[NAME].Constructor = SeparateBar;
  150. $.fn[NAME].noConflict = function () {
  151. $.fn[NAME] = JQUERY_NO_CONFLICT;
  152. return SeparateBar._jQueryInterface;
  153. };
  154. return SeparateBar;
  155. }(jQuery);
  156. exports.SeparateBar = SeparateBar;
  157. Object.defineProperty(exports, '__esModule', { value: true });
  158. })));