Skip to content

Commit

Permalink
Merge pull request Dynalon#248 from guillermocalvo/gimmicks/favicon
Browse files Browse the repository at this point in the history
Add favicon gimmick (master).
  • Loading branch information
Dynalon authored Nov 27, 2017
2 parents 44f0206 + fe71020 commit 3804ef2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions js/gimmicks/favicon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* # FAVICON GIMMICK
*
* Creates a link containing a favicon (through Google S2 API).
*
* ## Usage
*
* [gimmick:favicon](https://github.com/)
*
* [gimmick:favicon (caption: 'Github') ](https://github.com/)
*
* ## Options
*
* * **width**: Image width.
* * **height**: Image height.
* * **alt**: Alternative favicon.
* * **domain**: Favicon domain.
* * **caption**: Link caption.
* * **target**: Link target.
* * **cssClass**: Link CSS class.
*
* ## Author
*
* Copyright 2015 Guillermo Calvo
*
* <https://github.com/guillermocalvo/>
*/
(function($){
'use strict';
function favicon($link, opt, text){
var default_options = {
width: 16, /* image width */
height: 16, /* image height */
alt: '', /* alternative favicon */
domain: '', /* favicon domain */
caption: text, /* link caption */
target: '', /* link target */
cssClass: '' /* link css class */
};
var options = $.extend ({}, default_options, opt);
return $link.each( function(i,e){
var htmlImage = '<img src="https://www.google.com/s2/favicons?' + (options.domain ? 'domain=' + options.domain : 'domain_url=' + e) + (options.alt ? '&alt=' + options.alt : '') + '" width="' + options.width + '"' + ' height="' + options.height + '"' + ' alt="favicon"' + '>';
var htmlLink = '<a href="' + e + '"' + (options.target ? ' target="' + options.target + '"' : '') + (options.cssClass ? ' class="' + options.cssClass + '"' : '') + '>' + htmlImage + (options.caption ? ' ' + options.caption : '') + '</a>';
$(e).replaceWith(htmlLink);
});
}

var gimmick = new MDwiki.Core.Gimmick();
gimmick.addHandler('favicon', favicon);
$.md.wiki.gimmicks.registerGimmick(gimmick);

}(jQuery));

0 comments on commit 3804ef2

Please sign in to comment.