functions.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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 bx_get_report_comments(oSource, sModule, iContentId, oOptions, oVars) {
  599. var oOptions = oOptions || {};
  600. var oVars = oVars || {};
  601. var oOptions = $.extend({}, $.fn.dolPopupDefaultOptions, {
  602. id: sModule + '_report_comment_' + iContentId,
  603. url: bx_append_url_params('modules/?r=' + sModule + '/report_comment/', $.extend({ content_id: iContentId }, oVars)),
  604. closeOnOuterClick: false,
  605. removeOnClose: true,
  606. onBeforeShow: function (oPopup) {
  607. $(oPopup).find('.bx-popup-close-wrapper').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
  608. }
  609. }, oOptions);
  610. $(window).dolPopupAjax(oOptions);
  611. }
  612. function validateLoginForm(eForm) {
  613. return true;
  614. }
  615. /**
  616. * convert <time> tags to human readable format
  617. * @param sLang - use sLang localization
  618. * @param isAutoupdate - for internal usage only
  619. */
  620. function bx_time(sLang, isAutoupdate, sRootSel) {
  621. if ('undefined' == typeof(sRootSel))
  622. sRootSel = 'body';
  623. var iAutoupdate = 22*60*60; // autoupdate time in realtime if less than 22 hours
  624. var sSel = 'time';
  625. if (typeof(sLang) != 'undefined')
  626. glBxTimeLang = sLang;
  627. else if(typeof(glBxTimeLang) != 'undefined')
  628. sLang = glBxTimeLang;
  629. if(!sLang)
  630. return;
  631. if ('undefined' != typeof(isAutoupdate) && isAutoupdate)
  632. sSel += '.bx-time-autoupdate';
  633. $(sRootSel).find(sSel).each(function () {
  634. var s;
  635. var sTime = $(this).attr('datetime');
  636. var iSecondsDiff = moment(sTime).unix() - moment().unix();
  637. if (iSecondsDiff < 0)
  638. iSecondsDiff = -iSecondsDiff;
  639. if (iSecondsDiff < $(this).attr('data-bx-autoformat'))
  640. s = moment(sTime).locale(sLang).fromNow(); // 'time ago' format
  641. else
  642. s = moment(sTime).locale(sLang).format($(this).attr('data-bx-format')); // custom format
  643. if (iSecondsDiff < iAutoupdate)
  644. $(this).addClass('bx-time-autoupdate');
  645. else
  646. $(this).removeClass('bx-time-autoupdate');
  647. $(this).html(s);
  648. });
  649. if ($('time.bx-time-autoupdate').size()) {
  650. setTimeout(function () {
  651. bx_time(sLang, true);
  652. }, 20000);
  653. }
  654. }
  655. (function($) {
  656. $.fn.bxTime = function() {
  657. bx_time(undefined, undefined, this);
  658. return this;
  659. };
  660. /**
  661. * process HTML which was added dynamicly on the page
  662. */
  663. $.fn.bxProcessHtml = function (oCallback) {
  664. var eElement = $(this);
  665. if ('undefined' !== typeof(eElement)) {
  666. // process js time
  667. eElement.bxTime();
  668. // process web forms
  669. if ($.isFunction($.fn.addWebForms))
  670. eElement.addWebForms();
  671. // process animating icons
  672. bx_activate_anim_icons();
  673. // process syntax hightlighing
  674. if ('undefined' !== typeof(Prism) && eElement.size())
  675. Prism.highlightAllUnder(eElement[0]);
  676. }
  677. if ('undefined' !== typeof(oCallback)) {
  678. oCallback(eElement);
  679. }
  680. if (typeof glOnProcessHtml !== 'undefined' && glOnProcessHtml instanceof Array) {
  681. for (var i = 0; i < glOnProcessHtml.length; i++)
  682. if (typeof glOnProcessHtml[i] === "function")
  683. glOnProcessHtml[i](this);
  684. }
  685. return this;
  686. }
  687. } (jQuery));
  688. /**
  689. * Perform connections AJAX request.
  690. * In case of error - it shows js alert with error message.
  691. * In case of success - the page is reloaded.
  692. *
  693. * @param sObj - connections object
  694. * @param sAction - 'add', 'remove' or 'reject'
  695. * @param iContentId - content id, initiator is always current logged in user
  696. * @param bConfirm - show confirmation dialog
  697. */
  698. function bx_conn_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  699. var fPerform = function() {
  700. var aParams = {
  701. obj: sObj,
  702. act: sAction,
  703. id: iContentId
  704. };
  705. var fCallback = function (data) {
  706. bx_loading_btn(e, 0);
  707. if ('object' != typeof(data))
  708. return;
  709. if (data.err) {
  710. bx_alert(data.msg);
  711. } else {
  712. if ('function' == typeof(fOnComplete))
  713. fOnComplete(data, e);
  714. else if (!loadDynamicBlockAuto(e))
  715. location.reload();
  716. else
  717. $('#bx-popup-ajax-wrapper-bx_persons_view_actions_more').remove();
  718. }
  719. };
  720. bx_loading_btn(e, 1);
  721. $.ajax({
  722. dataType: 'json',
  723. url: sUrlRoot + 'conn.php',
  724. data: aParams,
  725. type: 'POST',
  726. success: fCallback
  727. });
  728. };
  729. if (typeof(bConfirm) != 'undefined' && bConfirm)
  730. bx_confirm(_t('_Are_you_sure'), fPerform);
  731. else
  732. fPerform();
  733. }
  734. function bx_append_url_params (sUrl, mixedParams) {
  735. var sParams = sUrl.indexOf('?') == -1 ? '?' : '&';
  736. if(mixedParams instanceof Array) {
  737. for(var i in mixedParams)
  738. sParams += i + '=' + mixedParams[i] + '&';
  739. sParams = sParams.substr(0, sParams.length-1);
  740. }
  741. else if(mixedParams instanceof Object) {
  742. $.each(mixedParams, function(sKey, sValue) {
  743. sParams += sKey + '=' + sValue + '&';
  744. });
  745. sParams = sParams.substr(0, sParams.length-1);
  746. }
  747. else
  748. sParams += mixedParams;
  749. return sUrl + sParams;
  750. }
  751. function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, iMinLen) {
  752. var oForm = $(e.target).parents(sFormSel + ':first');
  753. if ('undefined' != typeof(e) && 13 == e.keyCode) {
  754. oForm.find('input[name=live_search]').val(0);
  755. oForm.submit();
  756. return false;
  757. }
  758. iMinLen = typeof(iMinLen) != 'undefined' ? parseInt(iMinLen) : 0;
  759. if(iMinLen > 0 && iMinLen > (oForm.find('input[name=keyword]').val().length + 1))
  760. return true;
  761. if ('undefined' != typeof(glBxSearchTimeoutHandler) && glBxSearchTimeoutHandler)
  762. clearTimeout(glBxSearchTimeoutHandler);
  763. glBxSearchTimeoutHandler = setTimeout(function () {
  764. bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults);
  765. }, 500);
  766. return true;
  767. }
  768. function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
  769. if ('undefined' == typeof(sLoadingContSel))
  770. sLoadingContSel = sResultsContSel;
  771. if ('undefined' == typeof(bSortResults))
  772. bSortResults = false;
  773. var sQuery = $('input', sFormSel).serialize();
  774. bx_loading($(sLoadingContSel), true);
  775. $.post(sUrlRoot + 'searchKeywordContent.php', sQuery, function(data) {
  776. bx_loading($(sLoadingContSel), false);
  777. if (bSortResults) {
  778. var aSortedUnits = $(data).find(".bx-def-unit-live-search").toArray().sort(function (a, b) {
  779. return b.getAttribute('data-ts') - a.getAttribute('data-ts');
  780. });
  781. data = '';
  782. $.each(aSortedUnits.slice(0, n), function (i, e) {
  783. data += e.outerHTML;
  784. });
  785. }
  786. $(sResultsContSel).html(data).bxProcessHtml();
  787. });
  788. return false;
  789. }
  790. function on_filter_apply(e, sInputId, sFilterName)
  791. {
  792. var oRegExp = new RegExp("[&]{0,1}" + sFilterName + "=.*");
  793. var s = ('' + document.location).replace(oRegExp, ''); // remove filter
  794. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  795. if (e.checked && $('#' + sInputId).val().length > 2)
  796. s += (-1 == s.indexOf('?') ? '?' : '&') + sFilterName + '=' + $('#' + sInputId).val(); // append filter
  797. document.location = s;
  798. }
  799. function on_filter_key_up (e, sCheckboxId)
  800. {
  801. if (13 == e.keyCode) {
  802. $('#' + sCheckboxId).click();
  803. return false;
  804. }
  805. else {
  806. $('#' + sCheckboxId).removeAttr('checked');
  807. return true;
  808. }
  809. }
  810. function on_copyright_click()
  811. {
  812. oDate = new Date();
  813. $(document).dolPopupAlert({
  814. message: _t('_copyright', oDate.getFullYear())
  815. });
  816. }
  817. function bx_activate_anim_icons(sColor)
  818. {
  819. if(typeof(sColor) != 'undefined')
  820. glBxAnimIconColor = sColor;
  821. else if(typeof(glBxAnimIconColor) != 'undefined')
  822. sColor = glBxAnimIconColor;
  823. if(!sColor)
  824. return;
  825. $('.sys-icon-a').not('.marka').each(function () {
  826. var e = $(this);
  827. var m = new Marka(e.get(0)), r = e.attr('data-rotate'), c = e.attr('data-color');
  828. m.set(e.attr('data-icon')).rotate(r ? r : 'down').color(c ? c : sColor);
  829. });
  830. }
  831. function bx_get_style(sUrl)
  832. {
  833. $("head").append($("<link rel='stylesheet' href='" + sUrl + "' type='text/css' />"));
  834. }
  835. function bx_get_param(s) {
  836. if (!window.aDolOptions || !aDolOptions[s])
  837. return false;
  838. return aDolOptions[s];
  839. }
  840. function bx_autocomplete_fields(iId, sUrl, sName, bShowImg, bOnlyOnce, onSelect){
  841. if (!$('#' + iId).hasClass('bx-form-input-autotoken'))
  842. $('#' + iId).addClass('bx-form-input-autotoken');
  843. $('#' + iId + ' input[type=text]').autocomplete({
  844. source: sUrl,
  845. select: function(e, ui) {
  846. $(this).val(ui.item.label);
  847. $(this).trigger('superselect', ui.item);
  848. if (typeof onSelect === 'function')
  849. onSelect(ui);
  850. e.preventDefault();
  851. }
  852. });
  853. if ($('#' + iId + ' .val').length > 0 && bOnlyOnce)
  854. $('#' + iId + ' input[type=text]').hide();
  855. $('#' + iId + ' input[type=text]').on('superselect', function(e, item) {
  856. $(this).hide();
  857. if ('undefined' != typeof(item)) {
  858. var sImage = '';
  859. if(bShowImg && item.unit != undefined)
  860. sImage = item.unit;
  861. else if(bShowImg && item.thumb != undefined)
  862. sImage = '<img class="bx-def-thumb bx-def-thumb-size bx-def-margin-sec-right" src="' + item.thumb + '">';
  863. $(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>');
  864. }
  865. if (!bOnlyOnce)
  866. {
  867. fAutoShrinkInput();
  868. $(this).show();
  869. this.value = '';
  870. }
  871. }).on('keydown', function(e) {
  872. // if: comma,enter (delimit more keyCodes with | pipe)
  873. if (/(13)/.test(e.which))
  874. e.preventDefault();
  875. });
  876. $('#' + iId).on('click', 'b', function() {
  877. $(this).remove();
  878. if (bOnlyOnce)
  879. $('#' + iId + ' input[type=text]').val('').show();
  880. else
  881. fAutoShrinkInput();
  882. });
  883. fAutoShrinkInput = function () {
  884. var iWidthCont = $('#' + iId + '.bx-form-input-autotoken').innerWidth();
  885. var iWidthExisting = 0;
  886. $('#' + iId + '.bx-form-input-autotoken b').each(function () {
  887. iWidthExisting += $(this).outerWidth(true);
  888. });
  889. $('#' + iId + '.bx-form-input-autotoken input').innerWidth(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
  890. };
  891. if (!bOnlyOnce)
  892. fAutoShrinkInput();
  893. else
  894. $('#' + iId + '.bx-form-input-autotoken input').outerWidth('100%');
  895. };
  896. function bx_alert(sMessage, fOnClickOk, oParams)
  897. {
  898. $(document).dolPopupAlert({
  899. message: sMessage,
  900. onClickOk: fOnClickOk,
  901. params: oParams
  902. });
  903. }
  904. function bx_confirm(sMessage, fOnClickYes, fOnClickNo, oParams)
  905. {
  906. $(document).dolPopupConfirm({
  907. message: sMessage,
  908. onClickYes: fOnClickYes,
  909. onClickNo: fOnClickNo,
  910. params: oParams
  911. });
  912. }
  913. function bx_prompt(sMessage, sValue, fOnClickOk, fOnClickCancel, oParams)
  914. {
  915. $(document).dolPopupPrompt({
  916. message: sMessage,
  917. value: sValue,
  918. onClickOk: fOnClickOk,
  919. onClickCancel: fOnClickCancel,
  920. params: oParams
  921. });
  922. }
  923. /**
  924. * This function loads the passed list of js files and executes callback function when the all files are loaded.
  925. * In case when this function is called for dynamic loading of the same file but many times (like Plyr video init)
  926. * it allows to avoid multiply loadings of the same file.
  927. */
  928. function bx_get_scripts (aFiles, fCallback)
  929. {
  930. let iCounter = 0;
  931. const
  932. iLength = aFiles.length,
  933. fHandler = function() {
  934. if (iCounter++ >= (iLength-1) && typeof(fCallback) === 'function')
  935. fCallback();
  936. else
  937. fExecute(aFiles[iCounter]);
  938. },
  939. // Check if js file is not loaded yet then start to load it and returns Promise.
  940. // All functions which try to load the same file will wait for loading of the file
  941. // and then continue to work
  942. fExecute = function(sFile) {
  943. if ('undefined' === typeof(glBxLoadedScripts[sFile]))
  944. glBxLoadedScripts[sFile] = { complete : $.bxGetCachedScript(sFile).done(fHandler) };
  945. else
  946. glBxLoadedScripts[sFile].complete.then(fHandler);
  947. };
  948. if ('undefined' === typeof(glBxLoadedScripts))
  949. glBxLoadedScripts = {};
  950. fExecute(aFiles[iCounter]);
  951. }
  952. jQuery.bxGetCachedScript = function(sUrl, oOptions)
  953. {
  954. oOptions = $.extend(oOptions || {}, {
  955. dataType: "script",
  956. cache: true,
  957. url: sUrl
  958. });
  959. return jQuery.ajax(oOptions);
  960. };
  961. /** @} */