mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-23 11:13:38 +00:00
e56303798c
Initial SickGear for Python 3.
2 lines
No EOL
3.8 KiB
JavaScript
2 lines
No EOL
3.8 KiB
JavaScript
/*jQuery collapser v3.0.1 - (c) 2020 Aakash Chakravarthy*/
|
|
!function(f){var t="collapser",a={mode:"words",speed:"slow",truncate:10,ellipsis:" ... ",controlBtn:null,showText:"Show more",hideText:"Hide text",showClass:"show-class",hideClass:"hide-class",atStart:"hide",blockTarget:"next",blockEffect:"fade",lockHide:!1,changeText:!1,beforeShow:null,afterShow:null,beforeHide:null,afterHide:null};function o(e,t){var o=this;o.o=f.extend({},a,t),o.e=f(e),o.init()}o.prototype={init:function(){var e=this;e.mode=e.o.mode,e.remaining=null,e.ctrlButton=f.isFunction(e.o.controlBtn)?e.o.controlBtn.call(e.e):f('<a href="#" data-ctrl></a>'),"lines"==e.mode&&e.e.wrapInner("<div>");var t=f.isFunction(e.o.atStart)?e.o.atStart.call(e.e):e.o.atStart;"hide"==(t=void 0!==e.e.attr("data-start")?e.e.attr("data-start"):t)?e.hide(0):e.show(0)},show:function(e){var t=this,o=t.e;t.collapsed=!1,void 0===e&&(e=t.o.speed),f.isFunction(t.o.beforeShow)&&t.o.beforeShow.call(t.e,t);function a(){f.isFunction(t.o.afterShow)&&t.o.afterShow.call(t.e,t)}if(o.find("[data-ctrl]").remove(),"block"==t.mode)t.blockMode(o,"show",e,a);else{var n="lines"==t.mode?o.children("div"):o,i=n.height();if("lines"==t.mode)n.height("auto");else{var l=n.data("collHTML");void 0!==l&&n.html(l)}var s=n.height();n.height(i),n.animate({height:s},e,function(){n.height("auto"),a()}),o.removeClass(t.o.hideClass).addClass(t.o.showClass),f.isFunction(t.o.controlBtn)||o.append(t.ctrlButton),t.ctrlButton.html(t.o.hideText)}t.bindEvent(),t.o.lockHide&&t.ctrlButton.remove()},hide:function(e){var t=this,o=t.e;t.collapsed=!0,void 0===e&&(e=t.o.speed),f.isFunction(t.o.beforeHide)&&t.o.beforeHide.call(t.e,t);function a(){f.isFunction(t.o.afterHide)&&t.o.afterHide.call(t.e,t)}if(o.find("[data-ctrl]").remove(),"chars"==t.mode||"words"==t.mode){var n=o.html(),i=t.getCollapsedHTML(n,t.mode,t.o.truncate);if(i){var l=o.text();t.remaining=l.split("words"==t.mode?" ":"").length-t.o.truncate,o.data("collHTML",n),o.html(i)}else t.remaining=0}if("lines"==t.mode){var s=o.children("div"),r=s.outerHeight();if(0==(c=s.find("[data-col-char]")).length){var c=f('<span style="display:none" data-col-char>.</span>');s.prepend(c)}var d=c.height(),h=d*t.o.truncate+d/4;r<=h?(h="auto",t.remaining=0):t.remaining=parseInt(Math.ceil((r-h)/d)),s.css({overflow:"hidden",height:h})}"block"==t.mode&&t.blockMode(o,"hide",e,a),a(),"block"!=t.mode&&(o.removeClass(t.o.showClass).addClass(t.o.hideClass),!f.isFunction(t.o.controlBtn)&&0<t.remaining&&o.append(t.ctrlButton),t.ctrlButton.html(t.o.showText)),t.bindEvent()},blockMode:function(e,t,o,a){var n=this,i=["fadeOut","slideUp","fadeIn","slideDown"],l="fade"==n.o.blockEffect?0:1,s="hide"==t?i[l]:i[2+l];f.isFunction(n.o.blockTarget)?n.o.blockTarget.call(n.e)[s](o,a):f.fn[n.o.blockTarget]&&f(e)[n.o.blockTarget]()[s](o,a),"show"==t?(e.removeClass(n.o.showClass).addClass(n.o.hideClass),n.o.changeText&&e.text(n.o.hideText)):(e.removeClass(n.o.hideClass).addClass(n.o.showClass),n.o.changeText&&e.text(n.o.showText))},getCollapsedHTML:function(e,t,o){for(var a=!1,n=0,i=0,l=!0,s=0;s<=e.length;s++){if(char=e.charAt(s),"<"==char&&(a=!0),">"==char&&(a=!1),n==o){i=s,l=!1;break}a||("words"==t&&" "==char&&n++,"chars"==t&&n++)}if(l)return!1;var r=e.slice(0,i);return this.balanceTags(r)+'<span class="coll-ellipsis">'+this.o.ellipsis+"</span>"},balanceTags:function(e){e.lastIndexOf("<")>e.lastIndexOf(">")&&(e=e.substring(0,e.lastIndexOf("<")));var t=e.match(/<[^>]+>/g),o=new Array;for(tag in t)t[tag].search("/")<=0?o.push(t[tag]):1==t[tag].search("/")&&o.pop();for(;0<o.length;){var a=o.pop();e+="</"+(a=a.substring(1,a.search(/[>]/)))+">"}return e},bindEvent:function(){var t=this;("block"==t.mode?t.e:t.ctrlButton).off("click").on("click",function(e){e.preventDefault(),t.collapsed?t.show():t.hide()})}},f.fn[t]=function(e){return this.each(function(){f.data(this,t)||f.data(this,t,new o(this,e))})}}(jQuery,(window,document)); |