Няма описание
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.

editor.jqueryui.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*! jQuery UI integration for DataTables' Editor
  2. * ©2015 SpryMedia Ltd - datatables.net/license
  3. */
  4. (function( factory ){
  5. if ( typeof define === 'function' && define.amd ) {
  6. // AMD
  7. define( ['jquery', 'datatables.net-jqui', 'datatables.net-editor'], function ( $ ) {
  8. return factory( $, window, document );
  9. } );
  10. }
  11. else if ( typeof exports === 'object' ) {
  12. // CommonJS
  13. module.exports = function (root, $) {
  14. if ( ! root ) {
  15. root = window;
  16. }
  17. if ( ! $ || ! $.fn.dataTable ) {
  18. $ = require('datatables.net-jqui')(root, $).$;
  19. }
  20. if ( ! $.fn.dataTable.Editor ) {
  21. require('datatables.net-editor')(root, $);
  22. }
  23. return factory( $, root, root.document );
  24. };
  25. }
  26. else {
  27. // Browser
  28. factory( jQuery, window, document );
  29. }
  30. }(function( $, window, document, undefined ) {
  31. 'use strict';
  32. var DataTable = $.fn.dataTable;
  33. var Editor = DataTable.Editor;
  34. var doingClose = false;
  35. /*
  36. * Set the default display controller to be our foundation control
  37. */
  38. Editor.defaults.display = "jqueryui";
  39. /*
  40. * Change the default classes from Editor to be classes for Bootstrap
  41. */
  42. var buttonClass = "btn ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only";
  43. $.extend( true, $.fn.dataTable.Editor.classes, {
  44. form: {
  45. button: buttonClass,
  46. buttonInternal: buttonClass
  47. }
  48. } );
  49. /*
  50. * jQuery UI display controller - this is effectively a proxy to the jQuery UI
  51. * modal control.
  52. */
  53. Editor.display.jqueryui = $.extend( true, {}, Editor.models.displayController, {
  54. init: function ( dte ) {
  55. dte.__dialouge = $('<div class="DTED"/>')
  56. .css('display', 'none')
  57. .appendTo('body')
  58. .dialog( $.extend( true, Editor.display.jqueryui.modalOptions, {
  59. autoOpen: false,
  60. buttons: { "A": function () {} }, // fake button so the button container is created
  61. closeOnEscape: false // allow editor's escape function to run
  62. } ) );
  63. // Need to know when the dialogue is closed using its own trigger
  64. // so we can reset the form
  65. $(dte.__dialouge).on( 'dialogclose', function (e) {
  66. if ( ! doingClose ) {
  67. dte.close();
  68. }
  69. } );
  70. return Editor.display.jqueryui;
  71. },
  72. open: function ( dte, append, callback ) {
  73. dte.__dialouge
  74. .append( append )
  75. .dialog( 'open' );
  76. $(dte.dom.formError).appendTo(
  77. dte.__dialouge.parent().find('div.ui-dialog-buttonpane')
  78. );
  79. dte.__dialouge.parent().find('.ui-dialog-title').html( dte.dom.header.innerHTML );
  80. dte.__dialouge.parent().addClass('DTED');
  81. // Modify the Editor buttons to be jQuery UI suitable
  82. var buttons = $(dte.dom.buttons)
  83. .children()
  84. .addClass( 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' )
  85. .each( function () {
  86. $(this).wrapInner( '<span class="ui-button-text" />' );
  87. } );
  88. // Move the buttons into the jQuery UI button set
  89. dte.__dialouge.parent().find('div.ui-dialog-buttonset')
  90. .empty()
  91. .append( buttons.parent() );
  92. if ( callback ) {
  93. callback();
  94. }
  95. },
  96. close: function ( dte, callback ) {
  97. if ( dte.__dialouge ) {
  98. // Don't want to trigger a close() call from dialogclose!
  99. doingClose = true;
  100. dte.__dialouge.dialog( 'close' );
  101. doingClose = false;
  102. }
  103. if ( callback ) {
  104. callback();
  105. }
  106. },
  107. node: function ( dte ) {
  108. return dte.__dialouge[0];
  109. },
  110. // jQuery UI dialogues perform their own focus capture
  111. captureFocus: false
  112. } );
  113. Editor.display.jqueryui.modalOptions = {
  114. width: 600,
  115. modal: true
  116. };
  117. return DataTable.Editor;
  118. }));