tooltip.commit.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * GitPHP Javascript commit tooltip
  3. *
  4. * Displays commit messages 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/geturl", "modules/getproject", 'modules/resources'],
  12. function($, url, project, resources) {
  13. function getCommitHash(element) {
  14. var hash = element.attr('href').match(/h=([0-9a-fA-F]{4,40}|HEAD)/);
  15. if (!hash) {
  16. hash = element.attr('href').match(/\/commits\/([0-9a-fA-F]{4,40}|HEAD)/);
  17. }
  18. return hash ? hash[1] : null;
  19. }
  20. function buildTipConfig(hash) {
  21. return {
  22. content: {
  23. text: '<img src="' + url + 'images/tooltip-loader.gif" alt="' + resources.Loading + '" />',
  24. ajax: {
  25. url: url,
  26. data: {
  27. p: project,
  28. a: 'commit',
  29. o: 'jstip',
  30. h: hash
  31. },
  32. type: 'GET'
  33. }
  34. },
  35. style: {
  36. classes: 'ui-tooltip-gitphp ui-tooltip-light ui-tooltip-shadow'
  37. },
  38. position: {
  39. viewport: $(window)
  40. }
  41. }
  42. }
  43. return function(elements) {
  44. if (elements && (elements.size() > 0)) {
  45. require(['qtip'], function() {
  46. elements.each(function(){
  47. var jThis = $(this);
  48. var hash = getCommitHash(jThis);
  49. if (!hash) {
  50. return;
  51. }
  52. var config = buildTipConfig(hash);
  53. jThis.qtip(config);
  54. });
  55. });
  56. }
  57. }
  58. }
  59. );