fancybox.js 725 B

123456789101112131415161718192021222324
  1. var rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)/;
  2. /**
  3. * Fancybox tag
  4. *
  5. * Syntax:
  6. * {% fancybox /path/to/image [/path/to/thumbnail] [title] %}
  7. */
  8. hexo.extend.tag.register('fancybox', function(args){
  9. var original = args.shift(),
  10. thumbnail = '';
  11. if (args.length && rUrl.test(args[0])){
  12. thumbnail = args.shift();
  13. }
  14. var title = args.join(' ');
  15. return '<a class="fancybox" href="' + original + '" title="' + title + '">' +
  16. '<img src="' + (thumbnail || original) + '" alt="' + title + '">'
  17. '</a>' +
  18. (title ? '<span class="caption">' + title + '</span>' : '');
  19. });