1(function ($) { 2 "use strict"; 3 4 var xhr,xhrList = {}, 5 cache = {}; 6 7 function _dispatchEvents(fireScroll) { 8 fireScroll = typeof fireScroll === 'undefined' ? true : fireScroll; 9 if(fireScroll) { 10 $(window).scroll(); // sticky column overflow fix 11 } 12 13 if (document.createEvent) { // W3C 14 var ev = document.createEvent('Event'); 15 ev.initEvent('resize', true, true); 16 window.dispatchEvent(ev); 17 } 18 else { // IE 19 element=document.documentElement; 20 var event=document.createEventObject(); 21 element.fireEvent("onresize",event); 22 } 23 } 24 25 function Better_Ajax_Pagination(settings) { 26 27 this.prefix = 'bs_ajax_paginate_'; 28 this.deferredPrefix = 'bs_deferred_loading_'; 29 this.isPrevPage = false; 30 this.$link_el = false; 31 this.id = false; 32 this.paginationStyle = false; 33 34 this.settings = $.extend({ 35 afterSuccessDeferredAjax: function() { 36 } 37 },settings); 38 39 return this; 40 } 41 42 Better_Ajax_Pagination.prototype.init = function (wrapper) { 43 var _this = this; 44 45 $(wrapper).on('click', '.bs-ajax-pagination a', function (e) { 46 e.preventDefault(); 47 48 var $this = $(this), 49 $pagination = $this.parent(); 50 51 if ($this.hasClass('disabled') || $pagination.hasClass('bs-pagination-loading')) { 52 return false; 53 } else { 54 $pagination.addClass('bs-pagination-loading') 55 } 56 57 var $this_pagination = $this.closest('.bs-pagination'); 58 59 _this.$link_el = $this; 60 _this.id = $this.data('id'); 61 62 try { 63 if (!_this.id) 64 throw 'invalid element'; 65 66 _this.setNewPageNumber(); 67 68 _this.paginationStyle = _this.getPaginationStyle(); 69 70 var props = _this.getAjaxProps(); 71 72 var cached_data = _this.cache_get(props[ 'current_page' ], _this.id); 73 if (typeof cached_data === 'object') { 74 _this.handle_response(cached_data); 75 $pagination.removeClass('bs-pagination-loading'); 76 } else { 77 78 var $this_pagination_wrapper = $this_pagination.prevAll('.bs-pagination-wrapper'); 79 80 // add first page to cache 81 if (props[ 'current_page' ] == 2) { 82 _this.cache_add( 83 1, 84 { 85 output: $this_pagination_wrapper.html(), 86 label: $this_pagination.find('.bs-pagination-label').html(), 87 have_next: true, 88 have_prev: false 89 }, 90 _this.id 91 ); 92 } 93 94 // add loading 95 switch (_this.paginationStyle) { 96 97 case 'next_prev': 98 $this_pagination_wrapper.children().addClass('bs-pagination-in-loading'); 99 $this_pagination_wrapper.prepend(_this.getLoadingRawHtml()); 100 break; 101 102 case 'more_btn_infinity': 103 $this.find('.loaded').hide(); 104 $this.find('.loading').show(); 105 $this.removeClass('more_btn_infinity') 106 .addClass('infinity') 107 .addClass('bs-pagination-in-loading'); 108 $this_pagination.removeClass('more_btn_infinity') 109 .addClass('infinity'); 110 break; 111 112 case 'infinity': 113 case 'more_btn': 114 $this.addClass('bs-pagination-in-loading'); 115 $this.find('.loaded').hide(); 116 $this.find('.loading').show(); 117 break; 118 119 } 120 121 xhr = $.ajax({ 122 url: props[ 'ajax_url' ], 123 type: 'POST', 124 dataType: 'json', 125 data: props 126 }) 127 .fail(function (e) { 128 $pagination.removeClass('bs-pagination-loading'); 129 130 // remove loading 131 switch (_this.paginationStyle) { 132 133 case 'more_btn_infinity': 134 case 'next_prev': 135 $this_pagination_wrapper.find('.bs-pagin-loading-wrapper').remove(); 136 $this.addClass('bs-pagination-in-loading'); 137 break; 138 139 case 'infinity': 140 case 'more_btn': 141 $this.addClass('bs-pagination-in-loading'); 142 $this.find('.loaded').show(); 143 $this.find('.loading').hide(); 144 break; 145 } 146 147 if (e.statusText !== "abort") 148 alert('cannot load data. please check your internet connection!'); // todo make decision for this 149 }) 150 .done(function (response) { 151 _this.handle_response(response); 152 153 if (_this.cacheThisStyle(_this.paginationStyle)) { 154 _this.cache_add(props[ 'current_page' ], response, _this.id); 155 } 156 157 // remove loading 158 switch (_this.paginationStyle) { 159 160 case 'more_btn_infinity': 161 $this.removeClass('bs-pagination-in-loading'); 162 $this_pagination_wrapper.find('.bs-pagin-loading-wrapper').remove(); 163 break; 164 165 case 'next_prev': 166 $this.removeClass('bs-pagination-in-loading'); 167 $this_pagination_wrapper.find('.bs-pagin-loading-wrapper').remove(); 168 $this_pagination_wrapper.children().removeClass('bs-pagination-in-loading'); 169 break; 170 171 case 'infinity': 172 case 'more_btn': 173 $this.removeClass('bs-pagination-in-loading'); 174 $this.find('.loaded').show(); 175 $this.find('.loading').hide(); 176 break; 177 178 } 179 180 $pagination.removeClass('bs-pagination-loading'); 181 }); 182 } 183 } catch (err) { 184 _this.debug(err); 185 } 186 }); 187 188 new OnScreen({ 189 tolerance: 0, 190 debounce: 100, 191 container: window 192 }).on('enter', '.bs-ajax-pagination.infinity', function (el) { 193 $(el).find('a').click(); 194 }); 195 } 196 Better_Ajax_Pagination.prototype.filter_slider_params = function (settings) { 197 198 if (typeof settings.autoplayspeed !== 'undefined') { 199 settings.autoplaySpeed = settings.autoplayspeed; 200 } 201 202 settings.dots = typeof settings.sliderControlDots !== 'undefined' && settings.sliderControlDots !== 'off'; 203 settings.autoplay = typeof settings.sliderAutoplay !== 'undefined' && parseInt(settings.sliderAutoplay); 204 settings.speed = settings.sliderAnimationSpeed; 205 206 if (typeof settings.sliderControlNextPrev !== 'undefined' && settings.sliderControlNextPrev == 'off') { 207 settings.appendArrows = false;
208 } 209 210 return settings; 211 }; 212 Better_Ajax_Pagination.prototype.handler_slider = function (sliderContext) { 213 var self = this; 214 215 if ($.fn.slick) { 216 $('.bs-slider-items-container',sliderContext).each(function () { 217 var $this = $(this), 218 is_rtl = $(document.body).hasClass('rtl'); 219 if($this.hasClass('slick-ready')) { 220 return ; 221 } 222 var defaults = $this.data(), 223 settings = self.filter_slider_params($.extend({ 224 sliderControlDots: 'off', 225 prevArrow: '<a class="btn-bs-pagination prev" rel="prev" title="Previous">\n\t\t\t<i class="fa fa-caret-' + ( is_rtl ? 'right' : 'left' ) + '" aria-hidden="true"></i>\n\t\t</a>', 226 nextArrow: '<a rel="next" class="btn-bs-pagination next" title="Next">\n\t\t\t<i class="fa fa-caret-' + ( is_rtl ? 'left' : 'right' ) + '" aria-hidden="true"></i>\n\t\t</a>', 227 rtl: $(document.body).hasClass('rtl'), 228 slideMargin: 25, 229 slide: '.bs-slider-item', 230 appendArrows: $this.find('.bs-slider-controls .bs-control-nav'), 231 classPrefix: 'bs-slider-', 232 dotsClass: 'bs-slider-dots', 233 customPaging: function (slider, i) { 234 return $('<span class="bts-bs-dots-btn"></span>').text(i + 1); 235 } 236 }, defaults)); 237 238 if (settings.sliderControlDots && defaults.sliderControlDots) { 239 settings.appendDots = $this.find('.bs-slider-controls'); 240 settings.dotsClass += ' ' + settings.dotsClass + '-' + defaults.sliderControlDots; 241 } 242 243 $this.slick(settings); 244 $this.addClass('slick-ready'); 245 }); 246 247 $('.multi-tab').on('shown.bs.tab', 'a[data-toggle="tab"]:not([data-deferred-init])', function (e) { 248 var selector = $(e.target).attr('href'); 249 $(selector).find('.bs-slider-items-container').slick('setPosition'); 250 _dispatchEvents(); 251 }); 252 } 253 }; 254 255 256 Better_Ajax_Pagination.prototype.bindDeferredEvents = function () { 257 //handler deferred html loading tabs 258 var tabHeight = 200, self = this; 259 $('.multi-tab').on('show.bs.tab', 'a[data-deferred-init]', function (e) { 260 var prev_el = $(this).closest('.multi-tab') 261 .find('.active') 262 .attr('href'); 263 tabHeight = $(prev_el).height(); 264 }); 265 $('.tabs-section').on('show.bs.tab', 'a[data-deferred-init]', function (e) { 266 var prev_el = $(this).closest('.tabs-section') 267 .find('.active:visible a') 268 .data('target'); 269 tabHeight = $(prev_el).height(); 270 }); 271 $('a[data-deferred-init]').each(function(e) { 272 273 var $this = $(this), 274 event = $this.data('deferred-event') || 'click'; 275 276 if($this.closest('.deferred-block-exclude').length > 0) { 277 return ; 278 } 279 $this.on(event, function (e) { 280 var $this = $(this), 281 blockID = $this.data('deferred-init'), 282 $wrapper = $("#bsd_" + blockID), 283 $container = $wrapper.closest('.bs-deferred-container'); 284 285 if ($wrapper.hasClass('bs-deferred-load-wrapper')) { 286 if ($wrapper.hasClass('bs-deferred-loaded')) { 287 var isPinned = $wrapper.closest('.bs-pinning-block.pinned').length; 288 _dispatchEvents(!isPinned); 289 } else { 290 $container.removeClass('bs-tab-animated'); 291 self.handleDeferredElements($wrapper, {loadingHeight: tabHeight ? tabHeight : undefined}, function () { 292 $container.addClass('bs-tab-animated'); 293 $wrapper.addClass('bs-deferred-loaded'); 294 295 var $pagination = $container.find('.bs-pagination'); 296 297 if (tabHeight && ( !$pagination || !$pagination.hasClass('more_btn') ) ) { 298 $container.css('min-height', tabHeight); 299 } 300 301 tabHeight = undefined; 302 }); 303 } 304 } 305 }); 306 }); 307 308 } 309 Better_Ajax_Pagination.prototype.handleDeferredElements = function ($el,args, successCallback) { 310 var self = this; 311 312 if(! $el.hasClass('bs-deferred-load-wrapper')) { 313 $el = $el.find('.bs-deferred-load-wrapper'); 314 } 315 316 $el.each(function () { 317 var $wrapper = $(this); 318 if ($wrapper.hasClass('deferred-html-exists')) { 319 return; 320 } 321 322 args = $.extend({ 323 loadingHeight: 100, 324 loadingMinHeight: 0 325 }
325,args); 326 327 if (!$wrapper.find('.deferred-loading-container').length) { 328 var $loading = $('<div></div>', { 329 'class': 'deferred-loading-container', 330 height: args.loadingHeight 331 }); 332 333 var $pagination = $wrapper.find('.bs-pagination'); 334 335 if (args.loadingMinHeight && ( ! $pagination || !$pagination.hasClass('more_btn') ) ) { 336 $loading.css('min-height', args.loadingMinHeight); 337 } 338 339 $loading.append(self.getLoadingRawHtml()); 340 $loading.appendTo($wrapper); 341 } 342 343 self.id = $wrapper.attr('id'); 344 var props = self.getAjaxProps('deferred'); 345 346 if (typeof xhrList[self.id] === 'object') 347 xhrList[self.id].abort(); 348 349 xhrList[self.id] = $.ajax({ 350 url: props[ 'ajax_url' ], 351 type: 'POST', 352 dataType: 'json', 353 data: props 354 }).done(function (response) { 355 $wrapper.find('.deferred-loading-container').remove(); 356 delete xhrList[self.id]; 357 358 $wrapper.addClass('deferred-html-exists').append(response.output); 359 self.handler_slider($wrapper); 360 361 if(successCallback) 362 successCallback.call($wrapper, response); 363 364 var isPinned = $wrapper.closest('.bs-pinning-block.pinned').length; 365 _dispatchEvents(!isPinned); 366 367 self.settings.afterSuccessDeferredAjax.call(self, $wrapper, response); 368 }); 369 }); 370 }; 371 /** 372 * Get loading html 373 * 374 * @returns {string} 375 */ 376 Better_Ajax_Pagination.prototype.getLoadingRawHtml = function () { 377 return '<div class="bs-pagin-loading-wrapper">' + bs_pagination_loc.loading + '</div>'; 378 } 379 380 /** 381 * Return Ajax Properties (data) 382 * 383 * @param type string pagination|deferred. get property of pagination or deferred loading. default: pagination 384 * @returns {Array} 385 */ 386 Better_Ajax_Pagination.prototype.getAjaxProps = function (propType) { 387 propType = propType || 'pagination'; 388 var prefix = propType === 'deferred' ? this.deferredPrefix : this.prefix; 389 390 var _jsonStringVarName = prefix + this.id, props; 391 if (typeof window[ _jsonStringVarName ] === 'undefined') 392 throw 'pagination settings not set'; 393 394 props = jQuery.parseJSON(window[ _jsonStringVarName ]); 395 396 switch(propType.toLowerCase()) { 397 case 'pagination': 398 props[ 'action' ] = 'pagination_ajax'; 399 props[ 'current_page' ] = this.$link_el.parent().data('current-page') || 1; 400 props[ 'pagin_type' ] = this.paginationStyle; 401 break; 402 403 case 'deferred': 404 props[ 'action' ] = 'deferred_loading'; 405 props[ 'current_page' ] = 1; 406 break; 407 } 408 409 return props; 410 }; 411 412 413 /** 414 * save current page number 415 */ 416 Better_Ajax_Pagination.prototype.setNewPageNumber = function () { 417 var $pagination = this.$link_el.parent(), 418 current_page = $pagination.data('current-page') || 1; 419 420 this.isPrevPage = this.$link_el.hasClass('prev'); 421 422 if (this.isPrevPage) { 423 if (current_page < 2) 424 throw 'Wrong page number!'; 425 426 current_page--; 427 } else { 428 current_page++; 429 } 430 431 $pagination.data('current-page', current_page); 432 433 }; 434 435 436 Better_Ajax_Pagination.prototype.debug = function (message) { 437 console.error(message); 438 }; 439 440 441 /** 442 * 443 * @param styleName string name of pagination style 444 * @returns {boolean} 445 */ 446 Better_Ajax_Pagination.prototype.cacheThisStyle = function (styleName) { 447 return 'next_prev' === styleName; 448 }; 449 450 451 /** 452 * get name of pagination style from pagination link element 453 * 454 * @returns {string} 455 */ 456 Better_Ajax_Pagination.prototype.getPaginationStyle = function () {
457 var valid_types = [ 458 'next_prev', 459 'more_btn', 460 'more_btn_infinity', 461 'infinity' 462 ]; 463 var $pagination_wrapper = this.$link_el.closest('.bs-pagination'), 464 current_class; 465 for (var i = 0; i < valid_types.length; i++) { 466 current_class = valid_types[ i ]; 467 if ($pagination_wrapper.hasClass(current_class)) 468 return current_class; 469 } 470 471 return ''; 472 }; 473 474 475 /** 476 * get cached data 477 * 478 * @param name string cache name 479 * @param group string cache group group name 480 * @returns {*} 481 */ 482 Better_Ajax_Pagination.prototype.cache_get = function (name, group) { 483 if (typeof cache[ group ] !== 'undefined' && typeof cache[ group ][ name ] !== 'undefined') { 484 485 return cache[ group ][ name ]; 486 } 487 }; 488 489 490 /** 491 * save data on cache 492 * 493 * @param name string cache name 494 * @param data mixed data to save 495 * @param group string cache group group name 496 */ 497 Better_Ajax_Pagination.prototype.cache_add = function (name, data, group) { 498 if (typeof cache[ group ] === 'undefined') 499 cache[ group ] = {}; 500 501 cache[ group ][ name ] = data; 502 }; 503 504 505 Better_Ajax_Pagination.prototype.handle_event = function (response, event) { 506 507 if (typeof response[ 'events' ] !== 'object') 508 return false; 509 510 if (typeof response[ 'events' ][ event ] === 'string') { 511 512 var callback_name = response[ 'events' ][ event ]; 513 //handle after ajax_event 514 if (typeof window[ callback_name ] === 'function') { 515 516 window[ callback_name ].call(this, response, event); 517 } 518 } 519 }; 520 521 /** 522 * handle ajax request, append html output and manage button classes and atts 523 * 524 * @param response ajax request response 525 */ 526 Better_Ajax_Pagination.prototype.handle_response = function (response) { 527 if ( response === null || typeof response[ 'error' ] === 'string' ) { 528 529 if( response === null ){ 530 this.debug( "Error!" ) ; 531 }else{ 532 this.debug( response[ 'error' ]); 533 } 534 535 return; 536 } 537 538 var $paginate = this.$link_el.closest('.bs-pagination'), 539 $outputSection = $paginate.prevAll('.bs-pagination-wrapper'); 540 541 var isPinned = $paginate.closest('.bs-pinning-block.pinned').length; 542 543 this.handle_event(response, 'before_append'); 544 switch (this.paginationStyle) { 545 546 case 'next_prev': 547 $outputSection.html(response[ 'output' ]); 548 this.handle_event(response, 'after_append'); 549 $outputSection 550 .addClass('bs-animate') 551 .addClass(this.isPrevPage ? 'bs-fadeInLeft' : 'bs-fadeInRight') 552 .delay(400) 553 .queue(function (n) { 554 $(this).removeClass('bs-animate bs-fadeInRight bs-fadeInLeft'); 555 n(); 556 }); 557 558 _dispatchEvents(!isPinned); 559 if (typeof response[ 'label' ] !== 'undefined') { 560 $paginate.find('.bs-pagination-label').html(response[ 'label' ]); 561 } 562 563 $paginate.find('.next')[ response[ 'have_next' ] ? 'removeClass' : 'addClass' ]('disabled'); 564 565 $paginate.find('.prev')[ response[ 'have_prev' ] ? 'removeClass' : 'addClass' ]('disabled'); 566 567 break; 568 569 case 'more_btn': 570 case 'more_btn_infinity': 571 case 'infinity': 572 573 if (typeof response[ 'add-to' ] === 'string') { 574 var $appended_el = $(response[ 'output' ]); 575 if (response[ 'add-type' ] == 'prepend') { 576 $outputSection.find(response[ 'add-to' ]).prepend($appended_el); 577 } else { 578 $outputSection.find(response[ 'add-to' ]).append($appended_el); 579 } 580 } else { 581 var $appended_el = $outputSection.append(response[ 'output' ]).children(':last'); 582 } 583 584 _dispatchEvents(!isPinned); 585 this.handle_event(response, 'after_append'); 586 587 $appended_el 588 .addClass('bs-animate bs-fadeInUp') 589 .delay(400) 590 .queue(function (n) { 591 $(this).removeClass('bs-animate bs-fadeInUp'); 592 n(); 593 }); 594 595 if (this.paginationStyle === 'infinity') { 596 if (!response[ 'have_next' ]) { 597 this.$link_el.unbind('inview').remove(); 598 } 599 } else { 600 601 if( response[ 'have_next' ] ){ 602 this.$link_el.removeClass('disabled'); 603 }else{ 604 this.$link_el.addClass('disabled'); 605 this.$link_el.find('.loaded').remove(); 606 this.$link_el.find('.no-more').show(); 607 } 608 } 609 610 break; 611 } 612 613 this.handle_event(response, 'after_response'); 614 }; 615 616 $.fn.Better_Ajax_Pagination = function(settings){ 617 new Better_Ajax_Pagination(settings).handler_slider(); 618 619 return this.each(function() { 620 new Better_Ajax_Pagination().init(this); 621 }); 622 }; 623 624 $.fn.Better_Deferred_Loading = function(settings) { 625 var pagination = new Better_Ajax_Pagination(settings); 626 pagination.bindDeferredEvents(); 627 628 return pagination; 629 } 630})(jQuery);
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.