You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

954 lines
26 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. // namespace
  2. window.semantic = {
  3. handler: {}
  4. };
  5. // Allow for console.log to not break IE
  6. if (typeof window.console == "undefined" || typeof window.console.log == "undefined") {
  7. window.console = {
  8. log : function() {},
  9. info : function(){},
  10. warn : function(){}
  11. };
  12. }
  13. if(typeof window.console.group == 'undefined' || typeof window.console.groupEnd == 'undefined' || typeof window.console.groupCollapsed == 'undefined') {
  14. window.console.group = function(){};
  15. window.console.groupEnd = function(){};
  16. window.console.groupCollapsed = function(){};
  17. }
  18. if(typeof window.console.markTimeline == 'undefined') {
  19. window.console.markTimeline = function(){};
  20. }
  21. window.console.clear = function(){};
  22. // ready event
  23. semantic.ready = function() {
  24. // selector cache
  25. var
  26. $sortableTables = $('.sortable.table'),
  27. $sticky = $('.ui.sticky'),
  28. $themeDropdown = $('.theme.dropdown'),
  29. $ui = $('.ui').not('.hover, .down'),
  30. $swap = $('.theme.menu .item'),
  31. $menu = $('#menu'),
  32. $hideMenu = $('#menu .hide.item'),
  33. $sortTable = $('.sortable.table'),
  34. $demo = $('.demo'),
  35. $container = $('.main.container'),
  36. $allHeaders = $('.main.container > h2, .main.container > .tab > h2, .main.container > .tab > .examples h2'),
  37. $sectionHeaders = $container.children('h2'),
  38. $followMenu = $container.find('.following.menu'),
  39. $sectionExample = $container.find('.example'),
  40. $exampleHeaders = $sectionExample.children('h4'),
  41. $footer = $('.page > .footer'),
  42. $menuPopup = $('.ui.main.menu .popup.item'),
  43. $pageDropdown = $('.ui.main.menu .page.dropdown'),
  44. $pageTabMenu = $('.tab.header.segment .tabular.menu'),
  45. $pageTabs = $('.tab.header.segment .menu .item'),
  46. $languageDropdown = $('.language.dropdown'),
  47. $languageModal = $('.language.modal'),
  48. $downloadDropdown = $('.download.buttons .dropdown'),
  49. $helpPopup = $('.header .help.icon'),
  50. $example = $('.example'),
  51. $shownExample = $example.filter('.shown'),
  52. $overview = $('.overview.button'),
  53. //$developer = $('.header .developer.item'),
  54. //$designer = $('.header .designer.item'),
  55. $sidebarButton = $('.fixed.launch.button'),
  56. $code = $('div.code').not('.existing'),
  57. $existingCode = $('.existing.code'),
  58. requestAnimationFrame = window.requestAnimationFrame
  59. || window.mozRequestAnimationFrame
  60. || window.webkitRequestAnimationFrame
  61. || window.msRequestAnimationFrame
  62. || function(callback) { setTimeout(callback, 0); },
  63. // alias
  64. handler
  65. ;
  66. // event handlers
  67. handler = {
  68. createIcon: function() {
  69. $example
  70. .each(function(){
  71. $('<i/>')
  72. .addClass('icon code')
  73. .insertAfter( $(this).children(':first-child') )
  74. ;
  75. })
  76. ;
  77. },
  78. createWaypoints: function() {
  79. $sectionHeaders
  80. .visibility({
  81. once: false,
  82. offset: 70,
  83. onTopVisible: handler.activate.accordion,
  84. onTopPassed: handler.activate.section,
  85. onBottomPassed: handler.activate.section,
  86. onTopPassedReverse: handler.activate.previous
  87. })
  88. ;
  89. $sectionExample
  90. .visibility({
  91. once: false,
  92. offset: 70,
  93. onTopPassed: handler.activate.example,
  94. onBottomPassedReverse: handler.activate.example
  95. })
  96. ;
  97. $footer
  98. .visibility({
  99. once: false,
  100. onTopVisible: function() {
  101. var
  102. $title = $followMenu.find('> .item > .title').last()
  103. ;
  104. $followMenu
  105. .accordion('open', $title)
  106. ;
  107. }
  108. })
  109. ;
  110. },
  111. activate: {
  112. previous: function() {
  113. var
  114. $menuItems = $followMenu.children('.item'),
  115. $section = $menuItems.filter('.active'),
  116. index = $menuItems.index($section)
  117. ;
  118. if($section.prev().size() > 0) {
  119. $section
  120. .removeClass('active')
  121. .prev('.item')
  122. .addClass('active')
  123. ;
  124. $followMenu
  125. .accordion('open', index - 1)
  126. ;
  127. }
  128. },
  129. accordion: function() {
  130. var
  131. $section = $(this),
  132. index = $sectionHeaders.index($section),
  133. $followSection = $followMenu.children('.item'),
  134. $activeSection = $followSection.eq(index)
  135. ;
  136. $followMenu
  137. .accordion('open', index)
  138. ;
  139. },
  140. section: function() {
  141. var
  142. $section = $(this),
  143. index = $sectionHeaders.index($section),
  144. $followSection = $followMenu.children('.item'),
  145. $activeSection = $followSection.eq(index)
  146. ;
  147. $followSection
  148. .removeClass('active')
  149. ;
  150. $activeSection
  151. .addClass('active')
  152. ;
  153. },
  154. example: function() {
  155. var
  156. $section = $(this).children('h4').eq(0),
  157. index = $exampleHeaders.index($section),
  158. $followSection = $followMenu.find('.menu > .item'),
  159. $activeSection = $followSection.eq(index)
  160. ;
  161. if($(this).not('.another.example').size() > 0) {
  162. $followSection
  163. .removeClass('active')
  164. ;
  165. $activeSection
  166. .addClass('active')
  167. ;
  168. }
  169. }
  170. },
  171. showLanguageModal: function(value, text, $choice) {
  172. var
  173. percent = $choice.data('percent') || 0
  174. ;
  175. window.Transifex.live.translateTo(value, true);
  176. if(percent < 100) {
  177. $('.language.modal')
  178. .find('.header .name')
  179. .html(text)
  180. .end()
  181. .find('.complete')
  182. .html(percent)
  183. .end()
  184. ;
  185. requestAnimationFrame(function() {
  186. $('.language.modal')
  187. .modal('show', function() {
  188. $('.language.modal .progress .bar').css('width', percent + '%');
  189. })
  190. ;
  191. });
  192. }
  193. },
  194. tryCreateMenu: function(event) {
  195. if($(window).width() > 1000) {
  196. if($container.find('.following.menu').size() === 0) {
  197. handler.createMenu();
  198. handler.createWaypoints();
  199. $(window).off('resize.menu');
  200. }
  201. }
  202. },
  203. createAnchors: function() {
  204. $allHeaders
  205. .each(function() {
  206. var
  207. $section = $(this),
  208. safeName = $section.text().trim().replace(/\s+/g, '-').replace(/[^-,'A-Za-z0-9]+/g, '').toLowerCase(),
  209. id = window.escape(safeName),
  210. $anchor = $('<a />').addClass('anchor').attr('id', id)
  211. ;
  212. $section
  213. .append($anchor)
  214. ;
  215. })
  216. ;
  217. $example
  218. .each(function() {
  219. var
  220. $title = $(this).children('h4').eq(0),
  221. safeName = $title.text().trim().replace(/\s+/g, '-').replace(/[^-,'A-Za-z0-9]+/g, '').toLowerCase(),
  222. id = window.escape(safeName),
  223. $anchor = $('<a />').addClass('anchor').attr('id', id)
  224. ;
  225. if($title.size() > 0) {
  226. $title.after($anchor);
  227. }
  228. })
  229. ;
  230. },
  231. createMenu: function() {
  232. // grab each h3
  233. var
  234. html = '',
  235. $sticky,
  236. $rail
  237. ;
  238. $sectionHeaders
  239. .each(function(index) {
  240. var
  241. $currentHeader = $(this),
  242. $nextElements = $currentHeader.nextUntil('h2'),
  243. $examples = $nextElements.find('.example').andSelf().filter('.example'),
  244. activeClass = (index === 0)
  245. ? 'active '
  246. : '',
  247. safeName = $currentHeader.text().trim().replace(/\s+/g, '-').replace(/[^-,'A-Za-z0-9]+/g, '').toLowerCase(),
  248. id = window.escape(safeName),
  249. $anchor = $('<a />').addClass('anchor').attr('id', id)
  250. ;
  251. html += '<div class="item">';
  252. if($examples.size() === 0) {
  253. html += '<a class="'+activeClass+'title" href="'+id+'"><b>' + $(this).text() + '</b></a>';
  254. }
  255. else {
  256. html += '<a class="'+activeClass+'title"><i class="dropdown icon"></i> <b>' + $(this).text() + '</b></a>';
  257. }
  258. if($examples.size() > 0) {
  259. html += '<div class="'+activeClass+'content menu">';
  260. $examples
  261. .each(function() {
  262. var
  263. $title = $(this).children('h4').eq(0),
  264. safeName = $title.text().trim().replace(/\s+/g, '-').replace(/[^-,'A-Za-z0-9]+/g, '').toLowerCase(),
  265. id = window.escape(safeName),
  266. $anchor = $('<a />').addClass('anchor').attr('id', id)
  267. ;
  268. if($title.size() > 0) {
  269. html += '<a class="item" href="#'+id+'">' + $(this).children('h4').html() + '</a>';
  270. }
  271. })
  272. ;
  273. html += '</div>';
  274. }
  275. html += '</div>';
  276. })
  277. ;
  278. $followMenu = $('<div />')
  279. .addClass('ui secondary vertical following fluid accordion menu')
  280. .html(html)
  281. ;
  282. $sticky = $('<div />')
  283. .addClass('ui sticky hidden transition')
  284. .html($followMenu)
  285. ;
  286. $rail = $('<div />')
  287. .addClass('ui close right rail')
  288. .html($sticky)
  289. .appendTo($container)
  290. ;
  291. $followMenu
  292. .accordion({
  293. exclusive: false,
  294. onChange: function() {
  295. $sticky.sticky('refresh');
  296. }
  297. })
  298. .find('.menu a[href], .title[href]')
  299. .on('click', handler.scrollTo)
  300. ;
  301. $sticky
  302. .transition('fade', function() {
  303. $sticky.sticky({
  304. context: $container,
  305. offset: 50
  306. });
  307. })
  308. ;
  309. },
  310. scrollTo: function(event) {
  311. var
  312. id = $(this).attr('href').replace('#', ''),
  313. $element = $('#'+id),
  314. position = $element.offset().top
  315. ;
  316. $element
  317. .addClass('active')
  318. ;
  319. $('html, body')
  320. .animate({
  321. scrollTop: position
  322. }, 500)
  323. ;
  324. location.hash = '#' + id;
  325. event.stopImmediatePropagation();
  326. event.preventDefault();
  327. return false;
  328. },
  329. less: {
  330. parseFile: function(content) {
  331. var
  332. variables = {},
  333. lines = content.match(/^(@[\s|\S]+?;)/gm),
  334. name,
  335. value
  336. ;
  337. if(lines) {
  338. $.each(lines, function(index, line) {
  339. // clear whitespace
  340. line = $.trim(line);
  341. // match variables only
  342. if(line[0] == '@') {
  343. name = line.match(/^@(.+):/);
  344. value = line.match(/:\s*([\s|\S]+?;)/);
  345. if( ($.isArray(name) && name.length >= 2) && ($.isArray(value) && value.length >= 2) ) {
  346. name = name[1];
  347. value = value[1];
  348. variables[name] = value;
  349. }
  350. }
  351. });
  352. }
  353. return variables;
  354. },
  355. changeTheme: function(theme) {
  356. var
  357. $themeDropdown = $(this),
  358. variableURL = '/build/less/themes/packages/{$theme}/{$type}s/{$element}.variables',
  359. overrideURL = '/build/less/themes/packages/{$theme}/{$type}s/{$element}.overrides',
  360. urlData = {
  361. theme : typeof(theme === 'string')
  362. ? theme.toLowerCase()
  363. : theme,
  364. type : $themeDropdown.data('type'),
  365. element : $themeDropdown.data('element')
  366. }
  367. ;
  368. $themeDropdown
  369. .api({
  370. on : 'now',
  371. url : variableURL,
  372. dataType : 'text',
  373. urlData : urlData,
  374. onSuccess: function(content) {
  375. less.modifyVars( handler.less.parseFile(content) );
  376. $themeDropdown
  377. .api({
  378. on : 'now',
  379. url : overrideURL,
  380. dataType : 'text',
  381. urlData : urlData,
  382. onSuccess: function(content) {
  383. if( $('style.override').size() > 0 ) {
  384. $('style.override').remove();
  385. }
  386. console.log(content);
  387. $('<style>' + content + '</style>')
  388. .addClass('override')
  389. .appendTo('body')
  390. ;
  391. }
  392. })
  393. ;
  394. }
  395. })
  396. ;
  397. }
  398. },
  399. create: {
  400. examples: function(json) {
  401. var
  402. types = json['Types'],
  403. text = json['Text'],
  404. states = json['States'],
  405. variations = json['Variations'],
  406. $element,
  407. html
  408. ;
  409. $.each(types, function(name, type){
  410. html += '<h2 class="ui dividing header">' + name + '</h2';
  411. if($.isPlainObject(type)) {
  412. $.each(type, function(name, subType) {
  413. $element = $.zc(subType);
  414. $element = handler.create.text($element, text);
  415. html += '<h3 class="ui header">' + name + '</h3';
  416. html += handler.create.variations($element, variations);
  417. });
  418. }
  419. else {
  420. $element = $.zc(type);
  421. $element = handler.create.text($element);
  422. html += handler.create.variations($element, variations);
  423. }
  424. });
  425. // Each TYPE
  426. // show type name
  427. // html = koan (html)
  428. // each text
  429. // find label
  430. // if(obj)
  431. // replace random text
  432. // else
  433. // replace text
  434. // end
  435. // Each variation
  436. // (if obj)
  437. // each
  438. // add class
  439. // (else)
  440. // add class
  441. // label = property
  442. // class = class
  443. // show html
  444. // end
  445. // end
  446. },
  447. element: function(koan, type, text, variation) {
  448. },
  449. variations: function($element, variations) {
  450. $.each(variations, function(name, variation){
  451. });
  452. },
  453. text: function($element, text) {
  454. $.each(text, function(selector, text) {
  455. $element.find(selector).text(text);
  456. });
  457. return $element;
  458. }
  459. },
  460. overviewMode: function() {
  461. var
  462. $button = $(this),
  463. $body = $('body'),
  464. $example = $('.example')
  465. ;
  466. $body.toggleClass('overview');
  467. $button.toggleClass('active');
  468. if($body.hasClass('overview')) {
  469. $example.each(function() {
  470. $(this).children().not('.ui.header:eq(0), .example p:eq(0), .annotation').hide();
  471. });
  472. $example.filter('.another').hide();
  473. }
  474. else {
  475. $example.each(function() {
  476. $(this).children().not('.ui.header:eq(0), .example p:eq(0), .annotation').show();
  477. });
  478. $example.filter('.another').show();
  479. }
  480. $('.sticky').sticky('refresh');
  481. },
  482. developerMode: function() {
  483. var
  484. $body = $('body'),
  485. $example = $('.example').not('.no')
  486. ;
  487. if($body.hasClass('overview')) {
  488. handler.overviewMode();
  489. }
  490. $example
  491. .each(function() {
  492. $.proxy(handler.createCode, $(this))('developer');
  493. })
  494. ;
  495. $('.sticky').sticky('refresh');
  496. },
  497. designerMode: function() {
  498. var
  499. $body = $('body'),
  500. $example = $('.example').not('.no')
  501. ;
  502. if($body.hasClass('overview')) {
  503. handler.overviewMode();
  504. }
  505. $example
  506. .each(function() {
  507. $.proxy(handler.createCode, $(this))('designer');
  508. })
  509. ;
  510. $('.sticky').sticky('refresh');
  511. },
  512. getIndent: function(text) {
  513. var
  514. lines = text.split("\n"),
  515. firstLine = (lines[0] === '')
  516. ? lines[1]
  517. : lines[0],
  518. spacesPerIndent = 2,
  519. leadingSpaces = firstLine.length - firstLine.replace(/^\s*/g, '').length,
  520. indent
  521. ;
  522. if(leadingSpaces !== 0) {
  523. indent = leadingSpaces;
  524. }
  525. else {
  526. // string has already been trimmed, get first indented line and subtract 2
  527. $.each(lines, function(index, line) {
  528. leadingSpaces = line.length - line.replace(/^\s*/g, '').length;
  529. if(leadingSpaces !== 0) {
  530. indent = leadingSpaces - spacesPerIndent;
  531. return false;
  532. }
  533. });
  534. }
  535. return indent || 4;
  536. },
  537. generateCode: function() {
  538. var
  539. $example = $(this).closest('.example'),
  540. $annotation = $example.find('.annotation'),
  541. $code = $annotation.find('.code'),
  542. $header = $example.not('.another').children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
  543. $ignored = $('i.code:last-child, .anchor, .code, .existing, .pointing.below.label, .instructive, .language.label, .annotation, br, .ignore, .ignored'),
  544. $demo = $example.children().not($header).not($ignored),
  545. code = ''
  546. ;
  547. if( $code.size() === 0) {
  548. $demo
  549. .each(function(){
  550. var $this = $(this).clone(false);
  551. if($this.not('br')) {
  552. // allow inline styles only with this one class
  553. if($this.is('.my-container')) {
  554. code += $this.get(0).outerHTML + "\n";
  555. }
  556. else {
  557. code += $this.removeAttr('style').get(0).outerHTML + "\n";
  558. }
  559. }
  560. })
  561. ;
  562. }
  563. $example.data('code', code);
  564. return code;
  565. },
  566. createCode: function(type) {
  567. var
  568. $example = $(this).closest('.example'),
  569. $header = $example.children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
  570. $annotation = $example.find('.annotation'),
  571. $code = $annotation.find('.code'),
  572. $ignoredContent = $('.ui.popup, i.code:last-child, .anchor, .code, .existing.segment, .instructive, .language.label, .annotation, br, .ignore, .ignored'),
  573. $demo = $example.children().not($header).not($ignoredContent),
  574. code = $example.data('code') || $.proxy(handler.generateCode, this)()
  575. ;
  576. if( $code.hasClass('existing') ) {
  577. $annotation.show();
  578. $code.removeClass('existing');
  579. $.proxy(handler.initializeCode, $code)();
  580. }
  581. if($annotation.size() === 0) {
  582. $annotation = $('<div/>')
  583. .addClass('annotation')
  584. .appendTo($example)
  585. ;
  586. }
  587. if( $example.find('.instructive').size() === 0) {
  588. $code = $('<div/>')
  589. .data('type', 'html')
  590. .addClass('code')
  591. .html(code)
  592. .hide()
  593. .appendTo($annotation)
  594. ;
  595. $.proxy(handler.initializeCode, $code)();
  596. }
  597. if( ($demo.first().is(':visible') || type == 'developer') && type != 'designer' ) {
  598. $demo.hide();
  599. $header.show();
  600. $annotation.fadeIn(500);
  601. }
  602. else {
  603. $annotation.hide();
  604. if($demo.size() > 1) {
  605. $demo.show();
  606. }
  607. else {
  608. $demo.fadeIn(500);
  609. }
  610. }
  611. },
  612. createAnnotation: function() {
  613. if(!$(this).data('type')) {
  614. $(this).data('type', 'html');
  615. }
  616. $(this)
  617. .wrap('<div class="annotation">')
  618. .parent()
  619. .hide()
  620. ;
  621. },
  622. makeCode: function() {
  623. if(window.hljs !== undefined) {
  624. $code
  625. .filter(':visible')
  626. .each(handler.initializeCode)
  627. ;
  628. $existingCode
  629. .each(handler.createAnnotation)
  630. ;
  631. }
  632. else {
  633. console.log('Syntax highlighting not found');
  634. }
  635. },
  636. initializeCode: function() {
  637. var
  638. $code = $(this).show(),
  639. code = $code.html(),
  640. existingCode = $code.hasClass('existing'),
  641. evaluatedCode = $code.hasClass('evaluated'),
  642. contentType = $code.data('type') || 'javascript',
  643. title = $code.data('title') || false,
  644. demo = $code.data('demo') || false,
  645. preview = $code.data('preview') || false,
  646. label = $code.data('label') || false,
  647. displayType = {
  648. html : 'HTML',
  649. javascript : 'Javascript',
  650. css : 'CSS',
  651. text : 'Command Line',
  652. sh : 'Command Line'
  653. },
  654. indent = handler.getIndent(code) || 2,
  655. padding = 20,
  656. name = (evaluatedCode)
  657. ? 'existing'
  658. : 'instructive',
  659. formattedCode = code,
  660. whiteSpace,
  661. $label,
  662. codeHeight
  663. ;
  664. var entityMap = {
  665. "&": "&amp;",
  666. "<": "&lt;",
  667. ">": "&gt;",
  668. '"': '&quot;',
  669. "'": '&#39;',
  670. "/": '&#x2F;'
  671. };
  672. function escapeHTML(string) {
  673. return String(string).replace(/[&<>"'\/]/g, function (s) {
  674. return entityMap[s];
  675. });
  676. }
  677. // evaluate if specified
  678. if(evaluatedCode) {
  679. eval(code);
  680. }
  681. // trim whitespace & escape
  682. whiteSpace = new RegExp('\\n\\s{' + indent + '}', 'g');
  683. formattedCode = $.trim(code).replace(whiteSpace, '\n');
  684. formattedCode = escapeHTML(formattedCode);
  685. $code.html(formattedCode);
  686. // wrap
  687. $code = $code
  688. .wrap('<div class="ui ' + name + ' segment"></div>')
  689. .wrap('<pre></pre>')
  690. ;
  691. // color code
  692. window.hljs.highlightBlock($code[0]);
  693. // add label
  694. if(title) {
  695. $('<div>')
  696. .addClass('ui attached top label')
  697. .html('<span class="title">' + title + '</span>' + '<em>' + (displayType[contentType] || contentType) + '</em>')
  698. .prependTo( $(this).closest('.segment') )
  699. ;
  700. }
  701. if(label) {
  702. $('<div>')
  703. .addClass('ui pointing below language label')
  704. .html(displayType[contentType] || contentType)
  705. .insertBefore ( $(this).closest('.segment') )
  706. ;
  707. }
  708. // add run code button
  709. if(demo) {
  710. $('<a>')
  711. .addClass('ui pointing below label')
  712. .html('Run Code')
  713. .on('click', function() {
  714. eval(code);
  715. })
  716. .insertBefore ( $(this).closest('.segment') )
  717. ;
  718. }
  719. // add preview if specified
  720. if(preview) {
  721. $(code)
  722. .insertAfter( $(this).closest('.segment') )
  723. ;
  724. }
  725. $code.removeClass('hidden');
  726. },
  727. swapStyle: function() {
  728. var
  729. theme = $(this).data('theme')
  730. ;
  731. $(this)
  732. .addClass('active')
  733. .siblings()
  734. .removeClass('active')
  735. ;
  736. $('head link.ui')
  737. .each(function() {
  738. var
  739. href = $(this).attr('href'),
  740. subDirectory = href.split('/')[3],
  741. newLink = href.replace(subDirectory, theme)
  742. ;
  743. $(this)
  744. .attr('href', newLink)
  745. ;
  746. })
  747. ;
  748. }
  749. };
  750. handler.createAnchors();
  751. if( $pageTabs.size() > 0 ) {
  752. $pageTabs
  753. .tab({
  754. context : '.main.container',
  755. childrenOnly : true,
  756. history : true,
  757. onTabInit : function() {
  758. handler.makeCode();
  759. $container = ($('.fixed.column').size() > 0 )
  760. ? $(this).find('.examples')
  761. : $(this)
  762. ;
  763. $sectionHeaders = $container.children('h2');
  764. $sectionExample = $container.find('.example');
  765. $exampleHeaders = $sectionExample.children('h4');
  766. // create code
  767. handler.tryCreateMenu();
  768. $(window).on('resize.menu', function() {
  769. handler.tryCreateMenu();
  770. });
  771. },
  772. onTabLoad : function() {
  773. $sticky.filter(':visible').sticky('refresh');
  774. }
  775. })
  776. ;
  777. }
  778. else {
  779. handler.makeCode();
  780. handler.tryCreateMenu();
  781. $(window).on('resize.menu', function() {
  782. handler.tryCreateMenu();
  783. });
  784. }
  785. $sticky
  786. .sticky({
  787. context : '.main.container',
  788. pushing : true
  789. })
  790. ;
  791. window.hljs.configure({
  792. languages: [
  793. 'xml',
  794. 'css',
  795. 'javascript'
  796. ]
  797. });
  798. $languageModal
  799. .modal()
  800. ;
  801. $menu
  802. .sidebar({
  803. transition : 'uncover',
  804. mobileTransition : 'overlay'
  805. })
  806. .sidebar('attach events', '.launch.button, .view-ui, .launch.item')
  807. .sidebar('attach events', $hideMenu, 'hide')
  808. ;
  809. handler.createIcon();
  810. $example
  811. .each(function() {
  812. $.proxy(handler.generateCode, this)();
  813. })
  814. .find('i.code')
  815. .on('click', handler.createCode)
  816. ;
  817. $shownExample
  818. .each(handler.createCode)
  819. ;
  820. $downloadDropdown
  821. .dropdown({
  822. on : 'click',
  823. transition : 'scale'
  824. })
  825. ;
  826. $themeDropdown
  827. .dropdown({
  828. action: 'select',
  829. onChange: handler.less.changeTheme
  830. })
  831. ;
  832. if($.fn.tablesort !== undefined && $sortTable.size() > 0) {
  833. $sortTable
  834. .tablesort()
  835. ;
  836. }
  837. $helpPopup
  838. .popup()
  839. ;
  840. $swap
  841. .on('click', handler.swapStyle)
  842. ;
  843. $overview
  844. .on('click', handler.overviewMode)
  845. ;
  846. $menuPopup
  847. .popup({
  848. position : 'bottom center',
  849. className : {
  850. popup: 'ui popup'
  851. }
  852. })
  853. ;
  854. $pageDropdown
  855. .dropdown({
  856. on : 'hover',
  857. action : 'nothing',
  858. allowTab : false
  859. })
  860. ;
  861. $languageDropdown
  862. .popup()
  863. .dropdown({
  864. on : 'click',
  865. onShow: function() {
  866. $(this).popup('hide');
  867. },
  868. onChange: handler.showLanguageModal
  869. })
  870. ;
  871. };
  872. // attach ready event
  873. $(document)
  874. .ready(semantic.ready)
  875. ;