Browse Source

Code samples should now automatically resize when browser resizes, code samples now generate on first mousemove so as to avoid changes in html markup from interacting with examples

pull/176/merge
jlukic 11 years ago
parent
commit
a78a8ca545
2 changed files with 68 additions and 20 deletions
  1. 4
      node/src/documents/modules/modal.html.eco
  2. 84
      node/src/files/javascript/semantic.js

4
node/src/documents/modules/modal.html.eco

@ -111,7 +111,7 @@ type : 'UI Module'
<h2 class="ui dividing header">Types</h2> <h2 class="ui dividing header">Types</h2>
<div class="example">
<div class="no example">
<h4 class="ui header">Standard</h4> <h4 class="ui header">Standard</h4>
<p>A standard modal</p> <p>A standard modal</p>
<div class="code" data-demo="true"> <div class="code" data-demo="true">
@ -121,7 +121,7 @@ type : 'UI Module'
</div> </div>
</div> </div>
<div class="example">
<div class="no example">
<h4 class="ui header">Basic</h4> <h4 class="ui header">Basic</h4>
<p>A modal can reduce its complexity</p> <p>A modal can reduce its complexity</p>
<div class="code" data-demo="true"> <div class="code" data-demo="true">

84
node/src/files/javascript/semantic.js

@ -234,27 +234,16 @@ semantic.ready = function() {
; ;
}, },
createCode: function(type) {
generateCode: function() {
var var
$example = $(this).closest('.example'), $example = $(this).closest('.example'),
$header = $example.children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
$demo = $example.children().not($header).not('i.code:first-child, .code, .language.label, .annotation, br, .ignore, .ignored'),
$annotation = $example.find('.annotation'), $annotation = $example.find('.annotation'),
$code = $annotation.find('.code'), $code = $annotation.find('.code'),
$header = $example.children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
$demo = $example.children().not($header).not('i.code:first-child, .code, .instructive, .language.label, .annotation, br, .ignore, .ignored'),
whiteSpace = new RegExp('\\n\\s{4}', 'g'), whiteSpace = new RegExp('\\n\\s{4}', 'g'),
code = ''
code = ''
; ;
if($annotation.size() === 0) {
$annotation = $('<div/>')
.addClass('annotation')
.appendTo($example)
;
}
if( $code.hasClass('existing') ) {
$annotation.show();
$code.removeClass('existing');
$.proxy(handler.initializeCode, $code)();
}
if( $code.size() === 0) { if( $code.size() === 0) {
$demo $demo
.each(function(){ .each(function(){
@ -264,15 +253,45 @@ semantic.ready = function() {
} }
}) })
; ;
//code = $.trim(code.replace(whiteSpace, '\n'));
}
$example.data('code', code);
return code;
},
createCode: function(type) {
var
$example = $(this).closest('.example'),
$header = $example.children('.ui.header:first-of-type').eq(0).add('p:first-of-type'),
$annotation = $example.find('.annotation'),
$code = $annotation.find('.code'),
$demo = $example.children().not($header).not('i.code:first-child, .code, .instructive, .language.label, .annotation, br, .ignore, .ignored'),
code = $example.data('code')
;
if( $code.hasClass('existing') ) {
$annotation.show();
$code.removeClass('existing');
$.proxy(handler.initializeCode, $code)();
}
$.proxy(handler.generateCode, this)();
if($annotation.size() === 0) {
$annotation = $('<div/>')
.addClass('annotation')
.appendTo($example)
;
}
if( $example.find('.ace_editor').size() === 0) {
$code = $('<div/>') $code = $('<div/>')
.data('type', 'html') .data('type', 'html')
.addClass('code') .addClass('code')
.html(code) .html(code)
.hide()
.appendTo($annotation) .appendTo($annotation)
; ;
$.proxy(handler.initializeCode, $code)(); $.proxy(handler.initializeCode, $code)();
} }
if( ($demo.first().is(':visible') || type == 'developer') && type != 'designer' ) { if( ($demo.first().is(':visible') || type == 'developer') && type != 'designer' ) {
$demo.hide(); $demo.hide();
$header.show(); $header.show();
@ -300,9 +319,29 @@ semantic.ready = function() {
; ;
}, },
resizeCode: function() {
$('.ace_editor')
.each(function() {
var
$code = $(this),
padding = 4,
editor,
editorSession,
codeHeight
;
$code.css('height', 'auto');
editor = ace.edit($code[0]);
editorSession = editor.getSession();
codeHeight = editor.session.getScreenLength() * (editor.renderer.lineHeight) + editor.renderer.scrollBar.getWidth() + padding;
$code.css('height', codeHeight);
editor.resize();
})
;
},
initializeCode: function() { initializeCode: function() {
var var
$code = $(this),
$code = $(this).show(),
code = $code.html(), code = $code.html(),
existingCode = $code.hasClass('existing'), existingCode = $code.hasClass('existing'),
contentType = $code.data('type') || 'javascript', contentType = $code.data('type') || 'javascript',
@ -354,7 +393,7 @@ semantic.ready = function() {
editorSession.setTabSize(2); editorSession.setTabSize(2);
editorSession.setUseSoftTabs(true); editorSession.setUseSoftTabs(true);
codeHeight = editor.session.getScreenLength() * (editor.renderer.lineHeight) + editor.renderer.scrollBar.getWidth() + padding;
codeHeight = editorSession.getScreenLength() * (editor.renderer.lineHeight) + editor.renderer.scrollBar.getWidth() + padding;
$(this) $(this)
.height(codeHeight + 'px') .height(codeHeight + 'px')
.wrap('<div class="ui instructive segment">') .wrap('<div class="ui instructive segment">')
@ -541,6 +580,13 @@ semantic.ready = function() {
} }
}; };
$(window)
.on('resize', function() {
clearTimeout(handler.timer);
handler.timer = setTimeout(handler.resizeCode, 100);
})
;
$downloadDropdown $downloadDropdown
.dropdown({ .dropdown({
on : 'click', on : 'click',
@ -565,7 +611,9 @@ semantic.ready = function() {
} }
handler.createIcon(); handler.createIcon();
$example $example
.one('mousemove', handler.generateCode)
.find('i.code') .find('i.code')
.on('click', handler.createCode) .on('click', handler.createCode)
; ;

Loading…
Cancel
Save