1/** 2* remote gallery api class 3*/ 4function UERemoteGeneralAPI(){ 5 6 var t = this, g_objParent; 7 var g_isTypeEvents = false; 8 var g_options = null; 9 10 var g_vars = { 11 parent_id:"", 12 class_items:"", 13 class_active:"", 14 selector_item_trigger:"", 15 add_set_active_code:false, 16 active_code_first_unselected:false, 17 listen_class_change:true, 18 enableDebug:false, 19 is_editor:false, 20 trigger_event: "click" 21 }; 22 23 var g_temp = { 24 handle:null, 25 trashold:50 26 }; 27 28 /** 29 * console log some string 30 */ 31 function trace(str){ 32 console.log(str); 33 } 34 35 /** 36 * get object property 37 */ 38 function getVal(obj, name, defaultValue){ 39 40 return window.ueRemoteConnection.getVal(obj, name, defaultValue); 41 } 42 43 44 /** 45 * run function with trashold 46 */ 47 function runWithTrashold(func, trashold){ 48 49 if(g_temp.handle) 50 clearTimeout(g_temp.handle); 51 52 g_temp.handle = setTimeout(func, g_temp.trashold); 53 54 }; 55 56 57 /** 58 * validate inited 59 */ 60 function validateInited(){ 61 62 var isInited = g_objParent.data("remote_inited"); 63 64 if(isInited == false) 65 throw new Error("The remote parent not inited"); 66 67 } 68 69 /** 70 * skip items from nested sliders / carousels 71 */ 72 function filterOwnItems(objItems){ 73 74 if(!objItems || objItems.length == 0) 75 return(objItems); 76 77 var objParent = g_objParent.eq(0); 78 var parentEl = objParent[0]; 79 var parentWidgetEl = objParent.closest(".elementor-widget")[0]; 80 81 objItems = objItems.filter(function(){ 82 83 var objItem = jQuery(this); 84 var objRemote = objItem.closest(".uc-remote-parent"); 85 86 if(objRemote.length && objRemote[0] !== parentEl) 87 return(false); 88 89 var itemWidgetEl = objItem.closest(".elementor-widget")[0]; 90 91 if(itemWidgetEl && parentWidgetEl && itemWidgetEl !== parentWidgetEl) 92 return(false); 93 94 return(true); 95 }); 96 97 return(objItems); 98 } 99 100 /** 101 * get items objet 102 */ 103 function getObjItems(){ 104 105 var objItems = g_objParent.find("."+g_vars.class_items); 106 107 objItems = filterOwnItems(objItems); 108 109 return(objItems); 110 } 111 112 113 /** 114 * get total items 115 */ 116 function getNumTotal(){ 117 118 var objItems = getObjItems(); 119 120 var numTotal = objItems.length; 121 122 return(numTotal); 123 } 124 125 126 /** 127 * get current item 128 */ 129 function getObjCurrentItem(){ 130 131 var objCurrent = getObjItems().filter("."+g_vars.class_active); 132 133 return(objCurrent); 134 } 135 136 137 /** 138 * get current item 139 */ 140 function getNumCurrent(){ 141 142 var objCurrent = getObjCurrentItem(); 143 144 if(objCurrent.length == 0) 145 return(-1); 146 147 var index = objCurrent.index(); 148 149 return(index); 150 } 151 152 /** 153 * get item by index 154 */ 155 function getItem(index){ 156 157 if(index < 0) 158 index = 0; 159 160 var objItems = getObjItems(); 161 162 if(objItems.length == 0) 163 return(null); 164 165 if(index >= objItems.length ) 166 index = objItems.length-1; 167 168 var objItem = jQuery(objItems[index]); 169 170 return(objItem); 171 } 172 173 174 175 /** 176 * get item number 177 */ 178 function getItemNum(num){ 179 180 var total = getNumTotal(); 181 182 if(jQuery.isNumeric(num) == false) 183 throw new Error("num item should be numeric"); 184 185 if(num >= total ) 186 num = total-1; 187 188 if(num < 0) 189 num = 0; 190 191 if(!num) 192 num = 0; 193 194 if(typeof num == "undefined") 195 num = 0; 196 197 return(num); 198 } 199 200 /** 201 * unselect all selected items if available 202 */ 203 function unselectItems(){ 204 205 var objItem = getObjCurrentItem(); 206 207 if(objItem.length == null){ 208 209 if(g_vars.enableDebug) 210 trace("Unselect Item - Selected Item not found "+g_vars.parent_id); 211 212 return(false); 213 } 214 215 objItem.removeClass(g_vars.class_active); 216 217 if(g_vars.enableDebug) 218 trace("Items Unselected: " + g_vars.parent_id); 219 220 } 221 222 223 /** 224 * change item 225 */ 226 function changeItem(mixed){ 227 228 var numItem = getItemNum(mixed); 229 230 var objItem = getItem(numItem); 231 232 if(objItem == null){ 233 234 if(g_vars.enableDebug) 235 trace("General API: changeItem - item not found"); 236 237 return(false); 238 } 239 240 var numCurrent = getNumCurrent(); 241 242 if(numCurrent === numItem){ 243 244 if(g_vars.enableDebug) 245 trace("General API: changeItem - num current == numitem - skip (" + numItem+" )"); 246 247 return(false); 248 } 249 250 251 if(!g_vars.selector_item_trigger){ 252 253 objItem.trigger(g_vars.trigger_event); 254 return(false); 255 } 256 257 var objInner = objItem.find(g_vars.selector_item_trigger); 258 259 if(objInner.length == 0){ 260 trace(objItem); 261 throw new Error("Can't find inner by selector:"+g_vars.selector_item_trigger); 262 } 263 264 objInner.trigger(g_vars.trigger_event); 265 266 } 267 268 269 270 /* 271 events 272 */ 273 this.onEvent = function(name, func){ 274 275 validateInited(); 276 277 switch(name){ 278 case "change": 279 280 g_objParent.on("uc_change", func); 281 282 break; 283 case "pause": // do nothing 284 break; 285 default: 286 throw new Error("General API: Wrong event: "+name); 287 break; 288 289 } 290 } 291 292 293 /** 294 * do some action 295 */ 296 this.doAction = function(action, arg1, arg2){ 297 298 validateInited(); 299 300 if(g_isTypeEvents == true){ 301 302 var funcRunAction = getVal(g_options, "func_doAction"); 303 304 if(!funcRunAction) 305 throw new Error("Missing option: 'func_doAction' "); 306 307 var response = g_options.func_doAction(action, arg1, arg2); 308 309 return(response); 310 } 311 312 if(g_vars.enableDebug){ 313 trace("Action (General): " + action+" arg1: "+arg1+" arg2: "+arg2); 314 } 315 316 switch(action){ 317 318 case 'get_num_current': 319 320 var current = getNumCurrent(); 321 322 if(g_vars.enableDebug) 323 trace("response: "+current); 324 325 return(current); 326 break; 327 case "get_total_items": 328 329 var total = getNumTotal(); 330 331 if(g_vars.enableDebug) 332 trace("response: "+total); 333 334 return(total); 335 336 break; 337 case 'change_item': 338 339 changeItem(arg1); 340 341 break; 342 case "unselect_items": 343 344 unselectItems(); 345 346 break; 347 case "pause": 348 case "play": 349 break; 350 default: 351 throw new Error("General API: Wrong action: "+action); 352 break; 353 } 354 355 } 356
357 /** 358 * listen to class change 359 */ 360 function initEvents_listenClassChange(){ 361 362 var objItems = getObjItems(); 363 364 if(g_vars.enableDebug == true){ 365 trace("generalAPI: listen class change: "); 366 trace(objItems); 367 } 368 369 jQuery.each(objItems, function(index, item){ 370 371 var objItem = jQuery(item); 372 373 var isSetObserver = objItem.data("uc_set_observer"); 374 if(isSetObserver === true){ 375 return(true); 376 } 377 378 var observer = new MutationObserver(function(records){ 379 380 runWithTrashold(function(){ 381 382 if(g_vars.enableDebug == true) 383 trace("generalAPI: trigger item change"); 384 385 g_objParent.trigger("uc_change"); 386 387 }); 388 389 }); 390 391 var config = { attributes: true}; 392 393 observer.observe(item, config); 394 395 objItem.data("uc_set_observer", true); 396 397 }); 398 399 400 } 401 402 403 /** 404 * add set active events 405 */ 406 function initEvents_setActive(){ 407 408 if(g_vars.enableDebug == true) 409 trace("start initEvents_setActive") 410 411 var objItems = getObjItems(); 412 413 if(objItems.length == 0){ 414 415 if(g_vars.enableDebug == true) 416 trace("no items, exit") 417 418 return(false); 419 } 420 421 //activate first item 422 423 var objFirstItem = getItem(0); 424 425 if(objFirstItem == null){ 426 427 if(g_vars.enableDebug == true) 428 trace("empty first item - exit") 429 430 return(false); 431 } 432 433 434 if(g_vars.active_code_first_unselected !== true) 435 objFirstItem.addClass(g_vars.class_active); 436 else if(g_vars.enableDebug == true) 437 trace("skip activating first item: g_vars.active_code_first_unselected=true"); 438 439 objItems.on(g_vars.trigger_event, function(event){ 440 441 var objItem = jQuery(this); 442 443 //clicked element 444 var objElement = jQuery(event.target); 445 var isLink = objElement.is("a"); 446 447 //quit on link inside 448 if(isLink == true && objElement.hasClass(g_vars.class_items) == false){ 449 450 return(true); 451 } 452 453 objItems.not(objItem).removeClass(g_vars.class_active); 454 455 objItem.addClass(g_vars.class_active); 456 457 g_objParent.trigger("uc_change"); 458 459 event.preventDefault(); 460 461 }); 462 463 464 } 465 466 467 /** 468 * init obzerver events 469 */ 470 function initEvents(){ 471 472 if(g_vars.enableDebug == true){ 473 trace("generalAPI: init events"); 474 trace(g_objParent); 475 } 476 477 if(g_vars.listen_class_change == true) 478 initEvents_listenClassChange(); 479 480 if(g_vars.add_set_active_code == true){ 481 482 initEvents_setActive(); 483 484 } 485 486 } 487 488 489 /** 490 * get element 491 */ 492 this.getElement = function(){ 493 494 return(g_objParent); 495 } 496 497 /** 498 * get api type 499 */ 500 this.getAPIType = function(){ 501 502 return("general"); 503 } 504 505 506 /** 507 * init by classes 508 */ 509 function initByClasses(){ 510 511 try{ 512 513 var widgetName = g_objParent.data("widgetname"); 514 515 g_vars.class_items = getVal(g_options, "class_items"); 516 517 if(!g_vars.class_items){ 518 519 var widgetID = g_objParent.attr("id"); 520 trace("missing class_items in "+widgetID); 521 trace(g_vars); 522 523 throw new Error(widgetName +" - missing 'class_items' option"); 524 } 525 526 g_vars.class_active = getVal(g_options, "class_active"); 527 528 if(!g_vars.class_active) 529 throw new Error(widgetName +" - missing 'class_active' in options"); 530 531 g_vars.parent_id = g_objParent.attr("id"); 532 533 g_vars.selector_item_trigger = getVal(g_options, "selector_item_trigger"); 534 535 g_vars.add_set_active_code = getVal(g_options, "add_set_active_code"); 536 537 g_vars.active_code_first_unselected = getVal(g_options, "active_code_first_unselected"); 538 539 if(g_vars.add_set_active_code === true) 540 g_vars.listen_class_change = false; 541 542 } 543 catch(e){ 544 545 trace("ERROR: "+e); 546 547 trace("passed options: "); 548 trace(g_options); 549 throw e; 550 } 551 } 552 553 554 555 /** 556 * init the api 557 */ 558 this.init = function(objParent, options, isEditor){ 559 560 //not allow to init general api without options 561 if(!options) 562 return(false); 563 564 g_vars.is_editor = isEditor; 565 566 g_objParent = objParent; 567 568 var connectType = getVal(options, "connect_type"); 569 if(connectType == "events") 570 g_isTypeEvents = true; //events allow to connect own functions 571 572 g_options = options; 573 574 var enableDebug = getVal(options, "trace_debug"); 575 576 if(enableDebug == true) 577 g_vars.enableDebug = true; 578 579 if(g_vars.enableDebug == true){ 580 trace("init general api"); 581 trace(objParent); 582 trace(options); 583 } 584 585 if(isEditor == true) 586 g_vars.trigger_event = "ucclick"; 587 588 if(g_isTypeEvents == false)
589 initByClasses(); 590 591 g_objParent.data("remote_inited", true); 592 593 if(g_isTypeEvents == false){ 594 595 if(g_vars.listen_class_change == true) 596 setTimeout(initEvents, 1000); 597 else 598 initEvents(); 599 600 g_objParent.on("uc_ajax_refreshed", function(){ 601 602 setTimeout(initEvents,500) 603 604 }); 605 606 } 607 608 609 return(true); 610 } 611 612} 613 614 615 616/** 617* remote gallery api class 618*/ 619function UERemoteGalleryAPI(){ 620 621 var g_api, g_isInited; 622 var g_objParent; 623 var t = this; 624 625 /** 626 * console log some string 627 */ 628 function trace(str){ 629 console.log(str); 630 } 631 632 /** 633 * validate that the object is inited 634 */ 635 function validateInited(){ 636 637 if(g_isInited == false) 638 throw new Error("The owl carousel API is not inited"); 639 } 640 641 /** 642 do some action 643 */ 644 this.doAction = function(action, arg1, arg2){ 645 646 validateInited(); 647 648 switch(action){ 649 case 'get_num_current': 650 651 var current = g_api.getNumCurrent(); 652 653 return(current); 654 break; 655 case "get_total_items": 656 657 var total = g_api.getNumItems(); 658 659 return(total); 660 break; 661 case 'change_item': 662 663 if(arg1 < 0) 664 arg1 = 0; 665 666 g_api.selectItem(arg1); 667 668 break; 669 case "unselect_items": 670 671 g_api.selectItem(0); 672 673 break; 674 case "is_playing": 675 676 var isPlaying = g_api.isPlaying(); 677 678 return(isPlaying); 679 680 break; 681 case "pause": 682 683 g_api.stop(); 684 685 break; 686 case "play": 687 688 g_api.play(); 689 break; 690 default: 691 throw new Error("GALLERY API: Wrong action: "+action); 692 break; 693 } 694 695 } 696 697 /* 698 events 699 */ 700 this.onEvent = function(name, func){ 701 702 validateInited(); 703 704 switch(name){ 705 case "change": 706 g_api.on("item_change", func); 707 break; 708 case "play": 709 g_api.on("play",func); 710 break; 711 case "pause": 712 g_api.on("stop",func); 713 break; 714 default: 715 throw new Error("Gallery API: Wrong event: "+name); 716 break; 717 718 } 719 } 720 721 722 /** 723 * get element 724 */ 725 this.getElement = function(){ 726 727 return(g_objParent); 728 } 729 730 731 /** 732 * get api type 733 */ 734 this.getAPIType = function(){ 735 736 return("gallery"); 737 } 738 739 740 /** 741 * init the api 742 */ 743 this.init = function(objParent, options){ 744 745 g_api = objParent.data("unitegallery-api"); 746 if(!g_api) 747 return(false); 748 749 g_objParent = objParent; 750 751 g_isInited = true; 752 753 return(true); 754 } 755 756 757 758} 759 760 761/** 762* remote carousel api class 763*/ 764function UERemoteCarouselAPI(){ 765 766 var g_owlCarousel, g_owl, g_isInited; 767 var t = this; 768 var g_enableDebug = false; 769 770 771 /** 772 * console log some string 773 */ 774 function trace(str){ 775 console.log(str); 776 } 777 778 /** 779 * validate that the object is inited 780 */ 781 function validateInited(){ 782 783 if(g_isInited == false) 784 throw new Error("The owl carousel API is not inited"); 785 } 786 787 /** 788 * get total items 789 */ 790 function getTotalItems(){ 791 792 var objCarousel = g_owlCarousel.eq(0); 793 794 var objItems = objCarousel.find(".owl-item:not(.cloned)").filter(function(){ 795 796 return(jQuery(this).closest(".owl-carousel")[0] === objCarousel[0]); 797 }); 798 799 var total = objItems.length; 800 801 return(total); 802 } 803 804 /** 805 * reset the autoplay if exists 806 */ 807 function resetAutoplay(){ 808 809 if(g_owl.settings.autoplay == false) 810 return(false); 811 812 g_owlCarousel.trigger('stop.owl.autoplay'); 813 g_owlCarousel.trigger('play.owl.autoplay'); 814 815 } 816 817 /** 818 do some action 819 */ 820 this.doAction = function(action, arg1, arg2){ 821 822 validateInited(); 823 824 if(g_enableDebug == true){ 825 826 var strAction = action; 827 828 if(arg1) 829 strAction += " "+arg1; 830 831 if(arg2) 832 strAction += " "+arg2; 833 834 trace("carousel action: "+strAction); 835 } 836 837 switch(action){ 838 case "next": 839 g_owlCarousel.trigger('next.owl.carousel'); 840 break; 841 case "prev": 842 g_owlCarousel.trigger('prev.owl.carousel'); 843 break; 844 case "play": 845 846 g_owlCarousel.trigger('start_autoplay.owl.autoplay'); 847 848 break; 849 case "pause": 850 851 g_owlCarousel.trigger('stop.owl.autoplay'); 852 853 break; 854 case "is_playing": 855 856 if (g_owl.settings.autoplay == true) 857 return(true) 858 else 859 return(false); 860 861 break; 862 case "get_total_items": 863 864 var total = getTotalItems() 865 866 return(total); 867 868 break; 869 case "get_progress_time": 870 871 var progressTime = g_owl.settings.autoplayTimeout / 1000; 872 return(progressTime); 873 874 break;
875 case "get_modified_progress_time": 876 877 var progressTime = (g_owl.settings.autoplayTimeout - g_owl.settings.smartSpeed) / 1000; 878 return(progressTime); 879 880 break; 881 case 'get_num_current': 882 883 var currentItem = g_owl.relative(g_owl.current()); 884 885 if(g_enableDebug === true){ 886 trace("num current: " + currentItem); 887 } 888 889 return(currentItem); 890 break; 891 case "get_total_text": 892 893 var owlTotalItems = getTotalItems(); 894 if(owlTotalItems.toString().length < 2){ 895 owlTotalItems = "0" + owlTotalItems; 896 } 897 return(owlTotalItems); 898 899 break; 900 case "get_current_text": 901 902 var owlCurrentItem = g_owl.relative(g_owl.current()) + 1; 903 if(owlCurrentItem.toString().length < 2){ 904 owlCurrentItem = "0" + owlCurrentItem; 905 } 906 return(owlCurrentItem); 907 908 break; 909 case 'change_item': 910 911 var total = getTotalItems() 912 var currentItem = g_owl.relative(g_owl.current()); 913 914 var slideNum = arg1; 915 916 if(slideNum == currentItem) 917 return(false); 918 919 if(slideNum >= total) 920 slideNum = (total-1); 921 else 922 if(slideNum < 0) 923 slideNum = 0; 924 925 g_owlCarousel.trigger('to.owl.carousel', [slideNum, null, true]); 926 927 resetAutoplay(); 928 929 break; 930 case "unselect_items": 931 break; 932 default: 933 throw new Error("Carousel API: Wrong action: "+action); 934 break; 935 } 936 937 } 938 939 940 /* 941 events 942 */ 943 this.onEvent = function(name, func){ 944 945 validateInited(); 946 947 switch(name){ 948 case "play": 949 950 g_owlCarousel.on("play_autoplay.owl.carousel", func); 951 952 break; 953 case "pause": 954 955 g_owlCarousel.on("stop_autoplay.owl.carousel", func); 956 957 break; 958 case "change": 959 960 g_owlCarousel.on("changed.owl.carousel", func); 961 962 break; 963 case "transition_start": 964 965 g_owlCarousel.on("translate.owl.carousel", func); 966 967 break; 968 case "transition_end": 969 970 g_owlCarousel.on("translated.owl.carousel", func); 971 972 break; 973 case "refreshed": 974 975 g_owlCarousel.on("refreshed.owl.carousel", func); 976 977 break; 978 default: 979 console.error("Carousel API: Wrong event: "+name); 980 throw new Error("Carousel API: Wrong event: "+name); 981 break; 982 983 } 984 } 985 986 /** 987 * get api type 988 */ 989 this.getAPIType = function(){ 990 991 return("carousel"); 992 } 993 994 /** 995 * get the element 996 */ 997 this.getElement = function(){ 998 999 return(g_owlCarousel); 1000 } 1001 1002 1003 /** 1004 * init the api 1005 */ 1006 this.init = function(objParent){ 1007 1008 if(typeof ucRemoteDebugEnabled != "undefined") 1009 g_enableDebug = true; 1010 1011 if(objParent.length > 1) 1012 objParent = objParent.first(); 1013 1014 if(objParent.hasClass("owl-carousel") == false) 1015 throw new Error("owl-carousel class not found"); 1016 1017 g_owlCarousel = objParent; 1018 1019 g_owl = g_owlCarousel.data("owl.carousel"); 1020 1021 g_owlCarousel.on("uc_ajax_refreshed", onAjaxRefreshed); 1022 1023 if(!g_owl) 1024 return(false); 1025 1026 g_isInited = true; 1027 1028 1029 return(true); 1030 } 1031 1032 /** 1033 * on ajax refreshed 1034 */ 1035 function onAjaxRefreshed(){ 1036 1037 g_owl = g_owlCarousel.data("owl.carousel"); 1038 1039 } 1040 1041 1042} 1043 1044/** 1045 * sync object 1046 */ 1047function UESyncObject(){ 1048 1049 var g_objApis = {}; 1050 var g_groupName, g_objIDs; 1051 var t = this; 1052 1053 var g_vars = { 1054 is_editor:false, 1055 is_editor_func_started:false, 1056 show_debug:false 1057 }; 1058 1059 /** 1060 * console log some string 1061 */ 1062 function trace(str){ 1063 console.log(str); 1064 } 1065 1066 1067 1068 /** 1069 * validate api, that they match the existing by number of items 1070 */ 1071 function validate(objAPI){ 1072 1073 if(g_objApis.length == 0) 1074 return(false); 1075 1076 var numItems = objAPI.doAction("get_total_items"); 1077 1078 //check with first existing api number of items 1079 for(var elID in g_objApis){ 1080 1081 var firstExistingAPI = g_objApis[elID]; 1082 1083 var numItemsExisting = firstExistingAPI.doAction("get_total_items"); 1084 1085 if(numItemsExisting !== numItems){ 1086 1087 var objElement = objAPI.getElement(); 1088 var elementID = objElement.attr("id"); 1089 1090 trace("Sync failed "+elementID+" has "+numItems+" items and "+elID+" has "+numItemsExisting+ " items"); 1091 1092 throw new Error("Sync failed, number of items should be the same. Now it's "+numItems+" and "+numItemsExisting); 1093 } 1094 1095 return(false); 1096 } 1097 1098 1099 } 1100 1101 1102 /** 1103 * set options 1104 */ 1105 this.setOptions = function(groupName, isEditor){ 1106 1107 if(isEditor === true) 1108 g_vars.is_editor = true; 1109 1110 if(!g_groupName) 1111 g_groupName = groupName; 1112 1113 } 1114 1115 1116 /** 1117 * get api parent id 1118 */ 1119 function getElementID(objAPI){ 1120 1121 var objElement = objAPI.getElement(); 1122 1123 var elementID = objElement.attr("id"); 1124 1125 return(elementID); 1126 } 1127 1128 1129 /** 1130 * get all ips except the given 1131 */ 1132 function mapAPIs(func, objElement){ 1133 1134 if(typeof ucRemoteDebugEnabled != "undefined") 1135 g_vars.show_debug = true; 1136 1137 var elementID = null; 1138 1139 if(objElement){ 1140 1141 var elementID = objElement.attr("id"); 1142 1143 if(g_objApis.length == 1) 1144 return(null); 1145 } 1146 1147 for(var elID in g_objApis){ 1148 1149 var api = g_objApis[elID]; 1150 1151 //except if exists 1152 if(elementID && elID == elementID) 1153 continue; 1154 1155 func(api); 1156 1157 } 1158 1159 } 1160 1161 1162 /** 1163 * activate change command on all other apis 1164 */ 1165 function onItemChange(objAPI){ 1166 1167 var numCurrent = objAPI.doAction("get_num_current"); 1168 1169 var objElement = objAPI.getElement(); 1170 1171 if(g_vars.show_debug == true){ 1172 1173 trace("sync onchange: " + numCurrent); 1174 trace(objElement); 1175 trace(g_objApis); 1176 } 1177 1178 mapAPIs(function(api){ 1179 1180 if(numCurrent < 0) 1181 api.doAction("unselect_items"); 1182 else 1183 api.doAction("change_item", numCurrent); 1184 1185 }, objElement); 1186 1187 } 1188
1189 /** 1190 * on pause - pause others as well 1191 */ 1192 function onPause(objAPI){ 1193 1194 var objElement = objAPI.getElement(); 1195 1196 mapAPIs(function(api){ 1197 1198 api.doAction("pause"); 1199 1200 }, objElement); 1201 1202 1203 } 1204 1205 1206 /** 1207 * trigger some action 1208 */ 1209 function trigger(action, params){ 1210 1211 var realAction = "uc_remote_sync_"+g_groupName+"_action_"+action; 1212 1213 jQuery("body").trigger(realAction, params); 1214 } 1215 1216 1217 /** 1218 * on event 1219 */ 1220 this.on = function(action, func){ 1221 1222 var realAction = "uc_remote_sync_"+g_groupName+"_action_"+action; 1223 1224 jQuery("body").on(realAction, func); 1225 1226 } 1227 1228 1229 /** 1230 * get debug text 1231 */ 1232 this.getDebugText = function(objElement){ 1233 1234 var text = "sync group: <b>" + g_groupName+"</b>, "; 1235 1236 var textWidgets = ""; 1237 1238 mapAPIs(function(api){ 1239 1240 var objElement = api.getElement(); 1241 var widgetName = objElement.data("widgetname"); 1242 var widgetID = objElement.attr("id"); 1243 1244 if(textWidgets) 1245 textWidgets += ", "; 1246 1247 textWidgets += "<a href='#"+widgetID+"' style='color:green;text-decoration:underline'><b>" + widgetName + "</b></a>"; 1248 1249 }, objElement); 1250 1251 if(textWidgets) 1252 text += "sync with: " + textWidgets; 1253 1254 return(text); 1255 } 1256 1257 1258 /** 1259 * remove deleted from page APIs 1260 */ 1261 function removeDeletedAPIs(){ 1262 1263 var objAPIsNew = {}; 1264 1265 mapAPIs(function(api){ 1266 1267 var elementID = getElementID(api); 1268 var objElement = jQuery("#"+elementID); 1269 1270 if(objElement.length == 0) 1271 return(false); 1272 1273 var parent = objElement.parent(); 1274 1275 objAPIsNew[elementID] = api; 1276 1277 }); 1278 1279 g_objApis = objAPIsNew; 1280 1281 } 1282 1283 1284 /** 1285 * on editor check 1286 */ 1287 function onEditorCheck(){ 1288 1289 removeDeletedAPIs(); 1290 1291 trigger("update_debug", g_groupName); 1292 1293 } 1294 1295 /** 1296 * get group name 1297 */ 1298 this.getGroupName = function(){ 1299 1300 return(g_groupName); 1301 } 1302 1303 /** 1304 * add widget to sync object 1305 */ 1306 this.addAPI = function(objAPI){ 1307 1308 1309 var id = getElementID(objAPI); 1310 1311 if(g_objApis.hasOwnProperty(id)) 1312 return(false); 1313 1314 g_objApis[id] = objAPI; 1315 1316 if(g_vars.is_editor == true) 1317 removeDeletedAPIs(); 1318 1319 validate(objAPI); 1320 1321 1322 //debug 1323 var objElement = objAPI.getElement(); 1324 1325 //add debug 1326 trigger("update_debug", g_groupName); 1327 1328 //set events 1329 objAPI.onEvent("change", function(){ 1330 1331 onItemChange(objAPI); 1332 1333 }); 1334 1335 //sync objects pause 1336 1337 objAPI.onEvent("pause", function(){ 1338 1339 onPause(objAPI); 1340 }); 1341 1342 1343 if(g_vars.is_editor == true && g_vars.is_editor_func_started == false){ 1344 1345 setInterval(onEditorCheck, 700); 1346 g_vars.is_editor_func_started = false; 1347 } 1348 1349 1350 } 1351 1352 /** 1353 * get all elements 1354 */ 1355 this.getElements = function(exceptID){ 1356 1357 if(!g_objApis) 1358 return(null); 1359 1360 var arrElements = []; 1361 1362 //check with first existing api number of items 1363 for(var elID in g_objApis){ 1364 1365 if(exceptID && exceptID == elID) 1366 continue; 1367 1368 var objApi = g_objApis[elID]; 1369 1370 var objElement = objApi.getElement(); 1371 1372 arrElements.push(objElement); 1373 } 1374 1375 if(arrElements.length == 0) 1376 return(null); 1377 1378 return(arrElements); 1379 } 1380 1381} 1382 1383/** 1384* --------------------------------------------------- 1385* remote widget api class 1386*/ 1387function UERemoteWidgets(){ 1388 1389 var g_objParent, g_objWidget, g_parentID; 1390 var g_api, g_objSync, g_remoteConnection = window.ueRemoteConnection; 1391 var t = this; 1392 1393 var g_vars = { 1394 is_inited:false, 1395 funcOnInit:null, 1396 is_editor:null, 1397 widget_id:null, 1398 init_options:null, 1399 is_parent_mode: false, 1400 syncid:null, 1401 options_api:null, 1402 show_connection_debug:false, 1403 debug_show_ids:false, 1404 debug_show_widget: "", 1405 trace_debug:false //debug 1406 }; 1407 1408 var g_types = { 1409 CAROUSEL:"carousel", 1410 GALLERY:"gallery", 1411 GENERAL:"general" 1412 }; 1413 1414 1415 /** 1416 * console log some string 1417 */ 1418 function trace(str){ 1419 console.log(str); 1420 } 1421 1422 /** 1423 * get object property 1424 */ 1425 function getVal(obj, name, defaultValue){ 1426 1427 return window.ueRemoteConnection.getVal(obj, name, defaultValue); 1428 } 1429 1430 1431 1432 function _______INIT_________(){} 1433 1434 /** 1435 * init widget 1436 */ 1437 function initWidget(widgetID){ 1438 1439 g_objWidget = jQuery("#"+widgetID); 1440 if(g_objWidget.length == 0) 1441 throw new Error("Widget not found by id: "+widgetID); 1442 1443 g_vars.widget_id = widgetID; 1444 1445 var forceID = getVal(g_vars.init_options, "force_parentid"); 1446 1447 if(forceID) 1448 g_parentID = forceID; 1449 else 1450 g_parentID = g_objWidget.data("parentid"); 1451 1452 if(!g_parentID) 1453 throw new Error("Parent controlled ID not set"); 1454 1455 } 1456
1457 /** 1458 * get controlled parent type 1459 */ 1460 function getParentType(){ 1461 1462 if(!g_objParent || g_objParent.length == 0) 1463 throw new Error("getParentType: no parent found"); 1464 1465 if(g_objParent.hasClass("owl-carousel")) 1466 return(g_types.CAROUSEL); 1467 1468 var dataType = g_objParent.data("remote-type"); 1469 1470 switch(dataType){ 1471 case "gallery": 1472 return g_types.GALLERY; 1473 break; 1474 } 1475 1476 1477 return(g_types.GENERAL); 1478 } 1479 1480 1481 /** 1482 * get offsets distance 1483 */ 1484 function getOffsetsDistance(offset1, offset2){ 1485 1486 var dx = offset2.left-offset1.left; 1487 var dy = offset2.top-offset1.top; 1488 1489 return Math.sqrt(dx*dx+dy*dy); 1490 } 1491 1492 1493 /** 1494 * get closest object by offset 1495 */ 1496 function getClosestByOffset(objParents, objElement){ 1497 1498 var objClosest = null; 1499 var minDiff = 1000000; 1500 1501 var elementOffset = objElement.offset(); 1502 1503 if(g_vars.trace_debug){ 1504 trace("Widget Offset: "); 1505 trace(elementOffset); 1506 } 1507 1508 jQuery.each(objParents, function(index, parent){ 1509 1510 var objParent = jQuery(parent); 1511 var parentOffset = objParent.offset(); 1512 1513 if(parentOffset.top == 0){ 1514 1515 var firstParent = getWidgetContainer(objParent); 1516 var parentOffset = firstParent.offset(); 1517 1518 } 1519 1520 var distance = getOffsetsDistance(parentOffset, elementOffset); 1521 1522 if(g_vars.trace_debug){ 1523 trace("Parent offset: "); 1524 trace(objParent); 1525 trace(parentOffset); 1526 trace("distance: " + distance); 1527 } 1528 1529 if(distance < minDiff){ 1530 minDiff = distance; 1531 objClosest = objParent; 1532 } 1533 1534 }); 1535 1536 return(objClosest); 1537 } 1538 1539 /** 1540 * filter parents by section 1541 */ 1542 function filterParentsBySection(objParents, objElement){ 1543 1544 var objSection = objElement.closest(".elementor-top-section"); 1545 1546 if(objSection.length == 0) 1547 return(objParents); 1548 1549 var section = objSection[0]; 1550 1551 var objFiltered = objParents.filter(function(index, parent){ 1552 1553 var isContains = jQuery.contains(section, parent); 1554 1555 return isContains; 1556 }); 1557 1558 if(objFiltered.length) 1559 return(objFiltered); 1560 1561 return(objParents); 1562 } 1563 1564 1565 /** 1566 * detect closest parent 1567 */ 1568 function detectClosestParent(objParents){ 1569 1570 var objContainer = jQuery("body"); 1571 1572 //twick for tempalte switcher 1573 var objTemplateHolder = g_objWidget.closest(".uc-template-holder"); 1574 1575 if(objTemplateHolder.length) 1576 objContainer = objTemplateHolder; 1577 1578 if(!objParents) 1579 var objParents = objContainer.find(".uc-remote-parent").not(g_objWidget); 1580 1581 if(g_vars.trace_debug){ 1582 trace("detect closest start. group:"); 1583 trace(objParents); 1584 } 1585 1586 var numParents = objParents.length; 1587 1588 if(numParents == 0) 1589 return(null); 1590 1591 if(numParents == 1) 1592 return(objParents); 1593 1594 //filter by auto 1595 1596 if(g_vars.trace_debug) 1597 trace("filter auto"); 1598 1599 var objParentsFiltered = objParents.filter("[data-remoteid='"+g_parentID+"']"); 1600 1601 if(objParentsFiltered.length == 1) 1602 return(objParentsFiltered); 1603 1604 //find by offset 1605 1606 if(g_vars.trace_debug){ 1607 trace("filter by section"); 1608 } 1609 1610 var objParents = filterParentsBySection(objParents, g_objWidget); 1611 1612 if(g_vars.trace_debug){ 1613 trace(objParents); 1614 } 1615 1616 if(objParents.length == 1) 1617 return(objParents); 1618 1619 if(g_vars.trace_debug) 1620 trace("get closest by parent"); 1621 1622 var objClosest = getClosestByOffset(objParents, g_objWidget); 1623 1624 if(objClosest) 1625 return(objClosest); 1626 1627 if(g_vars.trace_debug) 1628 trace("get first"); 1629 1630 var firstParent = jQuery(objParentsFiltered[0]); 1631 1632 1633 return(firstParent); 1634 } 1635 1636 /** 1637 * set parent object 1638 */ 1639 function setParentObject(){ 1640 1641 var objForceParent = getVal(g_vars.init_options, "force_parent_obj"); 1642 1643 var widgetID = g_objWidget.attr("id"); 1644 1645 if(g_vars.trace_debug) 1646 trace("start set parent for: "+widgetID+", parent name: "+g_parentID); 1647 1648 if(objForceParent){ 1649 1650 g_objParent = objForceParent; 1651 1652 if(g_vars.trace_debug){ 1653 trace("set force parent"); 1654 trace(g_objParent); 1655 } 1656 1657 return(true); 1658 } 1659 1660 1661 if(!g_parentID) 1662 throw new Error("Parent controller ID not found"); 1663 1664 if(!g_objParent || g_objParent.length == 0){ 1665 1666 if(g_parentID == "auto"){ 1667 1668 if(g_vars.trace_debug){ 1669 trace("auto detect selected"); 1670 } 1671 1672 g_objParent = detectClosestParent(); 1673 1674 if(g_vars.trace_debug){ 1675 trace("detect closest"); 1676 trace(g_objParent); 1677 } 1678 1679 if(!g_objParent) 1680 throw new Error("Can't detect remote parent"); 1681 1682 } 1683 else{ 1684 1685 var objParents = jQuery(".uc-remote-parent[data-remoteid='"+g_parentID+"']").not(g_objWidget); 1686 1687 if(g_vars.trace_debug) 1688 trace("Detect from group: "+g_parentID); 1689 1690 g_objParent = detectClosestParent(objParents); 1691 1692 if(g_vars.trace_debug){ 1693 trace("detected from group"); 1694 trace(g_objParent); 1695 } 1696 1697 if(!g_objParent || g_objParent.length == 0){ 1698 1699 //set another try 1700 var isAnotherTry = g_objWidget.data("uc_parent_detect_another_try"); 1701 if(!isAnotherTry){ 1702 g_objWidget.data("uc_parent_detect_another_try", true); 1703 1704 if(g_vars.trace_debug) 1705 trace("Set another try for parent detect"); 1706 1707 return(false); 1708 } 1709 1710 throw new Error("Parent widget with remote name: '"+g_parentID+"' not found"); 1711 } 1712 1713 } 1714 1715 } 1716 1717 if(g_objParent && g_objParent.length > 1){ 1718 g_objParent = jQuery(g_objParent[0]); 1719 } 1720 1721 if(g_vars.trace_debug == true){ 1722 1723 var parentID = g_objParent.attr("id"); 1724 var widgetID = g_objWidget.attr("id"); 1725 1726 trace("widget: "+widgetID+" connected to: "+parentID); 1727 1728 } 1729 1730 if(!g_objParent || g_objParent.length == 0) 1731 throw new Error("Remote parent not found"); 1732 1733 return(true); 1734 } 1735 1736 1737 /** 1738 * init api variable 1739 */ 1740 function initAPI(){ 1741 1742 if(g_vars.trace_debug == true){ 1743 trace("start init api function"); 1744 } 1745 1746 //set type and related objects 1747 if(!g_api){ 1748 1749 var parentType = getParentType(); 1750 1751 1752 if(!parentType){ 1753 trace(g_objParent); 1754 throw new Error("No parent type found"); 1755 } 1756 1757 if(g_vars.trace_debug == true){ 1758 1759 trace("init api: " + parentType); 1760 trace(g_objParent); 1761 } 1762 1763 //init the api 1764 switch(parentType){ 1765 case g_types.CAROUSEL: 1766 g_api = new UERemoteCarouselAPI(); 1767 break; 1768 case g_types.GENERAL: 1769 1770 g_api = new UERemoteGeneralAPI(); 1771 1772 break; 1773 case g_types.TABS: 1774 1775 //g_api = new UERemoteTabsAPI(); 1776 g_api = new UERemoteGeneralAPI(); 1777 1778 break; 1779 case g_types.GALLERY: 1780 1781 g_api = new UERemoteGalleryAPI(); 1782 1783 break; 1784 default: 1785 throw new Error("Wrong parent type: "+parentType); 1786 break; 1787 } 1788 1789 } 1790 1791 var optionsFromData = g_objParent.data("uc-remote-options"); 1792 1793 var isEditor = isInsideEditor(); 1794 1795 if(optionsFromData) 1796 g_vars.options_api = optionsFromData; 1797 1798 var optionsAPI = {}; 1799 1800 var optionsAPI = jQuery.extend({},g_vars.options_api); 1801 1802 if(jQuery.isEmptyObject(g_vars.options_api) == false) 1803 jQuery.extend({},optionsAPI, g_vars.options_api); 1804 1805 if(g_vars.trace_debug == true){ 1806 1807 if(optionsAPI) 1808 trace(optionsAPI); 1809 1810 optionsAPI["trace_debug"] = true; 1811 } 1812 1813 var isInited = g_api.init(g_objParent, g_vars.options_api, isEditor); 1814 1815 if(g_vars.trace_debug == true){ 1816 trace("inited: " + isInited); 1817 } 1818 1819 return(isInited); 1820 } 1821 1822 1823 /** 1824 * init parent 1825 */ 1826 function initParent(){ 1827
1828 var isParentSet = setParentObject(); 1829 1830 if(isParentSet == false) 1831 return(false); 1832 1833 var isInited = initAPI(); 1834 1835 return(isInited); 1836 } 1837 1838 1839 /** 1840 init global helper function 1841 */ 1842 function initGlobal(widgetID, func){ 1843 1844 if(!g_objWidget) 1845 initWidget(widgetID); 1846 1847 //init the debug related 1848 1849 var isDebug = g_objWidget.data("debug"); 1850 if(isDebug === true || typeof ucRemoteDebugEnabled != "undefined"){ 1851 1852 g_vars.trace_debug = true; 1853 g_vars.show_connection_debug = true; 1854 1855 } 1856 1857 if(g_vars.trace_debug){ 1858 if(!widgetID) 1859 widgetID = g_objWidget.attr("id"); 1860 1861 trace("Initing Remote Widget: "+widgetID); 1862 } 1863 1864 g_vars.is_inited = initParent(); 1865 1866 if(g_vars.is_inited == false){ 1867 1868 if(!g_objParent){ 1869 1870 setTimeout(func, 1000); //try onWidgetInit in a second again 1871 1872 }else{ 1873 1874 if(g_vars.trace_debug == true){ 1875 1876 trace(g_objParent); 1877 trace("set object ready event"); //onWidgetInit 1878 } 1879 1880 g_objParent.on("uc-object-ready", func); 1881 1882 } 1883 1884 1885 } 1886 } 1887 1888 1889 /** 1890 * set action, bind to some object 1891 * objElement can be jQuery object or selector 1892 */ 1893 this.setAction = function(action, objElement, allowMultiple){ 1894 1895 if(g_vars.trace_debug == true){ 1896 trace("set action: "+action); 1897 } 1898 1899 if(g_vars.is_inited == false) 1900 throw new Error("Widget not inited"); 1901 1902 if(typeof objElement == "string"){ 1903 var selector = objElement; 1904 objElement = g_objWidget.find(objElement); 1905 if(objElement.length == 0) 1906 throw new Error("Remote '"+action+"' action error: element: "+selector+" not found"); 1907 } 1908 1909 if(!objElement || objElement.length == 0) 1910 throw new Error("Element not inited"); 1911 1912 if(!g_api) 1913 throw new Error("API not inited!"); 1914 1915 //avoid double action 1916 var linkedAction = objElement.data("uc-action"); 1917 1918 if(allowMultiple !== true) 1919 if(linkedAction){ 1920 1921 trace("not allow multiple action: "+action); 1922 1923 return(false); 1924 } 1925 1926 objElement.data("uc-action", action); 1927 1928 objElement.on("click",function(){ 1929 1930 var objElement = jQuery(this); 1931 1932 if(objElement.hasClass("uc-disabled")) 1933 return(true); 1934 1935 t.doAction(action); 1936 1937 }); 1938 1939 } 1940 1941 1942 /** 1943 * run this function after the widget is ready to use 1944 */ 1945 function onWidgetReady(){ 1946 1947 checkWidgetDebug(); 1948 1949 var isEditorMode = isInsideEditor(); 1950 1951 //in editor mode check debug every second 1952 1953 if(isEditorMode == true){ 1954 1955 hideErrorOnWidget(); 1956 1957 setInterval(checkWidgetInsideEditor, 700); 1958 } 1959 1960 1961 } 1962 1963 1964 function _______TEXT_ON_WIDGET_________(){} 1965 1966 1967 /** 1968 * hide error on widget 1969 */ 1970 function hideErrorOnWidget(){ 1971 1972 if(!g_objWidget || g_objWidget.length == 0) 1973 return(false); 1974 1975 var objParent = getWidgetContainer(g_objWidget); 1976 1977 //don't hide if no message 1978 1979 var objError = objParent.find('.uc-remote-error'); 1980 1981 if(objError.length == 0) 1982 return(false); 1983 1984 if(objError.is(":visible") == false) 1985 return(false); 1986 1987 objError.hide(); 1988 1989 g_objWidget.css({ 1990 "border" : "none" 1991 }); 1992 1993 //try to set the debug if avaliable 1994 checkWidgetDebug(); 1995 1996 } 1997 1998 /** 1999 * get widget container 2000 */ 2001 function getWidgetContainer(objWidget){ 2002 2003 objParent = objWidget.parent(); 2004 2005 return(objParent); 2006 } 2007 2008 2009 /** 2010 * add error message div on the widget div 2011 * 2012 */ 2013 function addTextDiv(objWidget, type){ 2014 2015 var objParent = getWidgetContainer(objWidget); 2016 2017 var isDebug = (type == "debug"); 2018 2019 var className = "uc-remote-error"; 2020 if(isDebug == true) 2021 className = "uc-remote-debug"; 2022 2023 var divText = "<div class='"+className+"'></div>"; 2024 objParent.append(divText); 2025 2026 var objError = objParent.find('.'+className+''); 2027 2028 var css = { 2029 "position":"absolute", 2030 "color":"red", 2031 "top":"-30px", 2032 "left":"0px", 2033 "z-index":"999999", 2034 "background-color":"#ffffff" 2035 }; 2036 2037 if(isDebug == true){ 2038 css["color"] = "green"; 2039 css["z-index"] = "999998"; 2040 } 2041 2042 //fix position for bg 2043 var objParentsBG = objParent.parents(".unlimited-elements-background-overlay"); 2044 if(objParentsBG.length){ 2045 css["top"] = "0px"; 2046 } 2047 2048 objError.css(css); 2049 2050 var objError = objParent.find('.'+className+''); 2051 2052 return(objError); 2053 } 2054 2055 /** 2056 * display some error on widget interface 2057 */ 2058 function displayTextOnWidget(objWidget, message, type){ 2059 2060 var isDebug = (type == "debug"); 2061 2062 var className = "uc-remote-error"; 2063 if(isDebug == true) 2064 className = "uc-remote-debug"; 2065 2066 var objParent = getWidgetContainer(objWidget); 2067 2068 objText = objParent.find("."+className); 2069
2070 //add error div if missing. pause error in editor 2071 //second time the div will be not empty and it will show the message 2072 if(objText.length == 0){ 2073 2074 objText = addTextDiv(objWidget, type); 2075 2076 if(isDebug == false){ 2077 2078 var isInEditor = isInsideEditor(); 2079 2080 if(isInEditor == true){ 2081 2082 setTimeout(function(){ 2083 displayTextOnWidget(objWidget, message, type); 2084 },2000); 2085 2086 return(false); 2087 } 2088 2089 } 2090 2091 } 2092 2093 //add the error border 2094 if(isDebug == false){ 2095 2096 objWidget.css({ 2097 "border" : "2px solid red", 2098 "position" : "relative" 2099 }); 2100 2101 } 2102 2103 objText.show(); 2104 objText.html(message); 2105 2106 } 2107 2108 2109 /** 2110 * display error message 2111 */ 2112 function displayErrorMessage(message){ 2113 2114 if(typeof g_ucRemoteHideErrors !== "undefined" && g_ucRemoteHideErrors === true){ 2115 2116 trace("UE Remote Error: "+message); 2117 2118 return(false); 2119 } 2120 2121 2122 if(g_vars.is_parent_mode == false){ 2123 2124 if(g_objWidget && g_objWidget.length) 2125 displayTextOnWidget(g_objWidget, message,"error"); 2126 2127 }else{ 2128 2129 displayTextOnWidget(g_objParent, message, "error"); 2130 2131 } 2132 2133 //console.log("UE Remote Error: "+message); 2134 //console.log(message); 2135 2136 } 2137 2138 function _______DEBUG_________(){} 2139 2140 2141 /** 2142 * return if the debug is active 2143 */ 2144 function isDebugActive(objWidget){ 2145 2146 if(!objWidget) 2147 objWidget = g_objWidget; 2148 2149 var isActive = objWidget.data("debug_active"); 2150 2151 if(isActive === true) 2152 return(true); 2153 2154 return(false); 2155 } 2156 2157 2158 /** 2159 * remove debug visual from the widget 2160 */ 2161 function removeDebugVisual(objWidget){ 2162 2163 if(!objWidget) 2164 objWidget = g_objWidget; 2165 2166 g_objWidget.data("debug_active", false); 2167 2168 g_objWidget.css({ 2169 "border-style":"none" 2170 }); 2171 2172 } 2173 2174 2175 /** 2176 * set debug visual 2177 */ 2178 function setDebugVisual(color, objWidget){ 2179 2180 if(!objWidget) 2181 objWidget = g_objWidget; 2182 2183 objWidget.data("debug_active", true); 2184 2185 objWidget.css({ 2186 "border-style":"solid", 2187 "border-width":"3px", 2188 "border-color":color 2189 }); 2190 2191 } 2192 2193 /** 2194 * check if parent debug is active 2195 */ 2196 function isParentDebugActive(objParent){ 2197 2198 var dataDebug = objParent.data("debug"); 2199 var isDebug = (dataDebug === true); 2200 2201 return(isDebug); 2202 } 2203 2204 2205 /** 2206 * check widget debug work 2207 */ 2208 function checkWidgetDebugWork(objWidget, objParent){ 2209 2210 if(!objWidget) 2211 objWidget = g_objWidget; 2212 2213 if(!objParent) 2214 objParent = g_objParent; 2215 2216 var isDebug = isParentDebugActive(objParent); 2217 2218 var isActive = isDebugActive(objWidget); 2219 2220 /* 2221 trace("check! "+isActive+" "+isDebug); 2222 trace(objParent); 2223 trace(objWidget); 2224 */ 2225 2226 //remove debug if active but no need 2227 2228 if(isDebug == false){ 2229 2230 if(isActive == true) 2231 removeDebugVisual(objWidget); 2232 2233 return(false); 2234 } 2235 2236 //add debug is not in debug mode 2237 2238 if(isActive == false){ 2239 2240 //get parent color 2241 var color = addParentDebug(objParent); 2242 setDebugVisual(color, objWidget); 2243 2244 } 2245 2246 2247 } 2248 2249 /** 2250 * check and put debug connection 2251 */ 2252 function checkDebugConnectionText(){ 2253 2254 if(!g_objWidget) 2255 return(false); 2256 2257 if(g_vars.show_connection_debug == false) 2258 return(false); 2259 2260 if(!g_objParent || g_objParent.length == 0) 2261 throw new Error("Not conneted to no parent"); 2262 2263 var widgetName = g_objParent.data("widgetname"); 2264 var widgetID = g_objParent.attr("id"); 2265 2266 var text = "connected to <a href='#"+widgetID+"' style='color:green;text-decoration:underline'><b>" + widgetName + "</b></a>"; 2267 2268 displayTextOnWidget(g_objWidget, text, "debug"); 2269 2270 } 2271 2272 2273 /** 2274 * check widget debug 2275 */ 2276 function checkWidgetDebug(){ 2277 2278 var noDebugCheck = getVal(g_vars.init_options, "no_debug_check"); 2279 2280 if(noDebugCheck === true) 2281 return(false); 2282 2283 //get debug color 2284 if(!g_objParent || g_vars.is_inited == false){ 2285 removeDebugVisual(); 2286 return(false); 2287 } 2288 2289 checkWidgetDebugWork(); 2290 2291 checkDebugConnectionText(); 2292 2293 } 2294 2295 /** 2296 * on api event 2297 */ 2298 this.onEvent = function(name, func){ 2299 g_api.onEvent(name,func); 2300 } 2301 2302 2303 /** 2304 * change item by action (0 - total-1) 2305 */ 2306 function changeItemByAction(dir){ 2307 2308 var current = t.doAction("get_num_current"); 2309 var total = t.doAction("get_total_items"); 2310 2311 switch(dir){ 2312 case "next": 2313 2314 var num = current+1; 2315 if(num >= total ) 2316 num = 0; 2317 2318 break; 2319 case "prev": 2320 2321 var num = current-1; 2322 if(num < 0) 2323 num = total-1; 2324 2325 break; 2326 default: 2327 throw new Error("wrong direction type: "+dir); 2328 break; 2329 } 2330 2331 2332 t.doAction("change_item", num); 2333 2334 } 2335 2336 2337 /** 2338 * do api action 2339 */ 2340 this.doAction = function(action, arg1, arg2){ 2341 2342 if(g_vars.trace_debug){ 2343 2344 var strAction = action; 2345 if(arg1) 2346 strAction += " "+arg1; 2347 if(arg2) 2348 strAction += " "+arg2; 2349 2350 trace("Do Action: "); 2351 2352 trace(strAction); 2353 } 2354 2355 if(!g_api){ 2356 if(g_vars.trace_debug) 2357 trace("empty g_api, exit"); 2358 2359 return(false); 2360 } 2361 2362 switch(action){ 2363 case "prev": 2364 case "next": 2365 2366 var apiType = g_api.getAPIType(); 2367 2368 if(apiType == "carousel"){ 2369 2370 g_api.doAction(action); 2371 2372 return(false); 2373 } 2374 2375 changeItemByAction(action); 2376 return(false); 2377 break; 2378 } 2379 2380 var response = g_api.doAction(action, arg1, arg2); 2381
2382 if(g_vars.trace_debug){ 2383 trace("Response: "); 2384 trace(response); 2385 } 2386 2387 2388 return(response); 2389 } 2390 2391 /** 2392 * add the parent some debug color 2393 */ 2394 function addParentDebug(objParent){ 2395 2396 if(!objParent) 2397 objParent = g_objParent; 2398 2399 var color = g_objParent.data("uc-debug-color"); 2400 if(color) 2401 return(color); 2402 2403 var objBody = jQuery("body"); 2404 var dataColors = "uc-remote-debug-colors"; 2405 2406 var objColors = objBody.data(dataColors); 2407 2408 if(!objColors){ 2409 objColors = ["#ffeb00","blue","#808000","#d1e231","#01796f","#8e4585","#ff33cc","#436b95","#eaa221","#b86d29"]; 2410 } 2411 2412 var color = objColors.pop(); 2413 2414 g_objParent.data("uc-debug-color", color); 2415 objBody.data(dataColors, objColors); 2416 2417 g_objParent.css("border","3px solid "+color); 2418 2419 return(color); 2420 } 2421 2422 2423 /** 2424 * update sync debug 2425 */ 2426 function updateSyncDebug(event, syncID){ 2427 2428 //if show id's disable other debug 2429 if(g_vars.debug_show_ids == true) 2430 return(false); 2431 2432 try{ 2433 2434 if(syncID != g_vars.syncid){ 2435 2436 var name = g_objParent.data("widgetname"); 2437 throw new Error("Wrong sync group mishmash "+g_vars.syncid+" and " + syncID); 2438 } 2439 2440 var debugText = g_objSync.getDebugText(g_objParent); 2441 2442 if(!debugText) 2443 return(false); 2444 2445 displayTextOnWidget(g_objParent, debugText, "debug"); 2446 2447 }catch(error){ 2448 2449 displayErrorMessage(error); 2450 2451 } 2452 2453 } 2454 2455 2456 function _______EDITOR_RELATED_________(){} 2457 2458 2459 /** 2460 * check if inside editor 2461 */ 2462 function isInsideEditor(){ 2463 2464 if(g_vars.is_editor !== null) 2465 return g_vars.is_editor; 2466 2467 //check for gutenberg 2468 2469 if(typeof g_ucAdmin !== "undefined"){ 2470 g_vars.is_editor = true; 2471 return(true); 2472 } 2473 2474 // check for elementor 2475 if (window.self !== window.top && typeof window.parent.elementor !== "undefined") { 2476 2477 g_vars.is_editor = true; 2478 2479 return true; 2480 } 2481 2482 g_vars.is_editor = false; 2483 2484 return false; 2485 } 2486 2487 /** 2488 * reset the settings 2489 */ 2490 function resetSettingsInsideEditor(){ 2491 2492 g_objParent = null; 2493 g_api = null; 2494 g_vars.is_inited = false; 2495 2496 } 2497 2498 2499 /** 2500 * check widget inside editor 2501 */ 2502 function checkWidgetInsideEditor(){ 2503 2504 //check for disconnect 2505 try{ 2506 2507 hideErrorOnWidget(); 2508 2509 if(g_vars.is_inited == true){ 2510 2511 if(g_objParent.is(":hidden")){ 2512 2513 //disconnect 2514 resetSettingsInsideEditor(); 2515 } 2516 2517 }else{ 2518 2519 //check for connect 2520 g_vars.is_inited = initParent(); 2521 2522 if(g_vars.is_inited == true){ 2523 2524 g_vars.funcOnInit(); 2525 } 2526 else 2527 if(g_vars.is_inited == false){ 2528 2529 g_objParent.on("uc-object-ready", function(){ 2530 2531 g_vars.is_inited = true; 2532 g_vars.funcOnInit(); 2533 2534 }); 2535 } 2536 2537 } 2538 2539 checkWidgetDebug(); 2540 2541 }catch(message){ 2542 2543 displayErrorMessage(message); 2544 2545 return(false); 2546 } 2547 2548 2549 } 2550 2551 2552 2553 /** 2554 * on widget init 2555 */ 2556 this.onWidgetInit = function(widgetID, func, options){ 2557 2558 try{ 2559 2560 if(g_vars.is_inited == true) 2561 return(false); 2562 2563 if(g_vars.trace_debug == true){ 2564 trace("on widget init: " + widgetID); 2565 } 2566 2567 if(!g_vars.funcOnInit){ 2568 2569 if(typeof func != "function") 2570 throw new Error("onWidgetInit error: the second parameter should be a function"); 2571 2572 g_vars.funcOnInit = func; 2573 } 2574 2575 if(options && g_vars.init_options == null) 2576 g_vars.init_options = options; 2577 2578 if(g_vars.debug_show_widget && g_vars.debug_show_widget == widgetID) 2579 g_vars.trace_debug = true; 2580 2581 initGlobal(widgetID, t.onWidgetInit); 2582 2583 if(g_vars.is_inited == false){ 2584 2585 if(g_vars.trace_debug == true){ 2586 trace(widgetID+" not inited yet, waiting for parent init"); 2587 } 2588 2589 return(false); 2590 } 2591 2592 //show id's on the widgets 2593 if(g_vars.debug_show_ids == true){ 2594 2595 trace("start debug show id's"); 2596 2597 displayTextOnWidget(g_objWidget, g_objWidget.attr("id"), "debug"); 2598 } 2599 2600 if(g_vars.trace_debug == true) 2601 trace("start debug - show connect"); 2602 2603 if(g_objParent.length > 1){ 2604 2605 trace(g_objWidget); 2606 trace(g_objParent); 2607 2608 throw new Error("Remote widget can't connect to more then 1 parents"); 2609 } 2610 2611 //widget is inited 2612 2613 onWidgetReady(); 2614 2615 if(g_vars.funcOnInit){ 2616 2617 g_vars.is_inited = true; 2618 g_vars.funcOnInit(g_objWidget); 2619 } 2620 2621 }catch(message){ 2622 2623 2624 displayErrorMessage(message); 2625 2626 var isEditorMode = isInsideEditor(); 2627 2628 //in editor mode check debug every second 2629 2630 if(isEditorMode == true) 2631 setInterval(checkWidgetInsideEditor, 700); 2632 2633 return(false); 2634 } 2635 2636 } 2637 2638 2639 /** 2640 * start sync 2641 */ 2642 function startParentSync(){ 2643 2644 var syncID = g_objParent.data("syncid"); 2645 2646 //if under template switcher - modify sync id 2647 2648 if(g_vars.trace_debug == true){ 2649 trace("Start parent sync"); 2650 trace(g_objParent); 2651 } 2652 2653 if(!syncID){ 2654 2655 if(g_vars.trace_debug == true){ 2656 trace("no sync id"); 2657 } 2658 2659 return(false); 2660 } 2661 2662 //skip nested slider/carousel that sits inside another synced parent with the same group 2663 var objOuterSync = g_objParent.parent().closest(".uc-remote-parent[data-sync='true']"); 2664 2665 if(objOuterSync.length && objOuterSync.data("syncid") == syncID){ 2666 2667 if(g_vars.trace_debug == true) 2668 trace("skip nested sync parent, same group: "+syncID); 2669 2670 return(false); 2671 } 2672 2673 var objSync = g_remoteConnection.getSyncObject(syncID); 2674 2675 var isEditorMode = isInsideEditor(); 2676 2677 objSync.setOptions(syncID, isEditorMode); 2678 2679 var isInited = initAPI(); 2680 2681 if(isInited == false){ 2682 2683 var widgetID = g_objParent.attr("id"); 2684 2685 var parentType = getParentType(); 2686 2687 var message = "Sync Error - can't init api for "+widgetID; 2688 2689 if(parentType == g_types.CAROUSEL){ 2690 2691 message += ", please check that the owl carousel js file loading from unlimited elements plugin."; 2692 2693 }else{ 2694 message += ", please check if the widget is inited and working."; 2695 } 2696 2697 throw new Error(message); 2698 } 2699 2700 g_vars.syncid = syncID; 2701
2702 //add debug event listener 2703 if(g_vars.trace_debug === true) 2704 objSync.on("update_debug", updateSyncDebug); 2705 2706 g_objSync = objSync; 2707 2708 objSync.addAPI(g_api); 2709 2710 //if(isEditorMode == true) 2711 //setInterval(checkSyncInsideEditor, 700); 2712 2713 } 2714 2715 2716 /** 2717 * parent init, init the debug 2718 */ 2719 this.onParentInit = function(objParent, optionsAPI){ 2720 2721 try{ 2722 2723 g_objParent = objParent; 2724 2725 if(!g_objParent) 2726 return(false); 2727 2728 if(g_objParent.length == 0) 2729 return(false); 2730 2731 if(g_objParent.length > 1) 2732 g_objParent = g_objParent.first(); 2733 2734 g_vars.is_parent_mode = true; 2735 2736 var optionsFromData = g_objParent.data("uc-remote-options"); 2737 2738 if(optionsFromData) 2739 optionsAPI = optionsFromData; 2740 2741 if(optionsAPI) 2742 g_vars.options_api = optionsAPI; 2743 2744 var isDebug = g_objParent.data("debug"); 2745 2746 if(typeof ucRemoteDebugEnabled != "undefined") 2747 isDebug = true; 2748 2749 g_vars.trace_debug = isDebug; 2750 2751 if(isDebug === true) 2752 addParentDebug(objParent); 2753 2754 var isSync = objParent.data("sync"); 2755 2756 if(isSync == true) 2757 startParentSync(); 2758 2759 if(g_vars.debug_show_ids == true){ 2760 displayTextOnWidget(g_objParent, g_objParent.attr("id"), "debug"); 2761 } 2762 2763 }catch(message){ 2764 2765 displayErrorMessage(message); 2766 2767 return(false); 2768 2769 } 2770 2771 } 2772 2773 /** 2774 * show the info 2775 */ 2776 this.showInfo = function(){ 2777 2778 trace("parent"); 2779 trace(g_objParent); 2780 2781 trace("current widget"); 2782 trace(g_objWidget); 2783 2784 2785 } 2786 2787 2788 /** 2789 * get the connected parent 2790 */ 2791 this.getParent = function(){ 2792 2793 return(g_objParent); 2794 } 2795 2796} 2797 2798/** 2799 * remote connection class - for interacting with outside 2800 */ 2801function UERemoteConnection(){ 2802 2803 var t = this; 2804 2805 /** 2806 * get object property 2807 */ 2808 this.getVal = function(obj, name, defaultValue){ 2809 2810 if(!defaultValue) 2811 var defaultValue = ""; 2812 2813 var val = ""; 2814 2815 if(!obj || typeof obj != "object") 2816 val = defaultValue; 2817 else if(obj.hasOwnProperty(name) == false){ 2818 val = defaultValue; 2819 }else{ 2820 val = obj[name]; 2821 } 2822 2823 return(val); 2824 } 2825 2826 2827 /** 2828 * get the sync object, if not exists, create one 2829 */ 2830 this.getSyncObject = function(syncID){ 2831 2832 var syncRealID = "uc_sync_"+syncID; 2833 2834 var objSync = t.getVal(window, syncRealID); 2835 2836 if(objSync) 2837 return(objSync); 2838 2839 var objSync = new UESyncObject(); 2840 2841 window[syncRealID] = objSync; 2842 2843 return(objSync); 2844 } 2845 2846 2847 /** 2848 * get object synced other objets id's 2849 */ 2850 this.getSyncedElements = function(objElement){ 2851 2852 if(!objElement) 2853 return(null); 2854 2855 if(objElement.length == 0) 2856 return(null); 2857 2858 if(objElement.hasClass("uc-remote-parent") == false) 2859 return(null); 2860 2861 var isSync = objElement.data("sync"); 2862 2863 if(isSync !== true) 2864 return(null); 2865 2866 var syncID = objElement.data("syncid"); 2867 2868 if(!syncID) 2869 return(null); 2870 2871 var objSync = t.getSyncObject(syncID); 2872 2873 var currentID = objElement.attr("id"); 2874 2875 var arrElements = objSync.getElements(currentID); 2876 2877 return(arrElements); 2878 } 2879 2880} 2881 2882 2883//body init 2884 2885jQuery(document).on("uc-remote-parent-init",function(event, objParent, optionsAPI){ 2886 2887 var objRemote = new UERemoteWidgets(); 2888 objRemote.onParentInit(objParent, optionsAPI); 2889 2890}); 2891 2892window.ueRemoteConnection = new UERemoteConnection();
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.