functions.js 62 KB

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