functions.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699
  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. if ($(e).parents('.bx-search-result-block-pagination').length > 0){
  106. $([document.documentElement, document.body]).animate({
  107. scrollTop: $(e).parents('.bx-search-result-block-pagination').first().offset().top
  108. }, 500);
  109. }
  110. return loadDynamicBlockAuto(e, sUrl);
  111. }
  112. function loadDynamicBlockAutoSort (e, sort, sAdditionalUrlParams) {
  113. sUrl = location.href;
  114. console.log(sort);
  115. sUrl = sUrl.replace(/sort=\d+/, '').replace(/[&\?]+$/, '');
  116. sUrl = bx_append_url_params(sUrl, 'sort' + '=' + sort);
  117. if ('undefined' != typeof(sAdditionalUrlParams))
  118. sUrl = bx_append_url_params(sUrl, sAdditionalUrlParams);
  119. if ($(e).parents('.bx-search-result-block-pagination').length > 0){
  120. $([document.documentElement, document.body]).animate({
  121. scrollTop: $(e).parents('.bx-search-result-block-pagination').first().offset().top
  122. }, 500);
  123. }
  124. return loadDynamicBlockAuto(e, sUrl);
  125. }
  126. /**
  127. * This function reloads page block automatically,
  128. * just provide any element inside the block and this function will reload the block.
  129. * @param e - element inside the block
  130. * @return true on success, or false on error - particularly, if block isn't found
  131. */
  132. function loadDynamicBlockAuto(e, sUrl) {
  133. var oContainer = $(e).parents('.bx-page-block-container:first:not(.no-dynamic)');
  134. var sId = oContainer.attr('id');
  135. if ('undefined' == typeof(sUrl))
  136. sUrl = location.href;
  137. if (!sId || !sId.length)
  138. return false;
  139. var aMatches = sId.match(/\-(\d+)$/);
  140. if (!aMatches || !aMatches[1])
  141. return false;
  142. var oPaginate = oContainer.find('.bx-paginate');
  143. if(oPaginate.length > 0) {
  144. var iStart = parseInt(oPaginate.attr('bx-data-start'));
  145. var iPerPage = parseInt(oPaginate.attr('bx-data-perpage'));
  146. var oParams = {};
  147. if(!isNaN(iStart) && sUrl.indexOf('start') == -1)
  148. oParams.start = iStart;
  149. if(!isNaN(iPerPage) && sUrl.indexOf('per_page') == -1)
  150. oParams.per_page = iPerPage;
  151. sUrl = bx_append_url_params(sUrl, oParams);
  152. }
  153. loadDynamicBlock(parseInt(aMatches[1]), sUrl);
  154. return true;
  155. }
  156. function loadDynamicBlock(iBlockID, sUrl) {
  157. var oCallback = null;
  158. if($('#bx-page-block-' + iBlockID + ' .bx-base-unit-showcase-wrapper').length){
  159. oCallback = bx_showcase_view_init;
  160. }
  161. getHtmlData($('#bx-page-block-' + iBlockID), bx_append_url_params(sUrl, 'dynamic=tab&pageBlock=' + iBlockID), oCallback);
  162. return true;
  163. }
  164. function loadDynamicPopupBlock(iBlockID, sUrl) {
  165. if (!$('#dynamicPopup').length) {
  166. $('<div id="dynamicPopup" style="display:none;"></div>').prependTo('body');
  167. }
  168. $('#dynamicPopup').load(
  169. (sUrl + '&dynamic=popup&pageBlock=' + iBlockID),
  170. function() {
  171. $(this).dolPopup({
  172. left: 0,
  173. top: 0
  174. });
  175. }
  176. );
  177. }
  178. function closeDynamicPopupBlock() {
  179. $('#dynamicPopup').dolPopupHide();
  180. }
  181. function onAsyncBlockLoad() {
  182. var oBlock = $(this);
  183. if(!oBlock.html())
  184. oBlock.remove();
  185. }
  186. /**
  187. * Translate string
  188. */
  189. function _t(s, arg0, arg1, arg2) {
  190. if (!window.aDolLang || !aDolLang[s])
  191. return s;
  192. cs = aDolLang[s];
  193. cs = cs.replace(/\{0\}/g, arg0);
  194. cs = cs.replace(/\{1\}/g, arg1);
  195. cs = cs.replace(/\{2\}/g, arg2);
  196. return cs;
  197. }
  198. function showPopupAnyHtml(sUrl, sId) {
  199. var oPopupOptions = {};
  200. if (!sId || !sId.length)
  201. sId = 'login_div';
  202. $('#' + sId).remove();
  203. $('<div id="' + sId + '" style="display: none;"></div>').prependTo('body').load(
  204. sUrl.match('^http[s]{0,1}:\/\/') ? sUrl : sUrlRoot + sUrl,
  205. function() {
  206. $(this).dolPopup(oPopupOptions);
  207. }
  208. );
  209. }
  210. function bx_loading_svg(sType, sClass) {
  211. sClass = sClass != undefined && sClass.length > 0 ? sClass : '';
  212. if(sUseSvgLoading != undefined && sUseSvgLoading.length > 0)
  213. return sUseSvgLoading.replace(new RegExp('__type__','g'), sType).replace(new RegExp('__class__','g'), sClass);
  214. var s = '';
  215. 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">';
  216. s += '<g class="' + sType + '">';
  217. s += '<g class="inner">';
  218. 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"/>';
  219. 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"/>';
  220. s += '</g>';
  221. s += '<g class="outer">';
  222. 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"/>';
  223. 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"/>';
  224. s += '</g>';
  225. s += '</g>';
  226. s += '</svg>';
  227. return s;
  228. }
  229. function bx_loading_animate (e, aOptions) {
  230. e = $(e);
  231. if (!e.length)
  232. return false;
  233. if (e.find('.bx-sys-spinner').length)
  234. return false;
  235. return new Spinner(aOptions).spin(e.get(0));
  236. }
  237. function bx_loading_btn (oElement, bEnable) {
  238. var oButton = $(oElement);
  239. var sClassHeight = oButton.hasClass('bx-btn-small') ? 'bx-btn-small-height' : 'bx-btn-height';
  240. if (oButton.children('div').size())
  241. oButton = oButton.children('div').first();
  242. if(!bEnable)
  243. oButton.find('.bx-loading-ajax-btn').remove();
  244. else if (!oButton.find('.bx-loading-ajax-btn').length)
  245. oButton.append('<b class="bx-loading-ajax-btn ' + sClassHeight + '">' + (bUseSvgLoading ? bx_loading_svg('colored', sClassHeight) : '') + '</b>');
  246. if(!bUseSvgLoading)
  247. bx_loading_animate(oButton.find('.bx-loading-ajax-btn'), aSpinnerSmallOpts);
  248. }
  249. function bx_loading_content (oElement, bEnable, isReplace) {
  250. var oBlock = $(oElement);
  251. var oLoading = $('<div class="bx-loading-ajax bx-def-z-index-front">' + (bUseSvgLoading ? bx_loading_svg('colored') : '') + '</div>');
  252. if(!bEnable)
  253. oBlock.find(".bx-loading-ajax").remove();
  254. else if(!oBlock.find('.bx-loading-ajax').length) {
  255. if('undefined' != typeof(isReplace) && isReplace)
  256. oBlock.html(oLoading.addClass('static'));
  257. else
  258. oBlock.append(oLoading);
  259. if(!bUseSvgLoading)
  260. bx_loading_animate(oBlock.find('.bx-loading-ajax'), aSpinnerOpts);
  261. }
  262. }
  263. function bx_loading (elem, b) {
  264. if (typeof elem == 'string')
  265. elem = '#' + elem;
  266. var block = $(elem);
  267. if (block.hasClass('bx-btn')) {
  268. bx_loading_btn (block, b);
  269. return;
  270. }
  271. if (1 == b || true == b) {
  272. bx_loading_content(block, b);
  273. e = block.find(".bx-loading-ajax");
  274. e.css('left', parseInt(block.width()/2.0 - e.width()/2.0));
  275. var he = e.outerHeight();
  276. var hc = block.outerHeight();
  277. if (block.css('position') != 'relative' && block.css('position') != 'absolute') {
  278. if (!block.data('css-save-position'))
  279. block.data('css-save-position', block.css('position'));
  280. block.css('position', 'relative');
  281. }
  282. if (hc > he) {
  283. e.css('top', parseInt(hc/2.0 - he/2.0));
  284. }
  285. if (hc < he) {
  286. if (!block.data('css-save-min-height'))
  287. block.data('css-save-min-height', block.css('min-height'));
  288. block.css('min-height', he);
  289. e.css('top', 0);
  290. }
  291. } else {
  292. if (block.data('css-save-position'))
  293. block.css('position', block.data('css-save-position'));
  294. if (block.data('css-save-min-height'))
  295. block.css('min-height', block.data('css-save-min-height'));
  296. bx_loading_content(block, b);
  297. }
  298. }
  299. /**
  300. * Center content with floating blocks.
  301. * sSel - jQuery selector of content to be centered
  302. * sBlockSel - jquery selector of blocks
  303. */
  304. function bx_center_content (sSel, sBlockStyle, bListenOnResize) {
  305. var sId;
  306. if ($(sSel).parent().hasClass('bx-center-content-wrapper')) {
  307. sId = $(sSel).parent().attr('id');
  308. } else {
  309. sId = 'id' + (new Date()).getTime();
  310. $(sSel).wrap('<div id="'+sId+'" class="bx-center-content-wrapper"></div>');
  311. }
  312. var eCenter = $('#' + sId);
  313. var iAll = $('#' + sId + ' ' + sBlockStyle).size();
  314. var iWidthUnit = $('#' + sId + ' ' + sBlockStyle + ':first').outerWidth(true);
  315. var iWidthContainer = eCenter.innerWidth();
  316. var iPerRow = parseInt(iWidthContainer/iWidthUnit);
  317. var iLeft = (iWidthContainer - (iAll > iPerRow ? iPerRow * iWidthUnit : iAll * iWidthUnit)) / 2;
  318. if (iWidthUnit > iWidthContainer)
  319. return;
  320. if ('undefined' != typeof(bListenOnResize) && bListenOnResize) {
  321. $(window).on('resize.bx-center-content', function () {
  322. bx_center_content(sSel, sBlockStyle);
  323. });
  324. }
  325. eCenter.css("padding-left", iLeft);
  326. }
  327. /**
  328. * Show pointer popup with menu from URL.
  329. * @param o - menu object name
  330. * @param e - element to show popup at
  331. * @param options - popup options
  332. * @param vars - additional GET variables
  333. */
  334. function bx_menu_popup (o, e, options, vars) {
  335. var options = options || {};
  336. var vars = vars || {};
  337. var o = $.extend({}, $.fn.dolPopupDefaultOptions, {id: o, url: bx_append_url_params('menu.php', $.extend({o:o}, vars)), cssClass: 'bx-popup-menu'}, options);
  338. if ('undefined' == typeof(e))
  339. e = window;
  340. $(e).dolPopupAjax(o);
  341. }
  342. /**
  343. * Show pointer popup with menu from existing HTML.
  344. * @param jSel - jQuery selector for html to show in popup
  345. * @param e - element to show popup at
  346. * @param options - popup options
  347. */
  348. function bx_menu_popup_inline (jSel, e, options) {
  349. if ($(jSel + ':visible').length)
  350. $(jSel).dolPopupHide();
  351. else {
  352. var options = options || {};
  353. var o = $.extend({}, $.fn.dolPopupDefaultOptions, options, {
  354. pointer: e != undefined && $(e).length != 0 ? {el:$(e)} : false,
  355. cssClass: 'bx-popup-menu',
  356. onShow: function(oPopup) {
  357. oPopup.find('a').each(function () {
  358. $(this).off('click.bx-popup-menu');
  359. $(this).on('click.bx-popup-menu', function() {
  360. $(jSel).dolPopupHide();
  361. });
  362. });
  363. }
  364. });
  365. $(jSel).dolPopup(o);
  366. }
  367. }
  368. /**
  369. * Show pointer popup with menu from URL.
  370. * @param sObject - menu object name
  371. * @param oElement - element to show popup at
  372. * @param oOptions - popup options
  373. * @param oVars - additional GET variables
  374. */
  375. function bx_menu_slide (sObject, oElement, sPosition, oOptions, oVars) {
  376. var oVars = oVars || {};
  377. var oOptions = oOptions || {};
  378. oOptions = $.extend({}, {parent: 'body', container: '.bx-sliding-menu-content'}, oOptions);
  379. var sId = '';
  380. var sIdSel = '';
  381. var sIdPfx = 'bx-sliding-menu-wrapper-';
  382. if(typeof(oOptions.id) != 'undefined')
  383. switch(typeof(oOptions.id)) {
  384. case 'string':
  385. sId = sIdPfx + oOptions.id;
  386. break;
  387. case 'object':
  388. sId = typeof(oOptions.id.force) != 'undefined' && oOptions.id.force ? oOptions.id.value : sIdPfx + oOptions.id.value;
  389. break;
  390. }
  391. else
  392. sId = sIdPfx + parseInt(2147483647 * Math.random());
  393. sIdSel = '#' + sId;
  394. //--- If slider exists
  395. if ($(sIdSel).length) {
  396. bx_menu_slide_inline (sIdSel, oElement, sPosition);
  397. return;
  398. }
  399. //--- If slider doesn't exists
  400. else {
  401. var oMenuLoading = $('#bx-sliding-menu-loading');
  402. if(!oMenuLoading || !oMenuLoading.length)
  403. return;
  404. $('<div id="' + sId + '" style="display:none;">' + oMenuLoading.html() + '</div>').addClass(oMenuLoading.attr('class')).appendTo(oOptions.parent);
  405. var oLoading = $(sIdSel + ' .bx-sliding-menu-loading');
  406. bx_loading_content(oLoading, true, true);
  407. bx_menu_slide_inline (sIdSel, oElement, sPosition);
  408. var fOnLoad = function() {
  409. bx_loading_content(oLoading, false);
  410. $(sIdSel).bxProcessHtml().show();
  411. };
  412. $(sIdSel).find(oOptions.container).load(bx_append_url_params('menu.php', $.extend({o:sObject}, oVars)), function () {
  413. var f = function () {
  414. if($(sIdSel).find('img').length > 0 && !$(sIdSel).find('img').get(0).complete)
  415. $(sIdSel).find('img').load(fOnLoad);
  416. else
  417. fOnLoad();
  418. };
  419. setTimeout(f, 100); // TODO: better way is to check if item is animating before positioning it in the code where popup is positioning
  420. });
  421. }
  422. }
  423. /**
  424. * Show sliding menu from existing HTML.
  425. * @param sMenu - jQuery object or selector for html to show in popup
  426. * @param e - element to click to open/close slider
  427. * @param sPosition - 'block' for sliding menu in blocks, 'site' - for sliding main menu
  428. */
  429. function bx_menu_slide_inline (sMenu, e, sPosition) {
  430. var options = options || {};
  431. var eSlider = $(sMenu);
  432. if ('undefined' !== typeof (bx_menu_slide_inline_custom)) {
  433. return bx_menu_slide_inline_custom(sMenu, e, sPosition);
  434. }
  435. if ('undefined' == typeof(e))
  436. e = eSlider.data('data-control-btn');
  437. var eIcon = $(e).find('.sys-icon-a');
  438. var fPositionElement = function (oElement) {
  439. eSlider.css({
  440. position: 'absolute',
  441. top: oElement.outerHeight(true),
  442. left: 0
  443. });
  444. };
  445. var fPositionBlock = function () {
  446. var eBlock = eSlider.parents('.bx-page-block-container');
  447. eSlider.css({
  448. position: 'absolute',
  449. top: eBlock.find('.bx-db-header').outerHeight(true),
  450. left: 0
  451. //width: eBlock.width() TODO: Commited to test. Remove if everything is OK.
  452. });
  453. };
  454. var fPositionSite = function () {
  455. var eToolbar = $('#bx-toolbar');
  456. eSlider.css({
  457. position: 'fixed',
  458. top: eToolbar.outerHeight(true) + (typeof iToolbarSubmenuTopOffset != 'undefined' ? parseInt(iToolbarSubmenuTopOffset) : 0),
  459. left: 0
  460. });
  461. };
  462. var fClose = function () {
  463. if (eIcon.length)
  464. (new Marka(eIcon[0])).set(eIcon.attr('data-icon-orig'));
  465. eSlider.slideUp()
  466. };
  467. var fOpen = function () {
  468. if (eIcon.length) {
  469. eIcon.attr('data-icon-orig', eIcon.attr('data-icon'));
  470. (new Marka(eIcon[0])).set('times');
  471. }
  472. if(typeof sPosition == 'object')
  473. fPositionElement(sPosition);
  474. else if(typeof sPosition == 'string' && sPosition == 'block')
  475. fPositionBlock();
  476. else
  477. fPositionSite();
  478. eSlider.slideDown();
  479. eSlider.data('data-control-btn', e);
  480. };
  481. if ('undefined' == typeof(sPosition))
  482. sPosition = 'block';
  483. if (eSlider.is(':visible')) {
  484. fClose();
  485. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  486. $(window).off('resize.bx-sliding-menu');
  487. }
  488. else {
  489. bx_menu_slide_close_all_opened();
  490. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  491. $(window).off('resize.bx-sliding-menu');
  492. fOpen();
  493. eSlider.find('a').each(function () {
  494. $(this).off('click.bx-sliding-menu');
  495. $(this).on('click.bx-sliding-menu', function () {
  496. fClose();
  497. });
  498. });
  499. setTimeout(function () {
  500. var iWidthPrev = $(window).width();
  501. $(window).on('resize.bx-sliding-menu', function () {
  502. if ($(this).width() == iWidthPrev)
  503. return;
  504. iWidthPrev = $(this).width();
  505. bx_menu_slide_close_all_opened();
  506. });
  507. $(document).on('click.bx-sliding-menu touchend.bx-sliding-menu', function (event) {
  508. 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)
  509. event.stopPropagation();
  510. else
  511. bx_menu_slide_close_all_opened();
  512. });
  513. }, 10);
  514. }
  515. }
  516. /**
  517. * Close all opened sliding menus
  518. */
  519. function bx_menu_slide_close_all_opened () {
  520. $('.bx-sliding-menu:visible, .bx-sliding-menu-main:visible, .bx-popup-slide-wrapper:visible').each(function () {
  521. bx_menu_slide_inline('#' + this.id);
  522. });
  523. }
  524. /*
  525. * Note. oData.count_old and oData.count_new are also available and can be checked or used in notification popup.
  526. */
  527. function bx_menu_show_live_update(oData) {
  528. var sSelectorAddon = '.bx-menu-item-addon';
  529. //--- Update Child Menu Item
  530. if(oData.mi_child) {
  531. var oMenuItem = $('.bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item-' + oData.mi_child.menu_item);
  532. var oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  533. if(oMenuItemAddon.length > 0)
  534. oMenuItemAddon.html(oData.count_new);
  535. else
  536. oMenuItem.append(oData.code.replace('{count}', oData.count_new));
  537. //+++ Check for 0 value
  538. oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  539. if(parseInt(oData.count_new) > 0)
  540. oMenuItemAddon.show();
  541. else
  542. oMenuItemAddon.hide();
  543. }
  544. //--- Update Parent Menu Item
  545. if(oData.mi_parent) {
  546. var oMenuItem = $('.bx-menu-object-' + oData.mi_parent.menu_object + ' .bx-menu-item-' + oData.mi_parent.menu_item);
  547. var oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  548. var sMediaType = bx_check_mq();
  549. if(sMediaType == 'mobile')
  550. sMediaType = 'phone';
  551. var iSum = 0;
  552. $('.bx-media-' + sMediaType + ' .bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item:not(.bx-def-media-' + sMediaType + '-hide) .bx-menu-item-addon').each(function() {
  553. iValue = parseInt($(this).html());
  554. if(iValue && iValue > 0)
  555. iSum += iValue;
  556. });
  557. if(oMenuItemAddon.length > 0)
  558. oMenuItemAddon.html(iSum);
  559. else
  560. oMenuItem.append(oData.code.replace('{count}', iSum));
  561. //+++ Check for 0 value
  562. oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  563. if(iSum > 0)
  564. oMenuItemAddon.show();
  565. else
  566. oMenuItemAddon.hide();
  567. }
  568. }
  569. function bx_menu_show_more_less(oLink, sMenu, sSelectorParent) {
  570. if(!sSelectorParent)
  571. sSelectorParent = 'ul';
  572. var sClass = 'bx-mi-hidden';
  573. $(oLink).parents(sSelectorParent + ':first').find('.bx-mi-aux, .bx-psmi-show-more, .bx-psmi-show-less').toggleClass(sClass);
  574. $.get(sUrlRoot + 'menu.php', {
  575. o: sMenu,
  576. a: 'set_collapsed',
  577. v: $(oLink).parents(sSelectorParent + ':first').find('.bx-mi-aux').hasClass(sClass) ? 1 : 0
  578. });
  579. }
  580. function bx_menu_toggle_contents(oLink, sSelectorParent) {
  581. if(!sSelectorParent)
  582. sSelectorParent = '.bx-menu-contents';
  583. var sClass = 'bx-m-collapsed';
  584. var oParent = $(oLink).parents(sSelectorParent + ':first');
  585. oParent.toggleClass(sClass);
  586. oParent.siblings('.bx-menu-content').toggle();
  587. return false;
  588. }
  589. function bx_menu_toggle(oLink, sMenu, sMenuItem, sSelectorParent) {
  590. if(!sSelectorParent)
  591. sSelectorParent = 'li';
  592. var sClass = 'bx-mi-collapsed';
  593. var oParent = $(oLink).parents(sSelectorParent + ':first');
  594. oParent.toggleClass(sClass);
  595. $.get(sUrlRoot + 'menu.php', {
  596. o: sMenu,
  597. a: 'set_collapsed_submenu',
  598. i: sMenuItem,
  599. v: oParent.hasClass(sClass) ? 1 : 0
  600. });
  601. return false;
  602. }
  603. function bx_menu_followings_load_more(oLink, sMenu, sContextModule, iStart, iPerPage) {
  604. var oLoadingParent = $(oLink).length ? $(oLink).parents('.bx-menu-item:first') : $('body');
  605. bx_loading(oLoadingParent, true);
  606. $.get(sUrlRoot + 'menu.php', {
  607. o: sMenu,
  608. a: 'load_more',
  609. v: sContextModule,
  610. start: iStart,
  611. per_page: iPerPage
  612. }, function(oData) {
  613. bx_loading(oLoadingParent, false);
  614. if(oData && oData.content != undefined)
  615. $(oLink).parents('.bx-menu-subitem:first').replaceWith(oData.content);
  616. }, 'json');
  617. }
  618. /**
  619. * Set ACL level for specified profile
  620. * @param iProfileId - profile id to set acl level for
  621. * @param iAclLevel - acl level id to assign to a given rofile
  622. */
  623. function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
  624. var bBulk = !$.isNumeric(iProfileId);
  625. var iAclCard = !bBulk && $('#sys-acl-profile-' + iProfileId).length > 0 ? 1 : 0;
  626. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  627. if(bLoading)
  628. bx_loading($(mixedLoadingElement), true);
  629. $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', profile_id: iProfileId, level_id: iAclLevel, card:iAclCard}, function(oData) {
  630. bx_on_set_acl_level(oData, mixedLoadingElement);
  631. }, 'json');
  632. }
  633. function bx_on_set_acl_level(oData, oLoadingElement) {
  634. if(typeof(oLoadingElement) != 'undefined')
  635. bx_loading($(oLoadingElement), false);
  636. if(oData.msg != undefined && oData.msg.length) {
  637. bx_alert(oData.msg);
  638. return;
  639. }
  640. if($(oLoadingElement).hasClass('bx-popup-applied'))
  641. $(oLoadingElement).dolPopupHide().remove();
  642. if(typeof(oData.card) == 'object')
  643. for(var iField in oData.card) {
  644. var oCard = $(oData.card[iField]);
  645. $('#' + oCard.attr('id')).replaceWith(oCard.bxTime());
  646. }
  647. }
  648. /**
  649. * Set badge for specified content
  650. * @param sModule - current module for content
  651. * @param iContentId - content id to set badge for
  652. * @param iBadgeId - badge id to assign to a given content
  653. */
  654. function bx_set_badge (sModule, iContentId, iBadgeId, mixedLoadingElement) {
  655. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  656. if(bLoading)
  657. bx_loading($(mixedLoadingElement), true);
  658. $.post(sUrlRoot + 'menu.php', {o:'sys_set_badges', module: sModule, content_id: iContentId, badge_id: iBadgeId}, function(oData) {
  659. if(bLoading)
  660. bx_loading($(mixedLoadingElement), false);
  661. if(oData.msg != undefined && oData.msg.length) {
  662. bx_alert(oData.msg);
  663. return;
  664. }
  665. if($(mixedLoadingElement).hasClass('bx-popup-applied'))
  666. $(mixedLoadingElement).dolPopupHide().remove();
  667. if(typeof(oData.card) == 'object')
  668. for(var iField in oData.card) {
  669. var oCard = $(oData.card[iField]);
  670. $('#' + oCard.attr('id')).replaceWith(oCard);
  671. }
  672. $('.bx-base-bages-container').html(oData.html);
  673. }, 'json');
  674. }
  675. function bx_get_notes(oSource, sModule, iContentId, oOptions, oVars) {
  676. var oOptions = oOptions || {};
  677. var oVars = oVars || {};
  678. $.post(
  679. sUrlRoot + 'modules/?r=' + sModule + '/get_notes/',
  680. $.extend({content_id: iContentId}, oVars),
  681. function(oData) {
  682. if(oData && oData.popup != undefined) {
  683. if(typeof(oData.popup) == 'string')
  684. oData.popup = {html: oData.popup, options: {}};
  685. oData.popup.options = $.extend({}, $.fn.dolPopupDefaultOptions, oData.popup.options, {
  686. id: sModule + '_notes_' + iContentId,
  687. closeOnOuterClick: false,
  688. removeOnClose: true,
  689. onBeforeShow: function(oPopup) {
  690. $(oPopup).find('.bx-popup-element-close').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
  691. }
  692. }, oOptions);
  693. }
  694. processJsonData(oData);
  695. },
  696. 'json'
  697. );
  698. }
  699. function bx_approve(oSource, sModule, iContentId, oOptions, oVars) {
  700. var oOptions = oOptions || {};
  701. var oVars = oVars || {};
  702. var fPopupInit = function(oData) {
  703. if(oData && oData.popup != undefined) {
  704. if(typeof(oData.popup) == 'string')
  705. oData.popup = {html: oData.popup, options: {}};
  706. oData.popup.options = $.extend({}, $.fn.dolPopupDefaultOptions, oData.popup.options, {
  707. id: sModule + '_approve_' + iContentId,
  708. closeOnOuterClick: false,
  709. removeOnClose: true,
  710. onBeforeShow: function(oPopup) {
  711. $(oPopup).find('.bx-popup-element-close').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
  712. var oForm = $(oPopup).find('form');
  713. if(oForm.length > 0) {
  714. oForm.ajaxForm({
  715. dataType: 'json',
  716. beforeSubmit: function(aFormData, oForm, oOptions) {
  717. bx_loading(oForm, true);
  718. },
  719. success: function(oData) {
  720. $('.bx-popup-applied:visible').dolPopupHide();
  721. fPopupInit(oData);
  722. processJsonData(oData);
  723. }
  724. });
  725. }
  726. }
  727. }, oOptions);
  728. }
  729. };
  730. $.post(
  731. sUrlRoot + 'modules/?r=' + sModule + '/approve/',
  732. $.extend({content_id: iContentId}, oVars),
  733. function(oData) {
  734. fPopupInit(oData);
  735. processJsonData(oData);
  736. },
  737. 'json'
  738. );
  739. }
  740. function validateLoginForm(eForm) {
  741. return true;
  742. }
  743. /**
  744. * convert <time> tags to human readable format
  745. * @param sLang - use sLang localization
  746. * @param isAutoupdate - for internal usage only
  747. */
  748. function bx_time(sLang, isAutoupdate, sRootSel) {
  749. if ('undefined' == typeof(sRootSel))
  750. sRootSel = 'body';
  751. var iAutoupdate = 22*60*60; // autoupdate time in realtime if less than 22 hours
  752. var sSel = 'time';
  753. if (typeof(sLang) != 'undefined')
  754. glBxTimeLang = sLang;
  755. else if(typeof(glBxTimeLang) != 'undefined')
  756. sLang = glBxTimeLang;
  757. if(!sLang)
  758. return;
  759. if ('undefined' != typeof(isAutoupdate) && isAutoupdate)
  760. sSel += '.bx-time-autoupdate';
  761. $(sRootSel).find(sSel).each(function () {
  762. var s;
  763. var sTime = $(this).attr('datetime');
  764. var iSecondsDiff = moment(sTime).unix() - moment().unix();
  765. if (iSecondsDiff < 0)
  766. iSecondsDiff = -iSecondsDiff;
  767. if (iSecondsDiff < $(this).attr('data-bx-autoformat'))
  768. s = moment(sTime).locale(sLang).fromNow(); // 'time ago' format
  769. else if (1 == $(this).attr('data-bx-utc'))
  770. s = moment.utc(sTime).locale(sLang).format($(this).attr('data-bx-format'));
  771. else
  772. s = moment(sTime).locale(sLang).format($(this).attr('data-bx-format'));
  773. if (iSecondsDiff < iAutoupdate)
  774. $(this).addClass('bx-time-autoupdate');
  775. else
  776. $(this).removeClass('bx-time-autoupdate');
  777. $(this).html(s);
  778. });
  779. if ($('time.bx-time-autoupdate').size()) {
  780. setTimeout(function () {
  781. bx_time(sLang, true);
  782. }, 20000);
  783. }
  784. }
  785. (function($) {
  786. $.fn.bxTime = function() {
  787. bx_time(undefined, undefined, this);
  788. return this;
  789. };
  790. /**
  791. * process HTML which was added dynamicly on the page
  792. */
  793. $.fn.bxProcessHtml = function (oCallback) {
  794. var eElement = $(this);
  795. if ('undefined' !== typeof(eElement)) {
  796. // process js time
  797. eElement.bxTime();
  798. bx_process_links();
  799. // process web forms
  800. if ($.isFunction($.fn.addWebForms))
  801. eElement.addWebForms();
  802. // process animating icons
  803. bx_activate_anim_icons();
  804. // process syntax hightlighing
  805. if ('undefined' !== typeof(Prism) && eElement.size())
  806. Prism.highlightAllUnder(eElement[0]);
  807. // process links
  808. bx_redirect_for_external_links(eElement);
  809. // flickity update
  810. setTimeout(function () {
  811. const oFlickity = eElement.find('.flickity-enabled');
  812. if (oFlickity.length)
  813. oFlickity.flickity('resize');
  814. }, 250);
  815. }
  816. if ('undefined' !== typeof(oCallback)) {
  817. oCallback(eElement);
  818. }
  819. if (typeof glOnProcessHtml !== 'undefined' && glOnProcessHtml instanceof Array) {
  820. for (var i = 0; i < glOnProcessHtml.length; i++)
  821. if (typeof glOnProcessHtml[i] === "function")
  822. glOnProcessHtml[i](this);
  823. }
  824. return this;
  825. };
  826. $.fn.bxCheckOverflowHeight = function(sClass, onFind) {
  827. if(!sClass)
  828. sClass = 'bx-overflow';
  829. return this.each(function() {
  830. var oElement = $(this);
  831. if(oElement.hasClass(sClass) || oElement.css('overflow') != 'hidden')
  832. return;
  833. if(oElement.find('img').length > 0) {
  834. var oImg = oElement.find('img:first').get(0);
  835. const oImgCopy = new Image();
  836. oImgCopy.src = oImg.src;
  837. oImgCopy.onload = function() {
  838. var iHeightParent = oElement.height();
  839. var iHeightImg = oImg.clientHeight;
  840. var iOffsetTopImg = oImg.offsetTop;
  841. if(iOffsetTopImg < iHeightParent && iOffsetTopImg + iHeightImg > iHeightParent)
  842. oElement.css('max-height', (iOffsetTopImg + iHeightImg + 50) + 'px');
  843. if(oElement.prop('scrollHeight') <= Math.ceil(oElement.height()))
  844. return;
  845. oElement.addClass(sClass);
  846. if(typeof onFind === 'function')
  847. onFind(oElement);
  848. }
  849. }
  850. else {
  851. if(oElement.prop('scrollHeight') <= Math.ceil(oElement.height()))
  852. return;
  853. oElement.addClass(sClass);
  854. if(typeof onFind === 'function')
  855. onFind(oElement);
  856. }
  857. });
  858. };
  859. $.fn.bxConvertEmbeds = function() {
  860. return this.each(function() {
  861. $(this).find(".bx-embed-link").each(function() {
  862. var oItem = $(this);
  863. oItem.html(oItem.attr('source'));
  864. $.getJSON(sUrlRoot + '/embed.php?', {a: 'get_link', l: oItem.attr('source')}, function(oData) {
  865. oItem.html(oData.code)
  866. if(oItem.find('a').length > 0)
  867. bx_embed_link(oItem.find('a')[0]);
  868. });
  869. });
  870. });
  871. };
  872. } (jQuery));
  873. /**
  874. * Perform connections AJAX request.
  875. * In case of error - it shows js alert with error message.
  876. * In case of success - the page is reloaded.
  877. *
  878. * @param sObj - connections object
  879. * @param sAction - 'add', 'remove' or 'reject'
  880. * @param iContentId - content id, initiator is always current logged in user
  881. * @param bConfirm - show confirmation dialog
  882. */
  883. function bx_conn_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  884. var fPerform = function() {
  885. var aParams = {
  886. obj: sObj,
  887. act: sAction,
  888. id: iContentId
  889. };
  890. var fCallback = function (data) {
  891. bx_loading_btn(e, 0);
  892. if ('object' != typeof(data))
  893. return;
  894. if (data.err) {
  895. bx_alert(data.msg);
  896. } else {
  897. if ('function' == typeof(fOnComplete))
  898. fOnComplete(data, e);
  899. else if (!loadDynamicBlockAuto(e))
  900. location.reload();
  901. else
  902. $('#bx-popup-ajax-wrapper-bx_persons_view_actions_more').remove();
  903. }
  904. };
  905. bx_loading_btn(e, 1);
  906. $.ajax({
  907. dataType: 'json',
  908. url: sUrlRoot + 'conn.php',
  909. data: aParams,
  910. type: 'POST',
  911. success: fCallback
  912. });
  913. };
  914. if (typeof(bConfirm) != 'undefined' && bConfirm)
  915. bx_confirm(_t('_Are_you_sure'), fPerform);
  916. else
  917. fPerform();
  918. }
  919. /**
  920. * Perform recommendations AJAX request.
  921. * In case of error - it shows js alert with error message.
  922. * In case of success - the page is reloaded.
  923. *
  924. * @param sObj - recommendation object
  925. * @param sAction - 'ignore'
  926. * @param iContentId - content id, initiator is always current logged in user
  927. * @param bConfirm - show confirmation dialog
  928. */
  929. function bx_recommendation_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  930. var fPerform = function() {
  931. var aParams = {
  932. obj: sObj,
  933. act: sAction,
  934. id: iContentId
  935. };
  936. var fCallback = function (data) {
  937. bx_loading_btn(e, 0);
  938. if ('object' != typeof(data))
  939. return;
  940. if (data.msg)
  941. bx_alert(data.msg);
  942. else {
  943. if ('function' == typeof(fOnComplete))
  944. fOnComplete(data, e);
  945. else if (!loadDynamicBlockAuto(e))
  946. location.reload();
  947. }
  948. };
  949. bx_loading_btn(e, 1);
  950. $.ajax({
  951. dataType: 'json',
  952. url: sUrlRoot + 'recommendation.php',
  953. data: aParams,
  954. type: 'POST',
  955. success: fCallback
  956. });
  957. };
  958. if (typeof(bConfirm) != 'undefined' && bConfirm)
  959. bx_confirm(_t('_Are_you_sure'), fPerform);
  960. else
  961. fPerform();
  962. }
  963. function bx_append_url_params (sUrl, mixedParams) {
  964. var sParams = sUrl.indexOf('?') == -1 ? '?' : '&';
  965. var sHash = '';
  966. if(sUrl.indexOf('#') != -1) {
  967. var oUrl = new URL(sUrl);
  968. if(oUrl.hash.length > 0) {
  969. sHash = oUrl.hash;
  970. sUrl = sUrl.replace(sHash, '');
  971. }
  972. else
  973. sUrl = sUrl.replace('#', '');
  974. }
  975. if(mixedParams instanceof Array) {
  976. for(var i in mixedParams)
  977. sParams += i + '=' + mixedParams[i] + '&';
  978. sParams = sParams.substr(0, sParams.length-1);
  979. }
  980. else if(mixedParams instanceof Object) {
  981. $.each(mixedParams, function(sKey, sValue) {
  982. sParams += sKey + '=' + sValue + '&';
  983. });
  984. sParams = sParams.substr(0, sParams.length-1);
  985. }
  986. else
  987. sParams += mixedParams;
  988. return sUrl + sParams + sHash;
  989. }
  990. function bx_search_extnded_sort(obj, url){
  991. location.href = url + '&sort=' +$(obj).val();
  992. }
  993. function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, iMinLen, onComplete) {
  994. var oForm = $(e.target).parents(sFormSel + ':first');
  995. if ('undefined' != typeof(e) && 13 == e.keyCode) {
  996. oForm.find('input[name=live_search]').val(0);
  997. oForm.submit();
  998. return false;
  999. }
  1000. iMinLen = typeof(iMinLen) != 'undefined' ? parseInt(iMinLen) : 0;
  1001. if(iMinLen > 0 && iMinLen > (oForm.find('input[name=keyword]').val().length + 1))
  1002. return true;
  1003. if ('undefined' != typeof(glBxSearchTimeoutHandler) && glBxSearchTimeoutHandler)
  1004. clearTimeout(glBxSearchTimeoutHandler);
  1005. glBxSearchTimeoutHandler = setTimeout(function () {
  1006. bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, onComplete);
  1007. }, 500);
  1008. return true;
  1009. }
  1010. function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, onComplete) {
  1011. if ('undefined' == typeof(sLoadingContSel))
  1012. sLoadingContSel = sResultsContSel;
  1013. if ('undefined' == typeof(bSortResults))
  1014. bSortResults = false;
  1015. var sQuery = $('input', sFormSel).serialize();
  1016. bx_loading($(sLoadingContSel), true);
  1017. $.post(sUrlRoot + 'searchKeywordContent.php', sQuery, function(data) {
  1018. bx_loading($(sLoadingContSel), false);
  1019. if(!data)
  1020. return;
  1021. if (bSortResults) {
  1022. var sAsk = $(data).filter(".bx-btn.sys-agents-ask");
  1023. var aSortedUnits = $(data).find(".bx-def-unit-live-search").toArray().sort(function (a, b) {
  1024. return b.getAttribute('data-ts') - a.getAttribute('data-ts');
  1025. });
  1026. data = '';
  1027. if(sAsk.length)
  1028. data += sAsk.get(0).outerHTML;
  1029. $.each(aSortedUnits.slice(0, n), function (i, e) {
  1030. data += e.outerHTML;
  1031. });
  1032. }
  1033. var oContainer = $(sResultsContSel);
  1034. oContainer.html(data).bxProcessHtml();
  1035. if(typeof onComplete === 'function')
  1036. onComplete(oContainer, data);
  1037. });
  1038. return false;
  1039. }
  1040. function on_filter_apply(e, sInputId, sFilterName)
  1041. {
  1042. var oRegExp = new RegExp("[&]{0,1}" + sFilterName + "=.*");
  1043. var s = ('' + document.location).replace(oRegExp, ''); // remove filter
  1044. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  1045. if (e.checked && $('#' + sInputId).val().length > 2)
  1046. s += (-1 == s.indexOf('?') ? '?' : '&') + sFilterName + '=' + $('#' + sInputId).val(); // append filter
  1047. document.location = s;
  1048. }
  1049. function on_filter_key_up (e, sCheckboxId)
  1050. {
  1051. if (13 == e.keyCode) {
  1052. $('#' + sCheckboxId).click();
  1053. return false;
  1054. }
  1055. else {
  1056. $('#' + sCheckboxId).removeAttr('checked');
  1057. return true;
  1058. }
  1059. }
  1060. function on_copyright_click()
  1061. {
  1062. oDate = new Date();
  1063. $(document).dolPopupAlert({
  1064. message: _t('_copyright', oDate.getFullYear())
  1065. });
  1066. }
  1067. function bx_activate_anim_icons(sColor)
  1068. {
  1069. if(typeof(sColor) != 'undefined')
  1070. glBxAnimIconColor = sColor;
  1071. else if(typeof(glBxAnimIconColor) != 'undefined')
  1072. sColor = glBxAnimIconColor;
  1073. if(!sColor)
  1074. return;
  1075. $('.sys-icon-a').not('.marka').each(function () {
  1076. var e = $(this);
  1077. var m = new Marka(e.get(0)), r = e.attr('data-rotate'), c = e.attr('data-color');
  1078. m.set(e.attr('data-icon')).rotate(r ? r : 'down').color(c ? c : sColor);
  1079. });
  1080. }
  1081. function bx_get_param(s) {
  1082. if (!window.aDolOptions || !aDolOptions[s])
  1083. return false;
  1084. return aDolOptions[s];
  1085. }
  1086. function bx_autocomplete_fields(iId, sUrl, sName, bShowImg, bOnlyOnce, onSelect){
  1087. if (!$('#' + iId).hasClass('bx-form-input-autotoken'))
  1088. $('#' + iId).addClass('bx-form-input-autotoken');
  1089. $('#' + iId + ' input[type=text]').autocomplete({
  1090. source: sUrl,
  1091. focus: function(e, ui ) {
  1092. $(this).val(ui.item.label);
  1093. e.preventDefault();
  1094. },
  1095. select: function(e, ui) {
  1096. $(this).val(ui.item.label);
  1097. $(this).trigger('superselect', ui.item);
  1098. if (typeof onSelect === 'function')
  1099. onSelect(ui);
  1100. e.preventDefault();
  1101. }
  1102. });
  1103. if ($('#' + iId + ' .val').length > 0 && bOnlyOnce)
  1104. $('#' + iId + ' input[type=text]').hide();
  1105. $('#' + iId + ' input[type=text]').on('superselect', function(e, item) {
  1106. $(this).hide();
  1107. if ('undefined' != typeof(item)) {
  1108. var sImage = '';
  1109. if(bShowImg && item.unit != undefined)
  1110. sImage = item.unit;
  1111. else if(bShowImg && item.thumb != undefined)
  1112. sImage = '<img class="bx-def-thumb bx-def-icon-size bx-def-margin-sec-right" src="' + item.thumb + '">';
  1113. $(this).before('<b class="val 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>');
  1114. }
  1115. if (!bOnlyOnce)
  1116. {
  1117. fAutoShrinkInput();
  1118. $(this).show();
  1119. this.value = '';
  1120. }
  1121. }).on('keydown', function(e) {
  1122. // if: comma,enter (delimit more keyCodes with | pipe)
  1123. if (/(13)/.test(e.which))
  1124. e.preventDefault();
  1125. });
  1126. $('#' + iId).on('click', 'b', function() {
  1127. $(this).remove();
  1128. if (bOnlyOnce)
  1129. $('#' + iId + ' input[type=text]').val('').show();
  1130. else
  1131. fAutoShrinkInput();
  1132. });
  1133. fAutoShrinkInput = function () {
  1134. var iWidthCont = $('#' + iId + '.bx-form-input-autotoken').innerWidth();
  1135. var iWidthExisting = 0;
  1136. $('#' + iId + '.bx-form-input-autotoken b').each(function () {
  1137. iWidthExisting += $(this).outerWidth(true);
  1138. });
  1139. $('#' + iId + '.bx-form-input-autotoken input').innerWidth(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
  1140. };
  1141. if (!bOnlyOnce)
  1142. fAutoShrinkInput();
  1143. else
  1144. $('#' + iId + '.bx-form-input-autotoken input').outerWidth('100%');
  1145. };
  1146. function bx_alert(sMessage, fOnClickOk, oParams)
  1147. {
  1148. $(document).dolPopupAlert({
  1149. message: sMessage,
  1150. onClickOk: fOnClickOk,
  1151. params: oParams
  1152. });
  1153. }
  1154. function bx_confirm(sMessage, fOnClickYes, fOnClickNo, oParams)
  1155. {
  1156. $(document).dolPopupConfirm({
  1157. message: sMessage,
  1158. onClickYes: fOnClickYes,
  1159. onClickNo: fOnClickNo,
  1160. params: oParams
  1161. });
  1162. }
  1163. function bx_prompt(sMessage, sValue, fOnClickOk, fOnClickCancel, oParams)
  1164. {
  1165. $(document).dolPopupPrompt({
  1166. message: sMessage,
  1167. value: sValue,
  1168. onClickOk: fOnClickOk,
  1169. onClickCancel: fOnClickCancel,
  1170. params: oParams
  1171. });
  1172. }
  1173. function bx_is_color_scheme_dark()
  1174. {
  1175. return localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);
  1176. }
  1177. function bx_get_color_scheme()
  1178. {
  1179. return 'theme' in localStorage ? localStorage.theme : 'auto';
  1180. }
  1181. function bx_set_color_scheme(iCode)
  1182. {
  1183. switch(iCode) {
  1184. case 0:
  1185. localStorage.removeItem('theme');
  1186. break;
  1187. case 1:
  1188. localStorage.theme = 'sun'
  1189. break;
  1190. case 2:
  1191. localStorage.theme = 'dark'
  1192. break;
  1193. }
  1194. //--- Change scheme.
  1195. bx_set_color_scheme_html();
  1196. //--- Notify global handlers.
  1197. if(typeof glOnColorSchemeChange === 'undefined' || !(glOnColorSchemeChange instanceof Array))
  1198. return;
  1199. if(typeof iCode === 'undefined' || !iCode)
  1200. iCode = this.isColorSchemeDark() ? 2 : 1;
  1201. for(var i = 0; i < glOnColorSchemeChange.length; i++)
  1202. if(typeof glOnColorSchemeChange[i] === 'function')
  1203. glOnColorSchemeChange[i](iCode);
  1204. }
  1205. function bx_set_color_scheme_html()
  1206. {
  1207. if(bx_is_color_scheme_dark())
  1208. $('html').addClass('dark')
  1209. else
  1210. $('html').removeClass('dark')
  1211. }
  1212. function bx_is_mouse()
  1213. {
  1214. return matchMedia('(pointer:fine)').matches;
  1215. }
  1216. function bx_is_touch_device()
  1217. {
  1218. return (('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0));
  1219. }
  1220. /**
  1221. * Check if mobile or desktop device.
  1222. */
  1223. function bx_check_mq()
  1224. {
  1225. if (typeof glOnCheckMq === 'function') {
  1226. return glOnCheckMq();
  1227. }
  1228. return window.getComputedStyle(document.querySelector('body'), '::before').getPropertyValue('content').replace(/'/g, "").replace(/"/g, "");
  1229. }
  1230. /**
  1231. * This function loads the passed list of CSS files. In case when this function is called for dynamic loading
  1232. * of the same file but many times it allows to avoid multiply loadings of the same file.
  1233. */
  1234. function bx_get_style(mixedUrl)
  1235. {
  1236. if(typeof(mixedUrl) === 'string')
  1237. mixedUrl = new Array(mixedUrl);
  1238. for(let i = 0; i < mixedUrl.length; i++) {
  1239. if(mixedUrl[i] === undefined || !mixedUrl[i].length || $("link[href = '" + mixedUrl[i] + "']").length > 0)
  1240. continue;
  1241. $("head").append($("<link rel='stylesheet' href='" + mixedUrl[i] + "' type='text/css' />"));
  1242. }
  1243. }
  1244. /**
  1245. * This function loads the passed list of js files and executes callback function when the all files are loaded.
  1246. * In case when this function is called for dynamic loading of the same file but many times (like Plyr video init)
  1247. * it allows to avoid multiply loadings of the same file.
  1248. */
  1249. function bx_get_scripts (aFiles, fCallback)
  1250. {
  1251. let iCounter = 0;
  1252. const
  1253. iLength = aFiles.length,
  1254. fHandler = function() {
  1255. if (iCounter++ >= (iLength-1) && typeof(fCallback) === 'function')
  1256. fCallback();
  1257. else
  1258. fExecute(aFiles[iCounter]);
  1259. },
  1260. // Check if js file is not loaded yet then start to load it and returns Promise.
  1261. // All functions which try to load the same file will wait for loading of the file
  1262. // and then continue to work
  1263. fExecute = function(sFile) {
  1264. if ('undefined' === typeof(glBxLoadedScripts[sFile]))
  1265. glBxLoadedScripts[sFile] = { complete : $.bxGetCachedScript(sFile).done(fHandler) };
  1266. else
  1267. glBxLoadedScripts[sFile].complete.then(fHandler);
  1268. };
  1269. if ('undefined' === typeof(glBxLoadedScripts))
  1270. glBxLoadedScripts = {};
  1271. fExecute(aFiles[iCounter]);
  1272. }
  1273. jQuery.bxGetCachedScript = function(sUrl, oOptions)
  1274. {
  1275. oOptions = $.extend(oOptions || {}, {
  1276. dataType: "script",
  1277. cache: true,
  1278. url: sUrl
  1279. });
  1280. return jQuery.ajax(oOptions);
  1281. };
  1282. function bx_is_selector_in_stylesheet(sSel)
  1283. {
  1284. var a = [];
  1285. var aSs = document.styleSheets;
  1286. for (var sSheet = 0; sSheet < aSs.length; sSheet++) {
  1287. var ruleList = document.styleSheets[sSheet].cssRules;
  1288. for (var rule = 0; rule < ruleList.length; rule++)
  1289. a.push(ruleList[rule].selectorText);
  1290. }
  1291. return -1 !== a.indexOf(sSel);
  1292. }
  1293. function bx_copy_to_clipboard(s, onSuccess, onFail)
  1294. {
  1295. if ("undefined" === typeof(onSuccess))
  1296. onSuccess = function (){};
  1297. if ("undefined" === typeof(onFail))
  1298. onFail = function (){};
  1299. const oClip = navigator.clipboard;
  1300. if ("undefined" !== typeof(oClip)) {
  1301. navigator.clipboard.writeText(s).then(onSuccess, onFail);
  1302. }
  1303. else {
  1304. if (document.execCommand) {
  1305. const el = document.createElement("input");
  1306. el.value = s;
  1307. document.body.append(el);
  1308. el.select();
  1309. el.setSelectionRange(0, s.length);
  1310. if (document.execCommand("copy")) {
  1311. onSuccess();
  1312. }
  1313. el.remove();
  1314. }
  1315. else {
  1316. onFail();
  1317. }
  1318. }
  1319. }
  1320. function bx_regexp_escape(s)
  1321. {
  1322. return s
  1323. .replace(/[|\\{}()[\]^$+*?.]/mg, '\\$&')
  1324. .replace(/-/mg, '\\x2d');
  1325. }
  1326. function bx_get_regexp(sType)
  1327. {
  1328. var o = {
  1329. tag:"(<([^>]+bx-tag[^>]+)>)",
  1330. mention: "(<([^>]+bx-mention-link[^>]+)>)",
  1331. url: "(([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w]+@)[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%#\\/\\.\\w\\-_!\\(\\)]*)?\\??(?:[\\-\\+=&;%@\\.\\w_]*)#?(?:[\\.\\!\\/\\w]*))?"
  1332. };
  1333. return o[sType];
  1334. }
  1335. function bx_process_links()
  1336. {
  1337. // process links in container
  1338. $('.bx-lnk-cnt .bx-lnk-src:not(.bx-inited)').each(function() {
  1339. $(this).addClass('bx-inited');
  1340. var sUrl = $(this).prop('href');
  1341. $(this).parents('.bx-lnk-cnt').first().addClass('cursor-pointer').click(function(oEvent){
  1342. if ($(oEvent.target).closest('a').length == 0 && $(oEvent.target).closest('button').length == 0 && $(oEvent.target).closest('form').length == 0 && $(oEvent.target).closest('input').length == 0){
  1343. location.href = sUrl;
  1344. }
  1345. });
  1346. });
  1347. }
  1348. function bx_redirect_for_external_links (e)
  1349. {
  1350. if ('undefined' === typeof(aDolOptions.sys_confirmation_before_redirect) || 'on' !== aDolOptions.sys_confirmation_before_redirect)
  1351. return;
  1352. var aExclude = ['javascript:', 'about:', sUrlRoot];
  1353. var sPattern = 'a';
  1354. $(aExclude).each(function () {
  1355. sPattern += ':not([href^="' + this + '"])';
  1356. });
  1357. sPattern += ":is([href^='http://'],[href^='https://'])";
  1358. if ('undefined' === typeof(e))
  1359. e = $('document');
  1360. e.find(sPattern).each(function() {
  1361. $(this).on('contextmenu', function(e) {
  1362. e.preventDefault();
  1363. });
  1364. $(this).on('click', function() {
  1365. var $this = $(this);
  1366. bx_redirect_for_external_links_open($this.attr('href'));
  1367. return false;
  1368. });
  1369. });
  1370. }
  1371. function bx_redirect_for_external_links_open (sHref)
  1372. {
  1373. //bx_confirm(_t('_sys_redirect_confirmation', sHref).replace(/\&quot;/g, ''), function () {
  1374. // window.open(sHref, '_blank').focus();
  1375. //});
  1376. window.open(sUrlRoot + 'page.php?i=redirect&url=' + encodeURIComponent(sHref), '_blank').focus();
  1377. }
  1378. function bx_agents_action(oElement, sTool, sAction, aParams)
  1379. {
  1380. var oDate = new Date();
  1381. var sQueryUrl = sUrlRoot + 'agents.php';
  1382. var oQueryParams = jQuery.extend({}, {t: sTool, a: sAction, _t:oDate.getTime()}, aParams != undefined ? aParams : {});
  1383. bx_loading_btn(oElement, true);
  1384. jQuery.post (
  1385. sQueryUrl,
  1386. oQueryParams,
  1387. function(oData) {
  1388. bx_loading_btn(oElement, false);
  1389. processJsonData(oData);
  1390. },
  1391. 'json'
  1392. );
  1393. }
  1394. /** @} */