1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2024-12-12 11:26:17 +01:00
LocalCDN-Firefox-Chrome-Brave/resources/urlive/1.1.1/jquery.urlive.min.jsm

9 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-04-15 07:12:33 +02:00
/*
* jquery.urlive.min.js v1.1.1, jQuery URLive
*
* View the plugin repository at:
* https://github.com/markserbol/urlive
*
*/
(function(c){var k={container:".urlive-container",target:"_blank",imageSize:"auto",render:!0,disableClick:!1,regexp:/((https?:\/\/)?[\w-@]+(\.[a-z]+)+\.?(:\d+)?(\/\S*)?)/i,yqlSelect:"*",callbacks:{onStart:function(){},onSuccess:function(){},onFail:function(){},noData:function(){},onLoadEnd:function(){},imgError:function(){},onClick:function(){}}},l=function(a){var e=RegExp(window.location.protocol+"//"+window.location.hostname),g="http"+(/^https/.test(window.location.protocol)?"s":"")+"://query.yahooapis.com/v1/public/yql?callback=?";return function(d){var b=/^https?:\/\//i.test(d.url)?d.url:window.location.protocol+"//"+d.url;/get/i.test(d.type)&&!/json/i.test(d.dataType)&&!e.test(b)&&/:\/\//.test(b)&&(d.url=g,d.dataType="json",d.data={q:'select {SELECT} from html where url="{URL}" and xpath="*" and compat="html5"'.replace("{SELECT}",d.yqlSelect).replace("{URL}",b+(d.data?(/\?/.test(b)?"&":"?")+c.param(d.data):"")),format:"xml"},!d.success&&d.complete&&(d.success=d.complete,delete d.complete),d.success=function(c){return function(e){c&&c.call(this,{responseText:(e.results[0]||"").replace(/<script[^>]+?\/>|<script(.|\s)*?\/script>/gi,"")},"success")}}(d.success));return a.apply(this,arguments)}}(c.ajax),g=function(){var a=c(this).data("urlive-container")||c(this);return c(a).find(".urlive-link")},h={init:function(a){var e=c.extend(!0,k,a);return this.each(function(){function a(f){l({url:f,type:"GET",yqlSelect:e.yqlSelect,beforeSend:e.callbacks.onStart}).done(function(a){c.isEmptyObject(a.results)?(e.callbacks.noData(),c.error("YQL request succeeded but with empty results",a)):(a=a.results[0],html=c("<div/>",{html:a}),get=function(a){return html.find('[property="'+a+'"]').attr("content")||html.find('[name="'+a+'"]').attr("content")||html.find(a).html()||html.find(a).attr("src")},set={image:b.data("image")||get("og:image")||get("img"),title:b.data("title")||get("og:title")||get("title"),description:b.data("description")||get("og:description")||get("description"),url:b.data("url")||get("og:url")||f,type:b.data("type")||get("og:type"),sitename:b.data("site_name")||get("og:site_name")},e.callbacks.onSuccess(set),e.render&&d(set))}).fail(function(a,d,b){e.callbacks.onFail();c.error("YQL request error: ",d,b)})}function d(a){outer=c("<a/>",{"class":"urlive-link",href:a.url,target:e.target});imgWrapper=c("<div/>",{"class":"urlive-img-wrapper"});textWrapper=c("<div/>",{"class":"urlive-text-wrapper"});c.each(a,function(d,b){b&&("image"==d?(/^(?:[a-z]+:)?\/\//i.test(b)||(b=/^https?:\/\//i.test(a.url)?a.url+b:window.location.protocol+"//"+a.url+b),img=c("<img/>",{src:b}),img.error(e.callbacks.imgError),img.appendTo(imgWrapper),img.hide().load(function(){var a=c(this).width(),b=c(this).closest(".urlive-link");c(this).addClass("urlive-"+d).show();"auto"==e.imageSize?a>=b.width()?b.addClass("urlive-img-large"):b.addClass("urlive-img-small"):"large"==e.imageSize?b.addClass("urlive-img-large"):"small"==e.imageSize&&b.addClass("urlive-img-small");e.callbacks.onLoadEnd()})):(elem=c("<span/>",{"class":"urlive-"+d,text:b}),elem.appendTo(textWrapper)))});outer.append(imgWrapper,textWrapper).appendTo(b.data("urlive-container"));outer.on("click",e.callbacks.onClick);if(e.disableClick)outer.on("click",function(a){a.preventDefault()})}var b=c(this),f=void 0;b.data("urlive-container",e.container);if(b.is("a"))f=b.attr("href");else var f=b.val()||b.text(),g=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,f=(f=e.regexp.exec(f))&&!g.test(f[0])?f[0]:null;f&&(/\.(?:jpe?g|gif|png)/.test(f)?(g=f.substr(f.lastIndexOf("/")+1),d({image:f,title:g,url:f})):a(f))})},close:function(a){g.apply(this).fadeOut(a)},remove:function(a){var c=g.apply(this);a?c.fadeOut(a,function(){c.remove()}):c.remove()},open:function(a){g.apply(this).fadeIn(a)},disable:function(){g.apply(this).on("click",function(a){a.preventDefault()})},enable:function(){g.apply(this).off("click")}};c.fn.urlive=function(a){if(h[a])return h[a].apply(this,Array.prototype.slice.call(arguments,1)