@ -234,27 +234,16 @@ semantic.ready = function() {
;
;
} ,
} ,
cre ateCode: function ( type ) {
gener ateCode: 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 . s ession. getScreenLength ( ) * ( editor . renderer . lineHeight ) + editor . renderer . scrollBar . getWidth ( ) + padding ;
codeHeight = editorS ession . 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 )
;
;