Commit 81eb45fb authored by chriseth's avatar chriseth

Style.

parent 7985e986
...@@ -90,10 +90,10 @@ THE SOFTWARE. ...@@ -90,10 +90,10 @@ THE SOFTWARE.
var Range = ace.require('ace/range').Range; var Range = ace.require('ace/range').Range;
var errMarkerId = null; var errMarkerId = null;
var solFiles = JSON.parse( window.localStorage.getItem( SOL_CACHE_FILES_KEY ) ) || [SOL_CACHE_FILE]; var solFiles = JSON.parse(window.localStorage.getItem(SOL_CACHE_FILES_KEY)) || [SOL_CACHE_FILE];
if (solFiles.length === 0) solFiles = [SOL_CACHE_FILE]; if (solFiles.length === 0) solFiles = [SOL_CACHE_FILE];
var solCache = window.localStorage.getItem( SOL_CACHE_FILE ) || BALLOT_EXAMPLE; var solCache = window.localStorage.getItem(SOL_CACHE_FILE) || BALLOT_EXAMPLE;
window.localStorage.setItem( SOL_CACHE_FILE, solCache ) window.localStorage.setItem(SOL_CACHE_FILE, solCache)
if (window.localStorage.getItem('sol-cache')) { if (window.localStorage.getItem('sol-cache')) {
// Backwards-compatibility // Backwards-compatibility
...@@ -105,109 +105,109 @@ THE SOFTWARE. ...@@ -105,109 +105,109 @@ THE SOFTWARE.
solFiles.push('Untitled' + count); solFiles.push('Untitled' + count);
} }
window.localStorage.setItem( SOL_CACHE_FILES_KEY, JSON.stringify( solFiles ) ); window.localStorage.setItem(SOL_CACHE_FILES_KEY, JSON.stringify(solFiles));
editor.setValue( solCache, -1 ); editor.setValue(solCache, -1);
session.setMode("ace/mode/javascript"); session.setMode("ace/mode/javascript");
session.setTabSize(4); session.setTabSize(4);
session.setUseSoftTabs(true); session.setUseSoftTabs(true);
// ----------------- file selector------------- // ----------------- file selector-------------
var count = 0; var count = 0;
var $filesEl = $('#files'); var $filesEl = $('#files');
$filesEl.on( 'click','.newFile', function(){ $filesEl.on('click','.newFile', function() {
count++; count++;
var name = 'Unititled'+count; var name = 'Unititled' + count;
solFiles.push( name ) solFiles.push(name);
SOL_CACHE_FILE = name; SOL_CACHE_FILE = name;
window.localStorage.setItem( SOL_CACHE_FILES_KEY, JSON.stringify( solFiles ) ); window.localStorage.setItem(SOL_CACHE_FILES_KEY, JSON.stringify(solFiles));
window.localStorage.setItem( SOL_CACHE_FILE, '' ); window.localStorage.setItem(SOL_CACHE_FILE, '');
updateFiles(); updateFiles();
}) })
$filesEl.on( 'click','.file:not(.active)', showFileHandler ) $filesEl.on('click', '.file:not(.active)', showFileHandler);
$filesEl.on( 'click','.file.active', function(ev){ $filesEl.on('click', '.file.active', function(ev) {
var $fileTabEl = $(this); var $fileTabEl = $(this);
var originalName = $fileTabEl.find('.name').text(); var originalName = $fileTabEl.find('.name').text();
ev.preventDefault(); ev.preventDefault();
if ($(this).find('input').length > 0 ) return false; if ($(this).find('input').length > 0) return false;
var $fileNameInputEl = $('<input value="'+originalName+'"/>'); var $fileNameInputEl = $('<input value="'+originalName+'"/>');
$fileTabEl.html( $fileNameInputEl ); $fileTabEl.html($fileNameInputEl);
$fileNameInputEl.focus(); $fileNameInputEl.focus();
$fileNameInputEl.select(); $fileNameInputEl.select();
$fileNameInputEl.on( 'blur', handleRename ); $fileNameInputEl.on('blur', handleRename);
$fileNameInputEl.keyup( handleRename ); $fileNameInputEl.keyup(handleRename);
function handleRename (ev) { function handleRename(ev) {
ev.preventDefault(); ev.preventDefault();
if (ev.which && ev.which !== 13) return false; if (ev.which && ev.which !== 13) return false;
var newName = ev.target.value; var newName = ev.target.value;
$fileNameInputEl.off('blur'); $fileNameInputEl.off('blur');
$fileNameInputEl.off('keyup'); $fileNameInputEl.off('keyup');
if ( newName !== originalName && confirm( "Are you sure you want to rename: " + originalName + " to " + newName + '?' )) { if (newName !== originalName && confirm("Are you sure you want to rename: " + originalName + " to " + newName + '?')) {
solFiles.splice( solFiles.indexOf(originalName), 1, newName ); solFiles.splice(solFiles.indexOf(originalName), 1, newName);
window.localStorage.setItem( newName, window.localStorage.getItem(originalName) ); window.localStorage.setItem(newName, window.localStorage.getItem(originalName));
window.localStorage.setItem( SOL_CACHE_FILES_KEY, JSON.stringify( solFiles ) ); window.localStorage.setItem(SOL_CACHE_FILES_KEY, JSON.stringify(solFiles));
window.localStorage.removeItem( originalName ) window.localStorage.removeItem(originalName);
SOL_CACHE_FILE = newName; SOL_CACHE_FILE = newName;
} }
updateFiles() updateFiles();
return false; return false;
} }
return false; return false;
}) })
$filesEl.on( 'click','.file .remove', function(ev){ $filesEl.on('click', '.file .remove', function(ev) {
ev.preventDefault(); ev.preventDefault();
var name = $(this).parent().find('.name').text() var name = $(this).parent().find('.name').text();
if (confirm( "Are you sure you want to remove: " + name + " from local storage?" )) { if (confirm("Are you sure you want to remove: " + name + " from local storage?")) {
var index = solFiles.indexOf(name); var index = solFiles.indexOf(name);
solFiles.splice(index, 1 ); solFiles.splice(index, 1);
window.localStorage.setItem( SOL_CACHE_FILES_KEY, JSON.stringify( solFiles ) ); window.localStorage.setItem(SOL_CACHE_FILES_KEY, JSON.stringify(solFiles));
SOL_CACHE_FILE = solFiles[ Math.max(0, index - 1)] SOL_CACHE_FILE = solFiles[ Math.max(0, index - 1)];
window.localStorage.removeItem( name ) window.localStorage.removeItem(name);
updateFiles() updateFiles();
} }
return false; return false;
}); });
function showFileHandler (ev) { function showFileHandler(ev) {
ev.preventDefault() ev.preventDefault();
SOL_CACHE_FILE = $(this).find('.name').text(); SOL_CACHE_FILE = $(this).find('.name').text();
updateFiles() (updateFiles();
return false; return false;
} }
function fileTabFromName(name) { function fileTabFromName(name) {
return $('#files .file').filter(function(){ return $(this).find('.name').text() == name; }) return $('#files .file').filter(function(){ return $(this).find('.name').text() == name; });
} }
function updateFiles () { function updateFiles() {
$filesEl.find('.file').remove() $filesEl.find('.file').remove();
for (var f in solFiles) { for (var f in solFiles) {
if (solFiles[f]) $filesEl.append( fileTabTemplate(solFiles[f]) ); if (solFiles[f]) $filesEl.append(fileTabTemplate(solFiles[f]));
} }
var active = fileTabFromName(SOL_CACHE_FILE); var active = fileTabFromName(SOL_CACHE_FILE);
active.addClass('active') active.addClass('active');
editor.setValue( window.localStorage.getItem( SOL_CACHE_FILE ) || '', -1 ); editor.setValue(window.localStorage.getItem(SOL_CACHE_FILE) || '', -1);
$('#input').toggle( typeof SOL_CACHE_FILE === 'string' ) $('#input').toggle(typeof SOL_CACHE_FILE === 'string');
} }
function fileTabTemplate(name){ function fileTabTemplate(name) {
return $('<span class="file"><span class="name">'+name+'</span><span class="remove">x</span></span>'); return $('<span class="file"><span class="name">'+name+'</span><span class="remove">x</span></span>');
} }
SOL_CACHE_FILE = solFiles[0] SOL_CACHE_FILE = solFiles[0];
updateFiles(); updateFiles();
// ----------------- version selector------------- // ----------------- version selector-------------
...@@ -246,7 +246,7 @@ THE SOFTWARE. ...@@ -246,7 +246,7 @@ THE SOFTWARE.
}).prependTo('body'); }).prependTo('body');
$(document).mousemove(function(e){ $(document).mousemove(function(e){
ghostbar.css("left",e.pageX+2); ghostbar.css("left",e.pageX+2);
}); });
}); });
...@@ -258,20 +258,20 @@ THE SOFTWARE. ...@@ -258,20 +258,20 @@ THE SOFTWARE.
onResize(); onResize();
} }
$(document).mouseup(function(e){ $(document).mouseup(function(e){
if (dragging) { if (dragging) {
var delta = $body.width() - e.pageX+2; var delta = $body.width() - e.pageX+2;
$('#ghostbar').remove(); $('#ghostbar').remove();
$(document).unbind('mousemove'); $(document).unbind('mousemove');
dragging = false; dragging = false;
setEditorSize( delta ) setEditorSize(delta)
window.localStorage.setItem( EDITOR_SIZE_CACHE_KEY, delta ); window.localStorage.setItem(EDITOR_SIZE_CACHE_KEY, delta);
} }
}); });
// set cached defaults // set cached defaults
var cachedSize = window.localStorage.getItem( EDITOR_SIZE_CACHE_KEY ); var cachedSize = window.localStorage.getItem(EDITOR_SIZE_CACHE_KEY);
if (cachedSize) setEditorSize( cachedSize ); if (cachedSize) setEditorSize(cachedSize);
// ----------------- editor resize --------------- // ----------------- editor resize ---------------
...@@ -291,7 +291,7 @@ THE SOFTWARE. ...@@ -291,7 +291,7 @@ THE SOFTWARE.
window.onresize = onResize; window.onresize = onResize;
onResize(); onResize();
document.querySelector('#editor').addEventListener('change', onResize ); document.querySelector('#editor').addEventListener('change', onResize);
// ----------------- compiler ---------------------- // ----------------- compiler ----------------------
...@@ -306,9 +306,9 @@ THE SOFTWARE. ...@@ -306,9 +306,9 @@ THE SOFTWARE.
editor.getSession().removeMarker(errMarkerId); editor.getSession().removeMarker(errMarkerId);
$('#output').empty(); $('#output').empty();
var input = editor.getValue(); var input = editor.getValue();
window.localStorage.setItem( SOL_CACHE_FILE, input ); window.localStorage.setItem(SOL_CACHE_FILE, input);
var inputIncludingImports = includeLocalImports( input ); var inputIncludingImports = includeLocalImports(input);
var optimize = document.querySelector('#optimize').checked; var optimize = document.querySelector('#optimize').checked;
try { try {
...@@ -332,7 +332,7 @@ THE SOFTWARE. ...@@ -332,7 +332,7 @@ THE SOFTWARE.
var onChange = function() { var onChange = function() {
var input = editor.getValue(); var input = editor.getValue();
if (input === "") { if (input === "") {
window.localStorage.setItem( SOL_CACHE_FILE, '' ) window.localStorage.setItem(SOL_CACHE_FILE, '')
return; return;
} }
if (input === previousInput) if (input === previousInput)
...@@ -349,20 +349,20 @@ THE SOFTWARE. ...@@ -349,20 +349,20 @@ THE SOFTWARE.
onChange(); onChange();
}; };
function includeLocalImports( input ) { function includeLocalImports(input) {
var importRegex = /import\s[\'\"]([^\'\"]+)[\'\"];/g var importRegex = /import\s[\'\"]([^\'\"]+)[\'\"];/g
var imports = []; var imports = [];
var matches = []; var matches = [];
var match; var match;
while ((match = importRegex.exec(input)) !== null) { while ((match = importRegex.exec(input)) !== null) {
if (match[1] && solFiles.indexOf(match[1]) !== -1) { if (match[1] && solFiles.indexOf(match[1]) !== -1) {
imports.push( match[1] ) imports.push(match[1])
matches.push( match[0] ) matches.push(match[0])
} }
} }
for (var i in imports) { for (var i in imports) {
imported = includeLocalImports( window.localStorage.getItem( imports[i] ) ) imported = includeLocalImports(window.localStorage.getItem(imports[i]))
input = input.replace( matches[i], imported ); input = input.replace(matches[i], imported);
} }
return input; return input;
} }
...@@ -382,8 +382,8 @@ THE SOFTWARE. ...@@ -382,8 +382,8 @@ THE SOFTWARE.
.append($('<pre class="error"></pre>').text(message)); .append($('<pre class="error"></pre>').text(message));
var err = message.match(/^:([0-9]*):([0-9]*)/) var err = message.match(/^:([0-9]*):([0-9]*)/)
if (err && err.length) { if (err && err.length) {
var errLine = parseInt( err[1], 10 ) - 1; var errLine = parseInt(err[1], 10) - 1;
var errCol = err[2] ? parseInt( err[2], 10 ) : 0; var errCol = err[2] ? parseInt(err[2], 10) : 0;
sourceAnnotations[sourceAnnotations.length] ={ sourceAnnotations[sourceAnnotations.length] ={
row: errLine, row: errLine,
column: errCol, column: errCol,
...@@ -399,14 +399,14 @@ THE SOFTWARE. ...@@ -399,14 +399,14 @@ THE SOFTWARE.
var funABI = getConstructorInterface($.parseJSON(interface)); var funABI = getConstructorInterface($.parseJSON(interface));
$.each(funABI.inputs, function(i, inp) { $.each(funABI.inputs, function(i, inp) {
code += "var "+inp.name+" = /* var of type " + inp.type + " here */ ;\n"; code += "var " + inp.name + " = /* var of type " + inp.type + " here */ ;\n";
}); });
code += "\nvar "+contractName+"Contract = web3.eth.contract("+interface.replace("\n","")+");" code += "\nvar " + contractName + "Contract = web3.eth.contract(" + interface.replace("\n","") + ");"
+"\nvar "+contractName+" = "+contractName+"Contract.new("; +"\nvar " + contractName + " = " + contractName + "Contract.new(";
$.each(funABI.inputs, function(i, inp) { $.each(funABI.inputs, function(i, inp) {
code += "\n "+inp.name+","; code += "\n " + inp.name + ",";
}); });
code += "\n {"+ code += "\n {"+
...@@ -425,7 +425,7 @@ THE SOFTWARE. ...@@ -425,7 +425,7 @@ THE SOFTWARE.
}; };
var combined = function(contractName, interface, bytecode){ var combined = function(contractName, interface, bytecode){
return JSON.stringify( [{name: contractName, interface: interface, bytecode: bytecode}]); return JSON.stringify([{name: contractName, interface: interface, bytecode: bytecode}]);
}; };
...@@ -437,7 +437,7 @@ THE SOFTWARE. ...@@ -437,7 +437,7 @@ THE SOFTWARE.
var contractOutput = $('<div class="contractOutput"/>') var contractOutput = $('<div class="contractOutput"/>')
.append(title); .append(title);
var body = $('<div class="body" />') var body = $('<div class="body" />')
contractOutput.append( body ); contractOutput.append(body);
if (contract.bytecode.length > 0) if (contract.bytecode.length > 0)
title.append($('<div class="size"/>').text((contract.bytecode.length / 2) + ' bytes')) title.append($('<div class="size"/>').text((contract.bytecode.length / 2) + ' bytes'))
body.append(getExecuteInterface(contract, contractName)) body.append(getExecuteInterface(contract, contractName))
...@@ -451,7 +451,7 @@ THE SOFTWARE. ...@@ -451,7 +451,7 @@ THE SOFTWARE.
title.click(function(ev){ $(this).parent().toggleClass('hide') }); title.click(function(ev){ $(this).parent().toggleClass('hide') });
} }
$('.col2 input,textarea').click(function() { this.select(); } ); $('.col2 input,textarea').click(function() { this.select(); });
}; };
var tableRowItems = function(first, second, cls) { var tableRowItems = function(first, second, cls) {
return $('<div class="row"/>') return $('<div class="row"/>')
...@@ -532,7 +532,7 @@ THE SOFTWARE. ...@@ -532,7 +532,7 @@ THE SOFTWARE.
return text; return text;
}; };
$('.asmOutput button').click(function() {$(this).parent().find('pre').toggle(); } ) $('.asmOutput button').click(function() {$(this).parent().find('pre').toggle(); })
// ----------------- VM ---------------------- // ----------------- VM ----------------------
...@@ -621,7 +621,7 @@ THE SOFTWARE. ...@@ -621,7 +621,7 @@ THE SOFTWARE.
var appendFunctions = function(address) { var appendFunctions = function(address) {
var instance = $('<div class="contractInstance"/>'); var instance = $('<div class="contractInstance"/>');
var title = $('<span class="title"/>').text('Contract at ' + address.toString('hex') ); var title = $('<span class="title"/>').text('Contract at ' + address.toString('hex'));
instance.append(title); instance.append(title);
$.each(abi, function(i, funABI) { $.each(abi, function(i, funABI) {
if (funABI.type != 'function') return; if (funABI.type != 'function') return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment