extension_blockui.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # BlockUI extension
  4. *
  5. * Demo JS code for extension_blockui.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var BlockUi = function() {
  11. //
  12. // Setup module components
  13. //
  14. // BlockUI
  15. var _componentBlockUi = function() {
  16. if (!$().block) {
  17. console.warn('Warning - blockui.min.js is not loaded.');
  18. return;
  19. }
  20. // Page elements
  21. // ------------------------------
  22. // Block card
  23. $('#block-card').on('click', function() {
  24. var block = $(this).closest('.card');
  25. $(block).block({
  26. message: '<i class="icon-spinner4 spinner"></i>',
  27. timeout: 2000, //unblock after 2 seconds
  28. overlayCSS: {
  29. backgroundColor: '#fff',
  30. opacity: 0.8,
  31. cursor: 'wait'
  32. },
  33. css: {
  34. border: 0,
  35. padding: 0,
  36. backgroundColor: 'transparent'
  37. }
  38. });
  39. });
  40. // Block sidebar
  41. $('#block-sidebar').on('click', function() {
  42. var block = $('.sidebar-main');
  43. $(block).block({
  44. message: '<i class="icon-spinner4 spinner"></i>',
  45. timeout: 2000, //unblock after 2 seconds
  46. overlayCSS: {
  47. backgroundColor: '#1b2024',
  48. opacity: 0.6,
  49. cursor: 'wait'
  50. },
  51. centerY: 0,
  52. css: {
  53. top: '180px',
  54. border: 0,
  55. color: '#fff',
  56. padding: 0,
  57. backgroundColor: 'transparent'
  58. }
  59. });
  60. });
  61. // Block page
  62. $('#block-page').on('click', function() {
  63. $.blockUI({
  64. message: '<i class="icon-spinner4 spinner"></i>',
  65. timeout: 2000, //unblock after 2 seconds
  66. overlayCSS: {
  67. backgroundColor: '#1b2024',
  68. opacity: 0.8,
  69. zIndex: 1200,
  70. cursor: 'wait'
  71. },
  72. css: {
  73. border: 0,
  74. color: '#fff',
  75. padding: 0,
  76. zIndex: 1201,
  77. backgroundColor: 'transparent'
  78. }
  79. });
  80. });
  81. // Overlays
  82. // ------------------------------
  83. // Basic overlay
  84. $('#basic-overlay').on('click', function() {
  85. var block = $(this).closest('.card');
  86. $(block).block({
  87. message: '<i class="icon-spinner4 spinner"></i>',
  88. timeout: 2000, //unblock after 2 seconds
  89. overlayCSS: {
  90. backgroundColor: '#fff',
  91. opacity: 0.8,
  92. cursor: 'wait'
  93. },
  94. css: {
  95. border: 0,
  96. padding: 0,
  97. backgroundColor: 'transparent'
  98. }
  99. });
  100. });
  101. // Custom overlay
  102. $('#overlay-custom').on('click', function() {
  103. var block = $(this).closest('.card');
  104. $(block).block({
  105. message: '<i class="icon-spinner4 spinner"></i>',
  106. timeout: 2000, //unblock after 2 seconds
  107. overlayCSS: {
  108. backgroundColor: '#0E8F92',
  109. opacity: 0.9,
  110. cursor: 'wait'
  111. },
  112. css: {
  113. border: 0,
  114. padding: 0,
  115. color: '#fff',
  116. backgroundColor: 'transparent'
  117. }
  118. });
  119. });
  120. // Overlay with custom color
  121. $('#overlay-cover').on('click', function() {
  122. var block = $(this).closest('.card');
  123. $(block).block({
  124. message: '<i class="icon-spinner4 spinner"></i>',
  125. timeout: 2000, //unblock after 2 seconds
  126. overlayCSS: {
  127. backgroundColor: '#3F9EC3',
  128. opacity: 1,
  129. cursor: 'wait'
  130. },
  131. css: {
  132. border: 0,
  133. padding: 0,
  134. color: '#fff',
  135. backgroundColor: 'transparent'
  136. }
  137. });
  138. });
  139. // Overlay without text
  140. $('#no-message').on('click', function() {
  141. var block = $(this).closest('.card');
  142. $(block).block({
  143. message: null,
  144. timeout: 2000, //unblock after 2 seconds
  145. overlayCSS: {
  146. backgroundColor: '#fff',
  147. opacity: 0.8,
  148. cursor: 'wait'
  149. },
  150. css: {
  151. border: 0,
  152. padding: 0,
  153. backgroundColor: 'transparent'
  154. }
  155. });
  156. });
  157. // No overlay
  158. $('#no-overlay').on('click', function() {
  159. var block = $(this).closest('.card');
  160. $(block).block({
  161. message: '<i class="icon-spinner4 spinner"></i>',
  162. showOverlay: false,
  163. timeout: 2000, //unblock after 2 seconds
  164. css: {
  165. border: 0,
  166. padding: 15,
  167. backgroundColor: '#283133',
  168. color: '#fff',
  169. width: 46,
  170. height: 46,
  171. lineHeight: 1,
  172. '-webkit-border-radius': '2px',
  173. '-moz-border-radius': '2px',
  174. opacity: 0.95
  175. }
  176. });
  177. });
  178. // Messages
  179. // ------------------------------
  180. // Default message
  181. $('#default-message').on('click', function() {
  182. var block = $(this).closest('.card');
  183. $(block).block({
  184. message: '<span class="font-weight-semibold">Please wait...</span>',
  185. timeout: 2000, //unblock after 2 seconds
  186. overlayCSS: {
  187. backgroundColor: '#fff',
  188. opacity: 0.8,
  189. cursor: 'wait'
  190. },
  191. css: {
  192. border: 0,
  193. padding: 0,
  194. backgroundColor: 'transparent'
  195. }
  196. });
  197. });
  198. // Spinner only
  199. $('#spinner-only').on('click', function() {
  200. var block = $(this).closest('.card');
  201. $(block).block({
  202. message: '<i class="icon-spinner4 spinner"></i>',
  203. timeout: 2000, //unblock after 2 seconds
  204. overlayCSS: {
  205. backgroundColor: '#fff',
  206. opacity: 0.8,
  207. cursor: 'wait'
  208. },
  209. css: {
  210. border: 0,
  211. padding: 0,
  212. backgroundColor: 'transparent'
  213. }
  214. });
  215. });
  216. // Custom message
  217. $('#custom-message').on('click', function() {
  218. var block = $(this).closest('.card');
  219. $(block).block({
  220. message: '<span class="font-weight-semibold"><i class="icon-spinner4 spinner mr-2"></i>&nbsp; Updating data</span>',
  221. timeout: 2000, //unblock after 2 seconds
  222. overlayCSS: {
  223. backgroundColor: '#fff',
  224. opacity: 0.8,
  225. cursor: 'wait'
  226. },
  227. css: {
  228. border: 0,
  229. padding: '10px 15px',
  230. color: '#fff',
  231. width: 'auto',
  232. '-webkit-border-radius': 3,
  233. '-moz-border-radius': 3,
  234. backgroundColor: '#333'
  235. }
  236. });
  237. });
  238. // DOM message
  239. $('#dom-message').on('click', function() {
  240. var block = $(this).closest('.card');
  241. $(block).block({
  242. message: $(this).parent().parent().find('.blockui-message'),
  243. timeout: 2000, //unblock after 2 seconds
  244. overlayCSS: {
  245. backgroundColor: '#fff',
  246. opacity: 0.8,
  247. cursor: 'wait'
  248. },
  249. css: {
  250. width: 'auto',
  251. '-webkit-border-radius': 2,
  252. '-moz-border-radius': 2,
  253. padding: 0,
  254. border: 0,
  255. backgroundColor: 'transparent'
  256. }
  257. });
  258. });
  259. // Multiple messages
  260. $('#multiple-messages').on('click', function() {
  261. var message = $(this).parent().parent().find('.blockui-message');
  262. var block = $(this).closest('.card');
  263. $(block).block({
  264. message: message,
  265. overlayCSS: {
  266. backgroundColor: '#fff',
  267. opacity: 0.8,
  268. cursor: 'wait'
  269. },
  270. css: {
  271. width: 100,
  272. '-webkit-border-radius': 2,
  273. '-moz-border-radius': 2,
  274. border: 0,
  275. padding: 0,
  276. backgroundColor: 'transparent'
  277. },
  278. onBlock: function() {
  279. clearTimeout();
  280. }
  281. });
  282. window.setTimeout(function () {
  283. message.html('<i class="icon-spinner4 spinner mt-1"></i> <span class="font-weight-semibold d-block mt-2">Loading</span>')
  284. }, 0);
  285. window.setTimeout(function () {
  286. message.html('<i class="icon-spinner4 spinner mt-1"></i> <span class="font-weight-semibold d-block mt-2">Please wait</span>')
  287. }, 2000);
  288. window.setTimeout(function () {
  289. message.addClass('bg-danger').html('<i class="icon-warning mt-1"></i> <span class="font-weight-semibold d-block mt-2">Load error</span>')
  290. }, 4000);
  291. window.setTimeout(function () {
  292. $(block).unblock({
  293. onUnblock: function(){
  294. message.removeClass('bg-danger');
  295. }
  296. });
  297. }, 6000);
  298. });
  299. // Custom message animation
  300. $('#custom-message-animation').on('click', function() {
  301. var block = $(this).closest('.card');
  302. $(block).block({
  303. message: $('.blockui-animation-container'),
  304. timeout: 3000, //unblock after 3 seconds
  305. overlayCSS: {
  306. backgroundColor: '#fff',
  307. opacity: 0.8,
  308. cursor: 'wait'
  309. },
  310. css: {
  311. width: 36,
  312. height: 36,
  313. color: '#fff',
  314. border: 0,
  315. padding: 0,
  316. backgroundColor: 'transparent'
  317. }
  318. });
  319. var animation = $(this).data("animation");
  320. $('.blockui-animation-container').addClass("animated " + animation).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function () {
  321. $(this).removeClass("animated " + animation);
  322. });
  323. });
  324. // Custom message position
  325. $('#custom-position').on('click', function() {
  326. var block = $(this).closest('.card');
  327. $(block).block({
  328. message: '<i class="icon-spinner4 spinner"></i>',
  329. timeout: 2000, //unblock after 2 seconds
  330. centerX: 0,
  331. centerY: 0,
  332. overlayCSS: {
  333. backgroundColor: '#fff',
  334. opacity: 0.8,
  335. cursor: 'wait'
  336. },
  337. css: {
  338. width: 16,
  339. top: '15px',
  340. left: '',
  341. right: '15px',
  342. border: 0,
  343. padding: 0,
  344. backgroundColor: 'transparent'
  345. }
  346. });
  347. });
  348. // Unblock options
  349. // ------------------------------
  350. // Auto unblock
  351. $('#auto-unblock').on('click', function() {
  352. var block = $(this).closest('.card');
  353. $(block).block({
  354. message: '<i class="icon-spinner4 spinner"></i>',
  355. timeout: 2000, //unblock after 2 seconds
  356. overlayCSS: {
  357. backgroundColor: '#fff',
  358. opacity: 0.8,
  359. cursor: 'wait'
  360. },
  361. css: {
  362. border: 0,
  363. padding: 0,
  364. backgroundColor: 'transparent'
  365. }
  366. });
  367. });
  368. // Unblock on click
  369. $('#click-unblock').on('click', function() {
  370. var block = $(this).closest('.card');
  371. $(block).block({
  372. message: '<i class="icon-spinner4 spinner"></i>',
  373. overlayCSS: {
  374. backgroundColor: '#fff',
  375. opacity: 0.8,
  376. cursor: 'wait'
  377. },
  378. css: {
  379. width: 16,
  380. border: 0,
  381. padding: 0,
  382. backgroundColor: 'transparent'
  383. }
  384. });
  385. $('.blockOverlay').on('click', function() {
  386. $(block).unblock();
  387. });
  388. });
  389. // Callbacks
  390. // ------------------------------
  391. // Block callback
  392. $('#block-callback').on('click', function() {
  393. $.blockUI({
  394. message: '<i class="icon-spinner4 spinner"></i>',
  395. fadeIn: 800,
  396. timeout: 2000, //unblock after 2 seconds
  397. overlayCSS: {
  398. backgroundColor: '#1b2024',
  399. opacity: 0.8,
  400. zIndex: 1200,
  401. cursor: 'wait'
  402. },
  403. css: {
  404. border: 0,
  405. color: '#fff',
  406. zIndex: 1201,
  407. padding: 0,
  408. backgroundColor: 'transparent'
  409. },
  410. onBlock: function() {
  411. alert('Page is now blocked. FadeIn completed.');
  412. }
  413. });
  414. });
  415. // Unblock callback
  416. $('#unblock-callback').on('click', function() {
  417. $.blockUI({
  418. message: '<i class="icon-spinner4 spinner"></i>',
  419. timeout: 2000, //unblock after 2 seconds
  420. overlayCSS: {
  421. backgroundColor: '#1b2024',
  422. opacity: 0.8,
  423. zIndex: 1200,
  424. cursor: 'wait'
  425. },
  426. css: {
  427. border: 0,
  428. color: '#fff',
  429. padding: 0,
  430. zIndex: 1201,
  431. backgroundColor: 'transparent'
  432. },
  433. onUnblock: function() {
  434. alert('Page is now unblocked. FadeOut completed.');
  435. }
  436. });
  437. });
  438. // Overlay callback
  439. $('#overlay-callback').on('click', function() {
  440. $.blockUI({
  441. message: '<i class="icon-spinner4 spinner"></i>',
  442. overlayCSS: {
  443. backgroundColor: '#1b2024',
  444. opacity: 0.8,
  445. zIndex: 1200,
  446. cursor: 'wait'
  447. },
  448. css: {
  449. border: 0,
  450. color: '#fff',
  451. padding: 0,
  452. zIndex: 1201,
  453. backgroundColor: 'transparent'
  454. },
  455. onOverlayClick: $.unblockUI
  456. });
  457. });
  458. // Other options
  459. // ------------------------------
  460. // Growl notification
  461. $('#growl').on('click', function() {
  462. $.blockUI({
  463. message: $('.blockui-growl'),
  464. fadeIn: 700,
  465. fadeOut: 700,
  466. timeout: 3000000, //unblock after 3 seconds
  467. showOverlay: false,
  468. centerY: false,
  469. css: {
  470. width: '250px',
  471. backgroundColor: 'transparent',
  472. top: '20px',
  473. left: 'auto',
  474. right: '20px',
  475. border: 0,
  476. opacity: .95,
  477. zIndex: 1200,
  478. }
  479. });
  480. });
  481. };
  482. //
  483. // Return objects assigned to module
  484. //
  485. return {
  486. init: function() {
  487. _componentBlockUi();
  488. }
  489. }
  490. }();
  491. // Initialize module
  492. // ------------------------------
  493. document.addEventListener('DOMContentLoaded', function() {
  494. BlockUi.init();
  495. });