functions.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  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. if ('undefined' == typeof(e))
  338. e = window;
  339. var o = $.extend({}, $.fn.dolPopupDefaultOptions, {
  340. id: o,
  341. url: bx_append_url_params('menu.php', $.extend({o:o}, vars)),
  342. cssClass: 'bx-popup-menu'
  343. }, options);
  344. $(e).dolPopupAjax(o);
  345. }
  346. /**
  347. * Show pointer popup with menu from existing HTML.
  348. * @param jSel - jQuery selector for html to show in popup
  349. * @param e - element to show popup at
  350. * @param options - popup options
  351. */
  352. function bx_menu_popup_inline (jSel, e, options) {
  353. if ($(jSel + ':visible').length)
  354. $(jSel).dolPopupHide();
  355. else {
  356. var options = options || {};
  357. var bElement = e != undefined && $(e).length != 0;
  358. var o = $.extend({}, $.fn.dolPopupDefaultOptions, options, {
  359. pointer: bElement ? {el:$(e)} : false,
  360. cssClass: 'bx-popup-menu',
  361. onShow: function(oPopup) {
  362. oPopup.find('a').each(function () {
  363. $(this).off('click.bx-popup-menu');
  364. $(this).on('click.bx-popup-menu', function() {
  365. $(jSel).dolPopupHide();
  366. });
  367. });
  368. },
  369. });
  370. $(jSel).dolPopup(o);
  371. }
  372. }
  373. /**
  374. * Show pointer popup with menu from URL.
  375. * @param sObject - menu object name
  376. * @param oElement - element to show popup at
  377. * @param oOptions - popup options
  378. * @param oVars - additional GET variables
  379. */
  380. function bx_menu_slide (sObject, oElement, sPosition, oOptions, oVars) {
  381. var oVars = oVars || {};
  382. var oOptions = oOptions || {};
  383. oOptions = $.extend({}, {parent: 'body', container: '.bx-sliding-menu-content'}, oOptions);
  384. var sId = '';
  385. var sIdSel = '';
  386. var sIdPfx = 'bx-sliding-menu-wrapper-';
  387. if(typeof(oOptions.id) != 'undefined')
  388. switch(typeof(oOptions.id)) {
  389. case 'string':
  390. sId = sIdPfx + oOptions.id;
  391. break;
  392. case 'object':
  393. sId = typeof(oOptions.id.force) != 'undefined' && oOptions.id.force ? oOptions.id.value : sIdPfx + oOptions.id.value;
  394. break;
  395. }
  396. else
  397. sId = sIdPfx + parseInt(2147483647 * Math.random());
  398. sIdSel = '#' + sId;
  399. //--- If slider exists
  400. if ($(sIdSel).length) {
  401. bx_menu_slide_inline (sIdSel, oElement, sPosition);
  402. return;
  403. }
  404. //--- If slider doesn't exists
  405. else {
  406. var oMenuLoading = $('#bx-sliding-menu-loading');
  407. if(!oMenuLoading || !oMenuLoading.length)
  408. return;
  409. $('<div id="' + sId + '" style="display:none;">' + oMenuLoading.html() + '</div>').addClass(oMenuLoading.attr('class')).appendTo(oOptions.parent);
  410. var oLoading = $(sIdSel + ' .bx-sliding-menu-loading');
  411. bx_loading_content(oLoading, true, true);
  412. bx_menu_slide_inline (sIdSel, oElement, sPosition);
  413. var fOnLoad = function() {
  414. bx_loading_content(oLoading, false);
  415. $(sIdSel).bxProcessHtml().show();
  416. };
  417. $(sIdSel).find(oOptions.container).load(bx_append_url_params('menu.php', $.extend({o:sObject}, oVars)), function () {
  418. var f = function () {
  419. if($(sIdSel).find('img').length > 0 && !$(sIdSel).find('img').get(0).complete)
  420. $(sIdSel).find('img').load(fOnLoad);
  421. else
  422. fOnLoad();
  423. };
  424. setTimeout(f, 100); // TODO: better way is to check if item is animating before positioning it in the code where popup is positioning
  425. });
  426. }
  427. }
  428. /**
  429. * Show sliding menu from existing HTML.
  430. * @param sMenu - jQuery object or selector for html to show in popup
  431. * @param e - element to click to open/close slider
  432. * @param sPosition - 'block' for sliding menu in blocks, 'site' - for sliding main menu
  433. */
  434. function bx_menu_slide_inline (sMenu, e, sPosition) {
  435. var options = options || {};
  436. var eSlider = $(sMenu);
  437. if ('undefined' !== typeof (bx_menu_slide_inline_custom)) {
  438. return bx_menu_slide_inline_custom(sMenu, e, sPosition);
  439. }
  440. if ('undefined' == typeof(e))
  441. e = eSlider.data('data-control-btn');
  442. var eIcon = $(e).find('.sys-icon-a');
  443. var fPositionElement = function (oElement) {
  444. eSlider.css({
  445. position: 'absolute',
  446. top: oElement.outerHeight(true),
  447. left: 0
  448. });
  449. };
  450. var fPositionBlock = function () {
  451. var eBlock = eSlider.parents('.bx-page-block-container');
  452. eSlider.css({
  453. position: 'absolute',
  454. top: eBlock.find('.bx-db-header').outerHeight(true),
  455. left: 0
  456. //width: eBlock.width() TODO: Commited to test. Remove if everything is OK.
  457. });
  458. };
  459. var fPositionSite = function () {
  460. var eToolbar = $('#bx-toolbar');
  461. eSlider.css({
  462. position: 'fixed',
  463. top: eToolbar.outerHeight(true) + (typeof iToolbarSubmenuTopOffset != 'undefined' ? parseInt(iToolbarSubmenuTopOffset) : 0),
  464. left: 0
  465. });
  466. };
  467. var fClose = function () {
  468. if (eIcon.length)
  469. (new Marka(eIcon[0])).set(eIcon.attr('data-icon-orig'));
  470. eSlider.slideUp()
  471. };
  472. var fOpen = function () {
  473. if (eIcon.length) {
  474. eIcon.attr('data-icon-orig', eIcon.attr('data-icon'));
  475. (new Marka(eIcon[0])).set('times');
  476. }
  477. if(typeof sPosition == 'object')
  478. fPositionElement(sPosition);
  479. else if(typeof sPosition == 'string' && sPosition == 'block')
  480. fPositionBlock();
  481. else
  482. fPositionSite();
  483. eSlider.slideDown();
  484. eSlider.data('data-control-btn', e);
  485. };
  486. if ('undefined' == typeof(sPosition))
  487. sPosition = 'block';
  488. if (eSlider.is(':visible')) {
  489. fClose();
  490. $(e).focus();
  491. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  492. $(window).off('resize.bx-sliding-menu');
  493. }
  494. else {
  495. bx_menu_slide_close_all_opened();
  496. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  497. $(window).off('resize.bx-sliding-menu');
  498. fOpen();
  499. eSlider.find('.bx-popup-content a:first').focus();
  500. eSlider.find('a').each(function () {
  501. $(this).off('click.bx-sliding-menu');
  502. $(this).on('click.bx-sliding-menu', function () {
  503. fClose();
  504. });
  505. });
  506. setTimeout(function () {
  507. var iWidthPrev = $(window).width();
  508. $(window).on('resize.bx-sliding-menu', function () {
  509. if ($(this).width() == iWidthPrev)
  510. return;
  511. iWidthPrev = $(this).width();
  512. bx_menu_slide_close_all_opened();
  513. });
  514. $(document).on('click.bx-sliding-menu touchend.bx-sliding-menu', function (event) {
  515. 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)
  516. event.stopPropagation();
  517. else
  518. bx_menu_slide_close_all_opened();
  519. });
  520. }, 10);
  521. }
  522. }
  523. /**
  524. * Close all opened sliding menus
  525. */
  526. function bx_menu_slide_close_all_opened () {
  527. $('.bx-sliding-menu:visible, .bx-sliding-menu-main:visible, .bx-popup-slide-wrapper:visible').each(function () {
  528. bx_menu_slide_inline('#' + this.id);
  529. });
  530. }
  531. /*
  532. * Note. oData.count_old and oData.count_new are also available and can be checked or used in notification popup.
  533. */
  534. function bx_menu_show_live_update(oData) {
  535. var sSelectorAddon = '.bx-menu-item-addon';
  536. //--- Update Child Menu Item
  537. if(oData.mi_child) {
  538. var oMenuItem = $('.bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item-' + oData.mi_child.menu_item);
  539. var oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  540. if(oMenuItemAddon.length > 0)
  541. oMenuItemAddon.html(oData.count_new);
  542. else
  543. oMenuItem.append(oData.code.replace('{count}', oData.count_new));
  544. //+++ Check for 0 value
  545. oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  546. if(parseInt(oData.count_new) > 0)
  547. oMenuItemAddon.show();
  548. else
  549. oMenuItemAddon.hide();
  550. }
  551. //--- Update Parent Menu Item
  552. if(oData.mi_parent) {
  553. var oMenuItem = $('.bx-menu-object-' + oData.mi_parent.menu_object + ' .bx-menu-item-' + oData.mi_parent.menu_item);
  554. var oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  555. var sMediaType = bx_check_mq();
  556. if(sMediaType == 'mobile')
  557. sMediaType = 'phone';
  558. var iSum = 0;
  559. $('.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() {
  560. iValue = parseInt($(this).html());
  561. if(iValue && iValue > 0)
  562. iSum += iValue;
  563. });
  564. if(oMenuItemAddon.length > 0)
  565. oMenuItemAddon.html(iSum);
  566. else
  567. oMenuItem.append(oData.code.replace('{count}', iSum));
  568. //+++ Check for 0 value
  569. oMenuItemAddon = oMenuItem.find(sSelectorAddon);
  570. if(iSum > 0)
  571. oMenuItemAddon.show();
  572. else
  573. oMenuItemAddon.hide();
  574. }
  575. }
  576. function bx_menu_show_more_less(oLink, sMenu, sSelectorParent) {
  577. if(!sSelectorParent)
  578. sSelectorParent = 'ul';
  579. var sClass = 'bx-mi-hidden';
  580. $(oLink).parents(sSelectorParent + ':first').find('.bx-mi-aux, .bx-psmi-show-more, .bx-psmi-show-less').toggleClass(sClass);
  581. $.get(sUrlRoot + 'menu.php', {
  582. o: sMenu,
  583. a: 'set_collapsed',
  584. v: $(oLink).parents(sSelectorParent + ':first').find('.bx-mi-aux').hasClass(sClass) ? 1 : 0
  585. });
  586. }
  587. function bx_menu_toggle_contents(oLink, sSelectorParent) {
  588. if(!sSelectorParent)
  589. sSelectorParent = '.bx-menu-contents';
  590. var sClass = 'bx-m-collapsed';
  591. var oParent = $(oLink).parents(sSelectorParent + ':first');
  592. oParent.toggleClass(sClass);
  593. oParent.siblings('.bx-menu-content').toggle();
  594. return false;
  595. }
  596. function bx_menu_toggle(oLink, sMenu, sMenuItem, sSelectorParent) {
  597. if(!sSelectorParent)
  598. sSelectorParent = 'li';
  599. var sClass = 'bx-mi-collapsed';
  600. var oParent = $(oLink).parents(sSelectorParent + ':first');
  601. oParent.toggleClass(sClass);
  602. $.get(sUrlRoot + 'menu.php', {
  603. o: sMenu,
  604. a: 'set_collapsed_submenu',
  605. i: sMenuItem,
  606. v: oParent.hasClass(sClass) ? 1 : 0
  607. });
  608. return false;
  609. }
  610. function bx_menu_followings_load_more(oLink, sMenu, sContextModule, iStart, iPerPage) {
  611. var oLoadingParent = $(oLink).length ? $(oLink).parents('.bx-menu-item:first') : $('body');
  612. bx_loading(oLoadingParent, true);
  613. $.get(sUrlRoot + 'menu.php', {
  614. o: sMenu,
  615. a: 'load_more',
  616. v: sContextModule,
  617. start: iStart,
  618. per_page: iPerPage
  619. }, function(oData) {
  620. bx_loading(oLoadingParent, false);
  621. if(oData && oData.content != undefined)
  622. $(oLink).parents('.bx-menu-subitem:first').replaceWith(oData.content);
  623. }, 'json');
  624. }
  625. /**
  626. * Set ACL level for specified profile
  627. * @param iProfileId - profile id to set acl level for
  628. * @param iAclLevel - acl level id to assign to a given rofile
  629. */
  630. function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
  631. var bBulk = !$.isNumeric(iProfileId);
  632. var iAclCard = !bBulk && $('#sys-acl-profile-' + iProfileId).length > 0 ? 1 : 0;
  633. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  634. if(bLoading)
  635. bx_loading($(mixedLoadingElement), true);
  636. $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', profile_id: iProfileId, level_id: iAclLevel, card:iAclCard}, function(oData) {
  637. bx_on_set_acl_level(oData, mixedLoadingElement);
  638. }, 'json');
  639. }
  640. /**
  641. * Reset ACL level for specified profile to Standard.
  642. * @param iProfileId - profile id to reset acl level for
  643. */
  644. function bx_reset_acl_level (iProfileId, mixedLoadingElement) {
  645. var bBulk = !$.isNumeric(iProfileId);
  646. var iAclCard = !bBulk && $('#sys-acl-profile-' + iProfileId).length > 0 ? 1 : 0;
  647. var fPerform = function() {
  648. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  649. if(bLoading)
  650. bx_loading($(mixedLoadingElement), true);
  651. $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', profile_id: iProfileId, level_id: 3, card: iAclCard}, function(oData) {
  652. bx_on_set_acl_level(oData, mixedLoadingElement);
  653. }, 'json');
  654. };
  655. bx_confirm(_t('_Are_you_sure'), fPerform);
  656. }
  657. function bx_on_set_acl_level(oData, oLoadingElement) {
  658. if(typeof(oLoadingElement) != 'undefined')
  659. bx_loading($(oLoadingElement), false);
  660. if(oData.msg != undefined && oData.msg.length) {
  661. bx_alert(oData.msg);
  662. return;
  663. }
  664. if($(oLoadingElement).hasClass('bx-popup-applied'))
  665. $(oLoadingElement).dolPopupHide().remove();
  666. if(typeof(oData.card) == 'object')
  667. for(var iField in oData.card) {
  668. var oCard = $(oData.card[iField]);
  669. $('#' + oCard.attr('id')).replaceWith(oCard.bxTime());
  670. }
  671. }
  672. /**
  673. * Set badge for specified content
  674. * @param sModule - current module for content
  675. * @param iContentId - content id to set badge for
  676. * @param iBadgeId - badge id to assign to a given content
  677. */
  678. function bx_set_badge (sModule, iContentId, iBadgeId, mixedLoadingElement) {
  679. var bLoading = typeof(mixedLoadingElement) != 'undefined';
  680. if(bLoading)
  681. bx_loading($(mixedLoadingElement), true);
  682. $.post(sUrlRoot + 'menu.php', {o:'sys_set_badges', module: sModule, content_id: iContentId, badge_id: iBadgeId}, function(oData) {
  683. if(bLoading)
  684. bx_loading($(mixedLoadingElement), false);
  685. if(oData.msg != undefined && oData.msg.length) {
  686. bx_alert(oData.msg);
  687. return;
  688. }
  689. if($(mixedLoadingElement).hasClass('bx-popup-applied'))
  690. $(mixedLoadingElement).dolPopupHide().remove();
  691. if(typeof(oData.card) == 'object')
  692. for(var iField in oData.card) {
  693. var oCard = $(oData.card[iField]);
  694. $('#' + oCard.attr('id')).replaceWith(oCard);
  695. }
  696. $('.bx-base-bages-container').html(oData.html);
  697. }, 'json');
  698. }
  699. function bx_get_notes(oSource, sModule, iContentId, oOptions, oVars) {
  700. var oOptions = oOptions || {};
  701. var oVars = oVars || {};
  702. $.post(
  703. sUrlRoot + 'modules/?r=' + sModule + '/get_notes/',
  704. $.extend({content_id: iContentId}, oVars),
  705. function(oData) {
  706. if(oData && oData.popup != undefined) {
  707. if(typeof(oData.popup) == 'string')
  708. oData.popup = {html: oData.popup, options: {}};
  709. oData.popup.options = $.extend({}, $.fn.dolPopupDefaultOptions, oData.popup.options, {
  710. id: sModule + '_notes_' + iContentId,
  711. closeOnOuterClick: false,
  712. removeOnClose: true,
  713. onBeforeShow: function(oPopup) {
  714. $(oPopup).find('.bx-popup-element-close').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
  715. }
  716. }, oOptions);
  717. }
  718. processJsonData(oData);
  719. },
  720. 'json'
  721. );
  722. }
  723. function bx_approve(oSource, sModule, iContentId, oOptions, oVars) {
  724. var oOptions = oOptions || {};
  725. var oVars = oVars || {};
  726. var fPopupInit = function(oData) {
  727. if(oData && oData.popup != undefined) {
  728. if(typeof(oData.popup) == 'string')
  729. oData.popup = {html: oData.popup, options: {}};
  730. oData.popup.options = $.extend({}, $.fn.dolPopupDefaultOptions, oData.popup.options, {
  731. id: sModule + '_approve_' + iContentId,
  732. closeOnOuterClick: false,
  733. removeOnClose: true,
  734. onBeforeShow: function(oPopup) {
  735. $(oPopup).find('.bx-popup-element-close').removeClass('bx-def-media-desktop-hide bx-def-media-tablet-hide');
  736. var oForm = $(oPopup).find('form');
  737. if(oForm.length > 0) {
  738. oForm.ajaxForm({
  739. dataType: 'json',
  740. beforeSubmit: function(aFormData, oForm, oOptions) {
  741. bx_loading(oForm, true);
  742. },
  743. success: function(oData) {
  744. $('.bx-popup-applied:visible').dolPopupHide();
  745. fPopupInit(oData);
  746. processJsonData(oData);
  747. }
  748. });
  749. }
  750. }
  751. }, oOptions);
  752. }
  753. };
  754. $.post(
  755. sUrlRoot + 'modules/?r=' + sModule + '/approve/',
  756. $.extend({content_id: iContentId}, oVars),
  757. function(oData) {
  758. fPopupInit(oData);
  759. processJsonData(oData);
  760. },
  761. 'json'
  762. );
  763. }
  764. function bx_showcase_init(sSelWrapper, sSelItem) {
  765. var oWrapper = $(sSelWrapper);
  766. if(oWrapper.closest('.bx-popup-wrapper').length != 0)
  767. return;
  768. oWrapper.each(function() {
  769. var sClassEnabled = 'bx-sc-enabled';
  770. var oShowcase = $(this);
  771. var oCells = oShowcase.find(sSelItem);
  772. if(oCells.width() * oCells.length <= oShowcase.parent().width()) {
  773. if(oShowcase.hasClass('flickity-enabled'))
  774. oShowcase.flickity('destroy').removeClass(sClassEnabled);
  775. return;
  776. }
  777. if(oShowcase.hasClass('flickity-enabled'))
  778. return;
  779. var oShowcaseOptions = {
  780. cellSelector: sSelItem,
  781. cellAlign: 'left',
  782. imagesLoaded: true,
  783. wrapAround: true,
  784. pageDots: false
  785. };
  786. var iGroupCells = oShowcase.attr('bx-sc-group-cells');
  787. if(iGroupCells != undefined)
  788. oShowcaseOptions.groupCells = parseInt(iGroupCells);
  789. oShowcase.on('ready.flickity', function() {
  790. $(this).addClass(sClassEnabled);
  791. }).flickity(oShowcaseOptions);
  792. });
  793. }
  794. function validateLoginForm(eForm) {
  795. return true;
  796. }
  797. /**
  798. * convert <time> tags to human readable format
  799. * @param sLang - use sLang localization
  800. * @param isAutoupdate - for internal usage only
  801. */
  802. function bx_time(sLang, isAutoupdate, sRootSel) {
  803. if ('undefined' == typeof(sRootSel))
  804. sRootSel = 'body';
  805. var iAutoupdate = 22*60*60; // autoupdate time in realtime if less than 22 hours
  806. var sSel = 'time';
  807. if (typeof(sLang) != 'undefined')
  808. glBxTimeLang = sLang;
  809. else if(typeof(glBxTimeLang) != 'undefined')
  810. sLang = glBxTimeLang;
  811. if(!sLang)
  812. return;
  813. if ('undefined' != typeof(isAutoupdate) && isAutoupdate)
  814. sSel += '.bx-time-autoupdate';
  815. $(sRootSel).find(sSel).each(function () {
  816. var s;
  817. var sTime = $(this).attr('datetime');
  818. var iSecondsDiff = moment(sTime).unix() - moment().unix();
  819. if (iSecondsDiff < 0)
  820. iSecondsDiff = -iSecondsDiff;
  821. if (iSecondsDiff < $(this).attr('data-bx-autoformat'))
  822. s = moment(sTime).locale(sLang).fromNow(); // 'time ago' format
  823. else if (1 == $(this).attr('data-bx-utc'))
  824. s = moment.utc(sTime).locale(sLang).format($(this).attr('data-bx-format'));
  825. else
  826. s = moment(sTime).locale(sLang).format($(this).attr('data-bx-format'));
  827. if (iSecondsDiff < iAutoupdate)
  828. $(this).addClass('bx-time-autoupdate');
  829. else
  830. $(this).removeClass('bx-time-autoupdate');
  831. $(this).html(s);
  832. });
  833. if ($('time.bx-time-autoupdate').size()) {
  834. setTimeout(function () {
  835. bx_time(sLang, true);
  836. }, 20000);
  837. }
  838. }
  839. (function($) {
  840. $.fn.bxTime = function() {
  841. bx_time(undefined, undefined, this);
  842. return this;
  843. };
  844. /**
  845. * process HTML which was added dynamicly on the page
  846. */
  847. $.fn.bxProcessHtml = function (oCallback) {
  848. var eElement = $(this);
  849. if ('undefined' !== typeof(eElement)) {
  850. // process js time
  851. eElement.bxTime();
  852. bx_process_links();
  853. // process web forms
  854. if ($.isFunction($.fn.addWebForms))
  855. eElement.addWebForms();
  856. // process animating icons
  857. bx_activate_anim_icons();
  858. // process syntax hightlighing
  859. if ('undefined' !== typeof(Prism) && eElement.size())
  860. Prism.highlightAllUnder(eElement[0]);
  861. // process links
  862. bx_redirect_for_external_links(eElement);
  863. // flickity update
  864. setTimeout(function () {
  865. const oFlickity = eElement.find('.flickity-enabled');
  866. if (oFlickity.length)
  867. oFlickity.flickity('resize');
  868. }, 250);
  869. }
  870. if ('undefined' !== typeof(oCallback)) {
  871. oCallback(eElement);
  872. }
  873. if (typeof glOnProcessHtml !== 'undefined' && glOnProcessHtml instanceof Array) {
  874. for (var i = 0; i < glOnProcessHtml.length; i++)
  875. if (typeof glOnProcessHtml[i] === "function")
  876. glOnProcessHtml[i](this);
  877. }
  878. return this;
  879. };
  880. $.fn.bxCheckOverflowHeight = function(sClass, onFind) {
  881. if(!sClass)
  882. sClass = 'bx-overflow';
  883. return this.each(function() {
  884. var oElement = $(this);
  885. if(oElement.hasClass(sClass) || oElement.css('overflow') != 'hidden')
  886. return;
  887. if(oElement.find('img').length > 0) {
  888. var oImg = oElement.find('img:first').get(0);
  889. const oImgCopy = new Image();
  890. oImgCopy.src = oImg.src;
  891. oImgCopy.onload = function() {
  892. var iHeightParent = oElement.height();
  893. var iHeightImg = oImg.clientHeight;
  894. var iOffsetTopImg = oImg.offsetTop;
  895. if(iOffsetTopImg < iHeightParent && iOffsetTopImg + iHeightImg > iHeightParent)
  896. oElement.css('max-height', (iOffsetTopImg + iHeightImg + 50) + 'px');
  897. if(oElement.prop('scrollHeight') <= Math.ceil(oElement.height()))
  898. return;
  899. oElement.addClass(sClass);
  900. if(typeof onFind === 'function')
  901. onFind(oElement);
  902. }
  903. }
  904. else {
  905. if(oElement.prop('scrollHeight') <= Math.ceil(oElement.height()))
  906. return;
  907. oElement.addClass(sClass);
  908. if(typeof onFind === 'function')
  909. onFind(oElement);
  910. }
  911. });
  912. };
  913. $.fn.bxConvertEmbeds = function() {
  914. return this.each(function() {
  915. $(this).find(".bx-embed-link").each(function() {
  916. var oItem = $(this);
  917. oItem.html(oItem.attr('source'));
  918. $.getJSON(sUrlRoot + '/embed.php?', {a: 'get_link', l: oItem.attr('source')}, function(oData) {
  919. oItem.html(oData.code)
  920. if(oItem.find('a').length > 0)
  921. bx_embed_link(oItem.find('a')[0]);
  922. });
  923. });
  924. });
  925. };
  926. } (jQuery));
  927. /**
  928. * Perform connections AJAX request.
  929. * In case of error - it shows js alert with error message.
  930. * In case of success - the page is reloaded.
  931. *
  932. * @param sObj - connections object
  933. * @param sAction - 'add', 'remove' or 'reject'
  934. * @param iContentId - content id, initiator is always current logged in user
  935. * @param bConfirm - show confirmation dialog
  936. */
  937. function bx_conn_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  938. var fPerform = function() {
  939. var aParams = {
  940. obj: sObj,
  941. act: sAction,
  942. id: iContentId
  943. };
  944. var fCallback = function (data) {
  945. bx_loading_btn(e, 0);
  946. if ('object' != typeof(data))
  947. return;
  948. if (data.err) {
  949. bx_alert(data.msg);
  950. } else {
  951. if ('function' == typeof(fOnComplete))
  952. fOnComplete(data, e);
  953. else if (!loadDynamicBlockAuto(e))
  954. location.reload();
  955. else
  956. $('#bx-popup-ajax-wrapper-bx_persons_view_actions_more').remove();
  957. }
  958. };
  959. bx_loading_btn(e, 1);
  960. $.ajax({
  961. dataType: 'json',
  962. url: sUrlRoot + 'conn.php',
  963. data: aParams,
  964. type: 'POST',
  965. success: fCallback
  966. });
  967. };
  968. if (typeof(bConfirm) != 'undefined' && bConfirm)
  969. bx_confirm(_t('_Are_you_sure'), fPerform);
  970. else
  971. fPerform();
  972. }
  973. /**
  974. * Perform recommendations AJAX request.
  975. * In case of error - it shows js alert with error message.
  976. * In case of success - the page is reloaded.
  977. *
  978. * @param sObj - recommendation object
  979. * @param sAction - 'ignore'
  980. * @param iContentId - content id, initiator is always current logged in user
  981. * @param bConfirm - show confirmation dialog
  982. */
  983. function bx_recommendation_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  984. var fPerform = function() {
  985. var aParams = {
  986. obj: sObj,
  987. act: sAction,
  988. id: iContentId
  989. };
  990. var fCallback = function (data) {
  991. bx_loading_btn(e, 0);
  992. if ('object' != typeof(data))
  993. return;
  994. if (data.msg)
  995. bx_alert(data.msg);
  996. else {
  997. if ('function' == typeof(fOnComplete))
  998. fOnComplete(data, e);
  999. else if (!loadDynamicBlockAuto(e))
  1000. location.reload();
  1001. }
  1002. };
  1003. bx_loading_btn(e, 1);
  1004. $.ajax({
  1005. dataType: 'json',
  1006. url: sUrlRoot + 'recommendation.php',
  1007. data: aParams,
  1008. type: 'POST',
  1009. success: fCallback
  1010. });
  1011. };
  1012. if (typeof(bConfirm) != 'undefined' && bConfirm)
  1013. bx_confirm(_t('_Are_you_sure'), fPerform);
  1014. else
  1015. fPerform();
  1016. }
  1017. function bx_append_url_params (sUrl, mixedParams) {
  1018. var sParams = sUrl.indexOf('?') == -1 ? '?' : '&';
  1019. var sHash = '';
  1020. if(sUrl.indexOf('#') != -1) {
  1021. var oUrl = new URL(sUrl);
  1022. if(oUrl.hash.length > 0) {
  1023. sHash = oUrl.hash;
  1024. sUrl = sUrl.replace(sHash, '');
  1025. }
  1026. else
  1027. sUrl = sUrl.replace('#', '');
  1028. }
  1029. if(mixedParams instanceof Array) {
  1030. for(var i in mixedParams)
  1031. sParams += i + '=' + mixedParams[i] + '&';
  1032. sParams = sParams.substr(0, sParams.length-1);
  1033. }
  1034. else if(mixedParams instanceof Object) {
  1035. $.each(mixedParams, function(sKey, sValue) {
  1036. sParams += sKey + '=' + sValue + '&';
  1037. });
  1038. sParams = sParams.substr(0, sParams.length-1);
  1039. }
  1040. else
  1041. sParams += mixedParams;
  1042. return sUrl + sParams + sHash;
  1043. }
  1044. function bx_search_extnded_sort(obj, url){
  1045. location.href = url + '&sort=' +$(obj).val();
  1046. }
  1047. function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, iMinLen, onComplete, onCancel) {
  1048. var oForm = $(e.target).parents(sFormSel + ':first');
  1049. if ('undefined' != typeof(e)) {
  1050. if(e.keyCode == 13) {
  1051. oForm.find('input[name=live_search]').val(0);
  1052. oForm.submit();
  1053. return false;
  1054. }
  1055. if(e.keyCode == 27) {
  1056. if(typeof onCancel === 'function')
  1057. onCancel(oForm);
  1058. }
  1059. }
  1060. iMinLen = typeof(iMinLen) != 'undefined' ? parseInt(iMinLen) : 0;
  1061. if(iMinLen > 0 && iMinLen > (oForm.find('input[name=keyword]').val().length + 1))
  1062. return true;
  1063. if ('undefined' != typeof(glBxSearchTimeoutHandler) && glBxSearchTimeoutHandler)
  1064. clearTimeout(glBxSearchTimeoutHandler);
  1065. glBxSearchTimeoutHandler = setTimeout(function () {
  1066. bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, onComplete);
  1067. }, 500);
  1068. return true;
  1069. }
  1070. function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, onComplete) {
  1071. if ('undefined' == typeof(sLoadingContSel))
  1072. sLoadingContSel = sResultsContSel;
  1073. if ('undefined' == typeof(bSortResults))
  1074. bSortResults = false;
  1075. var sQuery = $('input', sFormSel).serialize();
  1076. bx_loading($(sLoadingContSel), true);
  1077. $.post(sUrlRoot + 'searchKeywordContent.php', sQuery, function(data) {
  1078. bx_loading($(sLoadingContSel), false);
  1079. if(!data)
  1080. return;
  1081. if (bSortResults) {
  1082. var sAsk = $(data).filter(".bx-btn.sys-agents-ask");
  1083. var aSortedUnits = $(data).find(".bx-def-unit-live-search").toArray().sort(function (a, b) {
  1084. return b.getAttribute('data-ts') - a.getAttribute('data-ts');
  1085. });
  1086. data = '';
  1087. if(sAsk.length)
  1088. data += sAsk.get(0).outerHTML;
  1089. $.each(aSortedUnits.slice(0, n), function (i, e) {
  1090. data += e.outerHTML;
  1091. });
  1092. }
  1093. var oContainer = $(sResultsContSel);
  1094. oContainer.html(data).bxProcessHtml();
  1095. if(typeof onComplete === 'function')
  1096. onComplete(oContainer, data);
  1097. });
  1098. return false;
  1099. }
  1100. function on_filter_apply(e, sInputId, sFilterName)
  1101. {
  1102. var oRegExp = new RegExp("[&]{0,1}" + sFilterName + "=.*");
  1103. var s = ('' + document.location).replace(oRegExp, ''); // remove filter
  1104. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  1105. if (e.checked && $('#' + sInputId).val().length > 2)
  1106. s += (-1 == s.indexOf('?') ? '?' : '&') + sFilterName + '=' + $('#' + sInputId).val(); // append filter
  1107. document.location = s;
  1108. }
  1109. function on_filter_key_up (e, sCheckboxId)
  1110. {
  1111. if (13 == e.keyCode) {
  1112. $('#' + sCheckboxId).click();
  1113. return false;
  1114. }
  1115. else {
  1116. $('#' + sCheckboxId).removeAttr('checked');
  1117. return true;
  1118. }
  1119. }
  1120. function on_copyright_click()
  1121. {
  1122. oDate = new Date();
  1123. $(document).dolPopupAlert({
  1124. message: _t('_copyright', oDate.getFullYear())
  1125. });
  1126. }
  1127. function bx_activate_anim_icons(sColor)
  1128. {
  1129. if(typeof(sColor) != 'undefined')
  1130. glBxAnimIconColor = sColor;
  1131. else if(typeof(glBxAnimIconColor) != 'undefined')
  1132. sColor = glBxAnimIconColor;
  1133. if(!sColor)
  1134. return;
  1135. $('.sys-icon-a').not('.marka').each(function () {
  1136. var e = $(this);
  1137. var m = new Marka(e.get(0)), r = e.attr('data-rotate'), c = e.attr('data-color');
  1138. m.set(e.attr('data-icon')).rotate(r ? r : 'down').color(c ? c : sColor);
  1139. });
  1140. }
  1141. function bx_get_param(s) {
  1142. if (!window.aDolOptions || !aDolOptions[s])
  1143. return false;
  1144. return aDolOptions[s];
  1145. }
  1146. function bx_autocomplete_fields(iId, sUrl, sName, bShowImg, bOnlyOnce, onSelect){
  1147. if (!$('#' + iId).hasClass('bx-form-input-autotoken'))
  1148. $('#' + iId).addClass('bx-form-input-autotoken');
  1149. $('#' + iId + ' input[type=text]').autocomplete({
  1150. source: sUrl,
  1151. focus: function(e, ui ) {
  1152. $(this).val(ui.item.label);
  1153. e.preventDefault();
  1154. },
  1155. select: function(e, ui) {
  1156. $(this).val(ui.item.label);
  1157. $(this).trigger('superselect', ui.item);
  1158. if (typeof onSelect === 'function')
  1159. onSelect(ui);
  1160. e.preventDefault();
  1161. }
  1162. });
  1163. if ($('#' + iId + ' .val').length > 0 && bOnlyOnce)
  1164. $('#' + iId + ' input[type=text]').hide();
  1165. $('#' + iId + ' input[type=text]').on('superselect', function(e, item) {
  1166. $(this).hide();
  1167. if ('undefined' != typeof(item)) {
  1168. var sImage = '';
  1169. if(bShowImg && item.unit != undefined)
  1170. sImage = item.unit;
  1171. else if(bShowImg && item.thumb != undefined)
  1172. sImage = '<img class="bx-def-thumb bx-def-icon-size bx-def-margin-sec-right" src="' + item.thumb + '">';
  1173. $(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>');
  1174. }
  1175. if (!bOnlyOnce)
  1176. {
  1177. fAutoShrinkInput();
  1178. $(this).show();
  1179. this.value = '';
  1180. }
  1181. }).on('keydown', function(e) {
  1182. // if: comma,enter (delimit more keyCodes with | pipe)
  1183. if (/(13)/.test(e.which))
  1184. e.preventDefault();
  1185. });
  1186. $('#' + iId).on('click', 'b', function() {
  1187. $(this).remove();
  1188. if (bOnlyOnce)
  1189. $('#' + iId + ' input[type=text]').val('').show();
  1190. else
  1191. fAutoShrinkInput();
  1192. });
  1193. fAutoShrinkInput = function () {
  1194. var iWidthCont = $('#' + iId + '.bx-form-input-autotoken').innerWidth();
  1195. var iWidthExisting = 0;
  1196. $('#' + iId + '.bx-form-input-autotoken b').each(function () {
  1197. iWidthExisting += $(this).outerWidth(true);
  1198. });
  1199. $('#' + iId + '.bx-form-input-autotoken input').innerWidth(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
  1200. };
  1201. if (!bOnlyOnce)
  1202. fAutoShrinkInput();
  1203. else
  1204. $('#' + iId + '.bx-form-input-autotoken input').outerWidth('100%');
  1205. };
  1206. function bx_alert(sMessage, fOnClickOk, oParams)
  1207. {
  1208. $(document).dolPopupAlert({
  1209. message: sMessage,
  1210. onClickOk: fOnClickOk,
  1211. params: oParams
  1212. });
  1213. }
  1214. function bx_confirm(sMessage, fOnClickYes, fOnClickNo, oParams)
  1215. {
  1216. $(document).dolPopupConfirm({
  1217. message: sMessage,
  1218. onClickYes: fOnClickYes,
  1219. onClickNo: fOnClickNo,
  1220. params: oParams
  1221. });
  1222. }
  1223. function bx_prompt(sMessage, sValue, fOnClickOk, fOnClickCancel, oParams)
  1224. {
  1225. $(document).dolPopupPrompt({
  1226. message: sMessage,
  1227. value: sValue,
  1228. onClickOk: fOnClickOk,
  1229. onClickCancel: fOnClickCancel,
  1230. params: oParams
  1231. });
  1232. }
  1233. function bx_is_color_scheme_dark()
  1234. {
  1235. return localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);
  1236. }
  1237. function bx_get_color_scheme()
  1238. {
  1239. return 'theme' in localStorage ? localStorage.theme : 'auto';
  1240. }
  1241. function bx_set_color_scheme(iCode)
  1242. {
  1243. switch(iCode) {
  1244. case 0:
  1245. localStorage.removeItem('theme');
  1246. break;
  1247. case 1:
  1248. localStorage.theme = 'sun'
  1249. break;
  1250. case 2:
  1251. localStorage.theme = 'dark'
  1252. break;
  1253. }
  1254. //--- Change scheme.
  1255. bx_set_color_scheme_html();
  1256. //--- Notify global handlers.
  1257. if(typeof glOnColorSchemeChange === 'undefined' || !(glOnColorSchemeChange instanceof Array))
  1258. return;
  1259. if(typeof iCode === 'undefined' || !iCode)
  1260. iCode = this.isColorSchemeDark() ? 2 : 1;
  1261. for(var i = 0; i < glOnColorSchemeChange.length; i++)
  1262. if(typeof glOnColorSchemeChange[i] === 'function')
  1263. glOnColorSchemeChange[i](iCode);
  1264. }
  1265. function bx_set_color_scheme_html()
  1266. {
  1267. if(bx_is_color_scheme_dark())
  1268. $('html').addClass('dark')
  1269. else
  1270. $('html').removeClass('dark')
  1271. }
  1272. function bx_is_mouse()
  1273. {
  1274. return matchMedia('(pointer:fine)').matches;
  1275. }
  1276. function bx_is_touch_device()
  1277. {
  1278. return (('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0));
  1279. }
  1280. /**
  1281. * Check if mobile or desktop device.
  1282. */
  1283. function bx_check_mq()
  1284. {
  1285. if (typeof glOnCheckMq === 'function') {
  1286. return glOnCheckMq();
  1287. }
  1288. return window.getComputedStyle(document.querySelector('body'), '::before').getPropertyValue('content').replace(/'/g, "").replace(/"/g, "");
  1289. }
  1290. /**
  1291. * This function loads the passed list of CSS files. In case when this function is called for dynamic loading
  1292. * of the same file but many times it allows to avoid multiply loadings of the same file.
  1293. */
  1294. function bx_get_style(mixedUrl)
  1295. {
  1296. if(typeof(mixedUrl) === 'string')
  1297. mixedUrl = new Array(mixedUrl);
  1298. for(let i = 0; i < mixedUrl.length; i++) {
  1299. if(mixedUrl[i] === undefined || !mixedUrl[i].length || $("link[href = '" + mixedUrl[i] + "']").length > 0)
  1300. continue;
  1301. $("head").append($("<link rel='stylesheet' href='" + mixedUrl[i] + "' type='text/css' />"));
  1302. }
  1303. }
  1304. /**
  1305. * This function loads the passed list of js files and executes callback function when the all files are loaded.
  1306. * In case when this function is called for dynamic loading of the same file but many times (like Plyr video init)
  1307. * it allows to avoid multiply loadings of the same file.
  1308. */
  1309. function bx_get_scripts (aFiles, fCallback)
  1310. {
  1311. let iCounter = 0;
  1312. const
  1313. iLength = aFiles.length,
  1314. fHandler = function() {
  1315. if (iCounter++ >= (iLength-1) && typeof(fCallback) === 'function')
  1316. fCallback();
  1317. else
  1318. fExecute(aFiles[iCounter]);
  1319. },
  1320. // Check if js file is not loaded yet then start to load it and returns Promise.
  1321. // All functions which try to load the same file will wait for loading of the file
  1322. // and then continue to work
  1323. fExecute = function(sFile) {
  1324. if ('undefined' === typeof(glBxLoadedScripts[sFile]))
  1325. glBxLoadedScripts[sFile] = { complete : $.bxGetCachedScript(sFile).done(fHandler) };
  1326. else
  1327. glBxLoadedScripts[sFile].complete.then(fHandler);
  1328. };
  1329. if ('undefined' === typeof(glBxLoadedScripts))
  1330. glBxLoadedScripts = {};
  1331. fExecute(aFiles[iCounter]);
  1332. }
  1333. jQuery.bxGetCachedScript = function(sUrl, oOptions)
  1334. {
  1335. oOptions = $.extend(oOptions || {}, {
  1336. dataType: "script",
  1337. cache: true,
  1338. url: sUrl
  1339. });
  1340. return jQuery.ajax(oOptions);
  1341. };
  1342. function bx_is_selector_in_stylesheet(sSel)
  1343. {
  1344. var a = [];
  1345. var aSs = document.styleSheets;
  1346. for (var sSheet = 0; sSheet < aSs.length; sSheet++) {
  1347. var ruleList = document.styleSheets[sSheet].cssRules;
  1348. for (var rule = 0; rule < ruleList.length; rule++)
  1349. a.push(ruleList[rule].selectorText);
  1350. }
  1351. return -1 !== a.indexOf(sSel);
  1352. }
  1353. function bx_copy_to_clipboard(s, onSuccess, onFail)
  1354. {
  1355. if ("undefined" === typeof(onSuccess))
  1356. onSuccess = function (){};
  1357. if ("undefined" === typeof(onFail))
  1358. onFail = function (){};
  1359. const oClip = navigator.clipboard;
  1360. if ("undefined" !== typeof(oClip)) {
  1361. navigator.clipboard.writeText(s).then(onSuccess, onFail);
  1362. }
  1363. else {
  1364. if (document.execCommand) {
  1365. const el = document.createElement("input");
  1366. el.value = s;
  1367. document.body.append(el);
  1368. el.select();
  1369. el.setSelectionRange(0, s.length);
  1370. if (document.execCommand("copy")) {
  1371. onSuccess();
  1372. }
  1373. el.remove();
  1374. }
  1375. else {
  1376. onFail();
  1377. }
  1378. }
  1379. }
  1380. function bx_regexp_escape(s)
  1381. {
  1382. return s
  1383. .replace(/[|\\{}()[\]^$+*?.]/mg, '\\$&')
  1384. .replace(/-/mg, '\\x2d');
  1385. }
  1386. function bx_get_regexp(sType)
  1387. {
  1388. var o = {
  1389. tag:"(<([^>]+bx-tag[^>]+)>)",
  1390. mention: "(<([^>]+bx-mention-link[^>]+)>)",
  1391. url: "(([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[\\-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9\\.\\-]+|(?:www\\.|[\\-;:&=\\+\\$,\\w]+@)[A-Za-z0-9\\.\\-]+)((?:\\/[\\+~%#\\/\\.\\w\\-_!\\(\\)]*)?\\??(?:[\\-\\+=&;%@\\.\\w_]*)#?(?:[\\.\\!\\/\\w]*))?"
  1392. };
  1393. return o[sType];
  1394. }
  1395. function bx_process_links()
  1396. {
  1397. // process links in container
  1398. $('.bx-lnk-cnt .bx-lnk-src:not(.bx-inited)').each(function() {
  1399. $(this).addClass('bx-inited');
  1400. var sUrl = $(this).prop('href');
  1401. $(this).parents('.bx-lnk-cnt').first().addClass('cursor-pointer').click(function(oEvent){
  1402. 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){
  1403. location.href = sUrl;
  1404. }
  1405. });
  1406. });
  1407. }
  1408. function bx_redirect_for_external_links (e)
  1409. {
  1410. if ('undefined' === typeof(aDolOptions.sys_confirmation_before_redirect) || 'on' !== aDolOptions.sys_confirmation_before_redirect)
  1411. return;
  1412. var aExclude = ['javascript:', 'about:', sUrlRoot];
  1413. var sPattern = 'a';
  1414. $(aExclude).each(function () {
  1415. sPattern += ':not([href^="' + this + '"])';
  1416. });
  1417. if ('undefined' !== typeof(aDolOptions.sys_storage_s3_endpoint) && aDolOptions.sys_storage_s3_endpoint.length)
  1418. sPattern += ':not([href^="https://' + aDolOptions.sys_storage_s3_endpoint + '"])';
  1419. sPattern += ":is([href^='http://'],[href^='https://'])";
  1420. if ('undefined' === typeof(e))
  1421. e = $('document');
  1422. e.find(sPattern).each(function() {
  1423. if ($(this).attr('href').match(/s3\.amazonaws\.com/))
  1424. return;
  1425. $(this).on('contextmenu', function(e) {
  1426. e.preventDefault();
  1427. });
  1428. $(this).on('click', function() {
  1429. var $this = $(this);
  1430. bx_redirect_for_external_links_open($this.attr('href'));
  1431. return false;
  1432. });
  1433. });
  1434. }
  1435. function bx_redirect_for_external_links_open (sHref)
  1436. {
  1437. //bx_confirm(_t('_sys_redirect_confirmation', sHref).replace(/\&quot;/g, ''), function () {
  1438. // window.open(sHref, '_blank').focus();
  1439. //});
  1440. window.open(sUrlRoot + 'page.php?i=redirect&url=' + encodeURIComponent(sHref), '_blank').focus();
  1441. }
  1442. function bx_agents_action(oElement, sTool, sAction, aParams)
  1443. {
  1444. var oDate = new Date();
  1445. var sQueryUrl = sUrlRoot + 'agents.php';
  1446. var oQueryParams = jQuery.extend({}, {t: sTool, a: sAction, _t:oDate.getTime()}, aParams != undefined ? aParams : {});
  1447. bx_loading_btn(oElement, true);
  1448. jQuery.post (
  1449. sQueryUrl,
  1450. oQueryParams,
  1451. function(oData) {
  1452. bx_loading_btn(oElement, false);
  1453. processJsonData(oData);
  1454. },
  1455. 'json'
  1456. );
  1457. }
  1458. function bx_get_focusable(oContext = 'document')
  1459. {
  1460. return Array.from(oContext.querySelectorAll('button, [href], input:not([type="hidden"]), textarea, select, [tabindex]:not(.bx-focus-trap, [tabindex="-1"])')).filter(function(oElement) {
  1461. return !$(oElement).closest(':hidden').length;
  1462. });
  1463. }
  1464. function bx_clicked_stack_register()
  1465. {
  1466. const iStackMaxLenth = 3;
  1467. $('a,button').filter(function(iIndex, oElement) {
  1468. return !$(oElement).closest('.bx-sidebar').length;
  1469. }).on('click', function() {
  1470. if(typeof window.glClickedStack === 'undefined')
  1471. window.glClickedStack = [];
  1472. window.glClickedStack.push(this);
  1473. if(window.glClickedStack && window.glClickedStack.length > iStackMaxLenth)
  1474. window.glClickedStack = window.glClickedStack.slice(-iStackMaxLenth);
  1475. });
  1476. }
  1477. function bx_clicked_stack_lenth()
  1478. {
  1479. return window.glClickedStack ? window.glClickedStack.length : 0;
  1480. }
  1481. function bx_clicked_stack_get()
  1482. {
  1483. const iLenth = bx_clicked_stack_lenth();
  1484. return iLenth > 0 ? window.glClickedStack[iLenth - 1] : false;
  1485. }
  1486. function bx_clicked_stack_pop()
  1487. {
  1488. return window.glClickedStack && window.glClickedStack.length > 0 ? window.glClickedStack.pop() : false;
  1489. }
  1490. /** @} */