PageSourceSearch

https://wsm.org/wp-content/uploads/ac_assets/uc_content_accordion/content_accordion.js?ver=2.0.20

js wsm.org collected 2026-09-24 11:21:31 UTC 8,295 bytes, 325 lines download raw bytes

1
2function UCContentAccordion(objAccordion){
3  
4  var g_activeClass;
5  var g_dataLinkNum, g_accItem, g_scrollOffset;
6
7  //scroll func
8  function scrollToTop(){
9    var panel = jQuery(this).closest(".uc_ac_box");
10    
11    jQuery('html, body').animate({
12      scrollTop: panel.offset().top + g_scrollOffset
13    }, 400);
14  }
15  
16  /**
17  * set hash
18  */
19  function setHash(objTab){
20    
21    var isHashSet = objAccordion.data("set-hash");
22    
23    if(isHashSet == false)
24    return(false);
25    
26    var objTabDataId = objTab.parent().attr('id');
27    
28    window.location.hash = objTabDataId;    
29    
30  }
31
32  function onItemClick(){
33    
34    var objCaption = jQuery(this);
35    var objContent = objCaption.next();
36    var objItem = objCaption.parent();
37    
38    setHash(objCaption);
39    
40    var isActive = objItem.hasClass(g_activeClass);
41    var dataCloseothers = objAccordion.data("closeothers");
42    
43    if(isActive == true){    
44      //remove active class from clicked
45      objItem.removeClass(g_activeClass);
46      objContent.slideUp();    
47      return(false);
48    }
49    
50    if(dataCloseothers == true){
51
52       
53      var objItems = objItem.siblings();
54
55      objItems.each(function(){
56
57        var objTab = jQuery(this);
58        var isTabActive = objTab.hasClass(g_activeClass);
59     
60        //remove active class from all other tabs
61        //use carefully, not to touch inner accordion if such exists
62        if(isTabActive == true){
63          objTab.removeClass(g_activeClass);
64          objTab.find(" > .uc_content").slideUp();        
65        }
66      });      
67      
68      
69    }
70   
71    objItem.addClass(g_activeClass);
72    
73    var dataScroll = objAccordion.data('scroll');
74    
75    if (dataScroll == "desktop"){
76      if(window.matchMedia("(min-width: 1024px)").matches){
77        objContent.slideDown(scrollToTop);
78      }else{
79        objContent.slideDown();
80      }
81    }
82    
83    if (dataScroll == "mobile"){
84      if(window.matchMedia("(max-width: 1024px)").matches){
85        objContent.slideDown(scrollToTop);
86      }else{
87        objContent.slideDown();
88      }
89    }
90    
91    if (dataScroll == "desktop+mobile"){
92      objContent.slideDown(scrollToTop);
93    }
94    
95    if (dataScroll == "off"){
96      objContent.slideDown();
97    }
98    
99    return false;
100  }
101  
102  
103  function linkToSlideScroll(){ 
104    
105    jQuery('html, body').animate({
106      scrollTop: g_accItem.offset().top + g_scrollOffset
107    }, 400);
108  }
109  
110  /*
111  * check if element is in viewport
112  */
113  function isElementInViewport(objElement) {
114    
115    var elementTop = objElement.offset().top;
116    var elementBottom = elementTop + objElement.outerHeight();
117    
118    var viewportTop = jQuery(window).scrollTop();
119    var viewportBottom = viewportTop + jQuery(window).height();
120    
121    var isInViwport = elementBottom > viewportTop && elementTop < viewportBottom;
122    
123    return(isInViwport);
124  } 
125  
126  /*
127  * on trigger link click
128  */
129  function onLinkClick(e){
130    
131    var objLink = jQuery(this);
132    
133    var dataAccName = objAccordion.data('name');
134    var dataLinkName = objLink.data('name');
135    g_dataLinkNum = objLink.data('num');
136    g_accItem = objAccordion.find('.uc_ac_box .uc_trigger').eq(g_dataLinkNum - 1);
137    var accItemNumber = objAccordion.find('.uc_ac_box').length;
138    
139    
140    if(dataLinkName != dataAccName)
141    return(false);
142    
143    if(dataLinkName == undefined || g_dataLinkNum == '' || g_dataLinkNum > accItemNumber)
144    return(false);
145    
146    var accItemContent = g_accItem.next();
147    var accItemParent = g_accItem.parent();
148    var isItemParentActive = accItemParent.hasClass(g_activeClass);
149    
150    e.preventDefault();
151    
152    if(isItemParentActive == true){
153
154      if(isElementInViewport(objAccordion) == false)
155      linkToSlideScroll();
156
157      accItemContent.slideUp();
158      accItemParent.removeClass(g_activeClass);
159      
160    }else if(isItemParentActive == false && isElementInViewport(objAccordion) == false){
161      
162      onItemClick();	      
163      accItemContent.slideDown(linkToSlideScroll);
164      accItemParent.addClass(g_activeClass);
165      
166    }else if(isItemParentActive == false && isElementInViewport(objAccordion) == true){
167      
168      onItemClick();	      
169      accItemContent.slideDown();
170      accItemParent.addClass(g_activeClass);
171    }
172    
173    
174  }
175
176  /**
177   * on expand all item clik
178   */
179function onExpandAllClick(e) {
180  e.preventDefault();
181
182  var objAllItems = objAccordion.find(".uc_ac_box");
183
184  var anyAccordionClosed = objAllItems.filter(":not(." + g_activeClass + ")").length > 0;
185
186  objAllItems.each(function () {
187    var objItem = jQuery(this);
188    var objItemContent = objItem.find("> .uc_content");
189
190    if (anyAccordionClosed) {
191      // If any accordion is closed, open all
192      objItem.addClass(g_activeClass);
193      if (objItemContent) objItemContent.show();
194    } else {
195      // If all accordions are open, close all
196      objItem.removeClass(g_activeClass);
197      if (objItemContent) objItemContent.hide();
198    }
199  });
200}
201  
202  /**
203  * init open links
204  */
205  function initLinks(){
206    
207    var objLinks = jQuery('.ue-link-goto-item').not(".uc-link-inited");
208    
209    if(objLinks.length == 0){
210      return(false);
211    }
212    
213    var elementName = objAccordion.data("name");
214    
215    jQuery.each(objLinks, function(index, linkElement){
216      
217      var objLink = jQuery(linkElement);      
218      var name = objLink.data("name");
219      
220      if(name != elementName)
221      return(true);
222      
223      objLink.addClass("uc-link-inited");
224      
225      objLink.on("click", onLinkClick);
226      
227    });
228    
229  }
230  
231  
232  function runPostAccordion(){
233    //init globals
234    
235    g_activeClass = "uc-item-active";    
236    g_scrollOffset = objAccordion.data('offset');
237    
238    initLinks();
239    
240    //init events    
241    objAccordion.on("click", ".uc_trigger", onItemClick);
242    objAccordion.on("ucclick", ".uc_trigger", onItemClick);
243    jQuery(".ue-content-accordion-expand-all").on("click", onExpandAllClick);
244
245    //check if in owl carousel
246    var objParentCarousel = objAccordion.parents(".owl-carousel");
247
248    if(objParentCarousel && objParentCarousel.length > 0){
249      objParentCarousel.on("click", ".uc_trigger", onItemClick);
250      objParentCarousel.on("ucclick", ".uc_trigger", onItemClick);
251    } 
252    
253    //init hash
254    if(!window.location.hash)
255    return(false);
256        
257    //find hashed tab object
258    var objHashedTabs = jQuery('[id=' + window.location.hash + ']');
259
260    objHashedTabs.each(function(){
261
262      var objHashedTab = jQuery(this);
263
264      //find main widget wrapper of the hashed tab
265      var objHashedTabWrapper = objHashedTab.parents('.uc_material_accordion'); 
266
267      //find if main widget wrapper is inside another accordion tab
268      var objWrapperParent = objHashedTabWrapper.parents('.uc_ac_box');
269
270      //if not than trigger click on hashed tab only and move to another hashed tab object
271      //do nothing with inner accordion on this stage (if its exists)
272      if(!objWrapperParent.length){
273          
274        setTimeout(function(){
275
276          //find if tab is active
277          var isActive = objHashedTab.hasClass(g_activeClass);
278
279          if(isActive == true)
280          return(true);
281
282          objHashedTab.find(' > .uc_trigger').trigger('click');
283
284        },200);
285
286        return(true);
287      }
288      
289      //if wrapper is inside another accordion tab
290      setTimeout(function(){
291
292        //if tab is active then skip and go to another one
293        var isActive = objHashedTab.hasClass('uc-item-active');
294        
295        if(isActive == true)
296        return(true);
297
298        objHashedTab.find(' > .uc_trigger').trigger('click');
299       
300        //open parent accordion tab it wasn't open already
301        var isParentTabActive = objWrapperParent.hasClass('uc-item-active');
302
303        if(isParentTabActive == true)
304        return(true);
305
306        var objParentAccordionTab = objWrapperParent.find(' > .uc_trigger');
307        var accItemContent = objParentAccordionTab.next();
308        var accItemParent = objParentAccordionTab.parent();          
309
310        accItemContent.slideDown();
311        accItemParent.addClass("uc-item-active");
312   
313      },300);
314
315      
316    });
317
318	objAccordion.addClass('uc-inited');
319    
320  }
321  
322  if(objAccordion.hasClass('uc-inited') == false)
323  runPostAccordion();
324  
325}

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.