functions.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaCore UNA Core
  6. * @{
  7. */
  8. function processJsonData(oData) {
  9. var fContinue = function(oData) {
  10. if(oData && oData.reload != undefined && parseInt(oData.reload) == 1)
  11. document.location = document.location;
  12. if(oData && oData.redirect != undefined && oData.redirect.length != 0)
  13. document.location = oData.redirect;
  14. if(oData && oData.popup != undefined) {
  15. var oPopup = null;
  16. var oOptions = {
  17. fog: {
  18. color: '#fff',
  19. opacity: .7
  20. },
  21. closeOnOuterClick: false
  22. };
  23. if(typeof(oData.popup) == 'object') {
  24. oOptions = $.extend({}, oOptions, oData.popup.options);
  25. oPopup = $(oData.popup.html);
  26. }
  27. else
  28. oPopup = $(oData.popup);
  29. if ('undefined' !== typeof(bx_editor_remove_all))
  30. bx_editor_remove_all($('#' + oPopup.attr('id')));
  31. $('#' + oPopup.attr('id')).remove();
  32. oPopup.hide().prependTo('body').bxProcessHtml().dolPopup(oOptions);
  33. }
  34. if(oData && oData.form != undefined && oData.form_id != undefined)
  35. $('form#' + oData.form_id).replaceWith(oData.form).bxProcessHtml();
  36. if (oData && oData.eval != undefined)
  37. eval(oData.eval);
  38. };
  39. if(oData && oData.object != undefined && oData.grid != undefined)
  40. if(glGrids[oData.object] != undefined)
  41. glGrids[oData.object].processJson(oData);
  42. if(oData && oData.message != undefined && oData.message.length != 0)
  43. bx_alert(oData.message, function() {
  44. fContinue(oData);
  45. });
  46. else if(oData && oData.msg != undefined && oData.msg.length != 0)
  47. bx_alert(oData.msg, function() {
  48. fContinue(oData);
  49. });
  50. else
  51. fContinue(oData);
  52. };
  53. function getHtmlData( elem, url, callback, method, confirmation, values, loading)
  54. {
  55. var fPerform = function() {
  56. // in most cases it is element ID, in other cases - object of jQuery
  57. if (typeof elem == 'string')
  58. elem = '#' + elem; // create selector from ID
  59. var $block = $(elem);
  60. var blockPos = $block.css('position');
  61. $block.css('position', 'relative'); // set temporarily for displaying "loading icon"
  62. if ('undefined' === typeof(loading) || loading) {
  63. bx_loading_content($block, true);
  64. var $loadingDiv = $block.find('.bx-loading-ajax');
  65. var iLeftOff = parseInt(($block.innerWidth() / 2.0) - ($loadingDiv.outerWidth() / 2.0));
  66. var iTopOff = parseInt(($block.innerHeight() / 2.0) - ($loadingDiv.outerHeight()));
  67. if (iTopOff<0) iTopOff = 0;
  68. $loadingDiv.css({
  69. position: 'absolute',
  70. left: iLeftOff,
  71. top: iTopOff
  72. });
  73. }
  74. if (undefined != method && (method == 'post' || method == 'POST')) {
  75. if (typeof values == 'undefined')
  76. values = {};
  77. $.post(url, values, function(data) {
  78. $block.html(data);
  79. $block.css('position', blockPos).bxProcessHtml();
  80. if (typeof callback == 'function')
  81. callback.apply($block);
  82. });
  83. }
  84. else {
  85. $block.load(url + '&_r=' + Math.random(), function() {
  86. $(this).css('position', blockPos).bxProcessHtml();
  87. if (typeof callback == 'function')
  88. callback.apply(this);
  89. });
  90. }
  91. };
  92. if (typeof(confirmation) != 'undefined' && confirmation)
  93. bx_confirm(_t('_Are_you_sure'), fPerform);
  94. else
  95. fPerform();
  96. }
  97. function loadDynamicBlockAutoPaginate (e, iStart, iPerPage, sAdditionalUrlParams, sStartParamName, sPerPageParamName) {
  98. sUrl = location.href;
  99. sStartParamName = typeof sStartParamName !== 'undefined' ? sStartParamName : 'start';
  100. sPerPageParamName = typeof sPerPageParamName !== 'undefined' ? sPerPageParamName : 'per_page';
  101. sUrl = sUrl.replace(/start=\d+/, '').replace(/per_page=\d+/, '').replace(/[&\?]+$/, '');
  102. sUrl = bx_append_url_params(sUrl, sStartParamName + '=' + parseInt(iStart) + '&' + sPerPageParamName + '=' + parseInt(iPerPage));
  103. if ('undefined' != typeof(sAdditionalUrlParams))
  104. sUrl = bx_append_url_params(sUrl, sAdditionalUrlParams);
  105. return loadDynamicBlockAuto(e, sUrl);
  106. }
  107. /**
  108. * This function reloads page block automatically,
  109. * just provide any element inside the block and this function will reload the block.
  110. * @param e - element inside the block
  111. * @return true on success, or false on error - particularly, if block isn't found
  112. */
  113. function loadDynamicBlockAuto(e, sUrl) {
  114. var oContainer = $(e).parents('.bx-page-block-container:first');
  115. var sId = oContainer.attr('id');
  116. if ('undefined' == typeof(sUrl))
  117. sUrl = location.href;
  118. if (!sId || !sId.length)
  119. return false;
  120. var aMatches = sId.match(/\-(\d+)$/);
  121. if (!aMatches || !aMatches[1])
  122. return false;
  123. var oPaginate = oContainer.find('.bx-paginate');
  124. if(oPaginate.length > 0) {
  125. var iStart = parseInt(oPaginate.attr('bx-data-start'));
  126. var iPerPage = parseInt(oPaginate.attr('bx-data-perpage'));
  127. var oParams = {};
  128. if(!isNaN(iStart) && sUrl.indexOf('start') == -1)
  129. oParams.start = iStart;
  130. if(!isNaN(iPerPage) && sUrl.indexOf('per_page') == -1)
  131. oParams.per_page = iPerPage;
  132. sUrl = bx_append_url_params(sUrl, oParams);
  133. }
  134. loadDynamicBlock(parseInt(aMatches[1]), sUrl);
  135. return true;
  136. }
  137. function loadDynamicBlock(iBlockID, sUrl) {
  138. var oCallback = null;
  139. if($('#bx-page-block-' + iBlockID + ' .bx-base-unit-showcase-wrapper').length){
  140. oCallback = bx_showcase_view_init;
  141. }
  142. getHtmlData($('#bx-page-block-' + iBlockID), bx_append_url_params(sUrl, 'dynamic=tab&pageBlock=' + iBlockID), oCallback);
  143. return true;
  144. }
  145. function loadDynamicPopupBlock(iBlockID, sUrl) {
  146. if (!$('#dynamicPopup').length) {
  147. $('<div id="dynamicPopup" style="display:none;"></div>').prependTo('body');
  148. }
  149. $('#dynamicPopup').load(
  150. (sUrl + '&dynamic=popup&pageBlock=' + iBlockID),
  151. function() {
  152. $(this).dolPopup({
  153. left: 0,
  154. top: 0
  155. });
  156. }
  157. );
  158. }
  159. function closeDynamicPopupBlock() {
  160. $('#dynamicPopup').dolPopupHide();
  161. }
  162. /**
  163. * Translate string
  164. */
  165. function _t(s, arg0, arg1, arg2) {
  166. if (!window.aDolLang || !aDolLang[s])
  167. return s;
  168. cs = aDolLang[s];
  169. cs = cs.replace(/\{0\}/g, arg0);
  170. cs = cs.replace(/\{1\}/g, arg1);
  171. cs = cs.replace(/\{2\}/g, arg2);
  172. return cs;
  173. }
  174. function showPopupAnyHtml(sUrl, sId) {
  175. var oPopupOptions = {};
  176. if (!sId || !sId.length)
  177. sId = 'login_div';
  178. $('#' + sId).remove();
  179. $('<div id="' + sId + '" style="display: none;"></div>').prependTo('body').load(
  180. sUrl.match('^http[s]{0,1}:\/\/') ? sUrl : sUrlRoot + sUrl,
  181. function() {
  182. $(this).dolPopup(oPopupOptions);
  183. }
  184. );
  185. }
  186. function bx_loading_svg(sType, sClass) {
  187. sClass = sClass != undefined && sClass.length > 0 ? sClass : '';
  188. if(sUseSvgLoading != undefined && sUseSvgLoading.length > 0)
  189. return sUseSvgLoading.replace(new RegExp('__type__','g'), sType).replace(new RegExp('__class__','g'), sClass);
  190. var s = '';
  191. s += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 520 520" class="' + sClass + '" style="enable-background:new 0 0 520 520;" xml:space="preserve">';
  192. s += '<g class="' + sType + '">';
  193. s += '<g class="inner">';
  194. s += '<path class="p1" d="M152,260C152,260,152,260,152,260c0-59.8,48.4-108.4,108.1-108.4c43.3,0,80.9,25.6,97.9,62.4V107.3c-28-18.3-61.9-28.9-98.1-28.9C159.8,78.4,78.6,159.9,78.6,260c0,59.5,28.4,112.4,73.4,145.6V260z"/>';
  195. s += '<path class="p2" d="M368,114.4V260c0,59.8-48.4,108.4-108.1,108.4c-43.3,0-80.9-25.6-97.9-62.4v106.7c28,18.3,61.9,28.9,98.1,28.9c100.1,0,181.3-81.4,181.3-181.6C441.4,200.5,413,147.6,368,114.4z"/>';
  196. s += '</g>';
  197. s += '<g class="outer">';
  198. s += '<path class="p1" d="M146.9,106.7c-8.1-15-36.9-29.9-68.9-27.3v124.2C90,164.3,114.6,130.5,146.9,106.7z"/>';
  199. s += '<path class="p2" d="M373.1,413.3c8.1,15,36.7,29.9,68.9,27.3V316.4C429.8,355.7,405.4,389.5,373.1,413.3z"/>';
  200. s += '</g>';
  201. s += '</g>';
  202. s += '</svg>';
  203. return s;
  204. }
  205. function bx_loading_animate (e, aOptions) {
  206. e = $(e);
  207. if (!e.length)
  208. return false;
  209. if (e.find('.bx-sys-spinner').length)
  210. return false;
  211. return new Spinner(aOptions).spin(e.get(0));
  212. }
  213. function bx_loading_btn (oElement, bEnable) {
  214. var oButton = $(oElement);
  215. var sClassHeight = oButton.hasClass('bx-btn-small') ? 'bx-btn-small-height' : 'bx-btn-height';
  216. if (oButton.children('div').size())
  217. oButton = oButton.children('div').first();
  218. if(!bEnable)
  219. oButton.find('.bx-loading-ajax-btn').remove();
  220. else if (!oButton.find('.bx-loading-ajax-btn').length)
  221. oButton.append('<b class="bx-loading-ajax-btn ' + sClassHeight + '">' + (bUseSvgLoading ? bx_loading_svg('colored', sClassHeight) : '') + '</b>');
  222. if(!bUseSvgLoading)
  223. bx_loading_animate(oButton.find('.bx-loading-ajax-btn'), aSpinnerSmallOpts);
  224. }
  225. function bx_loading_content (oElement, bEnable, isReplace) {
  226. var oBlock = $(oElement);
  227. var oLoading = $('<div class="bx-loading-ajax bx-def-z-index-front">' + (bUseSvgLoading ? bx_loading_svg('colored') : '') + '</div>');
  228. if(!bEnable)
  229. oBlock.find(".bx-loading-ajax").remove();
  230. else if(!oBlock.find('.bx-loading-ajax').length) {
  231. if('undefined' != typeof(isReplace) && isReplace)
  232. oBlock.html(oLoading.addClass('static'));
  233. else
  234. oBlock.append(oLoading);
  235. if(!bUseSvgLoading)
  236. bx_loading_animate(oBlock.find('.bx-loading-ajax'), aSpinnerOpts);
  237. }
  238. }
  239. function bx_loading (elem, b) {
  240. if (typeof elem == 'string')
  241. elem = '#' + elem;
  242. var block = $(elem);
  243. if (block.hasClass('bx-btn')) {
  244. bx_loading_btn (block, b);
  245. return;
  246. }
  247. if (1 == b || true == b) {
  248. bx_loading_content(block, b);
  249. e = block.find(".bx-loading-ajax");
  250. e.css('left', parseInt(block.width()/2.0 - e.width()/2.0));
  251. var he = e.outerHeight();
  252. var hc = block.outerHeight();
  253. if (block.css('position') != 'relative' && block.css('position') != 'absolute') {
  254. if (!block.data('css-save-position'))
  255. block.data('css-save-position', block.css('position'));
  256. block.css('position', 'relative');
  257. }
  258. if (hc > he) {
  259. e.css('top', parseInt(hc/2.0 - he/2.0));
  260. }
  261. if (hc < he) {
  262. if (!block.data('css-save-min-height'))
  263. block.data('css-save-min-height', block.css('min-height'));
  264. block.css('min-height', he);
  265. e.css('top', 0);
  266. }
  267. } else {
  268. if (block.data('css-save-position'))
  269. block.css('position', block.data('css-save-position'));
  270. if (block.data('css-save-min-height'))
  271. block.css('min-height', block.data('css-save-min-height'));
  272. bx_loading_content(block, b);
  273. }
  274. }
  275. /**
  276. * Center content with floating blocks.
  277. * sSel - jQuery selector of content to be centered
  278. * sBlockSel - jquery selector of blocks
  279. */
  280. function bx_center_content (sSel, sBlockStyle, bListenOnResize) {
  281. var sId;
  282. if ($(sSel).parent().hasClass('bx-center-content-wrapper')) {
  283. sId = $(sSel).parent().attr('id');
  284. } else {
  285. sId = 'id' + (new Date()).getTime();
  286. $(sSel).wrap('<div id="'+sId+'" class="bx-center-content-wrapper"></div>');
  287. }
  288. var eCenter = $('#' + sId);
  289. var iAll = $('#' + sId + ' ' + sBlockStyle).size();
  290. var iWidthUnit = $('#' + sId + ' ' + sBlockStyle + ':first').outerWidth(true);
  291. var iWidthContainer = eCenter.innerWidth();
  292. var iPerRow = parseInt(iWidthContainer/iWidthUnit);
  293. var iLeft = (iWidthContainer - (iAll > iPerRow ? iPerRow * iWidthUnit : iAll * iWidthUnit)) / 2;
  294. if (iWidthUnit > iWidthContainer)
  295. return;
  296. if ('undefined' != typeof(bListenOnResize) && bListenOnResize) {
  297. $(window).on('resize.bx-center-content', function () {
  298. bx_center_content(sSel, sBlockStyle);
  299. });
  300. }
  301. eCenter.css("padding-left", iLeft);
  302. }
  303. /**
  304. * Show pointer popup with menu from URL.
  305. * @param o - menu object name
  306. * @param e - element to show popup at
  307. * @param options - popup options
  308. * @param vars - additional GET variables
  309. */
  310. function bx_menu_popup (o, e, options, vars) {
  311. var options = options || {};
  312. var vars = vars || {};
  313. var o = $.extend({}, $.fn.dolPopupDefaultOptions, {id: o, url: bx_append_url_params('menu.php', $.extend({o:o}, vars))}, options);
  314. if ('undefined' == typeof(e))
  315. e = window;
  316. $(e).dolPopupAjax(o);
  317. }
  318. /**
  319. * Show pointer popup with menu from existing HTML.
  320. * @param jSel - jQuery selector for html to show in popup
  321. * @param e - element to show popup at
  322. * @param options - popup options
  323. */
  324. function bx_menu_popup_inline (jSel, e, options) {
  325. var options = options || {};
  326. var o = $.extend({}, $.fn.dolPopupDefaultOptions, options, {pointer:{el:$(e)}});
  327. if ($(jSel + ':visible').length)
  328. $(jSel).dolPopupHide();
  329. else
  330. $(jSel).dolPopup(o);
  331. }
  332. /**
  333. * Show pointer popup with menu from URL.
  334. * @param sObject - menu object name
  335. * @param oElement - element to show popup at
  336. * @param oOptions - popup options
  337. * @param oVars - additional GET variables
  338. */
  339. function bx_menu_slide (sObject, oElement, sPosition, oOptions, oVars) {
  340. var oVars = oVars || {};
  341. var oOptions = oOptions || {};
  342. oOptions = $.extend({}, {parent: 'body', container: '.bx-sliding-menu-content'}, oOptions);
  343. var sId = '';
  344. var sIdSel = '';
  345. var sIdPfx = 'bx-sliding-menu-wrapper-';
  346. if(typeof(oOptions.id) != 'undefined')
  347. switch(typeof(oOptions.id)) {
  348. case 'string':
  349. sId = sIdPfx + oOptions.id;
  350. break;
  351. case 'object':
  352. sId = typeof(oOptions.id.force) != 'undefined' && oOptions.id.force ? oOptions.id.value : sIdPfx + oOptions.id.value;
  353. break;
  354. }
  355. else
  356. sId = sIdPfx + parseInt(2147483647 * Math.random());
  357. sIdSel = '#' + sId;
  358. //--- If slider exists
  359. if ($(sIdSel).length) {
  360. bx_menu_slide_inline (sIdSel, oElement, sPosition);
  361. return;
  362. }
  363. //--- If slider doesn't exists
  364. else {
  365. var oMenuLoading = $('#bx-sliding-menu-loading');
  366. if(!oMenuLoading || !oMenuLoading.length)
  367. return;
  368. $('<div id="' + sId + '" style="display:none;">' + oMenuLoading.html() + '</div>').addClass(oMenuLoading.attr('class')).appendTo(oOptions.parent);
  369. var oLoading = $(sIdSel + ' .bx-sliding-menu-loading');
  370. bx_loading_content(oLoading, true, true);
  371. bx_menu_slide_inline (sIdSel, oElement, sPosition);
  372. var fOnLoad = function() {
  373. bx_loading_content(oLoading, false);
  374. $(sIdSel).bxProcessHtml().show();
  375. };
  376. $(sIdSel).find(oOptions.container).load(bx_append_url_params('menu.php', $.extend({o:sObject}, oVars)), function () {
  377. var f = function () {
  378. if($(sIdSel).find('img').length > 0 && !$(sIdSel).find('img').get(0).complete)
  379. $(sIdSel).find('img').load(fOnLoad);
  380. else
  381. fOnLoad();
  382. };
  383. setTimeout(f, 100); // TODO: better way is to check if item is animating before positioning it in the code where popup is positioning
  384. });
  385. }
  386. }
  387. /**
  388. * Show sliding menu from existing HTML.
  389. * @param sMenu - jQuery object or selector for html to show in popup
  390. * @param e - element to click to open/close slider
  391. * @param sPosition - 'block' for sliding menu in blocks, 'site' - for sliding main menu
  392. */
  393. function bx_menu_slide_inline (sMenu, e, sPosition) {
  394. var options = options || {};
  395. var eSlider = $(sMenu);
  396. if ('undefined' !== typeof (bx_menu_slide_inline_custom)) {
  397. return bx_menu_slide_inline_custom(sMenu, e, sPosition);
  398. }
  399. if ('undefined' == typeof(e))
  400. e = eSlider.data('data-control-btn');
  401. var eIcon = $(e).find('.sys-icon-a');
  402. var fPositionElement = function (oElement) {
  403. eSlider.css({
  404. position: 'absolute',
  405. top: oElement.outerHeight(true),
  406. left: 0
  407. });
  408. };
  409. var fPositionBlock = function () {
  410. var eBlock = eSlider.parents('.bx-page-block-container');
  411. eSlider.css({
  412. position: 'absolute',
  413. top: eBlock.find('.bx-db-header').outerHeight(true),
  414. left: 0
  415. //width: eBlock.width() TODO: Commited to test. Remove if everything is OK.
  416. });
  417. };
  418. var fPositionSite = function () {
  419. var eToolbar = $('#bx-toolbar');
  420. eSlider.css({
  421. position: 'fixed',
  422. top: eToolbar.outerHeight(true) + (typeof iToolbarSubmenuTopOffset != 'undefined' ? parseInt(iToolbarSubmenuTopOffset) : 0),
  423. left: 0
  424. });
  425. };
  426. var fClose = function () {
  427. if (eIcon.length)
  428. (new Marka(eIcon[0])).set(eIcon.attr('data-icon-orig'));
  429. eSlider.slideUp()
  430. };
  431. var fOpen = function () {
  432. if (eIcon.length) {
  433. eIcon.attr('data-icon-orig', eIcon.attr('data-icon'));
  434. (new Marka(eIcon[0])).set('times');
  435. }
  436. if(typeof sPosition == 'object')
  437. fPositionElement(sPosition);
  438. else if(typeof sPosition == 'string' && sPosition == 'block')
  439. fPositionBlock();
  440. else
  441. fPositionSite();
  442. eSlider.slideDown();
  443. eSlider.data('data-control-btn', e);
  444. };
  445. if ('undefined' == typeof(sPosition))
  446. sPosition = 'block';
  447. if (eSlider.is(':visible')) {
  448. fClose();
  449. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  450. $(window).off('resize.bx-sliding-menu');
  451. }
  452. else {
  453. bx_menu_slide_close_all_opened();
  454. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  455. $(window).off('resize.bx-sliding-menu');
  456. fOpen();
  457. eSlider.find('a').each(function () {
  458. $(this).off('click.bx-sliding-menu');
  459. $(this).on('click.bx-sliding-menu', function () {
  460. fClose();
  461. });
  462. });
  463. setTimeout(function () {
  464. var iWidthPrev = $(window).width();
  465. $(window).on('resize.bx-sliding-menu', function () {
  466. if ($(this).width() == iWidthPrev)
  467. return;
  468. iWidthPrev = $(this).width();
  469. bx_menu_slide_close_all_opened();
  470. });
  471. $(document).on('click.bx-sliding-menu touchend.bx-sliding-menu', function (event) {
  472. if ($(event.target).parents('.bx-sliding-menu, .bx-sliding-menu-main, .bx-popup-slide-wrapper, .bx-db-header').length || $(event.target).filter('.bx-sliding-menu-main, .bx-popup-slide-wrapper, .bx-db-header').length || e === event.target)
  473. event.stopPropagation();
  474. else
  475. bx_menu_slide_close_all_opened();
  476. });
  477. }, 10);
  478. }
  479. }
  480. /**
  481. * Close all opened sliding menus
  482. */
  483. function bx_menu_slide_close_all_opened () {
  484. $('.bx-sliding-menu:visible, .bx-sliding-menu-main:visible, .bx-popup-slide-wrapper:visible').each(function () {
  485. bx_menu_slide_inline('#' + this.id);
  486. });
  487. }
  488. /*
  489. * Note. oData.count_old and oData.count_new are also available and can be checked or used in notification popup.
  490. */
  491. function bx_menu_show_live_update(oData) {
  492. var sSelectorAddon = '.bx-menu-item-addon';
  493. //--- Update Child Menu Item
  494. if(oData.mi_child) {
  495. var oMenuItem = $('.bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item-' + oData.mi_child.menu_item);
  496. var oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  497. if(oMenuItemAddon.length > 0)
  498. oMenuItemAddon.html(oData.count_new);
  499. else
  500. oMenuItem.append(oData.code.replace('{count}', oData.count_new));
  501. //+++ Check for 0 value
  502. oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  503. if(parseInt(oData.count_new) > 0)
  504. oMenuItemAddon.show();
  505. else
  506. oMenuItemAddon.hide();
  507. }
  508. //--- Update Parent Menu Item
  509. if(oData.mi_parent) {
  510. var oMenuItem = $('.bx-menu-object-' + oData.mi_parent.menu_object + ' .bx-menu-item-' + oData.mi_parent.menu_item);
  511. var oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  512. var iSum = 0;
  513. $('.bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item .bx-menu-item-addon').each(function() {
  514. iValue = parseInt($(this).html());
  515. if(iValue && iValue > 0)
  516. iSum += iValue;
  517. });
  518. if(oMenuItemAddon.length > 0)
  519. oMenuItemAddon.html(iSum);
  520. else
  521. oMenuItem.append(oData.code.replace('{count}', iSum));
  522. //+++ Check for 0 value
  523. oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  524. if(iSum > 0)
  525. oMenuItemAddon.show();
  526. else
  527. oMenuItemAddon.hide();
  528. }
  529. }
  530. /**
  531. * Set ACL level for specified profile
  532. * @param iProfileId - profile id to set acl level for
  533. * @param iAclLevel - acl level id to assign to a given rofile
  534. */
  535. function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
  536. var bBulk = !$.isNumeric(iProfileId);
  537. var iAclCard = !bBulk && $('#sys-acl-profile-' + iProfileId).length > 0 ? 1 : 0;
  538. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  539. if(bLoading)
  540. bx_loading($(mixedLoadingElement), true);
  541. $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', profile_id: iProfileId, acl_level_id: iAclLevel, acl_card:iAclCard}, function(oData) {
  542. if(bLoading)
  543. bx_loading($(mixedLoadingElement), false);
  544. if(oData.msg != undefined && oData.msg.length) {
  545. bx_alert(oData.msg);
  546. return;
  547. }
  548. if($(mixedLoadingElement).hasClass('bx-popup-applied'))
  549. $(mixedLoadingElement).dolPopupHide().remove();
  550. if(typeof(oData.card) == 'object')
  551. for(var iField in oData.card) {
  552. var oCard = $(oData.card[iField]);
  553. $('#' + oCard.attr('id')).replaceWith(oCard.bxTime());
  554. }
  555. }, 'json');
  556. }
  557. /**
  558. * Set ACL badge for specified content
  559. * @param sModule - current module for content
  560. * @param iContentId - content id to set badge for
  561. * @param iBadgeId - badge id to assign to a given content
  562. */
  563. function bx_set_badge (sModule, iContentId, iBadgeId, mixedLoadingElement) {
  564. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  565. if(bLoading)
  566. bx_loading($(mixedLoadingElement), true);
  567. $.post(sUrlRoot + 'menu.php', {o:'sys_set_badges', module: sModule, content_id: iContentId, badge_id: iBadgeId}, function(oData) {
  568. if(bLoading)
  569. bx_loading($(mixedLoadingElement), false);
  570. if(oData.msg != undefined && oData.msg.length) {
  571. bx_alert(oData.msg);
  572. return;
  573. }
  574. if($(mixedLoadingElement).hasClass('bx-popup-applied'))
  575. $(mixedLoadingElement).dolPopupHide().remove();
  576. if(typeof(oData.card) == 'object')
  577. for(var iField in oData.card) {
  578. var oCard = $(oData.card[iField]);
  579. $('#' + oCard.attr('id')).replaceWith(oCard);
  580. }
  581. $('.bx-base-bages-container').html(oData.html);
  582. }, 'json');
  583. }
  584. function bx_get_notes(oSource, sModule, iContentId, oOptions, oVars) {
  585. var oOptions = oOptions || {};
  586. var oVars = oVars || {};
  587. var oOptions = $.extend({}, $.fn.dolPopupDefaultOptions, {
  588. id: sModule + '_notes_' + iContentId,
  589. url: bx_append_url_params('modules/?r=' + sModule + '/get_notes/', $.extend({content_id: iContentId}, oVars)),
  590. closeOnOuterClick: false,
  591. removeOnClose: true,
  592. onBeforeShow: function(oPopup) {
  593. $(oPopup).find('.bx-popup-close-wrapper').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
  594. }
  595. }, oOptions);
  596. $(window).dolPopupAjax(oOptions);
  597. }
  598. function validateLoginForm(eForm) {
  599. return true;
  600. }
  601. /**
  602. * convert <time> tags to human readable format
  603. * @param sLang - use sLang localization
  604. * @param isAutoupdate - for internal usage only
  605. */
  606. function bx_time(sLang, isAutoupdate, sRootSel) {
  607. if ('undefined' == typeof(sRootSel))
  608. sRootSel = 'body';
  609. var iAutoupdate = 22*60*60; // autoupdate time in realtime if less than 22 hours
  610. var sSel = 'time';
  611. if (typeof(sLang) != 'undefined')
  612. glBxTimeLang = sLang;
  613. else if(typeof(glBxTimeLang) != 'undefined')
  614. sLang = glBxTimeLang;
  615. if(!sLang)
  616. return;
  617. if ('undefined' != typeof(isAutoupdate) && isAutoupdate)
  618. sSel += '.bx-time-autoupdate';
  619. $(sRootSel).find(sSel).each(function () {
  620. var s;
  621. var sTime = $(this).attr('datetime');
  622. var iSecondsDiff = moment(sTime).unix() - moment().unix();
  623. if (iSecondsDiff < 0)
  624. iSecondsDiff = -iSecondsDiff;
  625. if (iSecondsDiff < $(this).attr('data-bx-autoformat'))
  626. s = moment(sTime).locale(sLang).fromNow(); // 'time ago' format
  627. else
  628. s = moment(sTime).locale(sLang).format($(this).attr('data-bx-format')); // custom format
  629. if (iSecondsDiff < iAutoupdate)
  630. $(this).addClass('bx-time-autoupdate');
  631. else
  632. $(this).removeClass('bx-time-autoupdate');
  633. $(this).html(s);
  634. });
  635. if ($('time.bx-time-autoupdate').size()) {
  636. setTimeout(function () {
  637. bx_time(sLang, true);
  638. }, 20000);
  639. }
  640. }
  641. (function($) {
  642. $.fn.bxTime = function() {
  643. bx_time(undefined, undefined, this);
  644. return this;
  645. };
  646. /**
  647. * process HTML which was added dynamicly on the page
  648. */
  649. $.fn.bxProcessHtml = function (oCallback) {
  650. var eElement = $(this);
  651. if ('undefined' !== typeof(eElement)) {
  652. // process js time
  653. eElement.bxTime();
  654. // process web forms
  655. if ($.isFunction($.fn.addWebForms))
  656. eElement.addWebForms();
  657. // process animating icons
  658. bx_activate_anim_icons();
  659. // process syntax hightlighing
  660. if ('undefined' !== typeof(Prism) && eElement.size())
  661. Prism.highlightAllUnder(eElement[0]);
  662. // flickity update
  663. setTimeout(function () {
  664. const oFlickity = eElement.find('.flickity-enabled');
  665. if (oFlickity.length)
  666. oFlickity.flickity('resize');
  667. }, 250);
  668. }
  669. if ('undefined' !== typeof(oCallback)) {
  670. oCallback(eElement);
  671. }
  672. if (typeof glOnProcessHtml !== 'undefined' && glOnProcessHtml instanceof Array) {
  673. for (var i = 0; i < glOnProcessHtml.length; i++)
  674. if (typeof glOnProcessHtml[i] === "function")
  675. glOnProcessHtml[i](this);
  676. }
  677. return this;
  678. }
  679. } (jQuery));
  680. /**
  681. * Perform connections AJAX request.
  682. * In case of error - it shows js alert with error message.
  683. * In case of success - the page is reloaded.
  684. *
  685. * @param sObj - connections object
  686. * @param sAction - 'add', 'remove' or 'reject'
  687. * @param iContentId - content id, initiator is always current logged in user
  688. * @param bConfirm - show confirmation dialog
  689. */
  690. function bx_conn_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  691. var fPerform = function() {
  692. var aParams = {
  693. obj: sObj,
  694. act: sAction,
  695. id: iContentId
  696. };
  697. var fCallback = function (data) {
  698. bx_loading_btn(e, 0);
  699. if ('object' != typeof(data))
  700. return;
  701. if (data.err) {
  702. bx_alert(data.msg);
  703. } else {
  704. if ('function' == typeof(fOnComplete))
  705. fOnComplete(data, e);
  706. else if (!loadDynamicBlockAuto(e))
  707. location.reload();
  708. else
  709. $('#bx-popup-ajax-wrapper-bx_persons_view_actions_more').remove();
  710. }
  711. };
  712. bx_loading_btn(e, 1);
  713. $.ajax({
  714. dataType: 'json',
  715. url: sUrlRoot + 'conn.php',
  716. data: aParams,
  717. type: 'POST',
  718. success: fCallback
  719. });
  720. };
  721. if (typeof(bConfirm) != 'undefined' && bConfirm)
  722. bx_confirm(_t('_Are_you_sure'), fPerform);
  723. else
  724. fPerform();
  725. }
  726. function bx_append_url_params (sUrl, mixedParams) {
  727. var sParams = sUrl.indexOf('?') == -1 ? '?' : '&';
  728. var sHash = '';
  729. if(sUrl.indexOf('#') != -1) {
  730. var oUrl = new URL(sUrl);
  731. if(oUrl.hash.length > 0) {
  732. sHash = oUrl.hash;
  733. sUrl = sUrl.replace(sHash, '');
  734. }
  735. else
  736. sUrl = sUrl.replace('#', '');
  737. }
  738. if(mixedParams instanceof Array) {
  739. for(var i in mixedParams)
  740. sParams += i + '=' + mixedParams[i] + '&';
  741. sParams = sParams.substr(0, sParams.length-1);
  742. }
  743. else if(mixedParams instanceof Object) {
  744. $.each(mixedParams, function(sKey, sValue) {
  745. sParams += sKey + '=' + sValue + '&';
  746. });
  747. sParams = sParams.substr(0, sParams.length-1);
  748. }
  749. else
  750. sParams += mixedParams;
  751. return sUrl + sParams + sHash;
  752. }
  753. function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, iMinLen) {
  754. var oForm = $(e.target).parents(sFormSel + ':first');
  755. if ('undefined' != typeof(e) && 13 == e.keyCode) {
  756. oForm.find('input[name=live_search]').val(0);
  757. oForm.submit();
  758. return false;
  759. }
  760. iMinLen = typeof(iMinLen) != 'undefined' ? parseInt(iMinLen) : 0;
  761. if(iMinLen > 0 && iMinLen > (oForm.find('input[name=keyword]').val().length + 1))
  762. return true;
  763. if ('undefined' != typeof(glBxSearchTimeoutHandler) && glBxSearchTimeoutHandler)
  764. clearTimeout(glBxSearchTimeoutHandler);
  765. glBxSearchTimeoutHandler = setTimeout(function () {
  766. bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults);
  767. }, 500);
  768. return true;
  769. }
  770. function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
  771. if ('undefined' == typeof(sLoadingContSel))
  772. sLoadingContSel = sResultsContSel;
  773. if ('undefined' == typeof(bSortResults))
  774. bSortResults = false;
  775. var sQuery = $('input', sFormSel).serialize();
  776. bx_loading($(sLoadingContSel), true);
  777. $.post(sUrlRoot + 'searchKeywordContent.php', sQuery, function(data) {
  778. bx_loading($(sLoadingContSel), false);
  779. if (bSortResults) {
  780. var aSortedUnits = $(data).find(".bx-def-unit-live-search").toArray().sort(function (a, b) {
  781. return b.getAttribute('data-ts') - a.getAttribute('data-ts');
  782. });
  783. data = '';
  784. $.each(aSortedUnits.slice(0, n), function (i, e) {
  785. data += e.outerHTML;
  786. });
  787. }
  788. $(sResultsContSel).html(data).bxProcessHtml();
  789. });
  790. return false;
  791. }
  792. function on_filter_apply(e, sInputId, sFilterName)
  793. {
  794. var oRegExp = new RegExp("[&]{0,1}" + sFilterName + "=.*");
  795. var s = ('' + document.location).replace(oRegExp, ''); // remove filter
  796. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  797. if (e.checked && $('#' + sInputId).val().length > 2)
  798. s += (-1 == s.indexOf('?') ? '?' : '&') + sFilterName + '=' + $('#' + sInputId).val(); // append filter
  799. document.location = s;
  800. }
  801. function on_filter_key_up (e, sCheckboxId)
  802. {
  803. if (13 == e.keyCode) {
  804. $('#' + sCheckboxId).click();
  805. return false;
  806. }
  807. else {
  808. $('#' + sCheckboxId).removeAttr('checked');
  809. return true;
  810. }
  811. }
  812. function on_copyright_click()
  813. {
  814. oDate = new Date();
  815. $(document).dolPopupAlert({
  816. message: _t('_copyright', oDate.getFullYear())
  817. });
  818. }
  819. function bx_activate_anim_icons(sColor)
  820. {
  821. if(typeof(sColor) != 'undefined')
  822. glBxAnimIconColor = sColor;
  823. else if(typeof(glBxAnimIconColor) != 'undefined')
  824. sColor = glBxAnimIconColor;
  825. if(!sColor)
  826. return;
  827. $('.sys-icon-a').not('.marka').each(function () {
  828. var e = $(this);
  829. var m = new Marka(e.get(0)), r = e.attr('data-rotate'), c = e.attr('data-color');
  830. m.set(e.attr('data-icon')).rotate(r ? r : 'down').color(c ? c : sColor);
  831. });
  832. }
  833. function bx_get_style(sUrl)
  834. {
  835. $("head").append($("<link rel='stylesheet' href='" + sUrl + "' type='text/css' />"));
  836. }
  837. function bx_get_param(s) {
  838. if (!window.aDolOptions || !aDolOptions[s])
  839. return false;
  840. return aDolOptions[s];
  841. }
  842. function bx_autocomplete_fields(iId, sUrl, sName, bShowImg, bOnlyOnce, onSelect){
  843. if (!$('#' + iId).hasClass('bx-form-input-autotoken'))
  844. $('#' + iId).addClass('bx-form-input-autotoken');
  845. $('#' + iId + ' input[type=text]').autocomplete({
  846. source: sUrl,
  847. select: function(e, ui) {
  848. $(this).val(ui.item.label);
  849. $(this).trigger('superselect', ui.item);
  850. if (typeof onSelect === 'function')
  851. onSelect(ui);
  852. e.preventDefault();
  853. }
  854. });
  855. if ($('#' + iId + ' .val').length > 0 && bOnlyOnce)
  856. $('#' + iId + ' input[type=text]').hide();
  857. $('#' + iId + ' input[type=text]').on('superselect', function(e, item) {
  858. $(this).hide();
  859. if ('undefined' != typeof(item)) {
  860. var sImage = '';
  861. if(bShowImg && item.unit != undefined)
  862. sImage = item.unit;
  863. else if(bShowImg && item.thumb != undefined)
  864. sImage = '<img class="bx-def-thumb bx-def-thumb-size bx-def-margin-sec-right" src="' + item.thumb + '">';
  865. $(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">' + sImage + item.label + '<input type="hidden" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" name="' + sName + (bOnlyOnce ? '' : '[]') + '" value="' + item.value + '" /></b>');
  866. }
  867. if (!bOnlyOnce)
  868. {
  869. fAutoShrinkInput();
  870. $(this).show();
  871. this.value = '';
  872. }
  873. }).on('keydown', function(e) {
  874. // if: comma,enter (delimit more keyCodes with | pipe)
  875. if (/(13)/.test(e.which))
  876. e.preventDefault();
  877. });
  878. $('#' + iId).on('click', 'b', function() {
  879. $(this).remove();
  880. if (bOnlyOnce)
  881. $('#' + iId + ' input[type=text]').val('').show();
  882. else
  883. fAutoShrinkInput();
  884. });
  885. fAutoShrinkInput = function () {
  886. var iWidthCont = $('#' + iId + '.bx-form-input-autotoken').innerWidth();
  887. var iWidthExisting = 0;
  888. $('#' + iId + '.bx-form-input-autotoken b').each(function () {
  889. iWidthExisting += $(this).outerWidth(true);
  890. });
  891. $('#' + iId + '.bx-form-input-autotoken input').innerWidth(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
  892. };
  893. if (!bOnlyOnce)
  894. fAutoShrinkInput();
  895. else
  896. $('#' + iId + '.bx-form-input-autotoken input').outerWidth('100%');
  897. };
  898. function bx_alert(sMessage, fOnClickOk, oParams)
  899. {
  900. $(document).dolPopupAlert({
  901. message: sMessage,
  902. onClickOk: fOnClickOk,
  903. params: oParams
  904. });
  905. }
  906. function bx_confirm(sMessage, fOnClickYes, fOnClickNo, oParams)
  907. {
  908. $(document).dolPopupConfirm({
  909. message: sMessage,
  910. onClickYes: fOnClickYes,
  911. onClickNo: fOnClickNo,
  912. params: oParams
  913. });
  914. }
  915. function bx_prompt(sMessage, sValue, fOnClickOk, fOnClickCancel, oParams)
  916. {
  917. $(document).dolPopupPrompt({
  918. message: sMessage,
  919. value: sValue,
  920. onClickOk: fOnClickOk,
  921. onClickCancel: fOnClickCancel,
  922. params: oParams
  923. });
  924. }
  925. /**
  926. * Check if mobile or desktop device.
  927. */
  928. function bx_check_mq()
  929. {
  930. return window.getComputedStyle(document.querySelector('body'), '::before').getPropertyValue('content').replace(/'/g, "").replace(/"/g, "");
  931. }
  932. /**
  933. * This function loads the passed list of js files and executes callback function when the all files are loaded.
  934. * In case when this function is called for dynamic loading of the same file but many times (like Plyr video init)
  935. * it allows to avoid multiply loadings of the same file.
  936. */
  937. function bx_get_scripts (aFiles, fCallback)
  938. {
  939. let iCounter = 0;
  940. const
  941. iLength = aFiles.length,
  942. fHandler = function() {
  943. if (iCounter++ >= (iLength-1) && typeof(fCallback) === 'function')
  944. fCallback();
  945. else
  946. fExecute(aFiles[iCounter]);
  947. },
  948. // Check if js file is not loaded yet then start to load it and returns Promise.
  949. // All functions which try to load the same file will wait for loading of the file
  950. // and then continue to work
  951. fExecute = function(sFile) {
  952. if ('undefined' === typeof(glBxLoadedScripts[sFile]))
  953. glBxLoadedScripts[sFile] = { complete : $.bxGetCachedScript(sFile).done(fHandler) };
  954. else
  955. glBxLoadedScripts[sFile].complete.then(fHandler);
  956. };
  957. if ('undefined' === typeof(glBxLoadedScripts))
  958. glBxLoadedScripts = {};
  959. fExecute(aFiles[iCounter]);
  960. }
  961. jQuery.bxGetCachedScript = function(sUrl, oOptions)
  962. {
  963. oOptions = $.extend(oOptions || {}, {
  964. dataType: "script",
  965. cache: true,
  966. url: sUrl
  967. });
  968. return jQuery.ajax(oOptions);
  969. };
  970. /** @} */