dabory.data-linker.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function($) {
  2. $.fn.dataLinker = function(options) {
  3. }
  4. $.fn.dataLinker.appBase64 = null;
  5. $.fn.dataLinker.daboryApp = function (url, request, callback, async = true) {
  6. getParameter()
  7. $.ajax({
  8. url: `${$.fn.dataLinker.serverUrl}/dabory-app/${url}`,
  9. data: JSON.stringify(request),
  10. beforeSend: function (xhr) {
  11. xhr.setRequestHeader('Api23Key', $.fn.dataLinker.api23Key);
  12. },
  13. method: 'POST',
  14. dataType: 'json',
  15. async: async,
  16. })
  17. .done(function (json) {
  18. callback(json)
  19. })
  20. .fail(function(json, textStatus, errorThrown) {
  21. callback(json);
  22. iziToast.error({ title: 'Error', message: 'Dabory App API Error' });
  23. });
  24. }
  25. $.fn.dataLinker.api23Js = function (url, request, callback, async = true) {
  26. getParameter()
  27. $.ajax({
  28. url: `${$.fn.dataLinker.serverUrl}/dabory-app/api23-js`,
  29. data: JSON.stringify(request),
  30. beforeSend: function (xhr) {
  31. xhr.setRequestHeader('Url', url);
  32. xhr.setRequestHeader('Api23Key', $.fn.dataLinker.api23Key);
  33. },
  34. method: 'POST',
  35. dataType: 'json',
  36. async: async,
  37. })
  38. .done(function (json) {
  39. callback(json)
  40. })
  41. .fail(function(json, textStatus, errorThrown) {
  42. callback(json);
  43. iziToast.error({ title: 'Error', message: 'Dabory App api23-js API Error' });
  44. });
  45. }
  46. function getParameter() {
  47. if ($.fn.dataLinker.api23Key && $.fn.dataLinker.serverUrl) {
  48. return
  49. }
  50. let libFileName = '/dabory/js/widget.js',
  51. scripts = document.getElementsByTagName('script'),
  52. i, j, src, parts, basePath, options = {};
  53. for (i = 0; i < scripts.length; i++) {
  54. src = scripts[i].src;
  55. if (src.indexOf(libFileName) !== -1) {
  56. parts = src.split('?');
  57. basePath = parts[0].replace(libFileName, '');
  58. if (parts[1]) {
  59. const opt = parts[1].split('&');
  60. for (j = opt.length-1; j >= 0; --j) {
  61. const pair = opt[j].split(/=(.*)/s);
  62. options[pair[0]] = pair[1];
  63. }
  64. }
  65. break;
  66. }
  67. }
  68. $.fn.dataLinker.api23Key = options['api23Key']
  69. $.fn.dataLinker.serverUrl = options['serverUrl']
  70. }
  71. }(jQuery));