This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fff.widget.min.js
1 lines (1 loc) · 8.1 KB
/
fff.widget.min.js
1
var finurligeFaktaWidget=function(){"use strict";function e(a){var b=new RegExp("[?&]"+a+"=([^&]*)").exec(window.location.search);return b&&decodeURIComponent(b[1].replace(/\+/g," "))}function f(b,c){if(void 0===window._gaq){var e=d("<script />",{type:"text/javascript",async:!0,src:("https:"==document.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js"}),f=d('<script type="text/javascript">var _gaq = _gaq || [];</script>');d("body").append(e).append(f)}c===!0&&_gaq.push(["fff._setAccount",a.GAProfile],["fff._setDomainName",document.location.host],["fff._trackPageview"]);for(var g in b)_gaq.push(["fff._setAccount",a.GAProfile],["fff._setDomainName",document.location.host],["fff._trackEvent","Finurlig Fakta",g,b[g]])}function g(){this.widget="",this.data={},this.params={},this.reloaded=!1,this.init=function(a,b){this.data=a,this.params=b,this.build(),this.style()},this.build=function(){if(this.widget=d("<div/>",{"class":"fffW-"+this.params.widget+" fffW-widget"}).append(d("<div />",{"class":"fffW-innerwrapper"}).append(d("<h2 />",{"class":"fffW-title",text:this.data.title})).append(d("<p />",{"class":"fffW-text"}).append(this.data.content))),d(".fffW-innerwrapper",this.widget).append(d("<div />",{"class":"fffW-slogan"}).append(d("<p />",{"class":"fffw-slogan-text",text:"Viden fra biblioteket"}))),this.params.button.reload){var a=this,b=d('<a class="fffw-button fffw-button-reload" href="#">Indl\xe6s et nyt faktum</a>');d(".fffW-innerwrapper",this.widget).prepend(b),b.click(function(b){b.stopPropagation(),b.preventDefault(),a.params.tracking&&f({Reloaded:document.location.host}),a.params.guid=null,a.params.callback="finurligeFaktaWidget.reload",d(a.params.target).data("widget",a),j(a.params)})}if(this.params.button.create){var c=d('<a class="fffw-button fffw-button-create" href="#">Tilf\xf8j Fakta</a>');d(".fffW-slogan",this.widget).prepend(c),c.click(function(b){b.stopPropagation(),b.preventDefault(),a.params.tracking&&f({"New fact":document.location.host});var c=d("<div/>",{"class":"fffw-dialog"}).append(d("<h3/>",{"class":"fffw-header"}).html("Bidrag med Finurlige Fakta")).append(d("<a/>",{"class":"fffw-close",href:"#"}).html("Close")).append(d("<iframe/>",{"class":"fffw-dialog-iframe"}));d("body").append(d("<div/>",{"class":"fffw-overlay"})),d("body").append(c),d("iframe",c).attr("src","//finurligefakta.dk/ajax/create/fact"),d(".fffw-close",c).click(function(){c.remove(),d(".fffw-overlay").remove()})})}this.widget.hide()},this.style=function(){switch(this.params.style.type){case"none":d(".fffW-slogan",this.widget).before(this.getSourceLinks()),d(".fffW-slogan",this.widget).before(this.getAuthor()),d(".fffW-slogan",this.widget).before(this.getOrganization());break;case"minimal":this.addCSS(this.params.widget,"minimal",this.params.style.color),d(".fffW-innerwrapper",this.widget).prepend('<span class="fffw-logo"></span>');break;case"normal":d(".fffW-slogan",this.widget).before(this.getSourceLinks()),d(".fffW-innerwrapper",this.widget).prepend('<span class="fffw-logo"></span>'),this.addCSS(this.params.widget,"normal",this.params.style.color);break;case"full":d(".fffW-slogan",this.widget).before(this.getSourceLinks()),d(".fffW-slogan",this.widget).before(this.getAuthor()),d(".fffW-slogan",this.widget).before(this.getOrganization()),d(".fffW-innerwrapper",this.widget).prepend('<span class="fffw-logo"></span>'),this.addCSS(this.params.widget,"full",this.params.style.color)}},this.addCSS=function(b,c,e){var f=a.widgetDomain+"css/fffw-"+b+"."+c+"."+e+".css";document.createStyleSheet?document.createStyleSheet(f):d("head").append('<link media="all" rel="stylesheet" href="'+f+'" type="text/css" />')},this.getSourceLinks=function(){var a=d("<div />",{"class":"fffW-external-links fffW-extra"}).append(d("<span />",{"class":"fffW-label",text:"L\xe6s mere:"}));for(var b in this.data.sources)a.append(d("<a />",{"class":"fffw-link",rel:"external",href:this.data.sources[b].url,text:this.data.sources[b].title}));return a},this.getAuthor=function(){return d("<div />",{"class":"fffW-author fffW-extra"}).append(d("<span />",{text:"Forfatter:","class":"fffW-label"})).append(this.data.author)},this.getOrganization=function(){return d("<div />",{"class":"fffW-orgnization fffW-extra"}).append(d("<span />",{text:"Organisation:","class":"fffW-label"})).append(this.data.organization)},this.insert=function(){var a=d(this.params.target);return 1!=a.length?(alert("The target div was not found on the page. Please add it to the page and try again."),-1):(a.html(this.widget),null!==this.params.event.loadComplet&&this.params.event.loadComplet(),this.show(),void 0)},this.reload=function(a){var b=this;b.data=a,b.reloaded=!0,b.hide(function(){switch(d(".fffW-title",b.widget).text(b.data.title),d(".fffW-text",b.widget).html(b.data.content),b.params.style.type){case"none":case"normal":case"full":d(".fffW-external-links",b.widget).html(b.getSourceLinks()),d(".fffW-author",b.widget).html(b.getAuthor()),d(".fffW-orgnization",b.widget).html(b.getOrganization())}b.show()})},this.hide=function(a){this.widget.hide(0,function(){a&&a()})},this.show=function(a){this.widget.show(0,function(){a&&a()})}}function h(){}function i(){}function j(b){null!==b.guid?l(b):d.getJSON(a.domain+"?method=getGuid&api-key=714800b6f8ab26ce459c2d7ee11b15c3&callback=?",function(a){b.guid=a.guid,l(b)})}function k(a){var b=c[a.guid],e=d(b.target).data("widget");e.reload(a)}function l(b){var e="getFact";c[b.guid]=b,d.ajax({url:a.domain,cache:!0,data:{guid:b.guid,method:e,"api-key":"714800b6f8ab26ce459c2d7ee11b15c3"},dataType:"jsonp",jsonp:"callback",jsonpCallback:b.callback})}function m(a){var d,b=c[a.guid];switch(b.widget){case"interactive":d=new h,d.init(a,b),d.insert();break;case"slidein":d=new i,d.init(a,b),d.createTarget(),d.insert();break;default:alert("The selected firnulig fakta widget type is not supported")}}function n(c){d=c,a.baseGuid=e("fffGuid"),d.each(fffWidgetConfig,function(c,e){e.guid=a.baseGuid,e=d.extend({},b,e),e.style.color||(e.style.color="default"),e.style.type||(e.style.type="minimal"),e.tracking&&f({"Loaded at":document.location.host,"Widget type":e.widget,"Widget style":e.style.type,"Widget color":e.style.color},!0),j(e)})}var d,a={domain:"//service.finurligefakta.dk/",widgetDomain:"//service.finurligefakta.dk/widgets/",baseGuid:null,GAProfile:"UA-33089188-1"},b={callback:"finurligeFaktaWidget.load",widget:"interactive",target:"#fffwidget",style:{type:"normal",color:"default"},tracking:!0,button:{reload:!0,create:!1},event:{loadComplet:null}},c=[];return h.prototype=new g,h.prototype.show=function(){this.widget.fadeIn()},h.prototype.hide=function(a){this.widget.fadeOut(function(){a&&a()})},i.prototype=new g,i.prototype.createTarget=function(){var a;a="#"===this.params.target.charAt(0)?d("<div />",{id:this.params.target.substring(1)}):d("<div />",{"class":this.params.target.substring(1)}),a.addClass("fffW-widget-wrapper"),d("body").append(a)},i.prototype.show=function(){var a=this;d(window).scrollTop()>=d(document).height()-(d(window).height()+10)&&a.slideIn(),d(window).scroll(function(){d(window).scrollTop()>=d(document).height()-(d(window).height()+10)&&a.slideIn()})},i.prototype.hide=function(a){this.reloaded?this.widget.fadeOut(function(){a&&a()}):d(".fffW-slidein").animate({width:"0px"},{complete:function(){d(".fffW-slidein").removeClass("active"),a&&a()}},1e3)},i.prototype.slideIn=function(){var a=this;if(a.reloaded)a.widget.fadeIn(),a.reloaded=!1;else{var b=d(".fffW-slidein");b.hasClass("active")||(a.widget.show(),b.width("0px").animate({width:"370px"},{complete:function(){b.addClass("active")}},1e3))}},{init:n,load:m,reload:k}}();!function(){"use strict";var a=function(a,b){var c=document.createElement("script");c.type="text/javascript",c.readyState?c.onreadystatechange=function(){("loaded"==c.readyState||"complete"==c.readyState)&&(c.onreadystatechange=null,b())}:c.onload=function(){b()},c.src=a,document.getElementsByTagName("head")[0].appendChild(c)};"undefined"!=typeof jQuery&&parseFloat(jQuery.fn.jquery)>=1.4?jQuery(document).ready(function(){finurligeFaktaWidget.init(jQuery)}):a("https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js",function(){var a=jQuery.noConflict(!0);a(document).ready(function(){finurligeFaktaWidget.init(a)})})}();