1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /* * GitPHP Javascript snapshot tooltip * * Displays choices of snapshot format in a tooltip * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2011 Christopher Han * @package GitPHP * @subpackage Javascript */ define(["jquery", 'modules/snapshotformats'], function($, formats) { function buildTipContent(href) { var content = '<div>' + GitPHP.Resources.Snapshot + ': '; var first = true; var cleanurl = href.indexOf('/snapshot') != -1; for (var type in formats) { if (formats.hasOwnProperty(type)) { if (!first) { content += ' | '; } if (cleanurl) { var newhref = href.replace("/snapshot", "/" + type); content += '<a href="' + newhref + '">' + formats[type] + '</a>'; } else { content += '<a href="' + href + '&fmt=' + type + '">' + formats[type] + '</a>'; } first = false; } } content += '</div>'; return content; } function buildTipConfig(content) { return { content: { text: content }, show: { event: 'click' }, hide: { fixed: true, delay: 150 }, style: { classes: 'ui-tooltip-gitphp ui-tooltip-light ui-tooltip-shadow' }, position: { viewport: $(window) } } } return function(elements) { if (elements && (elements.size() > 0)) { require(['qtip'], function() { elements.each(function(){ var jThis = $(this); var href = jThis.attr('href'); var content = buildTipContent(href); var config = buildTipConfig(content); jThis.qtip(config); jThis.click(function() { return false; }); }); }); } } } ); |