bjui-dialog.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*!
  2. * B-JUI v1.2 (http://b-jui.com)
  3. * Git@OSC (http://git.oschina.net/xknaan/B-JUI)
  4. * Copyright 2014 K'naan (xknaan@163.com).
  5. * Licensed under Apache (http://www.apache.org/licenses/LICENSE-2.0)
  6. */
  7. /* ========================================================================
  8. * B-JUI: bjui-dialog.js v1.2
  9. * @author K'naan (xknaan@163.com)
  10. * -- Modified from dwz.dialog.js, dwz.dialogDrag.js, dwz.resize.js (author:Roger Wu)
  11. * http://git.oschina.net/xknaan/B-JUI/blob/master/BJUI/js/bjui-dialog.js
  12. * ========================================================================
  13. * Copyright 2014 K'naan.
  14. * Licensed under Apache (http://www.apache.org/licenses/LICENSE-2.0)
  15. * ======================================================================== */
  16. +function ($) {
  17. 'use strict';
  18. // DIALOG GLOBAL ELEMENTS
  19. // ======================
  20. var $resizable
  21. var $current, shadow, zindex
  22. $(function() {
  23. var INIT_DIALOG = function() {
  24. $resizable = $('#bjui-resizable')
  25. shadow = 'dialogShadow'
  26. zindex = Dialog.ZINDEX
  27. $('body').append('<!-- dialog resizable -->').append(FRAG.resizable)
  28. }
  29. INIT_DIALOG()
  30. })
  31. // DIALOG CLASS DEFINITION
  32. // ======================
  33. var Dialog = function(element, options) {
  34. this.$element = $(element)
  35. this.options = options
  36. this.tools = this.TOOLS()
  37. }
  38. Dialog.DEFAULTS = {
  39. id : 'dialog',
  40. title : 'New Dialog',
  41. url : undefined,
  42. type : 'GET',
  43. data : {},
  44. loadingmask : true,
  45. width : 500,
  46. height : 300,
  47. minW : 65,
  48. minH : 40,
  49. max : false,
  50. mask : false,
  51. resizable : true,
  52. drawable : true,
  53. maxable : true,
  54. minable : true,
  55. fresh : false,
  56. onLoad : null,
  57. beforeClose : null,
  58. onClose : null
  59. }
  60. Dialog.ZINDEX = 30
  61. Dialog.prototype.TOOLS = function() {
  62. var that = this
  63. var tools = {
  64. getDefaults: function() {
  65. return Dialog.DEFAULTS
  66. },
  67. init: function($dialog) {
  68. var width = that.options.width > that.options.minW ? that.options.width : that.options.minW
  69. var height = that.options.height > that.options.minH ? that.options.height : that.options.minH
  70. var wW = $(window).width(),
  71. wH = $(window).height(),
  72. iTop = that.options.max ? 0 : ((wH - height) / 2)
  73. if (width > wW) width = wW
  74. if (height > wH) height = wH
  75. $dialog
  76. .height(height)
  77. .width(width)
  78. .show()
  79. .css({left:(wW - width) / 2, top:0, opacity:0.1})
  80. .animate({top:iTop > 0 ? iTop : 0, opacity:1})
  81. .addClass(shadow)
  82. .find('> .dialogContent').height(height - $('> .dialogHeader', $dialog).outerHeight() - 6)
  83. $('body').find('> .bjui-dialog-container').not($dialog).removeClass(shadow)
  84. },
  85. reload: function($dialog, options) {
  86. var $dialogContent = $dialog.find('> .dialogContent'), onLoad
  87. options = options || $dialog.data('initOptions')
  88. onLoad = options.onLoad ? options.onLoad.toFunc() : null
  89. $dialog.trigger(BJUI.eventType.beforeLoadDialog)
  90. if (options.url) {
  91. $dialogContent.ajaxUrl({
  92. type:options.type || 'GET', url:options.url, data:options.data || {}, loadingmask:options.loadingmask, callback:function(response) {
  93. if (onLoad) onLoad.apply(that, [$dialog])
  94. if (BJUI.ui.clientPaging && $dialog.data('bjui.clientPaging')) $dialog.pagination('setPagingAndOrderby', $dialog)
  95. }
  96. })
  97. } else if (options.target) {
  98. var html = $(options.target).html() || $dialog.data('bjui.dialog.target')
  99. $(options.target).empty()
  100. $dialog.data('bjui.dialog.target', html)
  101. $dialogContent.trigger(BJUI.eventType.beforeAjaxLoad).html(html).initui()
  102. if (onLoad) onLoad.apply(that, [$dialog])
  103. }
  104. },
  105. resizeContent:function($dialog, width, height) {
  106. var $dialogContent = $dialog.find('> .dialogContent')
  107. $dialogContent
  108. .css({width:(width - 12), height:(height - $dialog.find('> .dialogHeader').outerHeight() - 6)})
  109. .resizePageH()
  110. $(window).trigger(BJUI.eventType.resizeGrid)
  111. }
  112. }
  113. return tools
  114. }
  115. Dialog.prototype.open = function() {
  116. var that = this, options = that.options
  117. var $body = $('body')
  118. var $dialog = $body.data(options.id)
  119. if (!options.target || !$(options.target).length) {
  120. if (!options.url && options.href) options.url = options.href
  121. if (!options.url) {
  122. BJUI.debug('Dialog Plugin: Error trying to open a dialog, url is undefined!')
  123. return
  124. } else {
  125. options.url = decodeURI(options.url).replacePlh(that.$element.closest('.unitBox'))
  126. if (!options.url.isFinishedTm()) {
  127. that.$element.alertmsg('error', (options.warn || FRAG.alertPlhMsg.replace('#plhmsg#', BJUI.regional.plhmsg)))
  128. BJUI.debug('Dialog Plugin: The new dialog\'s url is incorrect, url: '+ options.url)
  129. return
  130. }
  131. options.url = encodeURI(options.url)
  132. }
  133. } else {
  134. options.url = undefined
  135. }
  136. if ($dialog) { //if the dialog id already exists
  137. var op = $dialog.data('initOptions') || options
  138. this.switchDialog($dialog)
  139. if ($dialog.is(':hidden')) $dialog.show()
  140. if (op.fresh || options.fresh || !op.url || op.url != options.url) {
  141. that.reload(options)
  142. $dialog.data('initOptions', options)
  143. }
  144. } else { //open a new dialog
  145. var dr = BJUI.regional.dialog
  146. var dialog = FRAG.dialog
  147. .replace('#close#', dr.close)
  148. .replace('#maximize#', dr.maximize)
  149. .replace('#restore#', dr.restore)
  150. .replace('#minimize#', dr.minimize)
  151. .replace('#title#', dr.title)
  152. $dialog = $(dialog)
  153. .data('options', options)
  154. .data('initOptions', options)
  155. .css('zIndex', (zindex += 1))
  156. .hide()
  157. .appendTo($body)
  158. $dialog.find('> .dialogHeader > h1 > span.title').html(options.title)
  159. this.tools.init($dialog)
  160. if (options.maxable) $dialog.find('a.maximize').show()
  161. else $dialog.find('a.maximize').hide()
  162. if (options.minable) $dialog.find('a.minimize').show()
  163. else $dialog.find('a.minimize').hide()
  164. if (options.max) that.maxsize($dialog)
  165. if (options.mask) this.addMask($dialog)
  166. else if (options.minable && $.fn.taskbar) this.$element.taskbar({id:options.id, title:options.title})
  167. $dialog.on('click', function(e) {
  168. if (!$(e.target).data('bjui.dialog'))
  169. if ($current && $current[0] != $dialog[0]) that.switchDialog($dialog)
  170. }).on('click', '.btn-close', function(e) {
  171. that.close($dialog)
  172. e.preventDefault()
  173. }).on('click', '.dialogHeader > a', function(e) {
  174. var $a = $(this)
  175. if ($a.hasClass('close')) that.close($dialog)
  176. if ($a.hasClass('minimize')) {
  177. that.minimize($dialog)
  178. }
  179. if ($a.hasClass('maximize')) {
  180. that.switchDialog($dialog)
  181. that.maxsize($dialog)
  182. }
  183. if ($a.hasClass('restore')) that.restore($dialog)
  184. e.preventDefault()
  185. e.stopPropagation()
  186. }).on('dblclick', '.dialogHeader > h1', function(e) {
  187. if (options.maxable) {
  188. if ($dialog.find('> .dialogHeader > a.restore').is(':hidden')) $dialog.find('a.maximize').trigger('click')
  189. else $dialog.find('> .dialogHeader > a.restore').trigger('click')
  190. }
  191. }).on('mousedown.bjui.dialog.drag', '.dialogHeader > h1', function(e) {
  192. that.switchDialog($dialog)
  193. if (!options.drawable || $dialog.data('max')) return
  194. $dialog.data('bjui.dialog.task', true)
  195. setTimeout($.proxy(function () {
  196. if ($dialog.data('bjui.dialog.task')) that.drag(e, $dialog)
  197. }, that), 150)
  198. e.preventDefault()
  199. }).on('mouseup.bjui.dialog.drag', '.dialogHeader > h1', function(e) {
  200. $dialog.data('bjui.dialog.task', false)
  201. }).on('mousedown.bjui.dialog.resize', 'div[class^="resizable"]', function(e) {
  202. if (!options.drawable || $dialog.data('max')) return
  203. var $bar = $(this)
  204. that.switchDialog($dialog)
  205. that.resizeInit(e, $('#bjui-resizable'), $dialog, $bar)
  206. $bar.show()
  207. e.preventDefault()
  208. }).on('mouseup.bjui.dialog.resize', 'div[class^="resizable"]', function(e) {
  209. e.preventDefault()
  210. })
  211. $body.data(options.id, $dialog)
  212. this.tools.reload($dialog, options)
  213. }
  214. $.CurrentDialog = $current = $dialog
  215. }
  216. Dialog.prototype.addMask = function($dialog) {
  217. var $mask = $dialog.data('bjui.dialog.mask')
  218. $dialog.wrap('<div style="z-index:'+ zindex +'" class="bjui-dialog-wrap"></div>')
  219. $dialog.find('> .dialogHeader > a.minimize').hide()
  220. if (!$mask || !$mask.length) {
  221. $mask = $(FRAG.dialogMask)
  222. $mask.css('zIndex', 1).show().insertBefore($dialog)
  223. $dialog.data('bjui.dialog.mask', $mask)
  224. }
  225. }
  226. Dialog.prototype.refresh = function(id) {
  227. if (id && typeof id == 'string') {
  228. var arr = id.split(',')
  229. for (var i = 0; i < arr.length; i++) {
  230. var $dialog = $('body').data(arr[i].trim())
  231. if ($dialog) {
  232. $dialog.removeData('bjui.clientPaging')
  233. this.tools.reload($dialog)
  234. }
  235. }
  236. } else {
  237. $current.removeData('bjui.clientPaging')
  238. this.tools.reload($current)
  239. }
  240. }
  241. Dialog.prototype.reload = function(option, initOptionFlag) {
  242. var that = this
  243. var options = $.extend({}, typeof option == 'object' && option)
  244. var $dialog = (options.id && $('body').data(options.id)) || that.getCurrent()
  245. if ($dialog && $dialog.length) {
  246. var initOptions = $dialog.data('initOptions'), op = $.extend({}, initOptions, options)
  247. var _reload = function() {
  248. var $dialogContent = $dialog.find('> .dialogContent')
  249. if (initOptions.width != op.width) {
  250. if (!op.max) {
  251. $dialog.animate({ width:op.width}, 'normal', function() { $dialogContent.width(op.width) })
  252. } else {
  253. $dialog.width(op.width)
  254. $dialogContent.width(op.width)
  255. }
  256. }
  257. if (initOptions.height != op.height) {
  258. if (!op.max) {
  259. $dialog.animate({ height:op.height }, 'normal', function() {
  260. $dialogContent.height(op.height - $dialog.find('> .dialogHeader').outerHeight() - 6).resizePageH()
  261. })
  262. } else {
  263. $dialog.height(op.height)
  264. $dialogContent.height(op.height - $dialog.find('> .dialogHeader').outerHeight() - 6)
  265. }
  266. }
  267. if (initOptions.maxable != op.maxable) {
  268. if (op.maxable) $dialog.find('a.maximize').show()
  269. else $dialog.find('a.maximize').hide()
  270. }
  271. if (initOptions.minable != op.minable) {
  272. if (op.minable) $dialog.find('a.minimize').show()
  273. else $dialog.find('a.minimize').hide()
  274. }
  275. if (initOptions.max != op.max && op.max) setTimeout(that.maxsize($dialog), 10)
  276. if (initOptions.mask != op.mask) {
  277. if (op.mask) {
  278. that.addMask($dialog)
  279. if ($.fn.taskbar) that.$element.taskbar('closeDialog', op.id)
  280. } else if (op.minable && $.fn.taskbar) {
  281. that.$element.taskbar({id:op.id, title:op.title})
  282. }
  283. }
  284. if (initOptions.title != op.title) {
  285. $dialog.find('> .dialogHeader > h1 > span.title').html(op.title)
  286. $dialog.taskbar('changeTitle', op.id, op.title)
  287. }
  288. $dialog.data('options', op)
  289. if (!initOptionFlag) $dialog.data('initOptions', op)
  290. that.tools.reload($dialog, op)
  291. }
  292. if (op.reloadWarn) {
  293. $dialog.alertmsg('confirm', op.reloadWarn, {
  294. okCall: function() {
  295. _reload()
  296. }
  297. })
  298. } else {
  299. _reload()
  300. }
  301. }
  302. }
  303. Dialog.prototype.reloadForm = function(clearQuery, option) {
  304. var $dialog, options
  305. if (typeof option == 'string') {
  306. $dialog = $('body').data(option)
  307. options = $dialog.data('options')
  308. } else if (typeof option == 'object') {
  309. $dialog = (option.id && $('body').data(option.id)) || this.getCurrent()
  310. }
  311. if ($dialog) {
  312. if (typeof option == 'object') {
  313. if (option.title) $dialog.find('> .dialogHeader > h1 > span.title').html(option.title)
  314. options = $.extend({}, option, $dialog.data('options'))
  315. }
  316. var $pagerForm = $dialog.find('#pagerForm'), data = {}, pageData = {}
  317. if ($pagerForm.attr('action')) options.url = $pagerForm.attr('action')
  318. if ($pagerForm && $pagerForm.length) {
  319. pageData = $pagerForm.serializeJson()
  320. if (!option || !option.type) options.type = $pagerForm.attr('method') || 'POST'
  321. if (clearQuery) {
  322. var pageInfo = BJUI.pageInfo
  323. for (var key in pageInfo) {
  324. data[pageInfo[key]] = pageData[pageInfo[key]]
  325. }
  326. } else {
  327. data = pageData
  328. }
  329. options.data = $.extend({}, options.data || {}, data)
  330. }
  331. this.reload(options, true)
  332. }
  333. }
  334. Dialog.prototype.getCurrent = function() {
  335. return $current
  336. }
  337. Dialog.prototype.switchDialog = function($dialog) {
  338. var index = $dialog.css('zIndex')
  339. if ($current && $current != $dialog) {
  340. var cindex = $current.css('zIndex')
  341. $current.css('zIndex', index)
  342. $dialog.css('zIndex', cindex)
  343. $.CurrentDialog = $current = $dialog
  344. if ($.fn.taskbar) this.$element.taskbar('switchTask', $dialog.data('options').id)
  345. }
  346. $dialog.addClass(shadow)
  347. $('body').find('> .bjui-dialog-container').not($dialog).removeClass(shadow)
  348. }
  349. Dialog.prototype.close = function(dialog) {
  350. var that = this
  351. var $dialog = (typeof dialog == 'string') ? $('body').data(dialog) : dialog
  352. var $mask = $dialog.data('bjui.dialog.mask')
  353. var options = $dialog.data('options')
  354. var target = $dialog.data('bjui.dialog.target')
  355. var beforeClose = options.beforeClose ? options.beforeClose.toFunc() : null
  356. var onClose = options.onClose ? options.onClose.toFunc() : null
  357. var canClose = true
  358. if (!$dialog || !options) return
  359. if (beforeClose) canClose = beforeClose.apply(that, [$dialog])
  360. if (!canClose) {
  361. that.switchDialog($dialog)
  362. return
  363. }
  364. if (options.target && target) $(options.target).html(target)
  365. if ($mask && $mask.length) {
  366. $mask.remove()
  367. $dialog.unwrap()
  368. } else if ($.fn.taskbar) {
  369. this.$element.taskbar('closeDialog', options.id)
  370. }
  371. $dialog.animate({top:-$dialog.outerHeight(), opacity:0.1}, 'normal', function() {
  372. $('body').removeData(options.id)
  373. $dialog.trigger(BJUI.eventType.beforeCloseDialog).remove()
  374. if (onClose) onClose.apply(that)
  375. var $dialogs = $('body').find('.bjui-dialog-container')
  376. var $_current = undefined
  377. if ($dialogs.length) {
  378. $_current = that.$element.getMaxIndexObj($dialogs)
  379. } else {
  380. zindex = Dialog.ZINDEX
  381. $current = null
  382. }
  383. if ($_current && $_current.is(':visible')) that.switchDialog($_current)
  384. })
  385. }
  386. Dialog.prototype.closeCurrent = function() {
  387. this.close($current)
  388. }
  389. Dialog.prototype.checkTimeout = function() {
  390. var $dialogConetnt = $current.find('> .dialogContent')
  391. var json = JSON.parse($dialogConetnt.html())
  392. if (json && json[BJUI.keys.statusCode] == BJUI.statusCode.timeout) this.closeCurrent()
  393. }
  394. Dialog.prototype.maxsize = function($dialog) {
  395. $dialog.data('original', {
  396. top: $dialog.css('top'),
  397. left: $dialog.css('left'),
  398. width: $dialog.css('width'),
  399. height: $dialog.css('height')
  400. }).data('max', true)
  401. $dialog.find('> .dialogHeader > a.maximize').hide()
  402. $dialog.find('> .dialogHeader > a.restore').show()
  403. var iContentW = $(window).width()
  404. var iContentH = $(window).height() - $('#bjui-taskbar').height() - 1
  405. $dialog.css({ top:0, left:0, width:iContentW, height:iContentH })
  406. this.tools.resizeContent($dialog, iContentW, iContentH)
  407. }
  408. Dialog.prototype.restore = function($dialog) {
  409. var original = $dialog.data('original')
  410. var dwidth = parseInt(original.width)
  411. var dheight = parseInt(original.height)
  412. $dialog.css({
  413. top: original.top,
  414. left: original.left,
  415. width: dwidth,
  416. height: dheight
  417. })
  418. this.tools.resizeContent($dialog, dwidth, dheight)
  419. $dialog.find('> .dialogHeader > a.maximize').show()
  420. $dialog.find('> .dialogHeader > a.restore').hide()
  421. $dialog.data('max', false)
  422. }
  423. Dialog.prototype.minimize = function($dialog) {
  424. $dialog.hide()
  425. if ($.fn.taskbar) this.$element.taskbar('minimize', $dialog)
  426. }
  427. Dialog.prototype.drag = function(e, $dialog) {
  428. var $shadow = $('#bjui-dialogProxy')
  429. $dialog.find('> .dialogContent').css('opacity', '.3')
  430. $dialog.basedrag({
  431. selector : '> .dialogHeader',
  432. stop : function() {
  433. $dialog
  434. .css({left:$dialog.css('left'), top:$dialog.css('top')})
  435. .find('> .dialogContent').css('opacity', 1)
  436. },
  437. event : e,
  438. nounbind : true
  439. })
  440. }
  441. Dialog.prototype.resizeDialog = function($resizable, $dialog, target) {
  442. var tmove
  443. var oleft = parseInt($resizable.css('left'))
  444. var otop = parseInt($resizable.css('top'))
  445. var height = parseInt($resizable.css('height'))
  446. var width = parseInt($resizable.css('width'))
  447. if (target == 'n' || target == 'nw') tmove = parseInt($dialog.css('top')) - otop
  448. else tmove = height - parseInt($dialog.css('height'))
  449. if (otop < 0) otop = 0
  450. $dialog
  451. .css({top:otop, left:oleft, width:width + 2, height:height + 1})
  452. .find('> .dialogContent').css('width', (width - 10))
  453. if (target != 'w' && target != 'e') {
  454. var $dialogContent = $dialog.find('> .dialogContent')
  455. $dialogContent
  456. .css({height:height - $dialog.find('> .dialogHeader').outerHeight() - 6})
  457. .resizePageH()
  458. }
  459. $(window).trigger(BJUI.eventType.resizeGrid)
  460. }
  461. Dialog.prototype.resizeInit = function(e, $resizable, $dialog, $bar) {
  462. var that = this
  463. var target = $bar.attr('tar')
  464. $('body').css('cursor', target +'-resize')
  465. $resizable
  466. .css({
  467. top : $dialog.css('top'),
  468. left : $dialog.css('left'),
  469. height : $dialog.outerHeight(),
  470. width : $dialog.css('width')
  471. })
  472. .show()
  473. if (!this.options.dragCurrent) {
  474. this.options.dragCurrent = {
  475. $resizable : $resizable,
  476. $dialog : $dialog,
  477. target : target,
  478. oleft : parseInt($resizable.css('left')) || 0,
  479. owidth : parseInt($resizable.css('width')) || 0,
  480. otop : parseInt($resizable.css('top')) || 0,
  481. oheight : parseInt($resizable.css('height')) || 0,
  482. ox : e.pageX || e.screenX,
  483. oy : e.pageY || e.clientY
  484. }
  485. $(document).on('mouseup.bjui.dialog.resize', $.proxy(that.resizeStop, that))
  486. $(document).on('mousemove.bjui.dialog.resize', $.proxy(that.resizeStart, that))
  487. }
  488. }
  489. Dialog.prototype.resizeStart = function(e) {
  490. var current = this.options.dragCurrent
  491. if (!current) return
  492. if (!e) var e = window.event
  493. var lmove = (e.pageX || e.screenX) - current.ox
  494. var tmove = (e.pageY || e.clientY) - current.oy
  495. var $mask = current.$dialog.data('bjui.dialog.mask')
  496. if (!$mask || !$mask.length)
  497. if ((e.pageY || e.clientY) <= 0 || (e.pageY || e.clientY) >= ($(window).height() - current.$dialog.find('> .dialogHeader').outerHeight())) return
  498. var target = current.target
  499. var width = current.owidth
  500. var height = current.oheight
  501. if (target != 'n' && target != 's')
  502. width += (target.indexOf('w') >= 0) ? -lmove : lmove
  503. if (width >= this.options.minW) {
  504. if (target.indexOf('w') >= 0)
  505. current.$resizable.css('left', (current.oleft + lmove))
  506. if (target != 'n' && target != 's')
  507. current.$resizable.css('width', width)
  508. }
  509. if (target != 'w' && target != 'e')
  510. height += (target.indexOf('n') >= 0) ? -tmove : tmove
  511. if (height >= this.options.minH) {
  512. if (target.indexOf('n') >= 0)
  513. current.$resizable.css('top', (current.otop + tmove))
  514. if (target != 'w' && target != 'e')
  515. current.$resizable.css('height', height)
  516. }
  517. }
  518. Dialog.prototype.resizeStop = function(e) {
  519. var current = this.options.dragCurrent
  520. if (!current) return false
  521. $(document).off('mouseup.bjui.dialog.resize')
  522. $(document).off('mousemove.bjui.dialog.resize')
  523. this.options.dragCurrent = null
  524. this.resizeDialog(current.$resizable, current.$dialog, current.target)
  525. $('body').css('cursor', '')
  526. current.$resizable.hide()
  527. }
  528. // DIALOG PLUGIN DEFINITION
  529. // =======================
  530. function Plugin(option) {
  531. var args = arguments
  532. var property = option
  533. return this.each(function () {
  534. var $this = $(this)
  535. var options = $.extend({}, Dialog.DEFAULTS, typeof option == 'object' && option)
  536. var data = $this.data('bjui.dialog')
  537. if (!data) $this.data('bjui.dialog', (data = new Dialog(this, options)))
  538. if (typeof property == 'string' && $.isFunction(data[property])) {
  539. [].shift.apply(args)
  540. if (!args) data[property]()
  541. else data[property].apply(data, args)
  542. } else {
  543. data = new Dialog(this, options)
  544. data.open()
  545. }
  546. })
  547. }
  548. var old = $.fn.dialog
  549. $.fn.dialog = Plugin
  550. $.fn.dialog.Constructor = Dialog
  551. // DIALOG NO CONFLICT
  552. // =================
  553. $.fn.dialog.noConflict = function () {
  554. $.fn.dialog = old
  555. return this
  556. }
  557. // DIALOG DATA-API
  558. // ==============
  559. $(document).on('click.bjui.dialog.data-api', '[data-toggle="dialog"]', function(e) {
  560. var $this = $(this), href = $this.attr('href'), data = $this.data(), options = data.options
  561. if (options) {
  562. if (typeof options == 'string') options = options.toObj()
  563. if (typeof options == 'object')
  564. $.extend(data, options)
  565. }
  566. if (!data.title) data.title = $this.text()
  567. if (href && !data.url) data.url = href
  568. Plugin.call($this, data)
  569. e.preventDefault()
  570. })
  571. }(jQuery);