cosmoTheme.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. (function(){
  20. $(window).scroll(function () {
  21. var top = $(document).scrollTop();
  22. $('.splash').css({
  23. 'background-position': '0px -'+(top/3).toFixed(2)+'px'
  24. });
  25. if(top > 50)
  26. $('#home > .navbar').removeClass('navbar-transparent');
  27. else
  28. $('#home > .navbar').addClass('navbar-transparent');
  29. });
  30. $("a[href='#']").click(function(e) {
  31. e.preventDefault();
  32. });
  33. var $button = $("<div id='source-button' class='btn btn-primary btn-xs'>&lt; &gt;</div>").click(function(){
  34. var html = $(this).parent().html();
  35. html = cleanSource(html);
  36. $("#source-modal pre").text(html);
  37. $("#source-modal").modal();
  38. });
  39. $('.bs-component [data-toggle="popover"]').popover();
  40. $('.bs-component [data-toggle="tooltip"]').tooltip();
  41. $(".bs-component").hover(function(){
  42. $(this).append($button);
  43. $button.show();
  44. }, function(){
  45. $button.hide();
  46. });
  47. function cleanSource(html) {
  48. html = html.replace(/×/g, "&times;")
  49. .replace(/«/g, "&laquo;")
  50. .replace(/»/g, "&raquo;")
  51. .replace(/←/g, "&larr;")
  52. .replace(/→/g, "&rarr;");
  53. var lines = html.split(/\n/);
  54. lines.shift();
  55. lines.splice(-1, 1);
  56. var indentSize = lines[0].length - lines[0].trim().length,
  57. re = new RegExp(" {" + indentSize + "}");
  58. lines = lines.map(function(line){
  59. if (line.match(re)) {
  60. line = line.substring(indentSize);
  61. }
  62. return line;
  63. });
  64. lines = lines.join("\n");
  65. return lines;
  66. }
  67. })();