暫無描述
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.foundation.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*! Foundation 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-zf', '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-zf')(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. /*
  34. * Set the default display controller to be our foundation control
  35. */
  36. DataTable.Editor.defaults.display = "foundation";
  37. /*
  38. * Change the default classes from Editor to be classes for Foundation
  39. */
  40. $.extend( true, $.fn.dataTable.Editor.classes, {
  41. field: {
  42. wrapper: "DTE_Field row",
  43. label: "small-4 columns inline",
  44. input: "small-8 columns",
  45. error: "error",
  46. multiValue: "panel radius multi-value",
  47. multiInfo: "small",
  48. multiRestore: "panel radius multi-restore",
  49. "msg-labelInfo": "label secondary",
  50. "msg-info": "label secondary",
  51. "msg-message": "label secondary",
  52. "msg-error": "label alert"
  53. },
  54. form: {
  55. button: "button small",
  56. buttonInternal: "button small"
  57. }
  58. } );
  59. /*
  60. * Foundation display controller - this is effectively a proxy to the Foundation
  61. * modal control.
  62. */
  63. var self;
  64. DataTable.Editor.display.foundation = $.extend( true, {}, DataTable.Editor.models.displayController, {
  65. /*
  66. * API methods
  67. */
  68. "init": function ( dte ) {
  69. self._dom.content = $(
  70. '<div class="reveal reveal-modal DTED" data-reveal />'
  71. );
  72. self._dom.close = $('<button class="close close-button">&times;</div>');
  73. self._dom.close.click( function () {
  74. self._dte.close('icon');
  75. } );
  76. return self;
  77. },
  78. "open": function ( dte, append, callback ) {
  79. if ( self._shown ) {
  80. if ( callback ) {
  81. callback();
  82. }
  83. return;
  84. }
  85. self._dte = dte;
  86. self._shown = true;
  87. var content = self._dom.content;
  88. content.children().detach();
  89. content.append( append );
  90. content.prepend( self._dom.close );
  91. $(self._dom.content)
  92. .one('open.zf.reveal', function () {
  93. if ( callback ) {
  94. callback();
  95. }
  96. })
  97. .one('closed.zf.reveal', function () {
  98. self._shown = false;
  99. });
  100. if ( window.Foundation && window.Foundation.Reveal ) {
  101. // Foundation 6
  102. if ( ! self._reveal ) {
  103. self._reveal = new window.Foundation.Reveal( self._dom.content, {
  104. closeOnClick: false
  105. } );
  106. }
  107. //$(self._dom.content).appendTo('body');
  108. self._reveal.open();
  109. }
  110. else {
  111. // Foundation 5
  112. $(self._dom.content).foundation( 'reveal','open' );
  113. }
  114. $(document).on('click.dte-zf', 'div.reveal-modal-bg, div.reveal-overlay', function (e) {
  115. if ( $(e.target).closest(self._dom.content).length ) {
  116. return;
  117. }
  118. self._dte.background();
  119. } );
  120. },
  121. "close": function ( dte, callback ) {
  122. if ( !self._shown ) {
  123. if ( callback ) {
  124. callback();
  125. }
  126. return;
  127. }
  128. if ( self._reveal ) {
  129. self._reveal.close();
  130. }
  131. else {
  132. $(self._dom.content).foundation( 'reveal', 'close' );
  133. }
  134. $(document).off( 'click.dte-zf' );
  135. self._dte = dte;
  136. self._shown = false;
  137. if ( callback ) {
  138. callback();
  139. }
  140. },
  141. node: function ( dte ) {
  142. return self._dom.content[0];
  143. },
  144. /*
  145. * Private properties
  146. */
  147. "_shown": false,
  148. "_dte": null,
  149. "_dom": {}
  150. } );
  151. self = DataTable.Editor.display.foundation;
  152. return DataTable.Editor;
  153. }));