main.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. 'use strict';
  2. if (window.location.href.indexOf('index.html') > 0) {
  3. window.location = window.location.href.replace('index.html', '');
  4. }
  5. hljs.initHighlightingOnLoad();
  6. (function ($) {
  7. if ($.trumbowyg) {
  8. var configurations = {
  9. core: {},
  10. plugins: {
  11. btnsDef: {
  12. // Customizables dropdowns
  13. image: {
  14. dropdown: ['insertImage', 'upload', 'base64', 'noembed'],
  15. ico: 'insertImage'
  16. }
  17. },
  18. btns: [
  19. ['viewHTML'],
  20. ['undo', 'redo'],
  21. ['formatting'],
  22. ['strong', 'em', 'del', 'underline'],
  23. ['link'],
  24. ['image'],
  25. ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
  26. ['unorderedList', 'orderedList'],
  27. ['foreColor', 'backColor'],
  28. ['preformatted'],
  29. ['horizontalRule'],
  30. ['fullscreen']
  31. ],
  32. plugins: {
  33. // Add imagur parameters to upload plugin
  34. upload: {
  35. serverPath: 'https://api.imgur.com/3/image',
  36. fileFieldName: 'image',
  37. headers: {
  38. 'Authorization': 'Client-ID 9e57cb1c4791cea'
  39. },
  40. urlPropertyName: 'data.link'
  41. }
  42. }
  43. }
  44. };
  45. // Demo switch
  46. var $demoTextarea = $('#trumbowyg-demo');
  47. $demoTextarea.trumbowyg(configurations.core);
  48. $('.demo-switcher .button').on('click', function () {
  49. var $current = $('.demo-switcher .current');
  50. $(this).parent().removeClass('current-' + $current.data('config'));
  51. $current.removeClass('current');
  52. $(this).addClass('current');
  53. $(this).parent().addClass('current-' + $(this).data('config'));
  54. $demoTextarea.trumbowyg('destroy');
  55. $demoTextarea.trumbowyg(configurations[$(this).data('config')]);
  56. });
  57. // Lang accordion
  58. $('#lang-list-view-full').on('click', function () {
  59. $('#lang-list-light').slideUp(100);
  60. $('#lang-list-full').slideDown(350);
  61. });
  62. }
  63. // Languages continent switch
  64. var $continentNames = $('.continent-name');
  65. $continentNames.each(function () {
  66. $(this).parent().attr('data-height', $(this).parent().height());
  67. });
  68. $continentNames.click(function () {
  69. var $oldOpen = $('#languages').find('.col-list ul li[style]');
  70. $oldOpen.removeAttr('style');
  71. $(this).parent().css({
  72. height: $(this).parent().attr('data-height') + 'px'
  73. });
  74. });
  75. $continentNames.last().parent().css({
  76. height: $continentNames.last().parent().attr('data-height') + 'px'
  77. });
  78. // Add anchors
  79. $('.feature h3[id]').each(function () {
  80. $(this).after($('<a/>', {
  81. html: '<svg><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#trumbowyg-link"></use></svg>',
  82. 'class': 'title-link',
  83. href: '#' + $(this).attr('id'),
  84. title: 'Permalink to ' + $(this).text()
  85. }));
  86. });
  87. // Force scroll to anchor
  88. setTimeout(function () {
  89. if (window.location.hash.length > 1 &&
  90. $(window.location.hash).length > 0 &&
  91. $(window.location.hash).offset().top > 0
  92. ) {
  93. $('main').scrollTop($(window.location.hash).offset().top);
  94. }
  95. }, 100);
  96. // Show star count
  97. function setStarsCount(stars) {
  98. $('.star-count').text(stars);
  99. }
  100. var date = new Date();
  101. var starsKey = 'stars_' + date.getMonth() + '_' + date.getYear();
  102. var stars = localStorage.getItem(starsKey);
  103. if (!stars) {
  104. $.ajax('https://api.github.com/repos/Alex-D/Trumbowyg', {
  105. success: function (data) {
  106. var stars = data.stargazers_count; // jshint ignore:line
  107. localStorage.clear();
  108. localStorage.setItem(starsKey, stars);
  109. setStarsCount(stars);
  110. }
  111. });
  112. } else {
  113. setStarsCount(stars);
  114. }
  115. // Switch iframe src for demos
  116. if ($('.main-demos').length > 0) {
  117. $('.documentation-summary a').each(function() {
  118. var demoHash = $(this).attr('href').replace('.html', '').replace(/[\/.]/g, '-').replace(/^-*/g, '');
  119. $(this).attr('data-hash', demoHash);
  120. $(this).click(function() {
  121. $('.main-demos iframe').attr('src', $(this).attr('href'));
  122. window.location.hash = demoHash;
  123. return false;
  124. });
  125. });
  126. if (window.location.hash.length > 1) {
  127. var demoHref = $('[data-hash="' + window.location.hash.replace('#', '') + '"]').attr('href');
  128. $('.main-demos iframe').attr('src', demoHref);
  129. }
  130. }
  131. })(jQuery);
  132. /* Google Analytics */
  133. var _gaq = [['_setAccount', 'UA-35470243-1'], ['_trackPageview']]; // jshint ignore:line
  134. (function (d, t) {
  135. var g = d.createElement(t), s = d.getElementsByTagName(t)[0];
  136. g.src = ('https:' === location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';
  137. s.parentNode.insertBefore(g, s);
  138. }(document, 'script'));