Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. $(function() {
  2. // setInitial
  3. var body = $('body'),
  4. header = body.find('.header'),
  5. aside = body.find('.sidebar'),
  6. content = body.find('.content'),
  7. entry = content.find('.entry'),
  8. footer = body.find('.footer'),
  9. account = body.find('.site > .account');
  10.  
  11. /* add links */
  12. $('.addlinks').click(function() {
  13. window.open('/toolbar/popup/link', 'links add', 'width=400, height=185, scrollbars=no, status=no;');
  14.  
  15. return false;
  16. });
  17.  
  18. /* asideButton */
  19. var asideSecondary = aside.find('.secondary'),
  20. asideButton = header.find($('.aside-button')),
  21. asideCloseButton = aside.find($('.aside-close-button'));
  22.  
  23. asideButton.click(function() {
  24. if (!body.hasClass('aside-open') && ((asideSecondary.attr('aria-hidden') === 'true' || asideSecondary.attr('aria-hidden') === undefined))) {
  25. // toggle
  26. body.addClass('aside-open');
  27.  
  28. // visible
  29. setTimeout(function() {
  30. aside.addClass('open');
  31. }, 10);
  32.  
  33. // attr change
  34. setTimeout(function() {
  35. asideSecondary.attr('aria-hidden', 'false');
  36. }, 218);
  37. }
  38. });
  39.  
  40. /* asideCloseButton */
  41. asideCloseButton.click(function() {
  42. if (body.hasClass('aside-open') && asideSecondary.attr('aria-hidden') === 'false') {
  43. // visible
  44. aside.removeClass('open')
  45.  
  46. // toggle, attr change
  47. setTimeout(function() {
  48. body.removeClass('aside-open');
  49. asideSecondary.attr('aria-hidden', 'true');
  50. }, 218);
  51. }
  52. });
  53.  
  54. /* search_none */
  55. var currentUrl = window.location.pathname,
  56. url = currentUrl.split('/');
  57.  
  58. var pageType,
  59. listItem = entry.find('> .article'),
  60. tagContent = entry.find('> .entry-article.tag');
  61.  
  62. if ($.isNumeric(url[1])) {
  63. url[1] = 'article';
  64. }
  65.  
  66. switch (url[1]) {
  67. case 'tag':
  68. // check: tagContent.length < 1
  69. if (tagContent.length < 1) {
  70. pageType = 'list';
  71. }
  72. break;
  73. case 'category':
  74. pageType = 'list';
  75. break;
  76. case 'search':
  77. pageType = 'list';
  78. break;
  79. case 'archive':
  80. pageType = 'list';
  81. break;
  82. default:
  83. }
  84.  
  85. if (pageType === 'list') {
  86. // check: listItem < 1
  87. if (listItem.length < 1) {
  88. body.addClass('empty');
  89. }
  90. }
  91.  
  92. /* #################################################### */
  93. /* ################## DEVOLOPERS! #################### */
  94. /* #################################################### */
  95.  
  96. /* checkAccountDropdown() */
  97. function checkAccountDropdown() {
  98. if (!body.hasClass('account-open') && !account.hasClass('.open')) {
  99. // toggle
  100. body.addClass('account-open');
  101.  
  102. // visible
  103. setTimeout(function() {
  104. account.addClass('open');
  105. }, 10);
  106.  
  107. // attr change
  108. setTimeout(function() {
  109. account.attr('aria-hidden', 'false');
  110. }, 218);
  111. } else {
  112. // visible
  113. account.removeClass('open');
  114.  
  115. // toggle, attr change
  116. setTimeout(function() {
  117. body.removeClass('account-open');
  118. account.attr('aria-hidden', 'true');
  119. }, 218);
  120. }
  121. }
  122.  
  123. /* dropdownClose(el) */
  124. function dropdownClose(el) {
  125. // visible
  126. setTimeout(function() {
  127. checkDropdownOpen = 'close';
  128. $(el).removeClass('open');
  129. }, 10);
  130.  
  131. // attr change
  132. setTimeout(function() {
  133. $(el).attr('aria-hidden', 'true');
  134. }, 218);
  135. }
  136.  
  137. /* dropdownOpen(el) */
  138. function dropdownOpen(el) {
  139. // visible
  140. setTimeout(function() {
  141. checkDropdownOpen = 'open';
  142. $(el).addClass('open');
  143. }, 10);
  144.  
  145. // attr change
  146. setTimeout(function() {
  147. $(el).attr('aria-hidden', 'false');
  148. }, 218);
  149. }
  150.  
  151. /* dropdown */
  152. var dropdown = $('.dropdown'),
  153. dropdownToggle = dropdown.find('.toggle'),
  154. dropdownMenu = dropdown.find('.menu'),
  155. checkDropdownOpen = 'close';
  156.  
  157. dropdownToggle.click(function() {
  158. dropdownClose(dropdownMenu);
  159.  
  160. $(this).each(function() {
  161. // setInitial
  162. var thisDropdown = $(this).parent('.dropdown'),
  163. thisDropdownToggle = $(this),
  164. thisDropdownMenu = $(this).next('.menu');
  165.  
  166. // checkAccountDropdown
  167. if (thisDropdown.hasClass('account-dropdown')) {
  168. checkAccountDropdown();
  169. }
  170.  
  171. // checkDropdownMenu = open
  172. if (!thisDropdownMenu.hasClass('open') && (thisDropdownMenu.attr('aria-hidden') === 'true' || thisDropdownMenu.attr('aria-hidden') === undefined)) {
  173. dropdownOpen(thisDropdownMenu);
  174. } else if (thisDropdownMenu.hasClass('open') && thisDropdownMenu.attr('aria-hidden') === 'false') {
  175. dropdownClose(thisDropdownMenu);
  176. }
  177. })
  178. });
  179.  
  180. /* login link */
  181. var accountToolbar = header.find('.account'),
  182. tistoryToolbar = $('#tistorytoolbarid');
  183.  
  184. if (tistoryToolbar.length > 0) {
  185. var toolbarLogin = tistoryToolbar.find('.tt_menubar_logout > a'),
  186. toolbarLoginText = toolbarLogin.text(),
  187. toolbarLoginHref = toolbarLogin.attr('href');
  188.  
  189. accountToolbar.find('.account-dropdown .menu > nav ul').append('<li><a class="primary" href="' + toolbarLoginHref + '">' + toolbarLoginText + '</a>');
  190. }
  191.  
  192. /* document click */
  193. $(document).click(function(e) {
  194. if (!body.hasClass('account-open') && !account.hasClass('.open')) {
  195. // closest dropdown
  196. if (!$(e.target).closest(dropdown).length) {
  197. dropdownClose(dropdownMenu);
  198. }
  199. } else {
  200. // closest dropdown, account
  201. if (!$(e.target).closest(dropdown).length && !$(e.target).closest(account).length) {
  202. dropdownClose(dropdownMenu);
  203. }
  204. }
  205. });
  206. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement