index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. ---
  2. ---
  3. // Licensed to the Apache Software Foundation (ASF) under one
  4. // or more contributor license agreements. See the NOTICE file
  5. // distributed with this work for additional information
  6. // regarding copyright ownership. The ASF licenses this file
  7. // to you under the Apache License, Version 2.0 (the
  8. // "License"); you may not use this file except in compliance
  9. // with the License. You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing,
  14. // software distributed under the License is distributed on an
  15. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. // KIND, either express or implied. See the License for the
  17. // specific language governing permissions and limitations
  18. // under the License.
  19. function submitJiraSearchForm() {
  20. var queryTemplate1 = '(summary ~ "%1" OR description ~ "%1" OR comment ~ "%1") AND ';
  21. var queryTemplate2 = 'project = CB AND resolution = Unresolved %2ORDER BY created';
  22. var componentKeywords = [
  23. /\b(ios|iphone|ipad|ipod)\b/ig, 'iOS',
  24. /\b(android)\b/ig, 'Android',
  25. /\b(blackberry|rim|bb.?|bb10|webworks)\b/ig, 'BlackBerry',
  26. /\b(webos)\b/ig, 'webOS',
  27. /\b(wp7|windows phone)\b/ig, 'WP7',
  28. /\b(wp8|windows phone)\b/ig, 'WP8'
  29. ];
  30. var query = document.getElementById('jira-search-box').value;
  31. // Check for some platform keywords:
  32. var components = [];
  33. for (var i = 0; i < componentKeywords.length; i += 2) {
  34. if (query.match(componentKeywords[i])) {
  35. query = query.replace(componentKeywords[i], '');
  36. components.push(componentKeywords[i + 1]);
  37. }
  38. }
  39. var componentsQuery = '';
  40. if (components.length) {
  41. // Add in components that apply to all platforms.
  42. components.push('Docs', 'mobile-spec', 'CordovaJS');
  43. componentsQuery = 'AND component in (' + components.join(', ') + ') ';
  44. }
  45. // Remove quotes since we are adding them in.
  46. query = query.replace(/"/g, '');
  47. var tokens = query.split(/\s+/);
  48. query = '';
  49. for (var i = 0; i < tokens.length; ++i) {
  50. if (tokens[i]) {
  51. query += queryTemplate1.replace(/%1/g, tokens[i]);
  52. }
  53. }
  54. query += queryTemplate2.replace('%2', componentsQuery)
  55. window.open('https://issues.apache.org/jira/secure/IssueNavigator.jspa?mode=show&reset=true&navType=simple&jqlQuery=' + encodeURIComponent(query), '_newtab' + new Date);
  56. }
  57. function setCookie(cname, cvalue, exdays) {
  58. var d = new Date();
  59. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  60. var expires = "expires="+d.toUTCString();
  61. document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
  62. }
  63. function getCookie(cname) {
  64. var name = cname + "=";
  65. var ca = document.cookie.split(';');
  66. for(var i=0; i<ca.length; i++) {
  67. var c = ca[i];
  68. while (c.charAt(0)==' ') c = c.substring(1);
  69. if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
  70. }
  71. return "";
  72. }
  73. var lastVisit = getCookie("visitTime");
  74. function checkNotification() {
  75. var dates = [];
  76. if (lastVisit != "") {
  77. {% for post in site.posts %}
  78. dates.push('{{ post.date | date_to_rfc822 }}');{% endfor %}
  79. }
  80. var new_blog_count = 0;
  81. for(var i = 0; i < dates.length ; i++) {
  82. var blog_time = new Date(dates[i]).getTime();
  83. if(blog_time > lastVisit) {
  84. new_blog_count++;
  85. }
  86. else {
  87. break;
  88. }
  89. }
  90. return new_blog_count;
  91. }
  92. $(document).ready(function () {
  93. // code for blog badge
  94. $('.adorner').each(function(i) {
  95. var blog_time = new Date($(this).attr('blogTime')).getTime();
  96. if(lastVisit != "" && blog_time > lastVisit) {
  97. this.style.backgroundColor = "#3992ab";
  98. }
  99. });
  100. var new_blog_count = checkNotification();
  101. if (new_blog_count) {
  102. document.getElementById("new_blog_count").innerHTML = new_blog_count;
  103. }
  104. // code for click-to-copy functionality
  105. var client = new ZeroClipboard();
  106. client.on("ready", function(e) {
  107. var copyButtons = document.getElementsByClassName("btn-copy");
  108. for(var i = 0; i < copyButtons.length; i++) {
  109. client.clip(copyButtons[i]);
  110. }
  111. });
  112. // In the case that flash is disabled, fall back to browser API
  113. client.on("error", function(e) {
  114. var copyButtons = document.getElementsByClassName("btn-copy");
  115. for(var i = 0; i < copyButtons.length; i++) {
  116. copyButtons[i].addEventListener("click", function(clickEvent) {
  117. var id = clickEvent.target.getAttribute("data-clipboard-target");
  118. var range = document.createRange();
  119. range.selectNode(document.getElementById(id));
  120. var select = window.getSelection();
  121. select.removeAllRanges();
  122. select.addRange(range);
  123. try {
  124. document.execCommand("copy");
  125. } catch(e) {
  126. // Silently fail for now
  127. }
  128. select.removeAllRanges();
  129. });
  130. }
  131. });
  132. // Smooth scroll to anchor links
  133. $("a[href^='#']").on('click', function(e) {
  134. // scroll only if there is a hash in the link's href
  135. var hash = this.hash;
  136. if (hash) {
  137. // prevent default anchor click behavior
  138. e.preventDefault();
  139. // get the fragment without the "#" symbol because location.hash
  140. // is returned with it
  141. var targetName = hash.slice(1);
  142. // escape single quotes in target name because
  143. // we use them in the selector to find matching targets
  144. targetName.replace(/'/g, "\\\'").replace(/"/g, "\\\"");
  145. // check if the target exists by looking at either ID or name
  146. // NOTE:
  147. // we're not using "# + targetName" to select by ID
  148. // because the ID might contain special characters that
  149. // are annoying to escape
  150. var targetSelector = "*[id='" + targetName + "'], *[name='" + targetName + "']";
  151. var matchingTargets = $(targetSelector);
  152. if (matchingTargets.length < 1) {
  153. return;
  154. }
  155. if (matchingTargets.length > 1) {
  156. console.warn("found more than one anchor to go to; will go to the first one");
  157. }
  158. // get resulting scroll height
  159. var matchingTarget = matchingTargets.first();
  160. var scrollHeight = matchingTarget.offset().top;
  161. // add an extra offset (to account for the fixed page header),
  162. // but only if there is no "fragment-anchor" class (because it
  163. // already has an offset of its own for this purpose)
  164. if (!matchingTarget.hasClass("fragment-anchor")) {
  165. scrollHeight -= 50;
  166. }
  167. // animate
  168. $('html, body').animate(
  169. {scrollTop: scrollHeight},
  170. 300,
  171. function () {
  172. // when done, add hash to url (default click behaviour)
  173. window.location.hash = hash;
  174. }
  175. );
  176. }
  177. });
  178. // jira search code
  179. $("#jira-search-button").on("click", submitJiraSearchForm);
  180. $("#jira-search-box").on("keypress", function searchKeypressEventHandler (e) {
  181. if(e.keyCode == 13) {
  182. submitJiraSearchForm();
  183. }
  184. });
  185. });