Horriblesubs/fansub/js/fansub.min.js

1 line
22 KiB
JavaScript
Raw Normal View History

2018-03-28 07:11:18 +02:00
if(window.wp=window.wp||{},window.fansub=window.fansub||{},"undefined"==typeof jQuery)throw new Error(fansub.i18n.jquery_undefined_error);jQuery(document).ready(function(t){"use strict";var e=t.fn.jquery.split(" ")[0].split(".");if(e[0]<2&&e[1]<9||1==e[0]&&9==e[1]&&e[2]<1)throw new Error(fansub.i18n.jquery_version_error)}),fansub.media_frame=null,fansub.media_items={},jQuery(document).ready(function(t){"use strict";var e=t("body");fansub.getParamByName=function(t,e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var i=new RegExp("[\\?&]"+e+"=([^&#]*)"),n=i.exec(t);return null===n?"":decodeURIComponent(n[1].replace(/\+/g," "))},fansub.receiveSelectedMediaItems=function(t){return t.state().get("selection")},fansub.receiveSelectedMediaItem=function(t){var e=fansub.receiveSelectedMediaItems(t);return e.first().toJSON()},fansub.isImageUrl=function(e){if(!t.trim(e))return!1;var i=!0,n=e.slice(-4);return".png"!=n&&".jpg"!=n&&".gif"!=n&&".bmp"!=n&&"jpeg"!=n&&".ico"!=n&&(i=!1),i},fansub.getTagName=function(t){return t.length?t.get(0).tagName:""},fansub.isUrl=function(t){var e=new RegExp("^(http://www.|https://www.|ftp://www.|www.){1}([0-9A-Za-z]+.)");return e.test(t)},fansub.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},fansub.getFirstMediaItemJSON=function(t){return t.first().toJSON()},fansub.createImageHTML=function(e){e=e||{};var i=e.alt||"",n=e.id||0,o=e.src||"",a=e.element||null;if(t.isNumeric(n)&&n>0)t.ajax({type:"POST",dataType:"json",url:fansub.ajax_url,data:{action:"fansub_sanitize_media_value",url:o,id:n},success:function(t){t.is_image||(o=t.type_icon),a.length&&a.html('<img src="'+o+'" alt="'+i+'">')}});else if(t.trim(o))return'<img src="'+o+'" alt="'+i+'">'},fansub.autoReloadPageNoActive=function(e,i){function n(){(new Date).getTime()-o>=e?window.location.reload(!0):setTimeout(n,i)}e=e||6e4,i=i||1e4;var o=(new Date).getTime();t(document.body).bind("mousemove keypress",function(){o=(new Date).getTime()}),setTimeout(n,i)},fansub.autoReloadPage=function(t){function e(){(new Date).getTime()-i>=t?window.location.reload(!0):setTimeout(e,1e3)}t=t||2e3;var i=(new Date).getTime();setTimeout(e,1e3)},fansub.debugLog=function(e){var i=JSON.stringify(e);t.ajax({type:"POST",dataType:"json",url:fansub.ajax_url,data:{action:"fansub_debug_log",object:i},success:function(t){}})},fansub.limitUploadFile=function(e){e.on("change",function(){var i=e.get(0).files.length,n=parseInt(e.attr("data-max")),o=this,a=e.next();if(t.isNumeric(n)||(n=-1),n>0&&i>n)return alert("Bạn không được chọn quá "+n+" tập tin."),e.val(""),!1;if(a.length&&(a.empty(),"undefined"!=typeof FileReader))for(var s=0;i>s;s++){var r=new FileReader,l=o.files.item(s).name;r.onload=function(e){var i=t("<img>",{src:e.target.result,"class":"thumb-image",alt:""}).attr("data-file-name",l);i.appendTo(a)},a.show(),r.readAsDataURL(e.get(0).files[s])}})},fansub.setCookie=function(t,e,i){var n=new Date;n.setTime(n.getTime()+60*i*1e3);var o,a="expires="+n.toGMTString();o=t+"="+e+"; "+a+"; path=/",document.cookie=o},fansub.iconChangeCaptchaExecute=function(){var e=t("img.fansub-captcha-reload"),i=t("img.fansub-captcha-image");return i.length?(i.css({cursor:"text"}),e.css({opacity:"0.75"}),e.on("mouseover",function(e){e.preventDefault(),t(this).css({opacity:"1"})}),e.on("mouseout mouseleave",function(e){e.preventDefault(),t(this).css({opacity:"0.75"})}),void e.on("click",function(e){e.preventDefault();var i=t(this),n=i.parent(),o=n.find("img.fansub-captcha-image");i.css({opacity:"0.25","pointer-events":"none"}),t.ajax({type:"POST",dataType:"json",url:fansub.ajax_url,data:{action:"fansub_change_captcha_image"},success:function(t){t.success?o.attr("src",t.captcha_image_url):alert(t.message),i.css({opacity:"0.75","pointer-events":"inherit"})}})})):!1},fansub.addDefaultQuicktagButton=function(){var t=e.find(".quicktags-toolbar");!e.hasClass("front-end")&&t.length&&"ed_toolbar"==t.attr("id")&&(QTags.addButton("hr","hr","\n<hr>\n","","h","Horizontal rule line",30),QTags.addButton("dl","dl","<dl>\n","</dl>\n\n","d","HTML Description List Element",