tooltip.snapshot.js 1.7 KB

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