gallery_library.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Media library
  4. *
  5. * Demo JS code for gallery_library.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var MediaLibrary = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Datatable
  15. var _componentDatatable = function() {
  16. if (!$().DataTable) {
  17. console.warn('Warning - datatables.min.js is not loaded.');
  18. return;
  19. }
  20. // Initialize table
  21. var media_library = $('.media-library').DataTable({
  22. autoWidth: false,
  23. columnDefs: [
  24. {
  25. orderable: false,
  26. width: 20,
  27. targets: 0
  28. },
  29. {
  30. orderable: false,
  31. width: 100,
  32. targets: 1
  33. },
  34. {
  35. orderable: false,
  36. width: 90,
  37. targets: 6
  38. }
  39. ],
  40. order: [[ 2, 'asc' ]],
  41. lengthMenu: [ 25, 50, 75, 100 ],
  42. displayLength: 25,
  43. dom: '<"datatable-header"fl><"datatable-scroll"t><"datatable-footer"ip>',
  44. language: {
  45. search: '<span>Filter:</span> _INPUT_',
  46. searchPlaceholder: 'Type to filter...',
  47. lengthMenu: '<span>Show:</span> _MENU_',
  48. paginate: { 'first': 'First', 'last': 'Last', 'next': $('html').attr('dir') == 'rtl' ? '&larr;' : '&rarr;', 'previous': $('html').attr('dir') == 'rtl' ? '&rarr;' : '&larr;' }
  49. }
  50. });
  51. // Toggle success class
  52. $('.media-library tbody td input[type=checkbox]').on('change', function () {
  53. if ($(this).is(':checked')) {
  54. $(this).parents('tr').addClass('table-success');
  55. $.uniform.update();
  56. }
  57. else {
  58. $(this).parents('tr').removeClass('table-success');
  59. $.uniform.update();
  60. }
  61. });
  62. };
  63. // Lightbox
  64. var _componentFancybox = function() {
  65. if (!$().fancybox) {
  66. console.warn('Warning - fancybox.min.js is not loaded.');
  67. return;
  68. }
  69. // Image lightbox
  70. $('[data-popup="lightbox"]').fancybox({
  71. padding: 3
  72. });
  73. };
  74. // Uniform
  75. var _componentUniform = function() {
  76. if (!$().uniform) {
  77. console.warn('Warning - uniform.min.js is not loaded.');
  78. return;
  79. }
  80. // Initialize
  81. $('.form-input-styled').uniform();
  82. };
  83. // Select2
  84. var _componentSelect2 = function() {
  85. if (!$().select2) {
  86. console.warn('Warning - select2.min.js is not loaded.');
  87. return;
  88. }
  89. // Initialize
  90. $('.dataTables_length select').select2({
  91. minimumResultsForSearch: Infinity,
  92. dropdownAutoWidth: true,
  93. width: 'auto'
  94. });
  95. };
  96. //
  97. // Return objects assigned to module
  98. //
  99. return {
  100. init: function() {
  101. _componentDatatable();
  102. _componentFancybox();
  103. _componentUniform();
  104. _componentSelect2();
  105. }
  106. }
  107. }();
  108. // Initialize module
  109. // ------------------------------
  110. document.addEventListener('DOMContentLoaded', function() {
  111. MediaLibrary.init();
  112. });