widget.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function($) {
  2. $.fn.widget = function(options) {
  3. }
  4. $.fn.widget.spinnerLoading = function (dom, loading) {
  5. if (loading) {
  6. $(dom).addClass('button--loading')
  7. } else {
  8. $(dom).removeClass('button--loading')
  9. }
  10. }
  11. $.fn.widget.loadModule = async function(callback) {
  12. loadVendor()
  13. await $.getJSON($.fn.widget.defaults['modFilePath'], function (data) {
  14. data['require']['css'].forEach(path => {
  15. $('head').append(`<link rel="stylesheet" href="${path}">`)
  16. })
  17. data['require']['js'].forEach(path => {
  18. $('head').append(`<script src="${path}"></script>`)
  19. })
  20. });
  21. callback()
  22. }
  23. function loadVendor() {
  24. const vendorPath = $.fn.widget.defaults['vendorPath']
  25. if (typeof iziToast == 'undefined') {
  26. $('head').append(`<script src="${vendorPath}/iziToast/iziToast.js"></script>`)
  27. }
  28. if (typeof Swiper === 'undefined') {
  29. $('head').append(`<script src="${vendorPath}/swiper/swiper-bundle.js"></script>`)
  30. }
  31. if (typeof moment == 'undefined') {
  32. $('head').append(`<script src="${vendorPath}/moment/moment.min.js"></script>`)
  33. }
  34. if (jQuery().draggable === undefined) {
  35. $('head').append(`<script src="${vendorPath}/jquery-ui.js"></script>`)
  36. }
  37. if ($.cookie === undefined) {
  38. $('head').append(`<script src="${vendorPath}/jquery.cookie.js"></script>`)
  39. }
  40. }
  41. $.fn.widget.defaults = {
  42. widgetPath: '/dabory/widget',
  43. vendorPath: '/dabory/vendor',
  44. modFilePath: '/dabory/mod.json',
  45. };
  46. }(jQuery));