1/** 2 * Frontend scripts 3 * 4 * @package YITH\FAQPluginForWordPress\Assets\JS 5 */ 6 7jQuery( 8 function ( $ ) { 9 10 var $ajax_call = false; 11 12 $( 13 function () { 14 15 set_actions(); 16 17 if ( window.location.hash ) { 18 find_faq( window.location.hash ); 19 } else { 20 $( '#yith-faqs-container' ).removeClass( 'yith-faqs-loading' ); 21 } 22 23 $( document ).trigger( 'yith_faq_loaded' ); 24 25 } 26 ); 27 28 $.fn.yith_faq_filtering = function ( e = false, obj ) { 29 if ( e ) { 30 e.preventDefault(); 31 } 32 var $href = obj.href, 33 $hash = window.location.hash, 34 $url = window.location.href, 35 $this = $( obj ), 36 $search_box = $( '.yith-faqs-search input' ), 37 $terms = ( $search_box !== undefined ? $search_box.val() : '' ), 38 $container = '#yith-faqs-container', 39 $categories = '.yith-faqs-categories', 40 $navigation = '.yith-faqs-pagination', 41 $new_page = '', 42 $old_page = ''; 43 44 if ( $url.indexOf( '?term_id=' ) !== -1 ) { 45 46 if ( $href && $href.indexOf( '?pg=' ) !== -1 ) { 47 48 $new_page = $href.substr( $href.indexOf( '=' ) + 1 ); 49 50 if ( $url.indexOf( '&pg=' ) !== -1 ) { 51 $old_page = $url.substr( $url.indexOf( '&pg=' ) + 4 ); 52 $href = $url.replace( 'pg=' + $old_page, 'pg=' + $new_page ) 53 } else { 54 $href = $url + '&pg=' + $new_page; 55 } 56 57 } 58 59 } 60 61 if ( $this.is( 'button' ) || $this.is( 'input' ) ) { 62 63 if ( $terms !== '' ) { 64 $terms = $terms.replace( ' ', '+' ); 65 $href = '?faq-s=' + $terms; 66 } 67 } 68 69 $( $container ).addClass( 'yith-faqs-loading' ); 70 $( $navigation ).hide(); 71 72 if ( $ajax_call !== false ) { 73 $ajax_call.abort(); 74 $ajax_call = false; 75 } 76 77 if ( undefined === $href ) { 78 if ( $url.indexOf( '?' ) > 0 ) { 79 $href = $url.substring( 0, $url.indexOf( '?' ) ); 80 window.history.replaceState( {}, document.title, $href ); 81 } else { 82 $href = $url; 83 } 84 } 85 86 $ajax_call = $.ajax( 87 { 88 url : $href, 89 success: function ( response ) { 90 91 $ajax_call = false; 92 $( $container ).removeClass( 'yith-faqs-loading' ); 93 94 if ( '' !== $( '.yith-faqs input' ).val() ) { 95 $( '.yith-faqs-reset' ).show( 500 ); 96 } else { 97 $( '.yith-faqs-reset' ).hide(); 98 } 99 100 if ( $( response ).find( $container ).length > 0 ) { 101 $( $container ).html( '' ).html( $( response ).find( $container ).html() ); 102 if ( yith_faq.enable_scroll ) { 103 var $scroll_top = $( '.yith-faqs' ).offset().top - yith_faq.scroll_offset; 104 $( window ).scrollTop( $scroll_top ); 105 } 106 set_actions(); 107 } else { 108 $( $container ).html( '' ).html( $( response ).find( '.woocommerce-info' ) ); 109 } 110 111 if ( $( response ).find( $navigation ).length > 0 ) { 112 if ( $( $navigation ).length === 0 ) { 113 $.jseldom( $navigation ).insertAfter( $( $navigation ) ); 114 } 115 $( $navigation ).html( $( response ).find( $navigation ).html() ).show(); 116 } else { 117 $( $navigation ).empty(); 118 } 119 120 if ( $( response ).find( $categories ).length > 0 ) { 121 if ( $( $categories ).length === 0 ) { 122 $.jseldom( $categories ).insertAfter( $( $categories ) ); 123 } 124 $( $categories ).html( $( response ).find( $categories ).html() ).show(); 125 } else { 126 $( $categories ).empty(); 127 } 128 129 // update browser history (IE doesn't support it). 130 if ( ! navigator.userAgent.match( /msie/i ) ) { 131 window.history.pushState( { "pageTitle": response.pageTitle }, "", $href + $hash ); 132 } 133 134 if ( $hash ) { 135 scroll_to_faq( $hash ); 136 } 137 138 // trigger ready event. 139 $( document ).trigger( 'ready' ); 140 $( window ).trigger( 'scroll' ); 141 $( document ).trigger( 'yith_faq_loaded' ); 142 143 } 144 } 145 ); 146 147 }; 148 149 $( document ).on( 150 'click', 151 '.yith-faqs-categories a, .yith-faqs-page a, .yith-faqs button, .yith-faqs-reset', 152 function ( e ) { 153 154 if ( $( this ).hasClass( 'yith-faqs-reset' ) ) { 155 $( '.yith-faqs input' ).val( '' ); 156 } 157 158 $( this ).yith_faq_filtering( e, this ); 159 } 160 ); 161 162 $( document ).on( 163 'keydown', 164 '.yith-faqs input', 165 function ( e ) { 166 var container = $( '.yith-faqs-search-container' ); 167 container.addClass( 'active' ); 168 if ( e.keyCode === 13 && ! e.shiftKey ) { 169 $( this ).yith_faq_filtering( e, this ); 170 container.removeClass( 'active' ); 171 } 172 } 173 ); 174 175 $( document ).on( 176 'focusin', 177 '.yith-faqs-search-input input', 178 function () { 179 $( '.yith-faqs-search-container' ).addClass( 'active' ); 180 } 181 ); 182 183 $( document ).on( 184 'focusout', 185 '.yith-faqs-search-input input', 186 function () { 187 $( '.yith-faqs-search-container' ).removeClass( 'active' ); 188 } 189 ); 190 191 $( document ).on( 192 'click', 193 '.yith-faqs-summary-link', 194 function ( e ) { 195 e.preventDefault(); 196 var page_id = $( this ).closest( '.yith-faqs-summary' ).data( 'page_id' ), 197 faq_id = $( this ).data( 'faq_id' ); 198 199 if ( String( page_id ) === yith_faq.page_id ) { 200 find_faq( faq_id ); 201 } else { 202 window.location.href = $( this ).data( 'href' ); 203 } 204 } 205 ); 206 207 function find_faq( hash ) { 208 var container = $( '#yith-faqs-container' ); 209 210 container.addClass( 'yith-faqs-loading' ); 211 if ( container.hasClass( 'yith-faqs-paged' ) ) { 212 $.post( 213 yith_faq.ajax_url, 214 { 215 action : 'yfwp_find_faq', 216 page_id: yith_faq.page_id, 217 faq_id : hash.replace( '#faq-', '' ) 218 }, 219 function ( response ) { 220 if ( response.success ) { 221 window.location.hash = hash; 222 223 var button = $( '.page-' + response.page + ' a' ); 224 if ( response.page >= 1 && button.length > 0 ) { 225 button.trigger( 'click' ); 226 } else { 227 scroll_to_faq( hash ); 228 container.removeClass( 'yith-faqs-loading' ); 229 } 230 } 231 } 232 ); 233 } else { 234 scroll_to_faq( hash ); 235 container.removeClass( 'yith-faqs-loading' ); 236 } 237 } 238 239 function scroll_to_faq( hash ) { 240 if ( $( hash ).length > 0 ) { 241 if ( ! $( hash ).hasClass( 'opened' ) ) { 242 $( hash ).find( '.yith-faqs-title' ).trigger( 'click' ); 243 } 244 $( 'html, body' ).animate( 245 { 246 scrollTop: $( hash ).offset().top - yith_faq.scroll_offset 247 }, 248 500 249 ); 250 } 251 } 252 253 function set_actions() { 254 255 $( '.yith-faq-type-toggle .yith-faqs-title' ).each( 256 function () { 257 $( this ).on( 258 'click', 259 function () { 260 261 var faq = $( this ).parent(), 262 icon = $( this ).find( '.icon' ), 263 icon_class = icon.attr( 'class' ), 264 new_icon_class; 265 266 faq.find( '.yith-faqs-content-wrapper' ).slideToggle(); 267 268 if ( faq.hasClass( 'opened' ) ) { 269 faq.removeClass( 'opened' ); 270 faq.removeClass( 'active' ); 271 272 } else { 273 faq.addClass( 'opened' ); 274 faq.addClass( 'active' ); 275 } 276 277 if ( faq.hasClass( 'active' ) && faq.hasClass( 'opened' ) ) { 278 new_icon_class = icon_class.replace( 'plus', 'minus' ).replace( 'down', 'up' ); 279 } else { 280 new_icon_class = icon_class.replace( 'minus', 'plus' ).replace( 'up', 'down' ); 281 } 282 283 icon.removeClass( icon_class ).addClass( new_icon_class ); 284 285 } 286 ); 287 } 288 ); 289 290 $( '.yith-faq-type-accordion .yith-faqs-title' ).each( 291 function () { 292 $( this ).on( 293 'click', 294 function () { 295 296 var faq = $( this ).parent(), 297 icon = $( this ).find( '.icon' ), 298 icon_class = icon.attr( 'class' ), 299 new_icon_class, 300 active_faq = $( '.yith-faqs-item.active.opened' ), 301 active_icon = active_faq.find( '.icon' ), 302 active_icon_class = active_icon.attr( 'class' ); 303 304 if ( active_icon_class !== undefined && faq.attr( 'id' ) !== active_faq.attr( 'id' ) ) { 305 var active_new_icon_class = active_icon_class.replace( 'minus', 'plus' ).replace( 'up', 'down' );
306 active_faq.find( '.yith-faqs-content-wrapper' ).slideUp(); 307 active_faq.removeClass( 'active' ); 308 active_faq.removeClass( 'opened' ); 309 active_icon.removeClass( active_icon_class ).addClass( active_new_icon_class ); 310 } 311 312 faq.find( '.yith-faqs-content-wrapper' ).slideToggle(); 313 if ( faq.hasClass( 'opened' ) ) { 314 faq.removeClass( 'opened' ); 315 faq.removeClass( 'active' ); 316 317 } else { 318 faq.addClass( 'opened' ); 319 faq.addClass( 'active' ); 320 } 321 322 if ( faq.hasClass( 'active' ) && faq.hasClass( 'opened' ) ) { 323 new_icon_class = icon_class.replace( 'plus', 'minus' ).replace( 'down', 'up' ); 324 } else { 325 new_icon_class = icon_class.replace( 'minus', 'plus' ).replace( 'up', 'down' ); 326 } 327 328 icon.removeClass( icon_class ).addClass( new_icon_class ); 329 330 } 331 ); 332 } 333 ); 334 335 $( '.yith-faqs-link a' ).each( 336 function () { 337 338 $( this ).on( 339 'click', 340 function ( e ) { 341 e.preventDefault(); 342 var $this = $( this ), 343 $hover_text = $this.find( '.hover-text' ), 344 $success_text = $this.find( '.success-text' ), 345 $temp = $( '<input>' ), 346 $href = $this.data( 'faq' ); 347 348 $hover_text.hide(); 349 $success_text.show(); 350 $( 'body' ).append( $temp ); 351 $temp.val( $href ).select(); 352 document.execCommand( "copy" ); 353 $temp.remove(); 354 355 setTimeout( 356 function () { 357 $this.removeClass( 'hover' ); 358 $hover_text.show(); 359 $success_text.hide(); 360 }, 361 1000 362 ); 363 364 } 365 ); 366 } 367 ); 368 369 } 370 371 } 372);
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.