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.

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