1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00
Sonarr/NzbDrone.Web/Scripts/2011.2.712/telerik.imagebrowser.min.js
Mark McDowall 8d0cdf272c Moved away from CDNs for 3rd party scripts.
Added Telerik MVC Controls, JQuery, JQueryUI and YUI.
2011-09-07 19:48:37 -07:00

1 line
16 KiB
JavaScript

(function(i,o){var n=i.telerik,e=i.telerik.query;n.scripts.push("telerik.imagebrowser.js");n.imageBrowser=function(q,r){this.element=q;this.wrapper=i(q);var t=r.filter||"*.png,*.gif,*.jpg,*.jpeg";var s=r.localization;this.wrapper.append('<div class="t-floatwrap"><div class="t-widget t-combobox t-header t-breadcrumbs"><div class="t-dropdown-wrap t-state-default"><input type="text" class="t-input" /><div class="t-breadcrumbs-wrap"/><span class="t-select t-header"><span class="t-icon t-arrow-down">select</span></span></div></div><div class="t-widget t-combobox t-dropdown-wrap t-search-wrap" /></div>').append(k(s,r.uploadUrl,r.createDirectoryUrl,r.deleteFileUrl||r.deleteDirectoryUrl)).append('<ul id="t-editor-image-list" class="t-reset t-floats t-tiles" />');var u=this.wrapper.find(".t-breadcrumbs");var y=this.wrapper.find(".t-tiles");var v=this.wrapper.find(".t-search-wrap");if(r.uploadUrl){this.wrapper.find(".t-upload input").tUpload({async:{saveUrl:r.uploadUrl,autoUpload:true},multiple:false,onUpload:function(B){var C=new RegExp(("("+t.split(",").join(")|(")+")").replace(/\*\./g,".*."),"i");var A=B.files[0].name;if(C.test(A)){B.data={path:u.val()};y.trigger("t:upload",[{name:A},function(){B.preventDefault()}])}else{B.preventDefault();alert(n.formatString(s.invalidFileType,A,t))}},onError:function(A){A.preventDefault();y.trigger("t:error",[A.files[0]]);var B=A.XMLHttpRequest;if(n.ajaxError(r.element,"error",B,B.statusText)){return}},onSuccess:function(A){y.trigger("t:completeFile",[i.extend(A.response,{path:u.val()})])}})}new n.searchBox(v[0]);new n.fileListView(y[0],{thumbnailUrl:r.thumbUrl,localization:s});var w=new n.dropDown({effects:n.fx.slide.defaults(),onClick:function(A){i(q).find(".t-tiles-arrange a span:first").html(i(A.item).text());w.close();u.trigger("t:change")}});var z=[{Text:s.orderByName,Value:"name"},{Text:s.orderBySize,Value:"size"}];w.dataBind(z);this.wrapper.find(".t-tiles-arrange a").click(function(B){B.preventDefault();var A=i(this);w.open({offset:A.offset(),outerHeight:A.outerHeight(),outerWidth:A.outerWidth(),zIndex:n.getElementZIndex(this)})}).end().delegate(".t-button:not(.t-state-disabled):has(.t-delete)","click",function(){var A=y.find(".t-state-selected");if(A.length&&confirm(n.formatString(s.deleteFile,A.find("strong").text()))){i.ajax({type:"POST",url:A.data("kind")=="f"?r.deleteFileUrl:r.deleteDirectoryUrl,data:{path:A.data("url")},error:function(C,B){if(n.ajaxError(r.element,"error",C,B)){return}},success:function(){y.trigger("t:delete");i(q).find(".t-delete").parent().addClass("t-state-disabled")}})}}).delegate(".t-button:not(.t-state-disabled):has(.t-addfolder)","click",function(){y.trigger("t:createDirectory",[function(A){i.ajax({type:"POST",url:r.createDirectoryUrl,data:{path:u.val(),name:A},error:function(C,B){y.trigger("t:errorDirectory",{name:A});if(n.ajaxError(r.element,"error",C,B)){return}},success:function(){y.trigger("t:completeDirectory",{path:u.val(),name:A})}})}])});i(document.documentElement).bind("mousedown",function(B){var A=w.$element[0];if(!i.contains(A,B.target)){w.close()}});var x=new n.dataSource({error:function(A,C){var B=n.trigger(r.element,"error",{XMLHttpRequest:A,textStatus:C});if(!B){if(C=="error"){if(A.status=="404"){alert(r.localization.directoryNotFound)}else{if(A.status!="0"){alert("Error! The requested URL returned "+A.status+" - "+A.statusText)}}}else{if(C=="timeout"){alert("Error! Server timeout.")}}}},url:r.selectUrl,callback:function(B){i(q).find(".t-delete").parent().addClass("t-state-disabled");if(!u.val()){new n.breadcrumbs(u[0],{path:B.Path,roots:B.ContentPaths})}u.val(B.Path).trigger("t:refresh");var C=i(q).find(".t-tiles-arrange a span:first").text();var A=i.map(z,function(E){if(E.Text==C){return E.Value}})[0];var D=v.val();y.trigger("t:refresh",[B,A,D])}});v.bind("t:change",function(){u.trigger("t:change")});x.get({path:""});y.bind("t:select",function(A){if(A.kind=="d"){x.get({path:A.url})}else{r.apply(A)}}).bind("t:change",function(B){var C=i(q).find(".t-delete").parent().addClass("t-state-disabled");if(B.kind=="f"){var A=B.url;if(r.imageUrl){A=r.imageUrl+"?path="+A}i(q).parent().find("#t-editor-image-url").val(A)}if((B.kind=="f"&&r.deleteFileUrl)||(B.kind=="d"&&r.deleteDirectoryUrl)){C.removeClass("t-state-disabled")}});u.bind("t:change",function(){var A=i(this).val();if(!A.match(/\/$/)){A=A+"/"}x.get({path:A})})};function k(r,s,t,q){var v=!s?"":'<div class="t-widget t-upload"><div class="t-button t-button-icontext t-button-bare t-upload-button"><span class="t-icon t-add"></span>'+r.uploadFile+'<input type="file" name="file" /></div></div>',u=!t?"":'<button type="button" class="t-button t-button-icon t-button-bare"><span class="t-icon t-addfolder"></span></button>',w=!q?"":'<button type="button" class="t-button t-button-icon t-button-bare t-state-disabled"><span class="t-icon t-delete"></span></button>&nbsp;';return'<div class="t-widget t-toolbar t-floatwrap"><div class="t-toolbar-wrap">'+v+u+w+'</div><div class="t-tiles-arrange">'+r.orderBy+' <a href="#" class="t-link"><span>'+r.orderByName+'</span><span class="t-icon t-arrow-down"></span></a></div></div>'}n.fileInfoReader=function(q){this._thumbnailUrl=q.thumbnailUrl||""};n.fileInfoReader.prototype={read:function(q,r){return r[q]||r[(q.charAt(0).toUpperCase()+q.substring(1))]},directories:function(q){return this.read("directories",q)},files:function(q){return this.read("files",q)},thumbUrl:function(q,r){return this._thumbnailUrl+"/?path="+q+r},size:function(s){var q=this.read("size",s);if(!q){return""}var r=" bytes";if(q>=1073741824){r=" GB";q/=1073741824}else{if(q>=1048576){r=" MB";q/=1048576}else{if(q>=1024){r=" KB";q/=1024}}}return Math.round(q*100)/100+r},name:function(q){return this.read("name",q)},path:function(q){return this.read("path",q)},concatPaths:function(q,r){if(q===o||!q.match(/\/$/)){q=(q||"")+"/"}return q+r}};n.fileListView=function(q,r){this.element=q;this.wrapper=i(q);this._localization=r.localization;this._reader=r.reader||new n.fileInfoReader({thumbnailUrl:r.thumbnailUrl});this._pageSize=r.pageSize||20;this.wrapper.bind({"t:refresh":i.proxy(this._refresh,this),"t:upload":i.proxy(this._upload,this),"t:completeFile":i.proxy(this._completeFile,this),"t:completeDirectory":i.proxy(this._completeDirectory,this),"t:delete":i.proxy(this._delete,this),"t:errorFile":i.proxy(this._errorFile,this),"t:errorDirectory":i.proxy(this._errorDirectory,this),"t:createDirectory":i.proxy(this._createDirectory,this),scroll:i.proxy(this._scroll,this)}).delegate("li[data-url]:not(.t-tile-empty)","click",i.proxy(this._click,this)).delegate("li[data-url]:not(.t-tile-empty)","dblclick",i.proxy(this._dblclick,this))};function d(q){return'<li class="t-tile" data-filename="'+q.name+'"><div class="t-thumb"><span class="t-icon t-loading"></span></div><strong>'+q.name+"</strong></li>"}function m(q){return'<li class="t-tile-empty"><strong>'+q+"</strong></li>"}function h(q){return'<li class="t-tile" data-filename="'+q.name+'" data-thumburl="'+q.thumbUrl+'" data-url="'+q.url+'" data-kind="'+q.kind+'"><div class="t-thumb"><span class="t-icon t-loading"></span></div><strong>'+q.name+'</strong><span class="t-filesize">'+q.size+"</span>";"</li>"}function l(q){return'<li class="t-tile" data-url="'+q.url+'" data-kind="'+q.kind+'"><div class="t-thumb"><span class="t-icon t-folder"></span></div><strong>'+q.name+"</strong></li>"}function p(q){return'<li class="t-tile" data-kind="d"><div class="t-thumb"><span class="t-icon t-folder"></span></div><input class="t-input" value="'+q+'" /></li>'}function b(r){var s=i(r);var q=i("<img />",{src:s.data("thumbUrl"),alt:s.data("filename")}).hide().bind("load",function(){i(this).prev().remove().end().addClass("t-image").fadeIn()});s.find(".t-loading").after(q);r.loaded=true}if(i.browser.msie&&parseFloat(i.browser.version)<8){var a=function(q){return q.offsetTop}}else{var a=function(q){return q.offsetTop-i(q).height()}}var f=/(\:|\^|\$|\/|\.|\+|\||\(|\)|\[|\]|\{|\}|\\)/g,j=/\*/g,c=/\?/g;function g(q){return new RegExp(q.replace(f,"\\$1").replace(j,".*").replace(c,".?"),"ig")}n.fileListView.prototype={bindTo:function(r,t,s){this._filter=s;var x=this._reader;this.wrapper.empty();var q=e(this._reader.directories(r)||[]);var v=e(this._reader.files(r)||[]);if(s){var w=function(z){return g(s).test(x.name(z))};q=q.where(w);v=v.where(w)}var y=function(z){return x[t](z)};this._data=this._process(this._reader.path(r),q.orderBy(y),v.orderBy(y));var u=this._data.select(function(z){return z.kind=="f"?h(z):l(z)}).toArray().join("");this.wrapper.append(u);this._tiles=this.wrapper.find("li[data-kind=f]");this._scroll();this._asEmpty()},_asEmpty:function(){if(!this._data.any()&&!this._filter){this.wrapper.append(m(this._localization.emptyFolder))}},_completeFile:function(u,r){var t=this._reader.name(r);var q=this._reader.path(r);var s=i(h({kind:"f",thumbUrl:this._reader.thumbUrl(q,t),url:this._reader.concatPaths(q,t),name:t,size:this._reader.size(r)}));this.wrapper.find("li").eq(this.fileIndex(t)).replaceWith(s);b(s[0]);s.click()},_completeDirectory:function(u,r){var t=this._reader.name(r);var q=this._reader.path(r);var s=i(l({kind:"d",url:this._reader.concatPaths(q,t),name:t}));this.wrapper.find("li").eq(this.directoryIndex(t)).replaceWith(s)},_delete:function(){var q=this.wrapper.find(".t-state-selected");if(q.length){var r=this._data.toArray();r.splice(q.index(),1);this._data=e(r);q.remove();this._scroll();this._asEmpty()}},_scroll:function(q){clearTimeout(this._timeout);this._timeout=setTimeout(i.proxy(function(){var r=this.wrapper.outerHeight();var t=this.wrapper.scrollTop();var s=t+r;this._tiles.each(function(){var v=a(this);var u=v+this.offsetHeight;if((v>=t&&v<s)||(u>=t&&u<s)){b(this)}if(v>s){return false}});this._tiles=this._tiles.filter(function(){return !this.loaded})},this),250)},_upload:function(u,q,v){var s=this.fileIndex(q.name);if(s>-1&&!confirm(n.formatString(this._localization.overwriteFile,q.name))){v()}else{this.wrapper.find(".t-tile-empty").remove();var w=i(d(q));if(s>-1){w.data("existing",true);this.wrapper.find("li").eq(s).replaceWith(w)}else{var t=this.wrapper.find("li[data-kind=f]:first");if(t.length){t.before(w)}else{this.wrapper.append(w)}var r=this._data.toArray();r.splice(w.index(),0,{name:q.name,kind:"f"})}this.wrapper.scrollTop(w.attr("offsetTop")-this.element.offsetHeight)}},_nameDirectory:function(){var t="New folder";var s=this._data.where(function(u){return u.kind=="d"&&u.name.indexOf(t)>-1}).select(function(u){return u.name}).toArray();if(i.inArray(t,s)>-1){var r=2;do{var q=t+" ("+r+")";r++}while(i.inArray(q,s)>-1);t=q}return t},_createDirectory:function(u,r){var t=this._nameDirectory();var w=i(p(t));var v=this.wrapper.find("li[data-kind=f]:first");if(v.length){v.before(w)}else{this.wrapper.append(w)}var q=this._data.toArray();var s=w.addClass("t-state-selected").siblings().removeClass("t-state-selected").end().find("input").keydown(function(x){if(x.keyCode==13){this.blur()}}).blur(i.proxy(function(x){var y=i.trim(x.target.value);if(!y||this._data.any(function(z){return z.kind=="d"&&z.name.toLowerCase()==y.toLowerCase()})){y=this._nameDirectory()}q.splice(w.index(),0,{name:y,kind:"d"});i(x.target).replaceWith("<strong>"+y+"</strong>");r(y)},this));setTimeout(function(){s.select()});this.wrapper.find(".t-tile-empty").remove();this.wrapper.scrollTop(w.attr("offsetTop")-this.element.offsetHeight)},_errorFile:function(u,s){var q=this.fileIndex(s.name);if(q>-1){var r=this.wrapper.find("li").eq(q);if(r.data("existing")){var t=i(h(this._data.toArray()[q]));r.replaceWith(t);b(t[0])}else{r.remove();this._data.toArray().splice(q,1)}this._asEmpty()}},_errorDirectory:function(s,r){var q=this.directoryIndex(r.name);if(q>-1){this.wrapper.find("li").eq(q).remove();this._data.toArray().splice(q,1);this._asEmpty()}},fileIndex:function(q){return this._index("f",q)},directoryIndex:function(q){return this._index("d",q)},_index:function(s,t){var q=-1,r=this._data?this._data.toArray():[];t=t.toLowerCase();i.each(r,function(u,v){if(v.kind==s&&v.name.toLowerCase()==t){q=u;return false}});return q},_raise:function(s,q){var r=i(s.currentTarget);n.trigger(this.wrapper,q,{kind:r.data("kind"),url:r.data("url")})},_click:function(q){i(q.currentTarget).addClass("t-state-selected").siblings().removeClass("t-state-selected");this._raise(q,"t:change")},_dblclick:function(q){if(document.selection&&document.selection.empty){document.selection.empty()}this._raise(q,"t:select")},_refresh:function(t,q,s,r){this.bindTo(q,s,r)},_process:function(s,q,r){var t=this._reader;var q=q.select(function(u){return{url:t.concatPaths(s,t.name(u)),name:t.name(u),kind:"d"}});var r=r.select(function(u){var v=t.name(u);return{url:t.concatPaths(s,v),name:v,kind:"f",thumbUrl:t.thumbUrl(s,v),size:t.size(u)}});return q.concat(r)}};n.dataSource=function(q){this._url=q.url;this._callback=q.callback;this._error=q.error};n.dataSource.prototype={_complete:function(q){if(this._callback){this._callback(q)}},get:function(q){i.ajax({type:"POST",url:this._url,data:q,success:i.proxy(this._complete,this),error:this._error})}};n.breadcrumbs=function(r,s){this.element=r;this.wrapper=i(r);this._gap=s.gap||50;this._initPaths(s.path);var q=new n.dropDown({effects:n.fx.slide.defaults(),onClick:i.proxy(function(t){var u=i(t.item).text();q.close();this._initPaths(u);i(r).val(u).trigger("t:change")},this)});q.dataBind(s.roots);this.wrapper.delegate("input","focus",i.proxy(this._focus,this)).delegate("input","blur",i.proxy(this._blur,this)).delegate("input","keydown",i.proxy(function(t){if(t.keyCode==13){this._blur()}},this)).delegate("a:not(.t-first)","click",n.stopAll(this._click,this)).delegate(".t-select","click",function(){var t=i(r);q.open({offset:t.offset(),outerHeight:t.outerHeight(),outerWidth:t.outerWidth(),zIndex:n.getElementZIndex(this)})}).bind("t:refresh",i.proxy(this.refresh,this));i(document.documentElement).bind("mousedown",function(u){var t=q.$element[0];if(!i.contains(t,u.target)){q.close()}});this.value(s.path)};n.breadcrumbs.prototype={_initPaths:function(q){this._basePath=(q||"").replace(/\/{2,}/g,"/").replace(/\/$/,"");q=this._basePath.split("/");q.pop();this._root=q.join("/")},_html:function(){var r=this._basePath.split("/").length-1;var q=this.value();if(q===o||!q.match(/^\//)){q="/"+(q||"")}return'<div class="t-dropdown-wrap t-state-default"><input type="text" class="t-input" /><div class="t-breadcrumbs-wrap">'+i.map(q.split("/"),function(t,s){if(t&&s>=r){return'<a class="t-link" href="#">'+t+"</a>"}}).join('<span class="t-icon t-arrow-next">&gt;</span>')+'</div><span class="t-select t-header"><span class="t-icon t-arrow-down">select</span></span></div>'},_path:function(q){return this._root+"/"+i.map(q,function(r){return i(r).text()}).join("/")},_update:function(q){q=q.charAt(0)==="/"?q:"/"+q;var r=this.value()!=q;this.value(q);if(r){this.wrapper.trigger("t:change")}},value:function(q){if(q!==o){this.wrapper.val(q.replace(/\/{2,}/g,"/"));this.refresh()}else{return this.wrapper.val()}},_click:function(q){this._update(this._path(i(q.target).prevAll("a").andSelf()))},refresh:function(){this.wrapper.empty().append(this._html());var r=this.wrapper.width()-this._gap;var q=this.wrapper.find("a");q.each(function(t){var s=i(this);if(s.parent().width()>r){if(t==q.length-1){s.width(r)}else{s.prev().andSelf().hide()}}})},_focus:function(){var q=this.wrapper.find(".t-breadcrumbs-wrap").hide().end().find("input").val(this.value());setTimeout(function(){q.select()})},_blur:function(){var q=this.wrapper.find("input").val().replace(/\/{2,}/g,"/");if(!q||q.toLowerCase().indexOf(this._basePath.toLowerCase())<0){q=this._basePath}this._update(q)}};n.searchBox=function(q){this.element=q;this.wrapper=i(q);this.wrapper.delegate("input","focus",i.proxy(this._focus,this)).delegate("input","blur",i.proxy(this._blur,this)).delegate("input","keydown",i.proxy(function(r){if(r.keyCode==13){this._blur()}},this)).delegate("a","click",n.stopAll(this._click,this));this._render()};n.searchBox.prototype={_render:function(){var q='<label for="t-imagebrowser-search">Search</label><input type="text" id="t-imagebrowser-search" class="t-input" /><a href="#" class="t-icon t-search">search</a>';this.wrapper.empty().append(i(q))},_focus:function(){this.wrapper.find("label").hide()},_blur:function(){this._update(this.wrapper.find("input").val());if(this.value()==""){this.wrapper.find("label").show()}},_update:function(q){var r=this.value()!=q;this.value(q);if(r){this.wrapper.trigger("t:change")}},value:function(q){if(q!==o){this.wrapper.val(q)}else{return this.wrapper.val()}},_click:function(){this._blur()}}})(jQuery);