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.

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