Skip to content

Instantly share code, notes, and snippets.

@jsicot
Last active December 14, 2015 20:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsicot/5142764 to your computer and use it in GitHub Desktop.
Save jsicot/5142764 to your computer and use it in GitHub Desktop.
linkToWikipedia (koha)
//Dans les XSLT au niveau des 7xx ajouter :
<a>
<xsl:attribute name="href"><xsl:text></xsl:text></xsl:attribute>
<xsl:attribute name="class"><xsl:text>wikipedia</xsl:text></xsl:attribute>
<xsl:attribute name="target"><xsl:text>_blank</xsl:text></xsl:attribute>
<xsl:value-of select="marc:subfield[@code='b']"/>
<xsl:text>+</xsl:text>
<xsl:value-of select="marc:subfield[@code='a']"/>
</a>
//Dans un script jquery
function linkToWikipedia() {
jQuery(".wikipedia").each(function() {
var link = jQuery(this);
var request = link.text();
jQuery.ajax({
type : 'GET',
async : false,
jsonpCallBack : 'testing',
contentType: 'application/json',
dataType: 'jsonp',
cache : false,
url : 'http://fr.wikipedia.org/w/api.php?action=opensearch&search='+request,
success : function(data, textStatus, jqXHR) {
if (data[1].length > 0) {
var result = "http://fr.wikipedia.org/wiki/"+data[1][0];
link.attr("href",result);
var parent = link.parent();
link.remove();
link.addClass("enabled");
link.html("");
parent.makeAppear(link);
}
},
error : makeAjaxError
});
});
}
// ***************************
// jQuery Object Expendation
// ***************************
(function($){
jQuery.fn.makeAppear = function(elt,_fx,_duration,_callback) {
elt = (jQuery.type(elt) == "string") ? jQuery(elt) : elt;
var fx = (_fx == "fade" || _fx == "slide") ? _fx : "fade";
var duration = _duration || 500;
var callback = _callback || function(){};
elt.css("display","none");
this.append(elt);
switch(fx) {
case "fade" :
elt.fadeIn(duration,callback);
break;
case "slide" :
elt.slideDown(duration,callback);
break;
default :
break;
}
};
jQuery.fn.fadeEmptying = function(_fx,_duration,_callback) {
var fx = (_fx == "fade" || _fx == "slide") ? _fx : "fade";
var duration = _duration || 500;
var callback = _callback || function(){};
var counter = 0;
var total = this.children().size();
var afterFX = function() {
jQuery(this).remove();
counter ++;
if (counter == total) {
callback();
}
};
this.children().each(function() {
switch(fx) {
case "fade" :
jQuery(this).fadeOut(duration,afterFX);
break;
case "slide" :
jQuery(this).slideUp(duration,afterFX);
break;
default :
break;
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment