functions.js 34 KB

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