You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
1.5 KiB

define(["jquery","core/custom_interaction_events","core/paged_content_events","core/pubsub"],function(a,b,c,d){var e={ROOT:'[data-region="paging-dropdown-container"]',DROPDOWN_ITEM:'[data-region="dropdown-item"]',DROPDOWN_TOGGLE:'[data-region="dropdown-toggle"]',ACTIVE_DROPDOWN_ITEM:'[data-region="dropdown-item"].active',CARET:'[data-region="caret"]'},f=function(a){return parseInt(a.attr("data-page-number"),10)},g=function(a){return a.find(e.DROPDOWN_ITEM)},h=function(b,c){var d=f(c);return g(b).filter(function(b,c){return f(a(c))<d})},i=function(a){return parseInt(a.attr("data-item-count"),10)},j=function(b,c){if(void 0!=c.attr("data-offset"))return parseInt(c.attr("data-offset"),10);var d=0;return h(b,c).each(function(b,c){c=a(c),d+=i(c)}),c.attr("data-offset",d),d},k=function(a){return a.find(e.ACTIVE_DROPDOWN_ITEM)},l=function(b,c){return c.map(function(c,d){return d=a(d),{pageNumber:f(d),limit:i(d),offset:j(b,d)}}).get()},m=function(b){b.each(function(b,c){c=a(c),c.attr("data-page-number",b+1)})},n=function(a,b,f){var g=h(a,b),i=g.add(b),j=l(a,i),m=a.find(e.DROPDOWN_TOGGLE),n=m.find(e.CARET);k(a).removeClass("active"),b.addClass("active"),m.html(b.text()),m.append(n),d.publish(f+c.SHOW_PAGES,j)},o=function(c,d){c=a(c);var f=g(c);m(f);var h=k(c);h.length&&n(c,h,d),b.define(c,[b.events.activate]),c.on(b.events.activate,e.DROPDOWN_ITEM,function(b,f){var g=a(b.target).closest(e.DROPDOWN_ITEM);n(c,g,d),f.originalEvent.preventDefault()})};return{init:o,rootSelector:e.ROOT}});