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.

980 lines
27 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. /*if($('.less.column').size() > 0) {
  377. var $code = $('<div />')
  378. .addClass('code')
  379. .attr('data-type', 'less')
  380. .attr('data-title', 'button.variables')
  381. .html(content)
  382. ;
  383. $('.less.column').html($code);
  384. $.proxy(handler.initializeCode, $code)();
  385. }*/
  386. $themeDropdown
  387. .api({
  388. on : 'now',
  389. url : overrideURL,
  390. dataType : 'text',
  391. urlData : urlData,
  392. onSuccess: function(content) {
  393. if( $('style.override').size() > 0 ) {
  394. $('style.override').remove();
  395. }
  396. console.log(content);
  397. $('<style>' + content + '</style>')
  398. .addClass('override')
  399. .appendTo('body')
  400. ;
  401. }
  402. })
  403. ;
  404. }
  405. })
  406. ;
  407. }
  408. },
  409. create: {
  410. examples: function(json) {
  411. var
  412. types = json['Types'],
  413. text = json['Text'],
  414. states = json['States'],
  415. variations = json['Variations'],
  416. $element,
  417. html
  418. ;
  419. $.each(types, function(name, type){
  420. html += '<h2 class="ui dividing header">' + name + '</h2';
  421. if($.isPlainObject(type)) {
  422. $.each(type, function(name, subType) {
  423. $element = $.zc(subType);
  424. $element = handler.create.text($element, text);
  425. html += '<h3 class="ui header">' + name + '</h3';
  426. html += handler.create.variations($element, variations);
  427. });
  428. }
  429. else {
  430. $element = $.zc(type);
  431. $element = handler.create.text($element);
  432. html += handler.create.variations($element, variations);
  433. }
  434. });
  435. // Each TYPE
  436. // show type name
  437. // html = koan (html)
  438. // each text
  439. // find label
  440. // if(obj)
  441. // replace random text
  442. // else
  443. // replace text
  444. // end
  445. // Each variation
  446. // (if obj)
  447. // each
  448. // add class
  449. // (else)
  450. // add class
  451. // label = property
  452. // class = class
  453. // show html
  454. // end
  455. // end
  456. },
  457. element: function(koan, type, text, variation) {
  458. },
  459. variations: function($element, variations) {
  460. $.each(variations, function(name, variation){
  461. });
  462. },
  463. text: function($element, text) {
  464. $.each(text, function(selector, text) {
  465. $element.find(selector).text(text);
  466. });
  467. return $element;
  468. }
  469. },
  470. overviewMode: function() {
  471. var
  472. $button = $(this),
  473. $body = $('body'),
  474. $example = $('.example')
  475. ;
  476. $body.toggleClass('overview');
  477. $button.toggleClass('active');
  478. if($body.hasClass('overview')) {
  479. $example.each(function() {
  480. $(this).children().not('.ui.header:eq(0), .example p:eq(0), .annotation').hide();
  481. });
  482. $example.filter('.another').hide();
  483. }
  484. else {
  485. $example.each(function() {
  486. $(this).children().not('.ui.header:eq(0), .example p:eq(0), .annotation').show();
  487. });
  488. $example.filter('.another').show();
  489. }
  490. $('.sticky').sticky('refresh');
  491. },
  492. developerMode: function() {
  493. var
  494. $body = $('body'),
  495. $example = $('.example').not('.no')
  496. ;
  497. if($body.hasClass('overview')) {
  498. handler.overviewMode();
  499. }
  500. $example
  501. .each(function() {
  502. $.proxy(handler.createCode, $(this))('developer');
  503. })
  504. ;
  505. $('.sticky').sticky('refresh');
  506. },
  507. designerMode: function() {
  508. var
  509. $body = $('body'),
  510. $example = $('.example').not('.no')
  511. ;
  512. if($body.hasClass('overview')) {
  513. handler.overviewMode();
  514. }
  515. $example
  516. .each(function() {
  517. $.proxy(handler.createCode, $(this))('designer');
  518. })
  519. ;
  520. $('.sticky').sticky('refresh');
  521. },
  522. getIndent: function(text) {
  523. var
  524. lines = text.split("\n"),
  525. firstLine = (lines[0] === '')
  526. ? lines[1]
  527. : lines[0],
  528. spacesPerIndent = 2,
  529. leadingSpaces = firstLine.length - firstLine.replace(/^\s*/g, '').length,
  530. indent
  531. ;
  532. if(leadingSpaces !== 0) {
  533. indent = leadingSpaces;
  534. }
  535. else {
  536. // string has already been trimmed, get first indented line and subtract 2
  537. $.each(lines, function(index, line) {
  538. leadingSpaces = line.length - line.replace(/^\s*/g, '').length;
  539. if(leadingSpaces !== 0) {
  540. indent = leadingSpaces - spacesPerIndent;
  541. return false;
  542. }
  543. });
  544. }
  545. return indent || 4;
  546. },
  547. generateCode: function() {
  548. var
  549. $example = $(this).closest('.example'),
  550. $annotation = $example.find('.annotation'),
  551. $code = $annotation.find('.code'),
  552. $header = $example.not('.another').children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
  553. $ignored = $('i.code:last-child, .anchor, .code, .existing, .pointing.below.label, .instructive, .language.label, .annotation, br, .ignore, .ignored'),
  554. $demo = $example.children().not($header).not($ignored),
  555. code = ''
  556. ;
  557. if( $code.size() === 0) {
  558. $demo
  559. .each(function(){
  560. var $this = $(this).clone(false);
  561. if($this.not('br')) {
  562. // allow inline styles only with this one class
  563. if($this.is('.my-container')) {
  564. code += $this.get(0).outerHTML + "\n";
  565. }
  566. else {
  567. code += $this.removeAttr('style').get(0).outerHTML + "\n";
  568. }
  569. }
  570. })
  571. ;
  572. }
  573. $example.data('code', code);
  574. return code;
  575. },
  576. createCode: function(type) {
  577. var
  578. $example = $(this).closest('.example'),
  579. $header = $example.children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
  580. $annotation = $example.find('.annotation'),
  581. $code = $annotation.find('.code'),
  582. $ignoredContent = $('.ui.popup, i.code:last-child, .anchor, .code, .existing.segment, .instructive, .language.label, .annotation, br, .ignore, .ignored'),
  583. $demo = $example.children().not($header).not($ignoredContent),
  584. code = $example.data('code') || $.proxy(handler.generateCode, this)()
  585. ;
  586. if( $code.hasClass('existing') ) {
  587. $annotation.show();
  588. $code.removeClass('existing');
  589. $.proxy(handler.initializeCode, $code)();
  590. }
  591. if($annotation.size() === 0) {
  592. $annotation = $('<div/>')
  593. .addClass('annotation')
  594. .appendTo($example)
  595. ;
  596. }
  597. if( $example.find('.instructive').size() === 0) {
  598. $code = $('<div/>')
  599. .data('type', 'html')
  600. .addClass('code')
  601. .html(code)
  602. .hide()
  603. .appendTo($annotation)
  604. ;
  605. $.proxy(handler.initializeCode, $code)();
  606. }
  607. if( ($demo.first().is(':visible') || type == 'developer') && type != 'designer' ) {
  608. $demo.hide();
  609. $header.show();
  610. $annotation.fadeIn(500);
  611. }
  612. else {
  613. $annotation.hide();
  614. if($demo.size() > 1) {
  615. $demo.show();
  616. }
  617. else {
  618. $demo.fadeIn(500);
  619. }
  620. }
  621. },
  622. createAnnotation: function() {
  623. if(!$(this).data('type')) {
  624. $(this).data('type', 'html');
  625. }
  626. $(this)
  627. .wrap('<div class="annotation">')
  628. .parent()
  629. .hide()
  630. ;
  631. },
  632. resizeCode: function() {
  633. $('.ace_editor')
  634. .each(function() {
  635. var
  636. $code = $(this),
  637. padding = 50,
  638. editor,
  639. editorSession,
  640. codeHeight
  641. ;
  642. $code.css('height', 'auto');
  643. editor = ace.edit($code[0]);
  644. editorSession = editor.getSession();
  645. codeHeight = editorSession.getScreenLength() * editor.renderer.lineHeight + padding;
  646. $code.css('height', codeHeight);
  647. editor.resize();
  648. })
  649. ;
  650. },
  651. makeCode: function() {
  652. if(window.ace !== undefined) {
  653. $code
  654. .filter(':visible')
  655. .each(handler.initializeCode)
  656. ;
  657. $existingCode
  658. .each(handler.createAnnotation)
  659. ;
  660. }
  661. },
  662. initializeCode: function() {
  663. var
  664. $code = $(this).show(),
  665. code = $code.html(),
  666. existingCode = $code.hasClass('existing'),
  667. evaluatedCode = $code.hasClass('evaluated'),
  668. contentType = $code.data('type') || 'javascript',
  669. title = $code.data('title') || false,
  670. demo = $code.data('demo') || false,
  671. preview = $code.data('preview') || false,
  672. label = $code.data('label') || false,
  673. displayType = {
  674. html : 'HTML',
  675. javascript : 'Javascript',
  676. css : 'CSS',
  677. text : 'Command Line',
  678. sh : 'Command Line'
  679. },
  680. indent = handler.getIndent(code) || 2,
  681. padding = 20,
  682. name = (evaluatedCode)
  683. ? 'existing'
  684. : 'instructive',
  685. whiteSpace,
  686. $label,
  687. editor,
  688. editorSession,
  689. codeHeight
  690. ;
  691. // trim whitespace
  692. whiteSpace = new RegExp('\\n\\s{' + indent + '}', 'g');
  693. code = $.trim(code).replace(whiteSpace, '\n');
  694. if(contentType == 'html') {
  695. $code.text(code);
  696. }
  697. else {
  698. $code.html(code);
  699. }
  700. // evaluate if specified
  701. if(evaluatedCode) {
  702. eval(code);
  703. }
  704. // initialize
  705. editor = ace.edit($code[0]);
  706. editorSession = editor.getSession();
  707. //editor.setTheme('ace/theme/tomorrow');
  708. editor.setTheme('ace/theme/github');
  709. editor.setShowPrintMargin(false);
  710. editor.setReadOnly(true);
  711. editor.renderer.setShowGutter(false);
  712. editor.setHighlightActiveLine(false);
  713. editorSession.setMode('ace/mode/'+ contentType);
  714. editorSession.setUseWrapMode(true);
  715. editorSession.setTabSize(2);
  716. editorSession.setUseSoftTabs(true);
  717. codeHeight = editorSession.getScreenLength() * editor.renderer.lineHeight + padding;
  718. $(this)
  719. .height(codeHeight + 'px')
  720. .wrap('<div class="ui ' + name + ' segment">')
  721. ;
  722. // add label
  723. if(title) {
  724. $('<div>')
  725. .addClass('ui attached top label')
  726. .html('<span class="title">' + title + '</span>' + '<em>' + (displayType[contentType] || contentType) + '</em>')
  727. .prependTo( $(this).parent() )
  728. ;
  729. }
  730. if(label) {
  731. $('<div>')
  732. .addClass('ui pointing below label')
  733. .html(displayType[contentType] || contentType)
  734. .insertBefore ( $(this).parent() )
  735. ;
  736. }
  737. // add run code button
  738. if(demo) {
  739. $('<a>')
  740. .addClass('ui pointing below label')
  741. .html('Run Code')
  742. .on('click', function() {
  743. eval(code);
  744. })
  745. .insertBefore ( $(this).parent() )
  746. ;
  747. }
  748. // add preview if specified
  749. if(preview) {
  750. $(code)
  751. .insertAfter( $(this).parent() )
  752. ;
  753. }
  754. editor.resize();
  755. },
  756. swapStyle: function() {
  757. var
  758. theme = $(this).data('theme')
  759. ;
  760. $(this)
  761. .addClass('active')
  762. .siblings()
  763. .removeClass('active')
  764. ;
  765. $('head link.ui')
  766. .each(function() {
  767. var
  768. href = $(this).attr('href'),
  769. subDirectory = href.split('/')[3],
  770. newLink = href.replace(subDirectory, theme)
  771. ;
  772. $(this)
  773. .attr('href', newLink)
  774. ;
  775. })
  776. ;
  777. }
  778. };
  779. handler.createAnchors();
  780. if( $pageTabs.size() > 0 ) {
  781. $pageTabs
  782. .tab({
  783. context : '.main.container',
  784. childrenOnly : true,
  785. history : true,
  786. onTabInit : function() {
  787. handler.makeCode();
  788. $container = ($('.fixed.column').size() > 0 )
  789. ? $(this).find('.examples')
  790. : $(this)
  791. ;
  792. $sectionHeaders = $container.children('h2');
  793. $sectionExample = $container.find('.example');
  794. $exampleHeaders = $sectionExample.children('h4');
  795. // create code
  796. handler.tryCreateMenu();
  797. $(window).on('resize.menu', function() {
  798. handler.tryCreateMenu();
  799. });
  800. },
  801. onTabLoad : function() {
  802. $sticky.filter(':visible').sticky('refresh');
  803. }
  804. })
  805. ;
  806. }
  807. else {
  808. handler.makeCode();
  809. handler.tryCreateMenu();
  810. $(window).on('resize.menu', function() {
  811. handler.tryCreateMenu();
  812. });
  813. }
  814. $sticky
  815. .sticky({
  816. context : '.main.container',
  817. pushing : true
  818. })
  819. ;
  820. $languageModal
  821. .modal()
  822. ;
  823. $menu
  824. .sidebar({
  825. transition : 'uncover',
  826. mobileTransition : 'scale down'
  827. })
  828. .sidebar('attach events', '.launch.button, .view-ui, .launch.item')
  829. .sidebar('attach events', $hideMenu, 'hide')
  830. ;
  831. handler.createIcon();
  832. $example
  833. .each(function() {
  834. $.proxy(handler.generateCode, this)();
  835. })
  836. .find('i.code')
  837. .on('click', handler.createCode)
  838. ;
  839. $shownExample
  840. .each(handler.createCode)
  841. ;
  842. $(window)
  843. .on('resize', function() {
  844. clearTimeout(handler.timer);
  845. handler.timer = setTimeout(handler.resizeCode, 500);
  846. })
  847. ;
  848. $downloadDropdown
  849. .dropdown({
  850. on : 'click',
  851. transition : 'scale'
  852. })
  853. ;
  854. $themeDropdown
  855. .dropdown({
  856. action: 'select',
  857. onChange: handler.less.changeTheme
  858. })
  859. ;
  860. if($.fn.tablesort !== undefined && $sortTable.size() > 0) {
  861. $sortTable
  862. .tablesort()
  863. ;
  864. }
  865. $helpPopup
  866. .popup()
  867. ;
  868. $swap
  869. .on('click', handler.swapStyle)
  870. ;
  871. $overview
  872. .on('click', handler.overviewMode)
  873. ;
  874. $menuPopup
  875. .popup({
  876. position : 'bottom center',
  877. className : {
  878. popup: 'ui popup'
  879. }
  880. })
  881. ;
  882. $pageDropdown
  883. .dropdown({
  884. on : 'hover',
  885. action : 'nothing',
  886. allowTab : false
  887. })
  888. ;
  889. $languageDropdown
  890. .popup()
  891. .dropdown({
  892. on : 'click',
  893. onShow: function() {
  894. $(this).popup('hide');
  895. },
  896. onChange: handler.showLanguageModal
  897. })
  898. ;
  899. };
  900. // attach ready event
  901. $(document)
  902. .ready(semantic.ready)
  903. ;