@ -51,51 +51,51 @@
}
// ----------------- storage --------------------
function syncStorage ( ) {
if ( ! chrome || ! chrome . storage || ! chrome . storage . sync ) return ;
var obj = { }
var done = false ;
var count = 0
var dont = 0 ;
function check ( key ) {
chrome . storage . sync . get ( key , function ( resp ) {
console . log ( "comparing to cloud" , key , resp )
if ( typeof resp [ key ] != 'undefined' && obj [ key ] !== resp [ key ] && confirm ( "Overwrite '" + fileNameFromKey ( key ) + "'? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud." ) ) {
console . log ( "Overwriting" , key )
localStorage . setItem ( key , resp [ key ] ) ;
updateFiles ( ) ;
} else {
console . log ( "add to obj" , obj , key )
obj [ key ] = localStorage [ key ] ;
}
done ++
if ( done >= count ) chrome . storage . sync . set ( obj , function ( ) {
console . log ( "updated cloud files with: " , obj , this , arguments )
} )
} )
}
for ( var y in window . localStorage ) {
console . log ( "checking" , y )
obj [ y ] = window . localStorage . getItem ( y ) ;
if ( y . indexOf ( SOL _CACHE _FILE _PREFIX ) !== 0 ) continue ;
count ++ ;
check ( y )
}
}
window . syncStorage = syncStorage ;
syncStorage ( )
// ----------------- storage --------------------
function syncStorage ( ) {
if ( ! chrome || ! chrome . storage || ! chrome . storage . sync ) return ;
var obj = { }
var done = false ;
var count = 0
var dont = 0 ;
function check ( key ) {
chrome . storage . sync . get ( key , function ( resp ) {
console . log ( "comparing to cloud" , key , resp )
if ( typeof resp [ key ] != 'undefined' && obj [ key ] !== resp [ key ] && confirm ( "Overwrite '" + fileNameFromKey ( key ) + "'? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud." ) ) {
console . log ( "Overwriting" , key )
localStorage . setItem ( key , resp [ key ] ) ;
updateFiles ( ) ;
} else {
console . log ( "add to obj" , obj , key )
obj [ key ] = localStorage [ key ] ;
}
done ++
if ( done >= count ) chrome . storage . sync . set ( obj , function ( ) {
console . log ( "updated cloud files with: " , obj , this , arguments )
} )
} )
}
for ( var y in window . localStorage ) {
console . log ( "checking" , y )
obj [ y ] = window . localStorage . getItem ( y ) ;
if ( y . indexOf ( SOL _CACHE _FILE _PREFIX ) !== 0 ) continue ;
count ++ ;
check ( y )
}
}
window . syncStorage = syncStorage ;
syncStorage ( )
// ----------------- editor ----------------------
var SOL _CACHE _FILE _PREFIX = 'sol-cache-file-' ;
@ -103,7 +103,8 @@
var SOL _CACHE _FILE = null ;
var editor = ace . edit ( "input" ) ;
var sessions = { } ;
var sessions = { } ;
var Range = ace . require ( 'ace/range' ) . Range ;
var errMarkerId = null ;
@ -120,22 +121,21 @@
SOL _CACHE _FILE = getFiles ( ) [ 0 ] ;
var files = getFiles ( ) ;
for ( var x in files )
sessions [ files [ x ] ] = newEditorSession ( files [ x ] )
editor . setSession ( sessions [ SOL _CACHE _FILE ] ) ;
var files = getFiles ( ) ;
for ( var x in files )
sessions [ files [ x ] ] = newEditorSession ( files [ x ] )
editor . setSession ( sessions [ SOL _CACHE _FILE ] ) ;
editor . resize ( true ) ;
function newEditorSession ( filename ) {
var s = new ace . EditSession ( window . localStorage [ filename ] )
s . setMode ( "ace/mode/javascript" ) ;
s . setTabSize ( 4 ) ;
s . setUseSoftTabs ( true ) ;
return s ;
}
function newEditorSession ( filekey ) {
var s = new ace . EditSession ( window . localStorage [ filekey ] , "ace/mode/javascript" )
s . setTabSize ( 4 ) ;
s . setUseSoftTabs ( true ) ;
aces [ filekey ] = s ;
return s ;
}
@ -143,7 +143,9 @@
$ ( '#options li' ) . click ( function ( ev ) {
var $el = $ ( this ) ;
var cls = /[a-z]+View/ . exec ( $el . get ( 0 ) . className ) [ 0 ] ;
var match = /[a-z]+View/ . exec ( $el . get ( 0 ) . className ) ;
if ( ! match ) return ;
var cls = match [ 0 ] ;
if ( ! $el . hasClass ( 'active' ) ) {
$el . parent ( ) . find ( 'li' ) . removeClass ( 'active' ) ;
$ ( '#optionViews' ) . attr ( 'class' , '' ) . addClass ( cls ) ;
@ -196,7 +198,7 @@
$ ( '#gist' ) . click ( function ( ) {
if ( confirm ( "Are you sure you want to publish all your files anonymously as a public gist on github.com?" ) ) {
var files = { } ;
var filesArr = getFiles ( ) ;
var description = "Created using soleditor: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity/?gist=" ;
@ -225,6 +227,7 @@
// ----------------- file selector-------------
var $filesEl = $ ( '#files' ) ;
$filesEl . on ( 'click' , '.newFile' , function ( ) {
while ( window . localStorage [ SOL _CACHE _UNTITLED + untitledCount ] )
@ -308,16 +311,17 @@
if ( SOL _CACHE _FILE ) {
var active = fileTabFromKey ( SOL _CACHE _FILE ) ;
active . addClass ( 'active' ) ;
editor . setSession ( sessions [ SOL _CACHE _FILE ] ) ;
editor . setSession ( sessions [ SOL _CACHE _FILE ] ) ;
editor . focus ( ) ;
}
$ ( '#input' ) . toggle ( ! ! SOL _CACHE _FILE ) ;
$ ( '#output' ) . toggle ( ! ! SOL _CACHE _FILE ) ;
reAdjust ( ) ;
}
function fileTabTemplate ( key ) {
var name = fileNameFromKey ( key ) ;
return $ ( '<span class="file"><span class="name">' + name + '</span><span class="remove"><i class="fa fa-close"></i></span></span >' ) ;
return $ ( '<li class="file"><span class="name">' + name + '</span><span class="remove"><i class="fa fa-close"></i></span></li >' ) ;
}
function fileKey ( name ) {
@ -333,7 +337,7 @@
for ( var f in localStorage ) {
if ( f . indexOf ( SOL _CACHE _FILE _PREFIX , 0 ) === 0 ) {
files . push ( f ) ;
if ( ! sessions [ f ] ) sessions [ f ] = newEditorSession ( f ) ;
if ( ! sessions [ f ] ) sessions [ f ] = newEditorSession ( f ) ;
}
}
return files ;
@ -341,6 +345,68 @@
updateFiles ( ) ;
var hidWidth ;
function widthOfList ( ) {
var itemsWidth = 0 ;
$ ( '.file' ) . each ( function ( ) {
var itemWidth = $ ( this ) . outerWidth ( ) ;
itemsWidth += itemWidth ;
} ) ;
return itemsWidth ;
} ;
function widthOfHidden ( ) {
return ( ( $ ( '.files-wrapper' ) . outerWidth ( ) ) - widthOfList ( ) - getLeftPosi ( ) ) ;
} ;
function widthOfVisible ( ) {
return $ ( '.files-wrapper' ) . outerWidth ( ) ;
} ;
function getLeftPosi ( ) {
return $ ( '#files' ) . position ( ) . left ;
} ;
function reAdjust ( ) {
console . log ( "left start: " , getLeftPosi ( ) )
console . log ( "outer width: " , widthOfVisible ( ) , "content width: " , widthOfList ( ) , " left+vis: " , getLeftPosi ( ) + widthOfVisible ( ) )
if ( widthOfList ( ) + getLeftPosi ( ) > + widthOfVisible ( ) ) {
console . log ( "show right scroll" )
$ ( '.scroller-right' ) . fadeIn ( 'fast' ) ;
} else {
console . log ( "hide right scroll" )
$ ( '.scroller-right' ) . fadeOut ( 'fast' ) ;
}
if ( getLeftPosi ( ) < 0 ) {
console . log ( "show left scroll" )
$ ( '.scroller-left' ) . fadeIn ( 'fast' ) ;
} else {
console . log ( "hide left scroll" )
$ ( '.scroller-left' ) . fadeOut ( 'fast' ) ;
$ ( '#files' ) . animate ( { left : getLeftPosi ( ) + "px" } , 'slow' ) ;
}
}
$ ( '.scroller-right' ) . click ( function ( ) {
var delta = ( getLeftPosi ( ) - 200 )
console . log ( delta )
$ ( '#files' ) . animate ( { left : delta + "px" } , 'slow' , function ( ) {
reAdjust ( ) ;
} ) ;
} ) ;
$ ( '.scroller-left' ) . click ( function ( ) {
var delta = Math . min ( ( getLeftPosi ( ) + 200 ) , 0 )
console . log ( delta )
$ ( '#files' ) . animate ( { left : delta + "px" } , 'slow' , function ( ) {
reAdjust ( ) ;
} ) ;
} ) ;
// ----------------- version selector-------------
// var soljsonSources is provided by bin/list.js
@ -395,6 +461,7 @@
dragging = false ;
setEditorSize ( delta ) ;
window . localStorage . setItem ( EDITOR _SIZE _CACHE _KEY , delta ) ;
reAdjust ( ) ;
}
} ) ;
@ -408,10 +475,11 @@
var hidingRHP = false ;
$ ( '.toggleRHP' ) . click ( function ( ) {
hidingRHP = ! hidingRHP ;
setEditorSize ( hidingRHP ? 0 : window . localStorage [ EDITOR _SIZE _CACHE _KEY ] ) ;
$ ( '.toggleRHP' ) . toggleClass ( 'hiding' , hidingRHP ) ;
if ( ! hidingRHP ) compile ( ) ;
hidingRHP = ! hidingRHP ;
setEditorSize ( hidingRHP ? 0 : window . localStorage [ EDITOR _SIZE _CACHE _KEY ] ) ;
$ ( '.toggleRHP i' ) . toggleClass ( 'fa-angle-double-right' , ! hidingRHP ) ;
$ ( '.toggleRHP i' ) . toggleClass ( 'fa-angle-double-left' , hidingRHP ) ;
if ( ! hidingRHP ) compile ( ) ;
} ) ;
@ -419,7 +487,7 @@
function onResize ( ) {
editor . resize ( ) ;
var session = editor . getSession ( ) ;
var session = editor . getSession ( ) ;
session . setUseWrapMode ( document . querySelector ( '#editorWrap' ) . checked ) ;
if ( session . getUseWrapMode ( ) ) {
var characterWidth = editor . renderer . characterWidth ;
@ -429,6 +497,7 @@
session . setWrapLimit ( parseInt ( contentWidth / characterWidth , 10 ) ) ;
}
}
reAdjust ( ) ;
}
window . onresize = onResize ;
onResize ( ) ;
@ -634,9 +703,9 @@
loadVersion ( 'soljson-latest.js' ) ;
editor . getSession ( ) . on ( 'change' , onChange ) ;
editor . on ( 'changeSession' , function ( ) {
editor . getSession ( ) . on ( 'change' , onChange ) ;
} )
editor . on ( 'changeSession' , function ( ) {
editor . getSession ( ) . on ( 'change' , onChange ) ;
} )
document . querySelector ( '#optimize' ) . addEventListener ( 'change' , compile ) ;
@ -756,9 +825,9 @@
$txOrigin . empty ( ) ;
for ( var a in accounts ) { $txOrigin . append ( $ ( '<option />' ) . val ( accounts [ a ] ) . text ( accounts [ a ] ) ) ; }
$txOrigin . val ( accounts [ 0 ] ) ;
} else $txOrigin . val ( 'unknown' ) ;
} else $txOrigin . val ( 'unknown' ) ;
}
if ( executionContext === 'vm' ) {
dapp . getAccounts ( renderAccounts ) ;
} else {
@ -770,7 +839,7 @@
$ ( '.col2 input,textarea' ) . click ( function ( ) { this . select ( ) ; } ) ;
} ;
var tableRowItems = function ( first , second , cls ) {
return $ ( '<div class="row"/>' )
return $ ( '<div class="c row"/>' )
. addClass ( cls )
. append ( $ ( '<div class="col1">' ) . append ( first ) )
. append ( $ ( '<div class="col2">' ) . append ( second ) ) ;
@ -861,6 +930,6 @@
return funABI ;
} ;
syncStorage ( )
syncStorage ( )
} ) ;