1/** 2 * JS utilities 3 * 4 * @package ThemeREX Addons 5 * @since v1.0 6 */ 7 8/* global jQuery, TRX_ADDONS_STORAGE */ 9 10(function() { 11 "use strict"; 12 13 var $window = jQuery( window ), 14 $document = jQuery( document ), 15 $html_dom = document.querySelector('html'), 16 $adminbar = jQuery( '#wpadminbar' ), 17 $body = jQuery( 'body' ); 18 19 20 /* Dev shorthands 21 ---------------------------------------------------------------- */ 22 23 window.dcl === undefined && ( window.dcl = function(s) { console.log(s); } ); 24 window.dcs === undefined && ( window.dcs = function() { console.trace(); } ); 25 window.dcts === undefined && ( window.dcts = function( name ) { console.time( name ? name : 'timer' ); } ); 26 window.dctl === undefined && ( window.dctl = function( name ) { console.timeLog( name ? name : 'timer' ); } ); 27 window.dcte === undefined && ( window.dcte = function( name ) { console.timeEnd( name ? name : 'timer' ); } ); 28 29 30 /* Cookies manipulations 31 ---------------------------------------------------------------- */ 32 33 window.trx_addons_get_cookie = function(name) { 34 var defa = arguments[1] !== undefined ? arguments[1] : null; 35 var start = document.cookie.indexOf(name + '='); 36 var len = start + name.length + 1; 37 if ((!start) && (name != document.cookie.substring(0, name.length))) { 38 return defa; 39 } 40 if (start == -1) { 41 return defa; 42 } 43 var end = document.cookie.indexOf(';', len); 44 if (end == -1) { 45 end = document.cookie.length; 46 } 47 return decodeURIComponent(document.cookie.substring(len, end)); 48 }; 49 50 51 window.trx_addons_set_cookie = function(name, value) { 52 var expires = arguments[2] !== undefined ? arguments[2] : 0; // In ms ( sec * 1000 ). If 0 (by default) - store the value for the current session only 53 var path = arguments[3] !== undefined ? arguments[3] : '/'; 54 var domain = arguments[4] !== undefined ? arguments[4] : ''; 55 var secure = arguments[5] !== undefined ? arguments[5] : ''; 56 var samesite = arguments[6] !== undefined ? arguments[6] : 'strict'; // strict | lax | none 57 var today = new Date(); 58 today.setTime(today.getTime()); 59 var expires_date = new Date(today.getTime() + (expires * 1)); 60 document.cookie = encodeURIComponent(name) + '=' 61 + encodeURIComponent(value) 62 + (expires ? ';expires=' + expires_date.toGMTString() : '') 63 + (path ? ';path=' + path : '') 64 + (domain ? ';domain=' + domain : '') 65 + (secure ? ';secure' : '') 66 + (samesite ? ';samesite=' + samesite : ''); 67 }; 68 69 70 window.trx_addons_del_cookie = function(name) { 71 var path = arguments[1] !== undefined ? arguments[1] : '/'; 72 var domain = arguments[2] !== undefined ? arguments[2] : ''; 73 var secure = arguments[3] !== undefined ? arguments[3] : ''; 74 var samesite = arguments[4] !== undefined ? arguments[4] : 'strict'; // strict | lax | none 75 if ( trx_addons_get_cookie(name) ) { 76 document.cookie = encodeURIComponent(name) + '=' 77 + ';expires=Thu, 01-Jan-1970 00:00:01 GMT' 78 + (path ? ';path=' + path : '') 79 + (domain ? ';domain=' + domain : '') 80 + (secure ? ';secure' : '') 81 + (samesite ? ';samesite=' + samesite : ''); 82 } 83 }; 84 85 86 /* Local storage manipulations 87 ---------------------------------------------------------------- */ 88 89 window.trx_addons_is_local_storage_exists = function() { 90 try { 91 return 'localStorage' in window && window['localStorage'] !== null; 92 } catch (e) { 93 return false; 94 } 95 }; 96 97 window.trx_addons_get_storage = function(name) { 98 var defa = arguments[1] !== undefined ? arguments[1] : null; 99 var val = null; 100 if (trx_addons_is_local_storage_exists()) { 101 val = window['localStorage'].getItem(name); 102 if (val === null) val = defa; 103 } else { 104 val = trx_addons_get_cookie(name, defa); 105 } 106 return val; 107 }; 108 109 window.trx_addons_set_storage = function(name, value) { 110 if (trx_addons_is_local_storage_exists()) 111 window['localStorage'].setItem(name, value); 112 else 113 trx_addons_set_cookie(name, value, 365 * 24 * 60 * 60 * 1000); // 1 year 114 }; 115 116 window.trx_addons_del_storage = function(name) { 117 if (trx_addons_is_local_storage_exists()) 118 window['localStorage'].removeItem(name); 119 else 120 trx_addons_del_cookie(name); 121 }; 122 123 window.trx_addons_clear_storage = function() { 124 if (trx_addons_is_local_storage_exists()) 125 window['localStorage'].clear(); 126 }; 127 128 129 130 /* Clipboard manipulations 131 ---------------------------------------------------------------- */ 132 133 window.trx_addons_copy_to_clipboard = function(str, strip_tags) { 134 var selected = document.getSelection().rangeCount > 0 // Check if there is any content selected previously 135 ? document.getSelection().getRangeAt(0) // Store selection if found 136 : false; // Mark as false to know no selection existed before 137 if ( typeof str == 'object' && str.length ) { 138 str = str.is( 'textarea' ) ? str.val() : str.html(); 139 } 140 if ( strip_tags ) { 141 str = str.replace(/<[^>]+>/g, ''); 142 } 143 var el = document.createElement('textarea'); // Create a <textarea> element 144 el.value = str; // Set its value to the string that you want copied 145 el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof
146 el.style.position = 'absolute'; // Move outside the screen to make it invisible 147 el.style.left = '-9999px'; 148 document.body.appendChild(el); // Append the <textarea> element to the HTML document 149 el.select(); // Select the <textarea> content 150 document.execCommand('copy'); // Copy - only works as a result of a user action (e.g. click events) 151 document.body.removeChild(el); // Remove the <textarea> element 152 if (selected) { // If a selection existed before copying 153 document.getSelection().removeAllRanges(); // Unselect everything on the HTML document 154 document.getSelection().addRange(selected); // Restore the original selection 155 } 156 }; 157 158 159 160 /* ListBox and ComboBox manipulations 161 ---------------------------------------------------------------- */ 162 163 window.trx_addons_clear_listbox = function(box) { 164 for (var i=box.options.length-1; i >= 0; i--) 165 box.options[i] = null; 166 }; 167 168 window.trx_addons_add_listbox_item = function(box, val, text) { 169 var item = new Option(); 170 item.value = val; 171 item.text = text; 172 box.options.add(item); 173 }; 174 175 window.trx_addons_del_listbox_item_by_value = function(box, val) { 176 for (var i=0; i < box.options.length; i++) { 177 if (box.options[i].value == val) { 178 box.options[i] = null; 179 break; 180 } 181 } 182 }; 183 184 window.trx_addons_del_listbox_item_by_text = function(box, txt) { 185 for (var i=0; i < box.options.length; i++) { 186 if (box.options[i].text == txt) { 187 box.options[i] = null; 188 break; 189 } 190 } 191 }; 192 193 window.trx_addons_find_listbox_item_by_value = function(box, val) { 194 var idx = -1; 195 for (var i=0; i < box.options.length; i++) { 196 if (box.options[i].value == val) { 197 idx = i; 198 break; 199 } 200 } 201 return idx; 202 }; 203 204 window.trx_addons_find_listbox_item_by_text = function(box, txt) { 205 var idx = -1; 206 for (var i=0; i < box.options.length; i++) { 207 if (box.options[i].text == txt) { 208 idx = i; 209 break; 210 } 211 } 212 return idx; 213 }; 214 215 window.trx_addons_select_listbox_item_by_value = function(box, val) { 216 for (var i = 0; i < box.options.length; i++) { 217 box.options[i].selected = (val == box.options[i].value); 218 } 219 }; 220 221 window.trx_addons_select_listbox_item_by_text = function(box, txt) { 222 for (var i = 0; i < box.options.length; i++) { 223 box.options[i].selected = (txt == box.options[i].text); 224 } 225 }; 226 227 window.trx_addons_get_listbox_values = function(box) { 228 var delim = arguments[1] ? arguments[1] : ','; 229 var str = ''; 230 for (var i=0; i < box.options.length; i++) { 231 str += (str ? delim : '') + box.options[i].value; 232 } 233 return str; 234 }; 235 236 window.trx_addons_get_listbox_texts = function(box) { 237 var delim = arguments[1] ? arguments[1] : ','; 238 var str = ''; 239 for (var i=0; i < box.options.length; i++) { 240 str += (str ? delim : '') + box.options[i].text; 241 } 242 return str; 243 }; 244 245 window.trx_addons_sort_listbox = function(box) { 246 var temp_opts = new Array(); 247 var temp = new Option(); 248 for(var i=0; i<box.options.length; i++) { 249 temp_opts[i] = box.options[i].clone(); 250 } 251 for(var x=0; x<temp_opts.length-1; x++) { 252 for(var y=(x+1); y<temp_opts.length; y++) { 253 if (temp_opts[x].text > temp_opts[y].text) { 254 temp = temp_opts[x]; 255 temp_opts[x] = temp_opts[y]; 256 temp_opts[y] = temp; 257 } 258 } 259 } 260 for(i=0; i<box.options.length; i++) { 261 box.options[i] = temp_opts[i].clone(); 262 } 263 }; 264 265 window.trx_addons_get_listbox_selected_index = function(box) { 266 for (var i = 0; i < box.options.length; i++) { 267 if (box.options[i].selected) { 268 return i; 269 } 270 } 271 return -1; 272 }; 273 274 window.trx_addons_get_listbox_selected_value = function(box) { 275 for (var i = 0; i < box.options.length; i++) { 276 if (box.options[i].selected) { 277 return box.options[i].value; 278 } 279 } 280 return null; 281 }; 282 283 window.trx_addons_get_listbox_selected_text = function(box) { 284 for (var i = 0; i < box.options.length; i++) { 285 if (box.options[i].selected) { 286 return box.options[i].text; 287 } 288 } 289 return null; 290 }; 291 292 window.trx_addons_get_listbox_selected_option = function(box) { 293 for (var i = 0; i < box.options.length; i++) { 294 if (box.options[i].selected) { 295 return box.options[i]; 296 } 297 } 298 return null; 299 }; 300 301 302 303 /* Radio buttons manipulations 304 ---------------------------------------------------------------- */ 305 306 window.trx_addons_get_radio_value = function(radioGroupObj) { 307 for (var i=0; i < radioGroupObj.length; i++) { 308 if (radioGroupObj[i].checked) { 309 return radioGroupObj[i].value; 310 } 311 } 312 return null; 313 }; 314 315 window.trx_addons_set_radio_checked_by_num = function(radioGroupObj, num) { 316 for (var i=0; i < radioGroupObj.length; i++) { 317 if (radioGroupObj[i].checked && i!=num) { 318 radioGroupObj[i].checked=false; 319 } else if (i==num) { 320 radioGroupObj[i].checked=true; 321 } 322 } 323 }; 324 325 window.trx_addons_set_radio_checked_by_value = function(radioGroupObj, val) { 326 for (var i=0; i < radioGroupObj.length; i++) { 327 if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) { 328 radioGroupObj[i].checked=false; 329 } else if (radioGroupObj[i].value==val) { 330 radioGroupObj[i].checked=true; 331 } 332 } 333 }; 334 335 336 337 /* Form validation 338 ---------------------------------------------------------------- */ 339 340 /* 341 // Usage example: 342 var error = trx_addons_form_validate(jQuery(form_selector), { // -------- Options --------- 343 error_message_show: true, // Display or not error message 344 error_message_time: 5000, // Time to display error message 345 success_message_class: 'trx_addons_message_box_success', // Should be removed from the error message block 346 error_message_class: 'trx_addons_message_box_error', // Class, appended to error message block 347 error_message_text: 'Global error text', // Global error message text (if not specify message in the checked field) 348 error_fields_class: 'trx_addons_field_error', // Class, appended to error fields 349 exit_after_first_error: false, // Cancel validation and exit after first error 350 rules: [ 351 { 352 field: 'author', // Checking field name 353 min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs 354 max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs 355 }, 356 { 357 field: 'email', 358 min_length: { value: 7, message: 'Too short (or empty) email address' }, 359 max_length: { value: 60, message: 'Too long email address'}, 360 mask: { value: '^([a-zA-Z0-9_\\-]+\\.)*[a-zA-Z0-9_\\-]+@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*\\.[a-zA-Z0-9]{2,6}$', message: 'Invalid email address'} 361 }, 362 { 363 field: 'comment', 364 min_length: { value: 1, message: 'The comment text can\'t be empty' }, 365 max_length: { value: 200, message: 'Too long comment'} 366 }, 367 { 368 field: 'pwd1', 369 min_length: { value: 5, message: 'The password can\'t be less then 5 characters' }, 370 max_length: { value: 20, message: 'Too long password'} 371 }, 372 { 373 field: 'pwd2', 374 equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' } 375 } 376 ] 377 }); 378 */ 379 380 window.trx_addons_form_validate = function(form, opt) { 381 // Default options 382 if (typeof(opt.error_message_show)=='undefined') opt.error_message_show = true; 383 if (typeof(opt.error_message_time)=='undefined') opt.error_message_time = 5000; 384 if (typeof(opt.error_message_class)=='undefined') opt.error_message_class = 'trx_addons_message_box_error'; 385 if (typeof(opt.success_message_class)=='undefined') opt.success_message_class = 'trx_addons_message_box_success'; 386 if (typeof(opt.error_message_text)=='undefined') opt.error_message_text = 'Incorrect data in the fields!'; 387 if (typeof(opt.error_fields_class)=='undefined') opt.error_fields_class = 'trx_addons_field_error'; 388 if (typeof(opt.exit_after_first_error)=='undefined') opt.exit_after_first_error = false;
389 // Validate fields 390 var error_msg = ''; 391 form.find(":input").each(function() { 392 if (error_msg !== '' && opt.exit_after_first_error) return; 393 for (var i = 0; i < opt.rules.length; i++) { 394 if (jQuery(this).attr("name") == opt.rules[i].field) { 395 var val = jQuery(this).val(); 396 var error = false; 397 if (typeof(opt.rules[i].min_length) == 'object') { 398 if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) { 399 if (error_msg === '') jQuery(this).get(0).focus(); 400 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].min_length.message)!='undefined' ? opt.rules[i].min_length.message : opt.error_message_text ) + '</p>'; 401 error = true; 402 } 403 } 404 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') { 405 if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) { 406 if (error_msg === '') jQuery(this).get(0).focus(); 407 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].max_length.message)!='undefined' ? opt.rules[i].max_length.message : opt.error_message_text ) + '</p>'; 408 error = true; 409 } 410 } 411 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') { 412 if (opt.rules[i].mask.value !== '') { 413 var regexp = new RegExp(opt.rules[i].mask.value); 414 if (!regexp.test(val)) { 415 if (error_msg === '') jQuery(this).get(0).focus(); 416 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>'; 417 error = true; 418 } 419 } 420 } 421 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].state) == 'object') { 422 if (opt.rules[i].state.value=='checked' && !jQuery(this).get(0).checked) { 423 if (error_msg === '') jQuery(this).get(0).focus(); 424 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].state.message)!='undefined' ? opt.rules[i].state.message : opt.error_message_text ) + '</p>'; 425 error = true; 426 } 427 } 428 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') { 429 if (opt.rules[i].equal_to.value !== '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) { 430 if (error_msg === '') jQuery(this).get(0).focus(); 431 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].equal_to.message)!='undefined' ? opt.rules[i].equal_to.message : opt.error_message_text ) + '</p>'; 432 error = true; 433 } 434 } 435 if (opt.error_fields_class !== '') jQuery(this).toggleClass(opt.error_fields_class, error); 436 } 437 438 } 439 }); 440 if (error_msg !== '' && opt.error_message_show) { 441 var error_message_box = form.find(".trx_addons_message_box"); 442 if (error_message_box.length === 0) error_message_box = form.parent().find(".trx_addons_message_box"); 443 if (error_message_box.length === 0) { 444 form.append('<div class="trx_addons_message_box"></div>'); 445 error_message_box = form.find(".trx_addons_message_box"); 446 } else 447 error_message_box.removeClass(opt.success_message_class); 448 if (opt.error_message_class) error_message_box.addClass(opt.error_message_class); 449 error_message_box.html(error_msg).fadeIn(); 450 setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time); 451 } 452 return error_msg !== ''; 453 }; 454 455 456 457 // Fill (refresh) list in specified field when parent fields is changed 458 // ------------------------------------------------------------------------------------- 459 460 // Compare two lists with objects 'key': 'value' for equal length and equal keys and values 461 function trx_addons_compare_lists( list1, list2 ) { 462 var result = list1.length == list2.length; 463 if ( result ) { 464 for ( var i in list1 ) { 465 if ( ! list2.hasOwnProperty(i) || list1[i] != list2[i] ) { 466 result = false;
467 break; 468 } 469 } 470 } 471 return result; 472 } 473 474 var _trx_addons_refresh_list_cache = {}; 475 window.trx_addons_refresh_list = function( parent_type, parent_val, list_fld, list_lbl, list_not_selected, elementor_obj ) { 476 477 // Need '- Select ... -' 478 if ( list_not_selected === undefined ) { 479 list_not_selected = list_fld.data('not-selected') === true // field has data-not-selected="true" 480 || list_fld.parents('.vc_edit-form-tab').length > 0 // or field in the VC shortcodes form 481 || list_fld.parents('#elementor-controls').length > 0 // or field in the Elementor shortcodes form 482 || list_fld.parents('[class*="widget_field_type_"]').length > 0 // or field in the new SOW form 483 || list_fld.parents('.widget-liquid-right').length > 0 // or field in the Widgets panel 484 || list_fld.parents('.widgets-holder-wrap').length > 0 // or field in the Widgets panel 485 || list_fld.parents('.customize-control-widget_form').length > 0; // or field in the Widget in the Customizer 486 } 487 488 var list_val = elementor_obj && list_fld.data( 'setting' ) 489 ? elementor_obj.model.getSetting( list_fld.data( 'setting' ) ) 490 : list_fld.val(); 491 list_val = ',' + list_val + ','; // Add ',' to the start and end of the string to simplify search 492 if ( list_lbl.find('.trx_addons_refresh').length === 0 ) { 493 list_lbl.append('<span class="trx_addons_refresh trx_addons_icon-spin3 animate-spin"></span>'); 494 } 495 496 if ( parent_val ) { 497 // Check cache 498 var cache_key = ( typeof parent_val == 'object' ? JSON.stringify( parent_val ) : parent_val ) + '_' + parent_type; 499 if ( _trx_addons_refresh_list_cache[cache_key] !== undefined ) { 500 trx_addons_refresh_field_items( _trx_addons_refresh_list_cache[cache_key] ); 501 } else { 502 // Get data from server 503 var data = { 504 action: 'trx_addons_refresh_list', 505 nonce: TRX_ADDONS_STORAGE['ajax_nonce'], 506 parent_type: parent_type, 507 parent_value: parent_val, 508 list_not_selected: list_not_selected 509 }; 510 511 jQuery.post( TRX_ADDONS_STORAGE['ajax_url'], data, function(response) { 512 var rez = {}; 513 try { 514 rez = JSON.parse(response); 515 } catch (e) { 516 rez = { error: TRX_ADDONS_STORAGE['msg_ajax_error'] }; 517 console.log(response); 518 } 519 if ( rez.error === '' ) { 520 _trx_addons_refresh_list_cache[cache_key] = rez.data; 521 trx_addons_refresh_field_items( rez.data ); 522 } 523 } ); 524 } 525 } else { 526 var args = []; 527 if ( list_not_selected ) { 528 var list_type = list_fld.prop('tagName').toLowerCase(); 529 if ( list_type == 'select' ) { 530 var opt = list_fld.find( 'option' ).eq(0); 531 if ( opt.length > 0 ) { 532 args[0] = { 533 key: opt.val(), 534 value: opt.text() 535 }; 536 } 537 } 538 } 539 trx_addons_refresh_field_items( args ); 540 } 541 542 function trx_addons_refresh_field_items( data ) { 543 var list = {}; 544 var opt_list = ''; 545 var list_type = list_fld.prop('tagName').toLowerCase(); 546 var list_name = list_type == 'select' 547 ? ( list_fld.attr('name') ? list_fld.attr('name') : list_fld.data('setting') ) 548 : list_fld.data('field_name'); 549 if ( data.length === 0 ) { 550 data = [ { key: 0, value: '' } ]; 551 } 552 for ( var i in data ) { 553 if ( list_type != 'select' && data[i]['key'] == 0 ) { 554 continue; 555 } 556 list[ data[i]['key'] ] = data[i]['value']; 557 opt_list += list_type == 'select' 558 ? '<option class="'+data[i]['key']+'"' 559 + ' value="'+data[i]['key']+'"' 560 + ( list_val.indexOf( ',' + ( '' + data[i]['key'] ).trim() + ',' ) >= 0 || list_val.indexOf( ',' + ( '' + data[i]['key'] ).trim() + ' ,' ) >= 0 561 ? ' selected="selected"' 562 : '' 563 ) 564 + '>' 565 + data[i]['value'] 566 + '</option>' 567 : '<label><input type="checkbox"' 568 + ' value="' + data[i]['key'] + '"' 569 + ' name="' + list_name + '"' 570 + '>' 571 + data[i]['value'] 572 + '</label>'; 573 } 574 // Update a list of the options 575 list_fld.html( opt_list ); 576 if ( list_type == 'select' && list_fld.find('option:selected').length === 0 && list_fld.find('option').length > 0 ) { 577 list_fld.find('option').get(0).selected = true; 578 } 579 // Update an options list for the Elementor controls 580 var need_refresh = true; 581 if ( elementor_obj ) { 582 need_refresh = ! trx_addons_compare_lists( elementor_obj.view.container.controls[ list_name ].options, list ); 583 if ( need_refresh ) { 584 //elementor_obj.model.attributes.settings.controls[ list_name ].options = list; 585 elementor_obj.view.container.controls[ list_name ].options = list; 586 } 587 } 588 // Remove a loading spinner 589 list_lbl.find('span.trx_addons_refresh').remove(); 590 // Remove placeholder from the field 'cat' 591 if ( list_fld.data( 'select2' ) ) { 592 setTimeout( function() { 593 list_fld.parent().find('input.select2-search__field[placeholder]').removeAttr( 'placeholder' ); 594 }, 1 ); 595 } 596 // Trigger change event 597 if ( need_refresh ) { 598 list_fld.trigger('change'); 599 } else { 600 list_fld.trigger('change.trx_addons_refresh_list'); 601 } 602 } 603 return false;
604 }; 605 606 607 608 /* Document manipulations 609 ---------------------------------------------------------------- */ 610 611 // Detect window width, height and scroll 612 var _window_width = $window.width(), 613 _window_height = $window.height(), 614 _window_scroll_top = $window.scrollTop(), 615 _window_scroll_left = $window.scrollLeft(); 616 $window.on( 'resize', function() { 617 _window_width = $window.width(); 618 _window_height = $window.height(); 619 _window_scroll_top = $window.scrollTop(); 620 _window_scroll_left = $window.scrollLeft(); 621 } ); 622 $window.on( 'scroll', function() { 623 _window_scroll_top = $window.scrollTop(); 624 _window_scroll_left = $window.scrollLeft(); 625 } ); 626 window.trx_addons_window_width = function( val ) { 627 if ( val ) _window_width = val; 628 return _window_width; 629 }; 630 window.trx_addons_window_height = function( val ) { 631 if ( val ) _window_height = val; 632 return _window_height; 633 }; 634 window.trx_addons_window_scroll_top = function() { 635 return _window_scroll_top; 636 }; 637 window.trx_addons_window_scroll_left = function() { 638 return _window_scroll_left; 639 }; 640 641 // Detect document height 642 var _document_height; 643 var _document_height_first_run = true; 644 var _update_document_height = function( e ) { 645 if ( _document_height_first_run && e && e.namespace == 'init_hidden_elements' ) { 646 _document_height_first_run = false; 647 return; 648 } 649 _document_height = $document.height(); 650 }; 651 $document.ready( _update_document_height ); 652 $document.on( 'action.init_hidden_elements action.got_ajax_response', // Maybe need for ' action.sc_layouts_row_fixed_on action.sc_layouts_row_fixed_off' 653 _update_document_height 654 ); 655 $window.on( 'resize', _update_document_height ); 656 window.trx_addons_document_height = function() { 657 return _document_height; 658 }; 659 660 // Detect adminbar height (if present and fixed) 661 var _adminbar_height = 0; 662 var _update_adminbar_height = function() { 663 _adminbar_height = trx_addons_adminbar_height_calc(); 664 }; 665 $document.ready( _update_adminbar_height ); 666 $window.on( 'resize', _update_adminbar_height ); 667 window.trx_addons_adminbar_height_calc = function() { 668 return trx_addons_apply_filters( 'trx_addons_filter_adminbar_height', 669 $adminbar.length === 0 670 || $adminbar.css( 'display' ) == 'none' 671 || $adminbar.css( 'position' ) == 'absolute' 672 ? 0 673 : $adminbar.height() 674 ); 675 }; 676 window.trx_addons_adminbar_height = function() { 677 return _adminbar_height; 678 }; 679 680 // Detect fixed rows height 681 var $fixed_rows = false, 682 _fixed_rows_height = 0; 683 var _update_fixed_rows = function() { 684 if ( $fixed_rows === false ) { 685 $fixed_rows = jQuery( '.sc_layouts_row_fixed'); 686 } 687 _fixed_rows_height = trx_addons_fixed_rows_height_calc(); 688 $html_dom.style.setProperty( '--fixed-rows-height', ( _fixed_rows_height + trx_addons_adminbar_height() ) + 'px' ); 689 }; 690 $document.ready( _update_fixed_rows ); 691 $document.on('action.ready_trx_addons action.sc_layouts_row_fixed_on action.sc_layouts_row_fixed_off', _update_fixed_rows ); 692 $window.on( 'resize', _update_fixed_rows ); 693 window.trx_addons_fixed_rows_height_calc = function() { 694 var oft = 0; 695 if ( $fixed_rows.length > 0 ) { 696 var $fixed_on = $fixed_rows.filter( '.sc_layouts_row_fixed_on' ); 697 if ( $fixed_on.length > 0 698 && ! $body.hasClass( 'hide_fixed_rows' ) 699// && ! $body.hasClass( 'hide_fixed_rows_enabled' ) 700// && ! $body.hasClass( 'header_position_over' ) 701 ) { 702 $fixed_on.each( function() { 703 var $row = jQuery( this ); 704 if ( $row.css( 'position' ) == 'fixed' ) { 705// if ( ! $body.hasClass( 'header_position_over' ) && ! $body.hasClass( 'header_position_under' ) || $row.parents( '.top_panel' ).length === 0 ) { 706 oft += $row.outerHeight(); 707// } 708 } 709 } ); 710 } 711 } 712 return trx_addons_apply_filters( 'trx_addons_filter_fixed_rows_height', oft ); 713 }; 714 window.trx_addons_fixed_rows_height = function() { 715 var with_admin_bar = arguments.length > 0 ? arguments[0] : true, 716 with_fixed_rows = arguments.length > 1 ? arguments[1] : true; 717 return ( with_admin_bar ? trx_addons_adminbar_height() : 0 ) 718 + ( with_fixed_rows ? _fixed_rows_height : 0 ); 719 }; 720 721 // Animated scroll to selected id 722 window.trx_addons_document_animate_to_busy = false;
723 window.trx_addons_document_animate_to = function(id, callback) { 724 var split_animation = true; 725 var oft = !isNaN(id) ? Number(id) : 0, 726 oft2 = -1; 727 var obj = null; 728 if ( isNaN(id) ) { 729 if ( typeof id == 'object' ) { 730 if ( id.length > 0 ) { 731 obj = id; 732 } else { 733 return; 734 } 735 } else { 736 if ( id.substring(0, 1) != '#' && id.substring(0, 1) != '.' ) { 737 id = '#' + id; 738 } 739 obj = jQuery(id).eq(0); 740 if ( obj.length === 0 ) { 741 return; 742 } 743 } 744 oft = split_animation ? obj.offset().top : Math.max( 0, obj.offset().top - trx_addons_fixed_rows_height() ); 745 if ( split_animation ) { 746 oft2 = Math.max( 0, oft - trx_addons_fixed_rows_height() ); 747 } 748 } 749 var speed = Math.min(1000, Math.max(300, Math.round(Math.abs( (oft2 < 0 ? oft : oft2) - jQuery(window).scrollTop()) / jQuery(window).height() * 300))); 750 // Recalc offset always (after the half animation time) to detect change size of the fullheight rows 751 window.trx_addons_document_animate_to_busy = true; 752 if ( oft2 >= 0 ) { 753 setTimeout( function() { 754 if (isNaN(id)) oft = obj.offset().top; 755 oft2 = Math.max( 0, oft - trx_addons_fixed_rows_height() ); 756 jQuery('body,html').stop(true).animate( {scrollTop: oft2}, Math.floor(speed/2), 'linear', function() { 757 _window_scroll_top = $window.scrollTop(); 758 window.trx_addons_document_animate_to_busy = false; 759 if ( callback ) callback( id, speed ); 760 } ); 761 }, Math.floor(speed/2) ); 762 } else { 763 oft2 = oft; 764 } 765 if ( speed > 0 ) { 766 jQuery('body,html').stop(true).animate( {scrollTop: oft2}, speed, 'linear', function() { 767 _window_scroll_top = $window.scrollTop(); 768 window.trx_addons_document_animate_to_busy = false; 769 if ( callback ) callback( id, speed ); 770 } ); 771 } else { 772 jQuery( 'body,html' ).stop( true ).scrollTop( oft2 ); 773 _window_scroll_top = $window.scrollTop(); 774 window.trx_addons_document_animate_to_busy = false; 775 if ( callback ) callback( id, speed ); 776 } 777 }; 778 779 // Return a requestAnimationFrame function 780 window.trx_addons_request_animation_frame = function() { 781 return window.requestAnimationFrame 782 || window.webkitRequestAnimationFrame 783 || window.mozRequestAnimationFrame 784 || window.oRequestAnimationFrame 785 || window.msRequestAnimationFrame 786 || null; 787 }; 788 789 // Change browser address without reload page 790 window.trx_addons_document_set_location = function( curLoc, state ) { 791 if ( history.pushState === undefined || navigator.userAgent.match(/MSIE\s[6-9]/i) !== null ) { 792 return; 793 } 794 try { 795 history.pushState( state ? state : { url: curLoc }, null, curLoc ); 796 return; 797 } catch( e ) {} 798 location.href = curLoc; 799 }; 800 801 // Add/Change arguments to the url address 802 window.trx_addons_add_to_url = function(loc, prm) { 803 var ignore_empty = arguments[2] !== undefined ? arguments[2] : true, 804 q = loc.split('?'), 805 attr = q.length > 1 ? trx_addons_parse_query_string(q[1]) : {}, 806 i = 0; 807 for (var p in prm) { 808 attr[p] = prm[p]; 809 } 810 loc = q[0] + '?'; 811 i = 0; 812 for (p in attr) { 813 if (ignore_empty && attr[p] === '') continue; 814 loc += (i++ > 0 ? '&' : '') + encodeURIComponent(p) + '=' + encodeURIComponent(attr[p]); 815 } 816 return loc; 817 }; 818 819 // Add extra parameters to all links on page 820 window.trx_addons_add_extra_args_to_links = function( args, cont ) { 821 if ( ! cont ) { 822 cont = $body; 823 } 824 cont.find( 'a' ).each( function() { 825 var link = jQuery( this ), 826 href = link.attr( 'href' ); 827 if ( href && href != '#' && ! trx_addons_is_local_link( href ) && ! link.data( 'trx-addons-extra-args-added' ) ) { 828 var loc = window.location.href, 829 page_valid = true; 830 for ( var i = 0; i < args.length; i++ ) { 831 // Check a current page URL 832 page_valid = true; 833 if ( args[i].page ) { 834 page_valid = false; 835 if ( typeof args[i].page == 'object' ) { 836 for ( var pg in args[i].page ) { 837 page_valid = loc.indexOf( args[i].page[pg] ) >= 0; 838 if ( page_valid ) break; 839 } 840 } else { 841 page_valid = loc.indexOf( args[i].page ) >= 0; 842 } 843 } 844 // Check a href against mask 845 if ( page_valid && ( ! args[i].mask || href.indexOf( args[i].mask ) >= 0 ) ) { 846 // Prepare args to add to the URL 847 var add = false;
848 if ( typeof args[i].args == 'object' ) { 849 add = {}; 850 for ( var a in args[i].args ) { 851 // Skip empty args 852 if ( args[i].args[a] === '' ) { 853 continue; 854 } 855 // Replace an arguments starts with the '@' by the value of the specified field 856 if ( args[i].args[a] == '@href' ) { 857 add[a] = href; 858 } else if ( args[i].args[a] == '@location' || args[i].args[a] == '@loc' ) { 859 add[a] = loc; 860 } else if ( args[i].args[a] == '@title' ) { 861 add[a] = document.title; 862 } else { 863 add[a] = args[i].args[a]; 864 } 865 } 866 } 867 if ( typeof args[i].link != 'undefined' ) { 868 href = args[i].link; 869 } 870 if ( add !== false ) { 871 href = trx_addons_add_to_url( href, add ); 872 } 873 if ( typeof args[i].hash != 'undefined' && href.indexOf('#') < 0 ) { 874 href += '#' + args[i].hash; 875 } 876 link.attr( 'href', href ); 877 link.data( 'trx-addons-extra-args-added', 1 ); 878 break; 879 } 880 } 881 } 882 } ); 883 }; 884 885 // Return value of URL parameter 886 window.trx_addons_get_value_gp = function(prm) { 887 var urlParams = new URLSearchParams(window.location.search), 888 value = urlParams.get(prm); 889 return decodeURIComponent( value ? value : ''); 890 }; 891 892 // Parse query string 893 window.trx_addons_parse_query_string = function(qs) { 894 var query = {}, 895 pairs = ( qs.indexOf('?') >= 0 ? qs.substring( qs.indexOf('?') + 1 ) : qs).split('&'), 896 pair = []; 897 for (var i = 0; i < pairs.length; i++) { 898 pair = pairs[i].split('='); 899 query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); 900 } 901 return query; 902 }; 903 904 // Check if url is page-inner (local) link 905 window.trx_addons_is_local_link = function(url) { 906 var rez = url!==undefined; 907 if (rez) { 908 var url_pos = url.indexOf('#'); 909 if (url_pos === 0 && url.length == 1) { 910 rez = false; 911 } else { 912 if (url_pos < 0) url_pos = url.length; 913 var loc = window.location.href; 914 var loc_pos = loc.indexOf('#'); 915 if (loc_pos > 0) loc = loc.substring(0, loc_pos); 916 rez = url_pos === 0; 917 if (!rez) rez = loc == url.substring(0, url_pos); 918 } 919 } 920 return rez; 921 }; 922 923 // Check if the specified path is url 924 window.trx_addons_is_url = function( url ) { 925 return url.indexOf( '//' ) === 0 || url.indexOf( '://' ) > 0; 926 }; 927 928 // Check if the specified url is local (from the current site) 929 window.trx_addons_is_local_url = function( url ) { 930 return url.indexOf( '//' ) < 0 || url.indexOf( window.location.hostname ) > 0; 931 }; 932 933 // Check if the specified url is external 934 window.trx_addons_is_external_url = function( url ) { 935 return ( url.indexOf( '//' ) === 0 || url.indexOf( '://' ) > 0 ) && url.indexOf( window.location.hostname ) === -1; 936 }; 937 938 // Get embed code from video URL 939 window.trx_addons_get_embed_from_url = function(url, autoplay, mute, loop ) { 940 if (autoplay === undefined) { 941 autoplay = true; 942 } 943 if (mute === undefined) { 944 mute = true; 945 } 946 if (loop === undefined) { 947 loop = true; 948 } 949 var embed = ''; 950 if ( url.indexOf( '.mp4' ) > 0 || trx_addons_is_local_link( url ) ) { 951 embed = '<video class="trx_addons_video_video" playsinline disablepictureinpicture' 952 + ( autoplay ? ' autoplay="autoplay"' : '' ) 953 + ( loop ? ' loop="loop"' : '' ) 954 + ( mute ? ' muted="muted"' : '' ) 955 + '>' 956 + '<source src="' + url + '" type="video/mp4" />' 957 + '</video>'; 958 } else { 959 url = url.replace('/watch?v=', '/embed/') 960 .replace('/youtu.be/', '/www.youtube.com/embed/') 961 .replace('/vimeo.com/', '/player.vimeo.com/video/') 962 .replace('/dai.ly/', '/dailymotion.com/embed/video/') 963 .replace('/dailymotion.com/video/', '/dailymotion.com/embed/video/'); 964 if (autoplay) { 965 url += (url.indexOf('?') > 0 ? '&' : '?') + 'autoplay=1'; 966 } 967 if (mute) { 968 url += (url.indexOf('?') > 0 ? '&' : '?') + 'muted=1'; 969 } 970 embed = '<iframe src="'+url+'" border="0" width="1280" height="720"' + (autoplay ? ' allow="autoplay"' : '') + '></iframe>'; 971 } 972 return embed; 973 }; 974 975 // Turn on autoplay for videos in the container 976 window.trx_addons_set_autoplay = function(container, value) { 977 if (value === undefined) { 978 value = 1; 979 } 980 container.find('.video_frame > iframe, iframe').each(function () { 981 if (value) { 982 jQuery(this).attr('allow', 'autoplay'); 983 } 984 var src = jQuery(this).data('src'); 985 if (src) { 986 jQuery(this).attr('src', src); 987 } else { 988 src = jQuery(this).attr('src'); 989 if (src === undefined) { 990 src = ''; 991 } 992 if (src.indexOf('youtube')>=0 || src.indexOf('vimeo')>=0) { 993 jQuery(this).attr('src', trx_addons_add_to_url(src, {'autoplay': value})); 994 } 995 } 996 }); 997 }; 998 999 // Insert an iframe with a video player after click on the preview image 1000 // If a video with autoplay and it hosted on Youtube - for iOS a Youtube API
1000script is used instead an iframe 1001 window.trx_addons_insert_video_iframe = function( $cont, iframe_html ) { 1002 if ( $cont.length === 0 ) { 1003 return; 1004 } 1005 // If we are in iOS and the video from Youtube - try to create player and start the video 1006 if ( trx_addons_browser_is_ios() && iframe_html.indexOf( 'youtu' ) > 0 && iframe_html.indexOf( 'autoplay=1' ) > 0 && typeof YT != 'undefined' ) { 1007 var id = 'trx_addons_yt_player_' + Math.floor( Math.random() * 100000 ); 1008 $cont.html( iframe_html.replace( /<iframe[\s]+[\s\S]+<\/iframe>/, '<div class="trx_addons_yt_player" id="' + id + '"></div>' ) ); 1009 var src = iframe_html.split('?'); 1010 var video_id = src[0].substring( src[0].indexOf('/embed/') + 7 ); 1011 var player = new YT.Player( id, { 1012 videoId: video_id, 1013 suggestedQuality: 'hd720', 1014 //height: '390', 1015 //width: '640', 1016 playerVars: { 1017 autoplay: 1, 1018 autohide: 0, 1019 modestbranding: 1, 1020 rel: 0, 1021 showinfo: 0, 1022 controls: 1, 1023 disablekb: 1, 1024 enablejsapi: 1, 1025 iv_load_policy: 3, 1026 playsinline: 1, 1027 loop: 0 1028 }, 1029 events: { 1030 'onReady': function onReady(e) { 1031 player.playVideo(); 1032 } 1033 } 1034 } ); 1035 1036 // Otherwise insert the iframe with a video to the block .video_embed 1037 } else { 1038 $cont.html( iframe_html ); 1039 } 1040 }; 1041 1042 1043 /* Browsers detection 1044 ---------------------------------------------------------------- */ 1045 window.trx_addons_browser_is_support = function( prop, value ) { 1046 var prefixes = ' -webkit- -moz- -o- -ms- '.split(' '); 1047 var el = document.createElement('a'); 1048 var style = el.style; 1049 if ( prop.slice( -1 ) != ':' ) { 1050 prop += ':'; 1051 } 1052 style.cssText = prop + prefixes.join( value + ';' + prop ).slice( 0, - prop.length ); 1053 return style.position.indexOf( value ) !== -1; 1054 }; 1055 1056 window.trx_addons_browser_is_support_css_sticky = function() { 1057 return trx_addons_browser_is_support( 'position', 'sticky' ); 1058 }; 1059 1060 window.trx_addons_browser_is_touch = function() { 1061 return 'ontouchstart' in document.documentElement; 1062 }; 1063 1064 window.trx_addons_browser_is_pointer_events = function() { 1065 return !!window.PointerEvent && ('maxTouchPoints' in window.navigator) && window.navigator.maxTouchPoints >= 0; 1066 }; 1067 1068 window.trx_addons_browser_is_mobile = function() { 1069 var check = false; 1070 ( function(a) { 1071 if ( /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( a.substr(0,4) ) ) { 1072 check = true; 1073 } 1074 } )( navigator.userAgent || navigator.vendor || window.opera ); 1075 return check; 1076 }; 1077 1078 window.trx_addons_browser_is_ios = function() { 1079 return navigator.userAgent.match(/iPad|iPhone|iPod/i) !== null 1080 ? true 1081 : false;
1082 }; 1083 1084 window.trx_addons_browser_is_iphone = function() { 1085 return navigator.userAgent.match(/iPhone/i) !== null 1086 ? true 1087 : false; 1088 }; 1089 1090 window.trx_addons_browser_is_ipad = function() { 1091 return navigator.userAgent.match(/iPad/i) !== null 1092 ? true 1093 : false; 1094 }; 1095 1096 window.trx_addons_browser_is_ipod = function() { 1097 return navigator.userAgent.match(/iPod/i) !== null 1098 ? true 1099 : false; 1100 }; 1101 1102 window.trx_addons_is_retina = function() { 1103 var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)'; 1104 return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia(mediaQuery).matches); 1105 }; 1106 1107 window.trx_addons_browser_classes = function() { 1108 var userAgent = navigator.userAgent, 1109 matchUserAgent = function( ua ) { 1110 return userAgent.indexOf( ua ) >= 0; 1111 }, 1112 classes = { 1113 // Platform 1114 'mobile': trx_addons_browser_is_mobile(), 1115 'mac': matchUserAgent('Macintosh'), 1116 'ios': trx_addons_browser_is_ios(), 1117 'iphone': trx_addons_browser_is_iphone() || trx_addons_browser_is_ipad() || trx_addons_browser_is_ipod(), 1118 'touch': trx_addons_browser_is_touch(), 1119 'retina': trx_addons_is_retina(), 1120 // Browser 1121 'firefox': matchUserAgent( 'Firefox' ), // Firefox 1.0+ 1122 'opera': !!window.opr && !!opr.addons || !!window.opera || matchUserAgent(' OPR/'), // Opera 8.0+ 1123 'safari': /^((?!chrome|android).)*safari/i.test(userAgent) // Safari 3.0+ "[object HTMLElementConstructor]" 1124 || /constructor/i.test(window.HTMLElement) 1125 || (p => { return '[object SafariRemoteNotification]' === p.toString(); })(!window.safari || typeof safari !== 'undefined' && safari.pushNotification), 1126 'ie': /Trident|MSIE/.test(userAgent) && ( false || !!document.documentMode ), // Internet Explorer 6-11 1127 'blink': matchUserAgent('Chrome') && !!window.CSS, // Blink engine 1128 'webkit': matchUserAgent('AppleWebKit') 1129 }; 1130 classes['edge'] = ! classes['ie'] && !!window.StyleMedia || matchUserAgent('Edg'); // Edge 20+ 1131 classes['chrome'] = !!window.chrome && matchUserAgent('Chrome') && ! classes['edge'] && ! classes['opera'];// Google Chrome (Not accurate) 1132 classes['applewebkit'] = matchUserAgent('AppleWebKit') && ! classes['blink']; // Apple Webkit engine 1133 classes['gecko'] = matchUserAgent('Gecko') && classes['firefox']; // Gecko 1134 return classes; 1135 }; 1136 1137 1138 /* File functions 1139 ---------------------------------------------------------------- */ 1140 1141 window.trx_addons_get_file_name = function(path) { 1142 path = path.replace(/\\/g, '/'); 1143 if ( path.indexOf('?') > 0 ) { 1144 path = path.substr( 0, path.indexOf('?') ); 1145 } 1146 var pos = path.lastIndexOf('/'); 1147 if (pos >= 0) 1148 path = path.substr(pos+1); 1149 return path; 1150 }; 1151 1152 window.trx_addons_get_file_ext = function(path) { 1153 if ( path.indexOf('?') > 0 ) { 1154 path = path.substr( 0, path.indexOf('?') ); 1155 } 1156 var pos = path.lastIndexOf('.'); 1157 path = pos >= 0 ? path.substr(pos+1) : ''; 1158 return path; 1159 }; 1160 1161 window.trx_addons_get_basename = function(path) { 1162 return trx_addons_get_file_name(path).replace('.'+trx_addons_get_file_ext(path), ''); 1163 }; 1164 1165 1166 1167 /* Image functions 1168 ---------------------------------------------------------------- */ 1169 1170 // Return true, if all images in the specified container are loaded 1171 window.trx_addons_is_images_loaded = function(cont) { 1172 var complete = true; 1173 cont.find('img').each(function() { 1174 // If any of previous images is not loaded - skip rest 1175 if ( ! complete ) { 1176 return; 1177 } 1178 var img = jQuery(this).get(0); 1179 if (typeof img.complete == 'boolean') { 1180 // See if "complete" property is available 1181 complete = img.complete; 1182 } else if (typeof img.naturalWidth == 'number' && typeof img.naturalHeight == 'number') { 1183 // See if "naturalWidth" and "naturalHeight" properties are available 1184 complete = !(img.naturalWidth == 0 && img.naturalHeight == 0); 1185 } 1186 }); 1187 return complete; 1188 }; 1189 1190 // Call function when all images in the specified container are loaded 1191 window.trx_addons_when_images_loaded = function(cont, callback, max_delay) { 1192 if (max_delay === undefined) { 1193 max_delay = 3000; 1194 } 1195 if (max_delay <= 0 || trx_addons_is_images_loaded(cont)) { 1196 callback( cont ); 1197 } else { 1198 setTimeout(function(){ 1199 trx_addons_when_images_loaded(cont, callback, max_delay - 200); 1200 }, 200); 1201 } 1202 }; 1203 1204 // Fetch content from URL 1205 window.trx_addons_fetch_url = function( url, callback ) { 1206 if ( typeof window.fetch == 'function' ) { 1207 fetch( url ) 1208 .then( function( response ) { 1209 return response.ok ? response.text() : ''; 1210 } ) 1211 .then( function( data ) { 1212 if ( callback ) { 1213 callback( data ); 1214 } 1215 } ); 1216 } else { 1217 jQuery.get( url ) 1218 .done( function( response ) { 1219 if ( typeof response == 'object' 1220 && typeof response.childElementCount != 'undefined' && response.childElementCount > 0 1221 && typeof response.children != 'undefined' && typeof response.children[0] != 'undefined' 1222 ) { 1223 response = response.children[0].outerHTML; 1224 } 1225 if ( callback ) { 1226 callback( response ); 1227 } 1228 } ) 1229 .fail( function() { 1230 if ( callback ) { 1231 callback( '' ); 1232 } 1233 } ); 1234 } 1235 }; 1236 1237 // Return cached SVG-file content or fetch a file if not in a cache 1238 var inline_svg = [];
1239 window.trx_addons_get_inline_svg = function( svg_url, view ) { 1240 var html = ''; 1241 for( var i = 0; i < inline_svg.length; i++ ) { 1242 if ( inline_svg[i].url == svg_url ) { 1243 html = inline_svg[i].html; 1244 break; 1245 } 1246 } 1247 if ( html === '' ) { 1248 trx_addons_fetch_url( svg_url, function( html ) { 1249 if ( html ) { 1250 inline_svg.push( { 1251 url: svg_url, 1252 html: html 1253 } ); 1254 } 1255 if ( view ) { 1256 view.render( html ); 1257 } 1258 } ); 1259 } else if ( view ) { 1260 view.render( html ); 1261 } 1262 return html; 1263 }; 1264 1265 // Legacy function to compatibility with the old themes 1266 if ( ! window.get_inline_svg ) { 1267 window.get_inline_svg = window.trx_addons_get_inline_svg; 1268 } 1269 1270 1271 /* Numbers functions 1272 ---------------------------------------------------------------- */ 1273 1274 // Round number to specified precision. 1275 // For example: num=1.12345, prec=2, rounded=1.12 1276 // num=12345, prec=-2, rounded=12300 1277 window.trx_addons_round_number = function(num) { 1278 var precision = arguments[1]!==undefined ? arguments[1] : 0; 1279 var p = Math.pow(10, precision); 1280 return Math.round(num*p)/p; 1281 }; 1282 1283 // Format money: 1284 // For example: (123456789.12345).formatMoney(2, '.', ','); 1285 Number.prototype.formatMoney = function(c, d, t) { 1286 var n = this, 1287 c = c == undefined ? 2 : (isNaN(c = Math.abs(c)) ? 2 : c), 1288 d = d == undefined ? "." : d, 1289 t = t == undefined ? "," : t, 1290 s = n < 0 ? "-" : "", 1291 i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), 1292 j = (j = i.length) > 3 ? j % 3 : 0; 1293 return s 1294 + (j ? i.substring(0, j) + t : "") 1295 + i.substring(j).replace(/(\d{3})(?=\d)/g, "$1" + t) 1296 + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); 1297 }; 1298 1299 // Return random integer from a to b 1300 window.trx_addons_random = function(a, b) { 1301 return Math.floor( Math.random() * ( b - a ) ) + a; 1302 }; 1303 1304 1305 /* Strings 1306 ---------------------------------------------------------------- */ 1307 1308 // Make first letter of every word 1309 window.trx_addons_proper = function(str) { 1310 return str.replace(/(\b\w)/gi, function(m) { return m.toUpperCase(); }); 1311 }; 1312 1313 // Replicate string several times 1314 window.trx_addons_replicate = function(str, num) { 1315 var rez = ''; 1316 for (var i=0; i < num; i++) { 1317 rez += str; 1318 } 1319 return rez; 1320 }; 1321 1322 // Split a string by delimiter, but not split if delimiter inside quotes 1323 window.trx_addons_split = function(str, delimiter) { 1324 var rez = [], 1325 quotes = false, 1326 pos = 0; 1327 for ( var i = 0; i < str.length; i++ ) { 1328 if ( str[i] == delimiter && ! quotes ) { 1329 rez.push( str.substring( pos, i ) ); 1330 pos = i + 1; 1331 } else if ( str[ i ] == '"' ) { 1332 quotes = ! quotes; 1333 } 1334 } 1335 rez.push( str.substring( pos, i ) ); 1336 return rez; 1337 }; 1338 1339 // Parse a string with arguments to the object 1340 window.trx_addons_parse_atts = function(str, delimiter) { 1341 var obj = {}; 1342 if ( ! delimiter ) { 1343 delimiter = ' '; 1344 } 1345 if ( str !== undefined ) { 1346 if ( delimiter == '&' ) { 1347 str = str.replace(/&/g, '&'); 1348 } 1349 var pairs = trx_addons_split( str, delimiter ); 1350 for ( var i in pairs ) { 1351 if ( pairs[i].indexOf('=') != -1 ) { 1352 var pair = pairs[i].split('='); 1353 obj[ pair[0] ] = ('' + pair[1]).slice(0, 1) == '"' && ('' + pair[1]).slice(-1) == '"' 1354 || ( '' + pair[1]).slice(0, 1) == "'" && ('' + pair[1]).slice(-1) == "'" 1355 ? pair[1].slice( 1, -1 ) 1356 : pair[1]; 1357 } 1358 } 1359 } 1360 return obj; 1361 }; 1362 1363 // Replace: 1364 // {{..}} to the <i>..</i> 1365 // ((..)) to the <b>..</b> 1366 // || to the <br> 1367 // ^N to the <sup>N</sup> 1368 window.trx_addons_prepare_macros = function(str) { 1369 if ( ! str || typeof str != 'string' ) { 1370 return str; 1371 } 1372 // Replace shortcodes 1373 if ( str.indexOf('[') >= 0 && str.indexOf(']') >= 0 ) { 1374 str = str.replace( 1375 /([\[])([\[\]\S]+?)[\s]+([^\[\]]+)?([\]])/g, 1376 function( match, p1, p2, p3, p4 ) { 1377 // Allowed CSS properties as attributes in format: 1378 // 'attribute': 'css_property' or 'attribute': { 'rule': 'css_property', 'default': 'default_value' } 1379 var allowed_css = trx_addons_apply_filters( 'trx_addons_filter_prepare_macros_allowed_css', { 1380 'valign': 'vertical-align', 1381 'color': 'color', 1382 'bgcolor': 'background-color', 1383 'bdcolor': 'border-color', 1384 'border': 'border-width',
1385 'radius': 'border-radius', 1386 'padding': 'padding', 1387 'margin': 'margin' 1388 }, 1389 'common' 1390 ), 1391 image_css = trx_addons_apply_filters( 'trx_addons_filter_prepare_macros_allowed_css', { 1392 'size': { 'rule': 'max-height', 'default': '1em' }, 1393 }, 1394 'image' 1395 ), 1396 icon_css = trx_addons_apply_filters( 'trx_addons_filter_prepare_macros_allowed_css', { 1397 'size': { 'rule': 'font-size', 'default': '1em' }, 1398 }, 1399 'icon' 1400 ), 1401 atts = false; 1402 if ( p2 == 'image' ) { 1403 atts = p3 ? trx_addons_parse_atts( p3 ) : {}; 1404 // Fetch an image url by id or replace it by default image 1405 if ( ! atts['url'] ) { 1406 // Default image 1407 atts['url'] = TRX_ADDONS_STORAGE['no_image']; 1408 // Get url with specified size 1409 var get_url_by_size = function( data, thumb_size ) { 1410 var url = ''; 1411 for ( var i in data['media_details']['sizes'] ) { 1412 if ( ('' + i).indexOf( thumb_size ) >= 0 ) { 1413 url = data['media_details']['sizes'][i]['source_url']; 1414 break; 1415 } 1416 } 1417 return url; 1418 }; 1419 // Fetch image by id 1420 if ( atts['id'] ) { 1421 if ( TRX_ADDONS_STORAGE['fetch_images' ] === undefined ) { 1422 TRX_ADDONS_STORAGE['fetch_images'] = {}; 1423 } 1424 if ( ! TRX_ADDONS_STORAGE['fetch_images'][ atts['id'] ] ) { 1425 jQuery.get( TRX_ADDONS_STORAGE['rest_url'] + 'wp/v2/media/' + atts['id'] + '/', function(response) { 1426 if ( response && response['media_details'] && response['media_details']['sizes'] ) { 1427 TRX_ADDONS_STORAGE['fetch_images'][ atts['id'] ] = response; 1428 } 1429 } ); 1430 } else { 1431 atts['url'] = get_url_by_size( TRX_ADDONS_STORAGE['fetch_images'][ atts['id'] ], atts['thumb'] ? '-' + atts['thumb'] : 'full' ); 1432 } 1433 } 1434 } 1435 return atts['url'] 1436 ? '<img src="' + atts['url'] + '"' 1437 + ( atts['id'] ? ' id="trx_addons_image_' + atts['id'] + '"' : '' ) 1438 + ( atts['alt'] ? ' alt="' + atts['alt'] + '"' : '' ) 1439 + ' style="' 1440 + trx_addons_get_css_from_atts( atts, trx_addons_object_merge( allowed_css, image_css ) ) 1441 + ( atts['css'] ? atts['css'] : '' ) 1442 + '"' 1443 + '>' 1444 : ''; 1445 } else if ( p2 == 'icon' ) { 1446 atts = p3 ? trx_addons_parse_atts( p3 ) : {}; 1447 if ( atts['name'] && atts['name'].slice( 0, 5 ) != 'icon-' ) { 1448 atts['name'] = 'icon-' + atts['name']; 1449 } 1450 return atts['name'] 1451 ? '<span class="' + atts['name'] + '"' 1452 + ' style="' 1453 + trx_addons_get_css_from_atts( atts, trx_addons_object_merge( allowed_css, icon_css ) ) 1454 + ( atts['css'] ? atts['css'] : '' ) 1455 + '"' 1456 + '></span>' 1457 : ''; 1458 } else if ( p2.slice( 0, 1 ) != '&' ) { 1459 return p1 + p2 + p4; 1460 } else { 1461 return match; 1462 } 1463 } 1464 ); 1465 } 1466 // Replace simple macros 1467 return str 1468 // Replace all shortcodes with its short variant - names only, without attributes 1469 // Commented because it's already done in the callback above 1470 //.replace(/([\[])([\[\]\S]+?)[\s]+([^\[\]]+)?([\]])/g, '$1$2$4') 1471 .replace(/\{\{/g, "<i>") 1472 .replace(/\}\}/g, "</i>") 1473 .replace(/\(\(/g, "<b>") 1474 .replace(/\)\)/g, "</b>") 1475 .replace(/\|\|/g, "<br>") 1476 .replace(/(\^(\d+))/g, "<sup>$2</sup>"); 1477 }; 1478 window.trx_addons_remove_macros = function(str) { 1479 return str 1480 .replace(/[^\[]([\[][^\[\]]+[\]])[^\]]/g, "") 1481 .replace(/\{\{/g, "") 1482 .replace(/\}\}/g, "") 1483 .replace(/\(\(/g, "") 1484 .replace(/\)\)/g, "") 1485 .replace(/\|\|/g, ""); 1486 }; 1487 1488 // Replace {{ and }} with < and > 1489 window.trx_addons_parse_codes = function(text, tag_start, tag_end) { 1490 if (tag_start === undefined) tag_start = '{{'; 1491 if (tag_end === undefined) tag_end = '}}'; 1492 var r1 = new RegExp(tag_start, 'g'); 1493 var r2 = new RegExp(tag_end, 'g'); 1494 return text.replace(r1, '<').replace(r2, '>'); 1495 }; 1496 1497 // Check value for "on" | "off" | "inherit" values 1498 window.trx_addons_is_on = function(prm) { 1499 return prm>0 || ['true', 'on', 'yes', 'show'].indexOf((''+prm).toLowerCase()) >= 0; 1500 }; 1501 window.trx_addons_is_off = function(prm) { 1502 return prm === undefined || prm === '' || prm === 0 || ['false', 'off', 'no', 'none', 'hide'].indexOf((''+prm).toLowerCase()) >= 0; 1503 }; 1504 window.trx_addons_is_inherit = function(prm) { 1505 return ['inherit'].indexOf((''+prm).toLowerCase()) >= 0; 1506 }; 1507 1508 // Check for an object is empty 1509 window.trx_addons_is_empty = function(prm) { 1510 return prm === undefined || prm === '' || prm === 0 || prm === false || ( typeof prm == 'object' && Object.keys( prm ).length === 0 ); 1511 }; 1512 1513 // Return class by prefix from classes string
1514 window.trx_addons_get_class_by_prefix = function(classes, prefix) { 1515 var rez = ''; 1516 if ( classes ) { 1517 classes = classes.split(' '); 1518 for (var i=0; i < classes.length; i++) { 1519 if (classes[i].indexOf(prefix) >= 0) { 1520 rez = classes[i].replace(/[\s]+/g, ''); // Remove \t\r\n and spaces from the new class 1521 break; 1522 } 1523 } 1524 } 1525 return rez; 1526 }; 1527 1528 // Replace class by prefix with new value 1529 window.trx_addons_chg_class_by_prefix = function(classes, prefix, new_value) { 1530 var chg = false; 1531 if ( ! classes ) classes = ''; 1532 classes = classes.replace(/[\s]+/g, ' ').split(' '); // Replace groups \t\r\n and spaces with the single space 1533 new_value = new_value.replace(/[\s]+/g, ''); // Remove \t\r\n and spaces from the new class 1534 if ( typeof prefix == 'string' ) { 1535 prefix = [prefix]; 1536 } 1537 for (var i=0; i < classes.length; i++) { 1538 for (var j = 0; j < prefix.length; j++ ) { 1539 if (classes[i].indexOf( prefix[j] ) >= 0) { 1540 classes[i] = new_value; 1541 chg = true; 1542 break; 1543 } 1544 } 1545 if ( chg ) break; 1546 } 1547 if ( ! chg && new_value ) { 1548 if (classes.length == 1 && classes[0] === '') 1549 classes[0] = new_value; 1550 else 1551 classes.push( new_value ); 1552 } 1553 return classes.join(' ').replace(/[\s]{2,}/g, ' '); 1554 }; 1555 1556 // Return icon class from classes string 1557 window.trx_addons_get_icon_class = function(classes) { 1558 if ( ! classes ) classes = ''; 1559 return trx_addons_get_class_by_prefix(classes, 'icon-'); 1560 }; 1561 1562 // Replace icon's class with new value 1563 window.trx_addons_chg_icon_class = function(classes, icon, prefix) { 1564 var chg = false, 1565 icon_parts = icon.split( '-' ); 1566 if ( prefix === undefined ) { 1567 prefix = ['none', 'icon-', 'image-']; 1568 } 1569 prefix.push( icon_parts[0] + '-' ); 1570 if ( ! classes ) classes = ''; 1571 classes = classes.split(' '); 1572 for (var i=0; i < classes.length; i++) { 1573 for (var j = 0; j < prefix.length; j++ ) { 1574 if (classes[i].indexOf( prefix[j] ) >= 0) { 1575 classes[i] = [ 'none', 'image-none' ].indexOf( icon ) != -1 ? '' : icon; 1576 chg = true; 1577 break; 1578 } 1579 } 1580 if ( chg ) break; 1581 } 1582 if ( ! chg && [ 'none', 'image-none' ].indexOf( icon ) == -1 ) { 1583 if ( classes.length == 1 && classes[0] === '' ) { 1584 classes[0] = icon; 1585 } else { 1586 classes.push( icon ); 1587 } 1588 } 1589 return classes.join(' '); 1590 }; 1591 1592 // Return column class by number of columns 1593 window.trx_addons_get_column_class = function( num, all, all_tablet, all_mobile ) { 1594 var column_class_tpl = TRX_ADDONS_STORAGE['column_class_template']; 1595 var column_class = column_class_tpl.replace( '$1', num ).replace( '$2', all ); 1596 if ( all_tablet ) { 1597 column_class += ' ' + column_class_tpl.replace( '$1', num ).replace( '$2', all_tablet ) + '-tablet'; 1598 } 1599 if ( all_mobile ) { 1600 column_class += ' ' + column_class_tpl.replace( '$1', num ).replace( '$2', all_mobile ) + '-mobile'; 1601 } 1602 return column_class; 1603 }; 1604 1605 // Return a list of the responsive classes for the shortcode's attribute 1606 window.trx_addons_get_responsive_classes = function( prefix, atts, param, default_value ) { 1607 var list = []; 1608 // Push a general or default value 1609 if ( atts[ param ] ) { 1610 list.push( prefix + atts[ param ] ); 1611 } else if ( default_value ) { 1612 list.push( prefix + default_value ); 1613 } 1614 // Add responsive values (if present) 1615 if ( TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1616 for ( var bp_name in TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1617 if ( atts[ param + '_' + bp_name ] ) { 1618 list.push( prefix + atts[ param + '_' + bp_name ] + '_' + bp_name ); 1619 } 1620 } 1621 } 1622 // Apply filters to allow 3rd-party plugins modify the list of the responsive classes 1623 list = trx_addons_apply_filters( 'trx_addons_filter_responsive_classes', list, prefix, atts, param ); 1624 return list.length ? list.join( ' ' ) : ''; 1625 }; 1626 1627 // Return a name of the current breakpoint 1628 window.trx_addons_get_responsive_breakpoint = function() { 1629 var rez = 'desktop', ww = trx_addons_window_width(); 1630 if ( TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1631 for ( var bp_name in TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1632 if ( TRX_ADDONS_STORAGE['elementor_breakpoints'][bp_name] < ww ) { 1633 break; 1634 } 1635 rez = bp_name; 1636 } 1637 } 1638 return rez; 1639 }; 1640 1641 // Get a next token from the string (character or a tag) 1642 // If a tag is <i>...</i> - return it as a single token 1643 function trx_addons_get_next_token( str, pos ) { 1644 var token = ''; 1645 if ( pos < str.length ) { 1646 if ( str[pos] == '<' ) { 1647 while ( pos < str.length && str[pos] != '>' ) { 1648 token += str[pos++]; 1649 } 1650 token += str[pos++]; 1651 if ( token.slice(0, 3) == '<i ' || token.slice(0, 3) == '<i>' ) { 1652 while ( pos < str.length && token.indexOf('</i>') == -1 ) { 1653 token += str[pos++]; 1654 } 1655 } 1656 } else { 1657 token = str[pos++]; 1658 } 1659 } 1660 return token; 1661 } 1662 1663 // Wrap each word to the specified tag 1664 window.trx_addons_wrap_words = function( txt, before, after ) { 1665 var rez = '', token = '', in_word = false, cnt = 0, is_icon = false;
1666 for ( var i = 0; i < txt.length; i++ ) { 1667 token = trx_addons_get_next_token( txt, i ); 1668 is_icon = token.slice(0, 3) == '<i ' || token.slice(0, 3) == '<i>' || token.slice(0, 4) == '<img'; 1669 if ( in_word ) { 1670 if ( token.slice(0, 1) == '<' || token == ' ' ) { 1671 rez += after; 1672 in_word = false; 1673 } 1674 } else { 1675 if ( token != ' ' && ( token.slice(0, 1) != '<' || is_icon ) ) { 1676 rez += before.replace( '>', ' data-animation-index="' + cnt + '">' ); 1677 in_word = true; 1678 cnt++; 1679 } 1680 } 1681 rez += token; 1682 i += token.length - 1; 1683 if ( is_icon || ( in_word && i == txt.length - 1 ) ) { 1684 rez += after; 1685 in_word = false; 1686 } 1687 } 1688 return rez; 1689 }; 1690 1691 // Wrap each character to the specified tag 1692 window.trx_addons_wrap_chars = function( txt, before, after, before_word, after_word ) { 1693 var rez = '', token = '', in_word = false, cnt = 0, is_icon = false; 1694 if ( before_word === undefined ) before_word = ''; 1695 if ( after_word === undefined ) after_word = ''; 1696 for ( var i = 0; i < txt.length; i++ ) { 1697 token = trx_addons_get_next_token( txt, i ); 1698 is_icon = token.slice(0, 3) == '<i ' || token.slice(0, 3) == '<i>' || token.slice(0, 4) == '<img'; 1699 if ( in_word ) { 1700 if ( token.slice(0, 1) == '<' || token == ' ' ) { 1701 rez += after_word; 1702 in_word = false; 1703 } 1704 } else { 1705 if ( token != ' ' && ( token.slice(0, 1) != '<' || is_icon ) ) { 1706 rez += before_word; 1707 in_word = true; 1708 } 1709 } 1710 rez += token.slice(0, 1) == '<' && ! is_icon 1711 ? token 1712 : ( before.replace( '>', ' data-animation-index="' + cnt + '">' ) 1713 + ( token == ' ' ? ' ' : token ) 1714 + after 1715 ); 1716 i += token.length - 1; 1717 if ( is_icon || ( in_word && i == txt.length - 1 ) ) { 1718 rez += after_word; 1719 in_word = false; 1720 } 1721 if ( token.slice(0, 1) != '<' || is_icon ) { 1722 cnt++; 1723 } 1724 } 1725 return rez; 1726 }; 1727 1728 // Function to clear string from tags 1729 window.trx_addons_clear_tags = function( str ) { 1730 return str.replace( /<\/?[^>]+>/g, '' ); 1731 }; 1732 1733 // Function to escape string for use it in HTML 1734 window.trx_addons_esc_html = function( str ) { 1735 // 1st case: use browser's built-in functionality to quickly and safely escape strings 1736 // var textarea = document.createElement( 'textarea' ); 1737 // textarea.textContent = str; 1738 // return textarea.innerHTML; 1739 1740 // 2nd case: use jQuery to escape strings 1741 // return jQuery('<div>').text(str).html(); 1742 1743 // 3rd case: use our own function to escape strings 1744 return str 1745 .replace( /&/g, '&' ) 1746 .replace( /</g, '<' ) 1747 .replace( />/g, '>' ) 1748 .replace( /"/g, '"' ) 1749 .replace( /'/g, ''' ); 1750 }; 1751 1752 1753 /* Colors functions 1754 ---------------------------------------------------------------- */ 1755 1756 window.trx_addons_hex2rgb = function(hex) { 1757 hex = hex.indexOf('#') > -1 ? hex.substring(1) : hex; 1758 if ( hex.length == 3 ) { 1759 hex = hex.slice(0,1).repeat(2) + hex.slice(1,2).repeat(2) + hex.slice(2,3).repeat(2); 1760 } 1761 var num = parseInt( hex, 16 ); 1762 if ( hex.length > 6 ) { 1763 return {r: ( num >> 24 ) + 256, g: (num & 0x00FF0000) >> 16, b: (num & 0x0000FF00) >> 8, a: (num & 0x000000FF)}; 1764 } else { 1765 return {r: num >> 16, g: (num & 0x00FF00) >> 8, b: (num & 0x0000FF)}; 1766 } 1767 }; 1768 1769 window.trx_addons_hex2rgba = function(hex, alpha) { 1770 var rgb = trx_addons_hex2rgb(hex); 1771 return 'rgba('+rgb.r+','+rgb.g+','+rgb.b+','+alpha+')'; 1772 }; 1773 1774 window.trx_addons_rgb2hex = function(color) { 1775 var aRGB; 1776 color = color.replace(/\s/g,"").toLowerCase(); 1777 if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)') { 1778 color = 'transparent'; 1779 } 1780 if (color.indexOf('rgba(')==0) 1781 aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 1782 else 1783 aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 1784 1785 if(aRGB) { 1786 color = ''; 1787 for (var i=1; i <= 3; i++) 1788 color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1'); 1789 } else { 1790 color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3'); 1791 } 1792 return (color.substr(0,1)!='#' ? '#' : '') + color; 1793 }; 1794 1795 window.trx_addons_components2hex = function(r,g,b,a) { 1796 return '#'+ 1797 Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 1798 Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 1799 Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 1800 ( a || a === 0 1801 ? Number(a).toString(16).toUpperCase().replace(/^(.)$/,'0$1') 1802 : '' 1803 ); 1804 }; 1805 1806 window.trx_addons_rgb2components = function(color) { 1807 color = trx_addons_rgb2hex(color); 1808 var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i); 1809 if (!matches) return false;
1810 for (var i=1, rgb = new Array(3); i <= 3; i++) { 1811 rgb[i-1] = parseInt(matches[i],16); 1812 } 1813 return rgb; 1814 }; 1815 1816 window.trx_addons_hex2hsb = function(hex) { 1817 var h = arguments[1]!==undefined ? arguments[1] : 0; 1818 var s = arguments[2]!==undefined ? arguments[2] : 0; 1819 var b = arguments[3]!==undefined ? arguments[3] : 0; 1820 var hsb = trx_addons_rgb2hsb(trx_addons_hex2rgb(hex)); 1821 hsb.h = Math.min(359, Math.max( 0, hsb.h + h)); 1822 hsb.s = Math.min(100, Math.max( 0, hsb.s + s)); 1823 hsb.b = Math.min(100, Math.max( 0, hsb.b + b)); 1824 return hsb; 1825 }; 1826 1827 window.trx_addons_hsb2hex = function(hsb) { 1828 var rgb = trx_addons_hsb2rgb(hsb); 1829 return trx_addons_components2hex(rgb.r, rgb.g, rgb.b); 1830 }; 1831 1832 window.trx_addons_rgb2hsb = function(rgb) { 1833 var hsb = {}; 1834 hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b); 1835 hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b); 1836 hsb.b = Math.round((hsb.b /255)*100); 1837 if ((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0; 1838 else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b); 1839 else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60 + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b); 1840 else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r); 1841 else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r); 1842 else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g); 1843 else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g); 1844 else hsb.h = 0; 1845 hsb.h = Math.round(hsb.h); 1846 return hsb; 1847 }; 1848 1849 window.trx_addons_hsb2rgb = function(hsb) { 1850 var rgb = {}; 1851 var h = Math.round(hsb.h); 1852 var s = Math.round(hsb.s*255/100); 1853 var v = Math.round(hsb.b*255/100); 1854 if (s == 0) { 1855 rgb.r = rgb.g = rgb.b = v; 1856 } else { 1857 var t1 = v; 1858 var t2 = (255-s)*v/255; 1859 var t3 = (t1-t2)*(h%60)/60; 1860 if (h==360) h = 0; 1861 if (h<60) { rgb.r=t1; rgb.b=t2; rgb.g=t2+t3; } 1862 else if (h<120) { rgb.g=t1; rgb.b=t2; rgb.r=t1-t3; } 1863 else if (h<180) { rgb.g=t1; rgb.r=t2; rgb.b=t2+t3; } 1864 else if (h<240) { rgb.b=t1; rgb.r=t2; rgb.g=t1-t3; } 1865 else if (h<300) { rgb.b=t1; rgb.g=t2; rgb.r=t2+t3; } 1866 else if (h<360) { rgb.r=t1; rgb.g=t2; rgb.b=t1-t3; } 1867 else { rgb.r=0; rgb.g=0; rgb.b=0; } 1868 } 1869 return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) }; 1870 }; 1871 1872 window.trx_addons_color_picker = function(){ 1873 var id = arguments[0]!==undefined ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000); 1874 var colors = arguments[1]!==undefined ? arguments[1] : 1875 '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,' 1876 +'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,' 1877 +'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,' 1878 +'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,' 1879 +'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,' 1880 +'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,' 1881 +'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026'; 1882 var colorsList = colors.split(','); 1883 var tbl = '<table class="colorPickerTable"><thead>'; 1884 for (var i=0; i < colorsList.length; i++) { 1885 if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>'; 1886 tbl += '<td style="background-color:'+colorsList[i]+'"> </td>'; 1887 } 1888 tbl += '</tr></thead><tbody>' 1889 + '<tr style="height:60px;">' 1890 + '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 1891 + '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" maxlength="7" />' 1892 + '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>' 1893 + '</td>' 1894 + '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 1895 + '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" readonly="readonly" />' 1896 + '</td>' 1897 + '</tr></tbody></table>'; 1898 1899 jQuery(document.createElement("div")) 1900 .attr("id", id) 1901 .css('display','none') 1902 .html(tbl) 1903 .appendTo("body") 1904 .addClass("iColorPickerTable") 1905 .on('mouseover', 'thead td', function(){ 1906 var aaa = trx_addons_rgb2hex(jQuery(this).css('background-color')); 1907 jQuery('#'+id+'_colorPreview').css('background',aaa); 1908 jQuery('#'+id+'_colorPreview input').val(aaa); 1909 }) 1910 .on('keypress', '#'+id+'_colorPreview input', function(key){ 1911 var aaa = jQuery(this).val(); 1912 if (key.which===13 && (aaa.length===4 || aaa.length===7)) { 1913 var fld = jQuery('#'+id).data('field'); 1914 var func = jQuery('#'+id).data('func'); 1915 if (func!=null && func!='undefined') { 1916 func(fld, aaa); 1917 } else { 1918 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 1919 } 1920 jQuery('#'+id+'_Bg').fadeOut(500); 1921 jQuery('#'+id).fadeOut(500); 1922 key.preventDefault(); 1923 return false;
1924 } 1925 }) 1926 .on('change', '#'+id+'_colorPreview input', function(key){ 1927 var aaa = jQuery(this).val(); 1928 if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) { 1929 jQuery('#'+id+'_colorPreview').css('background',aaa); 1930 } 1931 }) 1932 .on('click', 'thead td', function(e){ 1933 var fld = jQuery('#'+id).data('field'); 1934 var func = jQuery('#'+id).data('func'); 1935 var aaa = trx_addons_rgb2hex(jQuery(this).css('background-color')); 1936 if (func!=null && func!='undefined') { 1937 func(fld, aaa); 1938 } else { 1939 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 1940 } 1941 jQuery('#'+id+'_Bg').fadeOut(500); 1942 jQuery('#'+id).fadeOut(500); 1943 e.preventDefault(); 1944 return false; 1945 }) 1946 .on('click', 'tbody .iColorPicker_moreColors', function(e){ 1947 var thead = jQuery(this).parents('table').find('thead'); 1948 var out = ''; 1949 if (thead.hasClass('more_colors')) { 1950 for (var i=0; i < colorsList.length; i++) { 1951 if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 1952 out += '<td style="background-color:'+colorsList[i]+'"> </td>'; 1953 } 1954 thead.removeClass('more_colors').empty().html(out+'</tr>'); 1955 jQuery('#'+id+'_colorPreview').attr('colspan', 8); 1956 jQuery('#'+id+'_colorOriginal').attr('colspan', 8); 1957 } else { 1958 var rgb=[0,0,0], i=0, j=-1; // Set j=-1 or j=0 - show 2 different colors layouts 1959 while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) { 1960 if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 1961 i++; 1962 out += '<td style="background-color:'+trx_addons_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'"> </td>'; 1963 rgb[2]+=3; 1964 if (rgb[2]>0xF) { 1965 rgb[1]+=3; 1966 if (rgb[1]>(j===0 ? 6 : 0xF)) { 1967 rgb[0]+=3; 1968 if (rgb[0]>0xF) { 1969 if (j===0) { 1970 j=1; 1971 rgb[0]=0; 1972 rgb[1]=9; 1973 rgb[2]=0; 1974 } else { 1975 break; 1976 } 1977 } else { 1978 rgb[1]=(j < 1 ? 0 : 9); 1979 rgb[2]=0; 1980 } 1981 } else { 1982 rgb[2]=0; 1983 } 1984 } 1985 } 1986 thead.addClass('more_colors').empty().html(out+'<td style="background-color:#ffffff" colspan="8"> </td></tr>'); 1987 jQuery('#'+id+'_colorPreview').attr('colspan', 9); 1988 jQuery('#'+id+'_colorOriginal').attr('colspan', 9); 1989 } 1990 jQuery('#'+id+' table.colorPickerTable thead td') 1991 .css({ 1992 'width':'12px', 1993 'height':'14px', 1994 'border':'1px solid #000', 1995 'cursor':'pointer' 1996 }); 1997 e.preventDefault(); 1998 return false; 1999 }); 2000 jQuery(document.createElement("div")) 2001 .attr("id", id+"_Bg") 2002 .on('click', function(e) { 2003 jQuery("#"+id+"_Bg").fadeOut(500); 2004 jQuery("#"+id).fadeOut(500); 2005 e.preventDefault(); 2006 return false; 2007 }) 2008 .appendTo("body"); 2009 jQuery('#'+id+' table.colorPickerTable thead td') 2010 .css({ 2011 'width':'12px', 2012 'height':'14px', 2013 'border':'1px solid #000', 2014 'cursor':'pointer' 2015 }); 2016 jQuery('#'+id+' table.colorPickerTable') 2017 .css({'border-collapse':'collapse'}); 2018 jQuery('#'+id) 2019 .css({ 2020 'border':'1px solid #ccc', 2021 'background':'#333', 2022 'padding':'5px', 2023 'color':'#fff' 2024 }); 2025 jQuery('#'+id+'_colorPreview') 2026 .css({'height':'50px'}); 2027 return id; 2028 }; 2029 2030 window.trx_addons_color_picker_show = function(id, fld, func) { 2031 if (id === null || id === '') { 2032 id = jQuery('.iColorPickerTable').attr('id'); 2033 } 2034 var eICP = fld.offset(); 2035 var w = jQuery('#'+id).width(); 2036 var h = jQuery('#'+id).height(); 2037 var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w; 2038 var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13; 2039 jQuery("#"+id) 2040 .data({field: fld, func: func}) 2041 .css({ 2042 'top':t+"px", 2043 'left':l+"px", 2044 'position':'absolute', 2045 'z-index':999999 2046 }) 2047 .fadeIn(500); 2048 jQuery("#"+id+"_Bg") 2049 .css({ 2050 'position':'fixed', 2051 'z-index':999998, 2052 'top':0, 2053 'left':0, 2054 'width':'100%', 2055 'height':'100%' 2056 }) 2057 .fadeIn(500); 2058 var def = fld.val().substr(0, 1)=='#' ? fld.val() : trx_addons_rgb2hex(fld.css('backgroundColor')); 2059 jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def); 2060 jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def); 2061 }; 2062 2063 2064 /* Utils 2065 ---------------------------------------------------------------- */ 2066 2067 // Global callback to catch Googlemap loaded to prevent a warning from googlemap api 2068 window.trx_addons_googlemap_loaded = function() {}; 2069 2070 // Add unit to css value 2071 window.trx_addons_prepare_css_value = function(val) { 2072 if (val !== '' && val != 'inherit') { 2073 var parts = ('' + val).split( ' ' ); 2074 for ( var i = 0; i < parts.length; i++ ) { 2075 if ( parts[i] === '' ) { 2076 continue; 2077 } 2078 var ed = ('' + parts[i]).slice( -1 ); 2079 if ('0' <= ed && ed <= '9') { 2080 parts[i] += 'px'; 2081 } 2082 } 2083 val = parts.join( ' ' ); 2084 } 2085 return val; 2086 }; 2087 2088 // Convert CSS units to px 2089 window.trx_addons_units2px = function(val, block, dir) { 2090 var value = parseFloat( val ); 2091 var unit = ('' + val).replace( ('' + value), '' ).toLowerCase(); 2092 if ( unit ) { 2093 if ( unit == 'vw' ) { 2094 value = Math.round( value * trx_addons_window_width() / 100 ); 2095 } else if ( unit == 'vh' ) { 2096 value = Math.round( value * trx_addons_window_height() / 100 ); 2097 } else if ( unit == '%' && block && block.length ) { 2098 value = Math.round( value * ( dir == 'x' ? block.eq(0).outerWidth() : block.eq(0).outerHeight() ) / 100 ); 2099 } else if ( unit == 'em' && block && block.length ) { 2100 value = parseFloat( getComputedStyle( block.get(0) )['fontSize'] ) * value; 2101 } else if ( unit == 'rem' ) { 2102 value = parseFloat( getComputedStyle( $body.get(0) )['fontSize'] ) * value; 2103 } 2104 } 2105 return value; 2106 }; 2107 2108 // Return string with CSS rules from the shortcode's attributes 2109 window.trx_addons_get_css_from_atts = function( atts, allowed ) { 2110 var css = '', 2111 rule = '', 2112 atts_with_units = trx_addons_apply_filters( 'trx_addons_filter_atts_with_units', [ 'margin', 'padding', 'border-radius', 'border-width', 'font-size', 'line-height', 'letter-spacing', 'width', 'height', 'top', 'right', 'bottom', 'left' ] ); 2113 for ( var k in allowed ) { 2114 if ( allowed[ k ] && ( atts.hasOwnProperty( k ) || typeof allowed[ k ] == 'object' && allowed[ k ].hasOwnProperty( 'default' ) ) ) { 2115 rule = typeof allowed[ k ] == 'object' ? allowed[ k ]['rule'] : allowed[ k ]; 2116 if ( typeof allowed[ k ] == 'object' ) { 2117 css += rule + ':' + ( atts[ k ] 2118 ? ( atts_with_units.indexOf( rule ) >= 0 ? trx_addons_prepare_css_value( atts[ k ] ) : atts[ k ] ) 2119 : ( atts_with_units.indexOf( rule ) >= 0 ? trx_addons_prepare_css_value( allowed[ k ]['default'] ) : allowed[ k ]['default'] ) 2120 ) 2121 + ';'; 2122 } else { 2123 css += rule + ':' + ( atts_with_units.indexOf( rule ) >= 0 ? trx_addons_prepare_css_value( atts[ k ] ) : atts[ k ] ) + ';'; 2124 } 2125 } 2126 } 2127 return css; 2128 }; 2129 2130 // Return nested property of the object 2131 window.trx_addons_get_object_property = function(obj, property, defa) {
2132 var rez = defa === undefined ? false : defa, 2133 props = property.split('.'), 2134 cur = obj; 2135 if ( typeof cur == 'object' ) { 2136 for (var i = 0; i < props.length; i++) { 2137 if ( cur.hasOwnProperty( props[i] ) ) { 2138 cur = cur[ props[i] ]; 2139 if ( i == props.length - 1 ) { 2140 rez = cur; 2141 } 2142 } else { 2143 break; 2144 } 2145 } 2146 } 2147 return rez; 2148 }; 2149 2150 // Clone objects. Handle the 3 simple types, and null or undefined 2151 window.trx_addons_object_clone = function(obj) { 2152 var copy; 2153 // Handle null 2154 if (null === obj || "object" != typeof obj) { 2155 return obj; 2156 } 2157 // Handle Date 2158 if (obj instanceof Date) { 2159 copy = new Date(); 2160 copy.setTime(obj.getTime()); 2161 return copy; 2162 } 2163 // Handle Array 2164 if (obj instanceof Array) { 2165 copy = []; 2166 for (var i = 0, len = obj.length; i < len; i++) { 2167 copy[i] = trx_addons_object_clone(obj[i]); 2168 } 2169 return copy; 2170 } 2171 // Handle Object 2172 if (obj instanceof Object) { 2173 copy = {}; 2174 for (var attr in obj) { 2175 if (obj.hasOwnProperty(attr)) { 2176 copy[attr] = trx_addons_object_clone(obj[attr]); 2177 } 2178 } 2179 return copy; 2180 } 2181 return obj; 2182 }; 2183 2184 // Merge objects 2185 window.trx_addons_object_merge = function(o1, o2) { 2186 for (var i=1; i<arguments.length; i++) { 2187 if ( arguments[i] ) { 2188 for (var prop in arguments[i]) { 2189 if ( arguments[i].hasOwnProperty(prop) ) { 2190 o1[prop] = arguments[i][prop]; 2191 } 2192 } 2193 } 2194 } 2195 return o1; 2196 }; 2197 2198 // Return true if specified var is an object 2199 window.trx_addons_is_object = function( o ) { 2200 return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object; 2201 }; 2202 2203 // Extend an object with properties other objects 2204 window.trx_addons_object_extend = function() { 2205 var args = [], total = arguments.length; 2206 while ( total-- ) { 2207 args[ total ] = arguments[ total ]; 2208 } 2209 var to = Object( args[0] ); 2210 for ( var i = 1; i < args.length; i++ ) { 2211 var nextSource = args[i]; 2212 if ( nextSource !== undefined && nextSource !== null ) { 2213 var keysArray = Object.keys( Object( nextSource ) ); 2214 for ( var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++ ) { 2215 var nextKey = keysArray[ nextIndex ]; 2216 var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey ); 2217 if ( desc !== undefined && desc.enumerable ) { 2218 if ( trx_addons_is_object( to[ nextKey ] ) && trx_addons_is_object( nextSource[ nextKey ] ) ) { 2219 trx_addons_object_extend( to[ nextKey ], nextSource[ nextKey ] ); 2220 } else if ( ! trx_addons_is_object( to[ nextKey ] ) && trx_addons_is_object( nextSource[ nextKey ] ) ) { 2221 to[ nextKey ] = {}; 2222 trx_addons_object_extend( to[ nextKey ], nextSource[ nextKey ] ); 2223 } else { 2224 to[ nextKey ] = nextSource[ nextKey ]; 2225 } 2226 } 2227 } 2228 } 2229 } 2230 return to; 2231 }; 2232 2233 // Merge two arrays 2234 window.trx_addons_array_merge = function(a1, a2) { 2235 if ( a2 ) { 2236 for ( var i in a2 ) { 2237 a1[i] = a2[i]; 2238 } 2239 } 2240 return a1; 2241 }; 2242 2243 // Get first key from array 2244 window.trx_addons_array_first_key = function(arr) { 2245 var rez = null; 2246 for (var i in arr) { 2247 rez = i; 2248 break; 2249 } 2250 return rez; 2251 }; 2252 2253 // Get first value from array 2254 window.trx_addons_array_first_value = function(arr) { 2255 var rez = null; 2256 for (var i in arr) { 2257 rez = arr[i]; 2258 break; 2259 } 2260 return rez; 2261 }; 2262 2263 // Returns the name of the class of an object 2264 window.trx_addons_get_class = function(obj) { 2265 if (obj instanceof Object && !(obj instanceof Array) && !(obj instanceof Function) && obj.constructor) { 2266 var arr = obj.constructor.toString().match(/function\s*(\w+)/); 2267 if (arr && arr.length == 2) return arr[1]; 2268 } 2269 return false; 2270 }; 2271 2272 // Generates a storable representation of a value 2273 window.trx_addons_serialize = function(mixed_val) { 2274 var obj_to_array = arguments.length==1 || argument[1]===true; 2275 2276 switch ( typeof(mixed_val) ) { 2277 2278 case "number": 2279 if ( isNaN(mixed_val) || !isFinite(mixed_val) ) 2280 return false; 2281 else 2282 return (Math.floor(mixed_val) == mixed_val ? "i" : "d") + ":" + mixed_val + ";"; 2283 2284 case "string": 2285 return "s:" + mixed_val.length + ":\"" + mixed_val + "\";"; 2286 2287 case "boolean": 2288 return "b:" + (mixed_val ? "1" : "0") + ";"; 2289 2290 case "object": 2291 if (mixed_val == null) 2292 return "N;"; 2293 else if (mixed_val instanceof Array) { 2294 var idxobj = { idx: -1 }; 2295 var map = []; 2296 for (var i=0; i < mixed_val.length; i++) { 2297 idxobj.idx++; 2298 var ser = trx_addons_serialize(mixed_val[i]); 2299 if (ser) 2300 map.push(trx_addons_serialize(idxobj.idx) + ser); 2301 } 2302 return "a:" + mixed_val.length + ":{" + map.join("") + "}"; 2303 } else { 2304 var class_name = trx_addons_get_class(mixed_val); 2305 if (class_name == undefined) 2306 return false;
2307 var props = new Array(); 2308 for (var prop in mixed_val) { 2309 var ser = trx_addons_serialize(mixed_val[prop]); 2310 if (ser) 2311 props.push(trx_addons_serialize(prop) + ser); 2312 } 2313 if (obj_to_array) 2314 return "a:" + props.length + ":{" + props.join("") + "}"; 2315 else 2316 return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join("") + "}"; 2317 } 2318 2319 case "undefined": 2320 return "N;"; 2321 } 2322 return false; 2323 }; 2324 2325 // Encode / Decode Unicode string to / from single-byte characters 2326 ( function( $ ) { 2327 var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 2328 a256 = '', 2329 r64 = [256], 2330 r256 = [256], 2331 i = 0; 2332 2333 var UTF8 = { 2334 2335 /** 2336 * Encode multi-byte Unicode string into utf-8 multiple single-byte characters 2337 * (BMP / basic multilingual plane only) 2338 * 2339 * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars 2340 * 2341 * @param {String} strUni Unicode string to be encoded as UTF-8 2342 * @returns {String} encoded string 2343 */ 2344 encode: function(strUni) { 2345 // use regular expressions & String.replace callback function for better efficiency than procedural approaches 2346 var strUtf = strUni 2347 .replace( 2348 /[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz 2349 function(c) { 2350 var cc = c.charCodeAt(0); 2351 return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f); 2352 } 2353 ) 2354 .replace( 2355 /[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz 2356 function(c) { 2357 var cc = c.charCodeAt(0); 2358 return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f); 2359 } 2360 ); 2361 return strUtf; 2362 }, 2363 2364 /** 2365 * Decode utf-8 encoded string back into multi-byte Unicode characters 2366 * 2367 * @param {String} strUtf UTF-8 string to be decoded back to Unicode 2368 * @returns {String} decoded string 2369 */ 2370 decode: function(strUtf) { 2371 // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char! 2372 var strUni = strUtf 2373 .replace( 2374 /[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars 2375 function(c) { // (note parentheses for precence) 2376 var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f); 2377 return String.fromCharCode(cc); 2378 } 2379 ) 2380 .replace( 2381 /[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars 2382 function(c) { // (note parentheses for precence) 2383 var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f; 2384 return String.fromCharCode(cc); 2385 } 2386 ); 2387 return strUni; 2388 } 2389 }; 2390 2391 while( i < 256 ) { 2392 var c = String.fromCharCode(i); 2393 a256 += c; 2394 r256[i] = i; 2395 r64[i] = b64.indexOf(c); 2396 ++i; 2397 } 2398 2399 function code(s, discard, alpha, beta, w1, w2) { 2400 s = String(s); 2401 var buffer = 0, 2402 i = 0, 2403 length = s.length, 2404 result = '', 2405 bitsInBuffer = 0; 2406 2407 while (i < length) { 2408 var c = s.charCodeAt(i); 2409 c = c < 256 ? alpha[c] : -1; 2410 2411 buffer = (buffer << w1) + c; 2412 bitsInBuffer += w1; 2413 2414 while (bitsInBuffer >= w2) { 2415 bitsInBuffer -= w2; 2416 var tmp = buffer >> bitsInBuffer; 2417 result += beta.charAt(tmp); 2418 buffer ^= tmp << bitsInBuffer; 2419 } 2420 ++i; 2421 } 2422 if ( ! discard && bitsInBuffer > 0) { 2423 result += beta.charAt(buffer << (w2 - bitsInBuffer)); 2424 } 2425 return result; 2426 } 2427 2428 var Plugin = $.trx_addons_encoder = function(dir, input, encode) { 2429 return input ? Plugin[dir](input, encode) : dir ? null : this; 2430 }; 2431 2432 Plugin.btoa = Plugin.encode = function(plain, utf8encode) { 2433 plain = Plugin.raw === false || Plugin.utf8encode || utf8encode 2434 ? UTF8.encode(plain) 2435 : plain; 2436 plain = code(plain, false, r256, b64, 8, 6); 2437 return plain + '===='.slice((plain.length % 4) || 4); 2438 }; 2439 2440 Plugin.atob = Plugin.decode = function(coded, utf8decode) { 2441 coded = String(coded).split('='); 2442 var i = coded.length; 2443 do { 2444 --i; 2445 coded[i] = code(coded[i], true, r64, a256, 6, 8); 2446 } while (i > 0); 2447 coded = coded.join(''); 2448 return Plugin.raw === false || Plugin.utf8decode || utf8decode 2449 ? UTF8.decode(coded) 2450 : coded; 2451 }; 2452 }(jQuery) ); 2453 2454 2455 /* Timing functions 2456 ---------------------------------------------------------------- */ 2457 2458 // Make a first call of the 'func' immediatelly and the second call not closer then 'wait' (in ms) 2459 window.trx_addons_debounce = function(func, wait, first_call) { 2460 var timeout; 2461 if ( first_call === undefined ) { 2462 first_call = true; 2463 } 2464 return function () { 2465 var context = this, args = arguments; 2466 var later = function later() { 2467 timeout = null;
2468 func.apply(context, args); 2469 }; 2470 var callNow = !timeout && first_call; 2471 clearTimeout(timeout); 2472 timeout = setTimeout(later, wait); 2473 if (callNow) { 2474 func.apply(context, args); 2475 } 2476 }; 2477 }; 2478 2479 // First call a 'func' must be not closer then 'wait' (in ms) after the last call 2480 // a throttled function 2481 window.trx_addons_throttle = function(func, wait, debounce) { 2482 var timeout; 2483 return function () { 2484 var context = this, args = arguments; 2485 var throttler = function () { 2486 timeout = null; 2487 func.apply(context, args); 2488 }; 2489 if (debounce) clearTimeout(timeout); 2490 if (debounce || !timeout) timeout = setTimeout(throttler, wait); 2491 }; 2492 }; 2493 2494 // Linear interpolation 2495 window.trx_addons_lerp = function(start, end, amt){ 2496 return (1 - amt) * start + amt * end; 2497 }; 2498 2499 // Change value in specified time 2500 window.trx_addons_tween_value = function( args ) { 2501 // Defaults 2502 if ( args.start == args.end ) { 2503 return null; 2504 } 2505 if ( ! args.time ) { 2506 args.time = 1; // 1s 2507 } 2508 var t = { 2509 value: args.start 2510 }; 2511 // Use TweenMax (if loaded) 2512 if ( typeof TweenMax != 'undefined' ) { 2513 return TweenMax.to( t, args.time, { 2514 overwrite: true, 2515 value: args.end, 2516 ease: args.ease ? args.ease : Power2.easeOut, 2517 onUpdate: function() { 2518 args.callbacks.onUpdate( t.value ); 2519 }, 2520 onComplete: function() { 2521 if ( args.callbacks.onComplete ) { 2522 args.callbacks.onComplete(); 2523 } 2524 } 2525 } ); 2526 // Internal tween manager 2527 } else { 2528 var amount = 0.1; 2529 var interval = Math.min( args.time * 1000 / 20, Math.max( 1, Math.round( args.time * 1000 / ( Math.abs( args.end - args.start ) / amount ) ) ) ); 2530 return setInterval( function() { 2531 t.value = trx_addons_lerp( t.value, args.end, amount ); 2532 args.callbacks.onUpdate( t.value ); 2533 if ( Math.abs(t.value - args.end) < 0.0001 ) { 2534 t.value = args.end; 2535 args.callbacks.onUpdate( t.value ); 2536 if ( args.callbacks.onComplete ) { 2537 args.callbacks.onComplete(); 2538 } 2539 } 2540 }, interval ); 2541 } 2542 }; 2543 2544 // Stop changing value 2545 window.trx_addons_tween_stop = function( handler ) { 2546 // Use TweenMax (if loaded) 2547 if ( typeof TweenMax != 'undefined' ) { 2548 if ( handler ) handler.kill(); 2549 // Internal tween manager 2550 } else { 2551 if ( handler ) clearTimeout( handler ); 2552 2553 } 2554 }; 2555 2556 2557 // jQuery animate() easings 2558 //-------------------------------------------------- 2559 ( function( $ ) { 2560 2561 // Exit if easings are already extended 2562 if ( typeof $.easing['easeInSine'] != 'undefined' ) return; 2563 2564 // Based on easing equations from Robert Penner (http://www.robertpenner.com/easing) 2565 var baseEasings = {}; 2566 $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) { 2567 baseEasings[ name ] = function( p ) { 2568 return Math.pow( p, i + 2 ); 2569 }; 2570 } ); 2571 2572 $.extend( baseEasings, { 2573 Sine: function( p ) { 2574 return 1 - Math.cos( p * Math.PI / 2 ); 2575 }, 2576 Circ: function( p ) { 2577 return 1 - Math.sqrt( 1 - p * p ); 2578 }, 2579 Elastic: function( p ) { 2580 return p === 0 || p === 1 ? p : -Math.pow( 2, 8 * ( p - 1 ) ) * Math.sin( ( ( p - 1 ) * 80 - 7.5 ) * Math.PI / 15 ); 2581 }, 2582 Back: function( p ) { 2583 return p * p * ( 3 * p - 2 ); 2584 }, 2585 Bounce: function( p ) { 2586 var pow2, 2587 bounce = 4; 2588 while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {} 2589 return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 ); 2590 } 2591 } ); 2592 2593 $.each( baseEasings, function( name, easeIn ) { 2594 $.easing[ "easeIn" + name ] = easeIn; 2595 $.easing[ "easeOut" + name ] = function( p ) { 2596 return 1 - easeIn( 1 - p ); 2597 }; 2598 $.easing[ "easeInOut" + name ] = function( p ) { 2599 return p < 0.5 ? easeIn( p * 2 ) / 2 : 1 - easeIn( p * -2 + 2 ) / 2; 2600 }; 2601 } ); 2602 2603 } )( jQuery ); 2604 2605 // CSS transitions and animations listener 2606 //-------------------------------------------------- 2607 2608 // Detect a name of the event "transition end" 2609 window.trx_addons_transition_end = function() { 2610 var e = document.createElement("transitionDetector"), 2611 t = { 2612 WebkitTransition: "webkitTransitionEnd", 2613 MozTransition: "transitionend", 2614 transition: "transitionend" 2615 }, 2616 r = "transitionend"; 2617 for ( var n in t ) { 2618 if ( undefined !== e.style[n] ) { 2619 r = t[n]; 2620 break; 2621 } 2622 } 2623 return r; 2624 }; 2625 2626 // Detect a name of the event "animation end" 2627 window.trx_addons_animation_end = function() { 2628 var e = document.createElement("animationDetector"), 2629 t = { 2630 animation: "animationend", 2631 OAnimation: "oAnimationEnd", 2632 MozAnimation: "animationend", 2633 WebkitAnimation: "webkitAnimationEnd" 2634 }, 2635 r = "animationend"; 2636 for ( var n in t ) { 2637 if ( undefined !== e.style[n] ) { 2638 r = t[n]; 2639 break; 2640 } 2641 } 2642 return r; 2643 }; 2644 2645 var support = { 2646 transitions: window.Modernizr ? Modernizr.csstransitions : false, 2647 animations: window.Modernizr ? Modernizr.cssanimations : false 2648 }, 2649 trans_end_event_names = { 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd', 'msTransition': 'MSTransitionEnd', 'transition': 'transitionend' }, 2650 trans_end_event_name = window.Modernizr ? trans_end_event_names[ Modernizr.prefixed( 'transition' ) ] : trx_addons_transition_end(), 2651 anima_end_event_names = { 'WebkitAnimation': 'webkitAnimationEnd', 'MozAnimation': 'animationend', 'OAnimation': 'oAnimationEnd', 'msAnimation': 'MSAnimationEnd', 'animation': 'animationend' }, 2652 anima_end_event_name = window.Modernizr ? anima_end_event_names[ Modernizr.prefixed( 'animation' ) ] : trx_addons_animation_end(); 2653 2654 window.trx_addons_on_end_transition = function( el, callback, timeout ) { 2655 var on_end_callback = function( e ) { 2656 if ( support.transitions ) { 2657 if ( e.target != this ) { 2658 return; 2659 } 2660 this.removeEventListener( trans_end_event_name, on_end_callback ); 2661 } 2662 if ( callback && typeof callback === 'function' ) { 2663 callback.call( this ); 2664 } 2665 }; 2666 if ( support.transitions ) { 2667 el.addEventListener( trans_end_event_name, on_end_callback, false ); 2668 } else { 2669 setTimeout( function() { 2670 if ( callback && typeof callback === 'function' ) { 2671 callback.call( this ); 2672 } 2673 }, timeout || 0 ); 2674 } 2675 }; 2676 2677 window.trx_addons_on_end_animation = function( el, callback, timeout ) { 2678 var on_end_callback = function( e ) { 2679 if ( support.animations ) { 2680 if ( e.target != this ) { 2681 return; 2682 } 2683 this.removeEventListener( anima_end_event_name, on_end_callback ); 2684 } 2685 if ( callback && typeof callback === 'function' ) { 2686 callback.call( this ); 2687 } 2688 }; 2689 if ( support.animations ) { 2690 el.addEventListener( anima_end_event_name, on_end_callback, false ); 2691 } else { 2692 setTimeout( function() { 2693 if ( callback && typeof callback === 'function' ) { 2694 callback.call( this ); 2695 } 2696 }, timeout || 0 ); 2697 } 2698 }; 2699 2700 2701 /* Mutation observers 2702 ---------------------------------------------------------------- */ 2703 var trx_addons_observers = {}; 2704 2705 // Create mutations observer 2706 window.trx_addons_create_observer = function( id, obj, callback, args ) { 2707 if ( typeof window.MutationObserver !== 'undefined' && obj && obj.length ) { 2708 if ( typeof trx_addons_observers[ id ] == 'undefined' ) { 2709 var defa = { 2710 attributes: false, 2711 childList: true, 2712 subtree: true 2713 }; 2714 if ( args ) { 2715 defa = trx_addons_object_merge( defa, args ); 2716 } 2717 trx_addons_observers[ id ] = { 2718 observer: new MutationObserver( callback ), 2719 obj: obj.get(0) 2720 }; 2721 trx_addons_observers[ id ].observer.observe( trx_addons_observers[ id ].obj, defa ); 2722 } 2723 return true; 2724 } 2725 return false;
2726 }; 2727 2728 // Remove mutations observer 2729 window.trx_addons_remove_observer = function( id ) { 2730 if ( typeof window.MutationObserver !== 'undefined' ) { 2731 if ( typeof trx_addons_observers[ id ] !== 'undefined' ) { 2732 trx_addons_observers[ id ].observer.disconnect( 2733// trx_addons_observers[ id ].obj 2734 ); 2735 delete trx_addons_observers[ id ]; 2736 } 2737 return true; 2738 } 2739 return false; 2740 }; 2741 2742 // Check mutations for selector 2743 window.trx_addons_check_mutations = function( mutations, selector, action ) { 2744 var rez = false; 2745 if ( typeof mutations != 'object' || ! mutations.hasOwnProperty( 'length' ) || ! mutations.length ) { 2746 return rez; 2747 } 2748 var nodes = false; 2749 for ( var i = 0; i < mutations.length; i++ ) { 2750 nodes = action == 'add' ? mutations[i].addedNodes : mutations[i].removedNodes; 2751 for ( var n = 0; n < nodes.length; n++ ) { 2752 var $node = jQuery( nodes[n] ); 2753 if ( selector.charAt(0) == '.' && $node.hasClass( selector.slice( 1 ) ) 2754 || selector.charAt(0) == '#' && $node.attr( 'id' ) == selector.slice( 1 ) 2755 ) { 2756 rez = true; 2757 break; 2758 } 2759 } 2760 if ( rez ) break; 2761 } 2762 return rez; 2763 }; 2764 2765 2766 /* Sticky observers 2767 ---------------------------------------------------------------- */ 2768 var trx_addons_sticky_observers = {}; 2769 2770 // Create sticky observer 2771 window.trx_addons_sticky_observer_create = function( id, obj, callback, args ) { 2772 if ( typeof window.IntersectionObserver !== 'undefined' && obj && obj.length ) { 2773 if ( typeof trx_addons_sticky_observers[ id ] == 'undefined' ) { 2774 var defa = { 2775 root: null, 2776 rootMargin: ( 1 + trx_addons_fixed_rows_height() ) + 'px 0px 0px 0px', 2777 threshold: 1 //[1] 2778 2779 }; 2780 if ( args ) { 2781 defa = trx_addons_object_merge( defa, args ); 2782 } 2783 trx_addons_sticky_observers[ id ] = { 2784 observer: new IntersectionObserver( function( entries ) { 2785 entries.forEach( function( entry ) { 2786 var is_sticky = entry.isIntersecting && entry.intersectionRatio >= 1; 2787 jQuery( entry.target ).toggleClass( 'trx_addons_is_sticky', is_sticky ); 2788 if ( callback && typeof callback === 'function' ) { 2789 callback( entry, is_sticky ); 2790 } 2791 } ); 2792 }, defa ), 2793 obj: obj.get(0) 2794 }; 2795 trx_addons_sticky_observers[ id ].observer.observe( trx_addons_sticky_observers[ id ].obj ); 2796 } 2797 return true; 2798 } 2799 return false; 2800 }; 2801 2802 window.trx_addons_sticky_observer_remove = function( id ) { 2803 if ( typeof window.IntersectionObserver !== 'undefined' ) { 2804 if ( typeof trx_addons_sticky_observers[ id ] !== 'undefined' ) { 2805 // trx_addons_sticky_observers[ id ].observer.unobserve( trx_addons_sticky_observers[ id ].obj ); 2806 trx_addons_sticky_observers[ id ].observer.disconnect(); 2807 delete trx_addons_sticky_observers[ id ]; 2808 } 2809 return true; 2810 } 2811 return false; 2812 }; 2813 2814 2815 /* Wordpress-style functions 2816 Attention! wp.hooks available only in the admin area 2817 ---------------------------------------------------------------- */ 2818 2819 var filters = {}; 2820 var allow_wp_filters = true; 2821 2822 // Add filter's handler 2823 window.trx_addons_add_filter = function( filter, callback, priority ) { 2824 if ( priority === undefined ) priority = 10; 2825 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.addFilter != 'undefined' ) { 2826 wp.hooks.addFilter( filter, 'trx_addons', callback, priority ); 2827 } else { 2828 if ( ! filters[filter] ) filters[filter] = {}; 2829 if ( ! filters[filter][priority] ) filters[filter][priority] = []; 2830 filters[filter][priority].push( callback ); 2831 } 2832 }; 2833 2834 // Apply filter's handlers 2835 window.trx_addons_apply_filters = function( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) { 2836 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.applyFilters != 'undefined' ) { 2837 arg1 = wp.hooks.applyFilters( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 2838 } else if ( typeof filters[filter] == 'object' ) { 2839 var keys = Object.keys(filters[filter]).sort(); 2840 for (var i=0; i < keys.length; i++ ) { 2841 for (var j=0; j < filters[filter][keys[i]].length; j++ ) { 2842 if ( typeof filters[filter][keys[i]][j] == 'function' ) { 2843 arg1 = filters[filter][keys[i]][j](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 2844 } 2845 } 2846 } 2847 } 2848 return arg1; 2849 }; 2850 2851 // Add action's handler 2852 window.trx_addons_add_action = function( action, callback, priority ) { 2853 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.addAction != 'undefined' ) { 2854 wp.hooks.addAction( action, 'trx_addons', callback, priority == undefined ? 10 : priority ); 2855 } else { 2856 trx_addons_add_filter( action, callback, priority ); 2857 } 2858 }; 2859 2860 // Do action's handlers 2861 window.trx_addons_do_action = function( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) { 2862 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.doAction != 'undefined' ) { 2863 wp.hooks.doAction( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 2864 } else { 2865 trx_addons_apply_filters( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 2866 } 2867 }; 2868 2869})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.