cranefly.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. $(function () {
  2. // Register tooltips
  3. $('.tooltip-top').tooltip({placement: 'top', container: 'body'})
  4. $('.tooltip-bottom').tooltip({placement: 'bottom', container: 'body'})
  5. $('.tooltip-left').tooltip({placement: 'left', container: 'body'})
  6. $('.tooltip-right').tooltip({placement: 'right', container: 'body'})
  7. // Register popovers
  8. $('.popover-top').popover({placement: 'top'})
  9. $('.popover-bottom').popover({placement: 'bottom'})
  10. $('.popover-left').popover({placement: 'left'})
  11. $('.popover-right').popover({placement: 'right'})
  12. // Dont fire popovers on touch devices
  13. $("[class^='tooltip-']").on('show', function (e) {
  14. if ('ontouchstart' in document.documentElement) {
  15. e.preventDefault();
  16. }
  17. });
  18. // Start all dropdowns
  19. $('.dropdown-toggle').dropdown()
  20. // Dont hide clickable dropdowns
  21. $('.dropdown-clickable').on('click', function (e) {
  22. e.stopPropagation()
  23. });
  24. // Fancy user nav activation
  25. $('#fancy-user-nav').show();
  26. // Search form extension
  27. var nav_search_form = $('#navbar-search');
  28. nav_search_form.click(function() {
  29. nav_search_form.addClass('open');
  30. });
  31. $('html').click(function() {
  32. nav_search_form.removeClass('open');
  33. });
  34. nav_search_form.click(function(event) {
  35. event.stopPropagation();
  36. });
  37. // Checkbox Group Master
  38. $('input.checkbox-master').live('click', function(){
  39. if($(this).is(':checked')){
  40. $('input.checkbox-member').attr("checked" ,"checked");
  41. }
  42. else
  43. {
  44. $('input.checkbox-member').removeAttr('checked');
  45. }
  46. });
  47. // Checkbox Group Member
  48. $('input.checkbox-member').live('click', function(){
  49. if(!$(this).is(':checked')){
  50. $('input.checkbox-master').removeAttr('checked');
  51. }
  52. });
  53. // Check Confirmation on links
  54. $('a.confirm').live('click', function(){
  55. var decision = confirm(jQuery.data(this, 'jsconfirm'));
  56. return decision
  57. });
  58. // Check Confirmation on forms
  59. $('form.confirm').live('submit', function(){
  60. data = $(this).data();
  61. var decision = confirm(data.jsconfirm);
  62. return decision
  63. });
  64. // Show go back link?
  65. if (document.referrer
  66. && document.referrer.indexOf(location.protocol + "//" + location.host) === 0
  67. && document.referrer != document.url) {
  68. $('.go-back').show();
  69. }
  70. // Go back one page
  71. $('.go-back').on('click', function (e) {
  72. history.go(-1)
  73. return false;
  74. })
  75. })
  76. function EnhancePostsMD() {
  77. $(function () {
  78. // Add labels to images
  79. $('.markdown.js-extra img').not('.emoji').each(function() {
  80. $(this).addClass('img-rounded');
  81. if ($(this).attr('alt').length > 0 && $(this).attr('alt') != $(this).attr('src')) {
  82. $(this).attr('title', $(this).attr('alt'));
  83. $(this).tooltip({placement: 'top', container: 'body'});
  84. }
  85. });
  86. // Automagically turn links into players
  87. var players = new Array();
  88. $('.markdown.js-extra').each(function() {
  89. var post_players = 0;
  90. $(this).find('a').each(function() {
  91. match = link2player($.trim($(this).text()));
  92. if (match && $.inArray(match, players) == -1 && players.length < 16 && post_players < 4) {
  93. players.push(match);
  94. post_players ++;
  95. $(this).replaceWith(match);
  96. }
  97. });
  98. });
  99. });
  100. }
  101. // Turn link to player
  102. function link2player(link_href) {
  103. // Youtube link
  104. var re = /watch\?v=((\w|-)+)/;
  105. if (re.test(link_href)) {
  106. media_url = link_href.match(re);
  107. return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
  108. }
  109. // Youtube feature=embed
  110. var re = /watch\?feature=player_embedded&v=((\w|-)+)/;
  111. if (re.test(link_href)) {
  112. media_url = link_href.match(re);
  113. return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
  114. }
  115. // Youtube embed with start time
  116. var re = /youtu.be\/((\w|-)+)\?t=([A-Za-z0-9]+)/;
  117. if (re.test(link_href)) {
  118. media_url = link_href.match(re);
  119. media_minutes = media_url[2].match(/([0-9]+)m/);
  120. media_seconds = media_url[2].match(/([0-9]+)s/);
  121. media_url[2] = 0;
  122. if (media_minutes) { media_url[2] += (media_minutes[1] - 0) * 60; }
  123. if (media_seconds) { media_url[2] += (media_seconds[1] - 0); }
  124. return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '?start=' + media_url[2] + '" frameborder="0" allowfullscreen></iframe>';
  125. }
  126. // Youtube embed
  127. var re = /youtu.be\/((\w|-)+)/;
  128. if (re.test(link_href)) {
  129. media_url = link_href.match(re);
  130. return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
  131. }
  132. // Vimeo link
  133. var re = /vimeo.com\/([0-9]+)/;
  134. if (re.test(link_href)) {
  135. media_url = link_href.match(re);
  136. return '<iframe src="http://player.vimeo.com/video/' + media_url[1] + '?color=CF402E" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
  137. }
  138. // No link
  139. return false;
  140. }
  141. // Ajax: Post votes
  142. $(function() {
  143. $('.post-rating-actions').each(function() {
  144. var action_parent = this;
  145. var csrf_token = $(this).find('input[name="_csrf_token"]').val();
  146. $(this).find('form').submit(function() {
  147. var form = this;
  148. $.post(this.action, {'_csrf_token': csrf_token}, "json").done(function(data, textStatus, jqXHR) {
  149. // Reset stuff and set classess
  150. $(action_parent).find('.post-score').removeClass('post-score-good post-score-bad');
  151. if (data.score_total > 0) {
  152. $(action_parent).find('.post-score-total').addClass('post-score-good');
  153. } else if (data.score_total < 0) {
  154. $(action_parent).find('.post-score-total').addClass('post-score-bad');
  155. }
  156. if (data.score_upvotes > 0) {
  157. $(action_parent).find('.post-score-upvotes').addClass('post-score-good');
  158. }
  159. if (data.score_downvotes > 0) {
  160. $(action_parent).find('.post-score-downvotes').addClass('post-score-bad');
  161. }
  162. // Set votes
  163. $(action_parent).find('.post-score-total').text(data.score_total);
  164. $(action_parent).find('.post-score-upvotes').text(data.score_upvotes);
  165. $(action_parent).find('.post-score-downvotes').text(data.score_downvotes);
  166. // Disable and enable forms
  167. if (data.user_vote == 1) {
  168. $(action_parent).find('.form-upvote button').attr("disabled", "disabled");
  169. $(action_parent).find('.form-downvote button').removeAttr("disabled");
  170. } else {
  171. $(action_parent).find('.form-upvote button').removeAttr("disabled");
  172. $(action_parent).find('.form-downvote button').attr("disabled", "disabled");
  173. }
  174. }).fail(function() {
  175. $(form).unbind();
  176. $(form).trigger('submit');
  177. });
  178. return false;
  179. });
  180. });
  181. });
  182. // Ajax: Post reports
  183. $(function() {
  184. $('.form-report').each(function() {
  185. var action_parent = this;
  186. var csrf_token = $(this).find('input[name="_csrf_token"]').val();
  187. var button = $(this).find('button');
  188. $(this).submit(function() {
  189. var form = this;
  190. $.post(form.action, {'_csrf_token': csrf_token}, "json").done(function(data, textStatus, jqXHR) {
  191. $(button).text(l_post_reported);
  192. $(button).tooltip('destroy');
  193. $(button).attr("title", data.message);
  194. $(button).tooltip({placement: 'top', container: 'body'});
  195. $(button).tooltip("show");
  196. $(button).attr("disabled", "disabled");
  197. setTimeout(function() {
  198. $(button).tooltip('hide');
  199. }, 2500);
  200. }).fail(function() {
  201. $(form).unbind();
  202. $(form).trigger('submit');
  203. });
  204. return false;
  205. });
  206. });
  207. });