Commit 3a7bc52e authored by Alex Beregszaszi's avatar Alex Beregszaszi

Standard: add spacing as required

parent 4fb1947c
chrome.browserAction.onClicked.addListener(function(tab) { chrome.browserAction.onClicked.addListener(function (tab) {
chrome.storage.sync.set({'chrome-app-sync': true}); chrome.storage.sync.set({ 'chrome-app-sync' : true });
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) { chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) {
// tab opened // tab opened
}); });
......
This diff is collapsed.
...@@ -4,7 +4,7 @@ var Renderer = require('./renderer'); ...@@ -4,7 +4,7 @@ var Renderer = require('./renderer');
var Base64 = require('js-base64').Base64; var Base64 = require('js-base64').Base64;
function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) { function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles) {
var renderer = new Renderer(editor, this, updateFiles); var renderer = new Renderer(editor, this, updateFiles);
var compileJSON; var compileJSON;
...@@ -18,7 +18,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -18,7 +18,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
var compileTimeout = null; var compileTimeout = null;
function onChange() { function onChange () {
var input = editor.getValue(); var input = editor.getValue();
if (input === '') { if (input === '') {
editor.setCacheFileContent(''); editor.setCacheFileContent('');
...@@ -33,7 +33,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -33,7 +33,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
editor.onChangeSetup(onChange); editor.onChangeSetup(onChange);
var compile = function(missingInputs) { var compile = function (missingInputs) {
editor.clearAnnotations(); editor.clearAnnotations();
sourceAnnotations = []; sourceAnnotations = [];
outputField.empty(); outputField.empty();
...@@ -42,7 +42,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -42,7 +42,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
var files = {}; var files = {};
files[editor.getCacheFile()] = input; files[editor.getCacheFile()] = input;
gatherImports(files, missingInputs, function(input, error) { gatherImports(files, missingInputs, function (input, error) {
outputField.empty(); outputField.empty();
if (input === null) { if (input === null) {
renderer.error(error); renderer.error(error);
...@@ -54,41 +54,41 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -54,41 +54,41 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
}; };
this.compile = compile; this.compile = compile;
this.addAnnotation = function(annotation) { this.addAnnotation = function (annotation) {
sourceAnnotations[sourceAnnotations.length] = annotation; sourceAnnotations[sourceAnnotations.length] = annotation;
editor.setAnnotations(sourceAnnotations); editor.setAnnotations(sourceAnnotations);
}; };
this.setCompileJSON = function() { this.setCompileJSON = function () {
compileJSON = function(source, optimize) { compilationFinished('{}'); }; compileJSON = function (source, optimize) { compilationFinished('{}'); };
}; };
function onCompilerLoaded(setVersionText) { function onCompilerLoaded (setVersionText) {
if (worker === null) { if (worker === null) {
var compile; var compile;
var missingInputs = []; var missingInputs = [];
if ('_compileJSONCallback' in Module) { if ('_compileJSONCallback' in Module) {
compilerAcceptsMultipleFiles = true; compilerAcceptsMultipleFiles = true;
var missingInputsCallback = Module.Runtime.addFunction(function(path, contents, error) { var missingInputsCallback = Module.Runtime.addFunction(function (path, contents, error) {
missingInputs.push(Module.Pointer_stringify(path)); missingInputs.push(Module.Pointer_stringify(path));
}); });
var compileInternal = Module.cwrap('compileJSONCallback', 'string', ['string', 'number', 'number']); var compileInternal = Module.cwrap('compileJSONCallback', 'string', [ 'string', 'number', 'number' ]);
compile = function(input, optimize) { compile = function (input, optimize) {
missingInputs.length = 0; missingInputs.length = 0;
return compileInternal(input, optimize, missingInputsCallback); return compileInternal(input, optimize, missingInputsCallback);
}; };
} else if ('_compileJSONMulti' in Module) { } else if ('_compileJSONMulti' in Module) {
compilerAcceptsMultipleFiles = true; compilerAcceptsMultipleFiles = true;
compile = Module.cwrap('compileJSONMulti', 'string', ['string', 'number']); compile = Module.cwrap('compileJSONMulti', 'string', [ 'string', 'number' ]);
} else { } else {
compilerAcceptsMultipleFiles = false; compilerAcceptsMultipleFiles = false;
compile = Module.cwrap('compileJSON', 'string', ['string', 'number']); compile = Module.cwrap('compileJSON', 'string', [ 'string', 'number' ]);
} }
compileJSON = function(source, optimize, cb) { compileJSON = function (source, optimize, cb) {
try { try {
var result = compile(source, optimize); var result = compile(source, optimize);
} catch (exception) { } catch (exception) {
result = JSON.stringify({error: 'Uncaught JavaScript exception:\n' + exception}); result = JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception });
} }
compilationFinished(result, missingInputs); compilationFinished(result, missingInputs);
}; };
...@@ -99,7 +99,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -99,7 +99,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
}; };
this.onCompilerLoaded = onCompilerLoaded; this.onCompilerLoaded = onCompilerLoaded;
function compilationFinished(result, missingInputs) { function compilationFinished (result, missingInputs) {
var data; var data;
var noFatalErrors = true; // ie warnings are ok var noFatalErrors = true; // ie warnings are ok
...@@ -115,7 +115,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -115,7 +115,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
if (utils.errortype(data['error']) !== 'warning') noFatalErrors = false; if (utils.errortype(data['error']) !== 'warning') noFatalErrors = false;
} }
if (data['errors'] !== undefined) { if (data['errors'] !== undefined) {
data['errors'].forEach(function(err) { data['errors'].forEach(function (err) {
renderer.error(err); renderer.error(err);
if (utils.errortype(err) !== 'warning') noFatalErrors = false; if (utils.errortype(err) !== 'warning') noFatalErrors = false;
}); });
...@@ -127,11 +127,11 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -127,11 +127,11 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
renderer.contracts(data, editor.getValue()); renderer.contracts(data, editor.getValue());
} }
this.initializeWorker = function(version, setVersionText) { this.initializeWorker = function (version, setVersionText) {
if (worker !== null) if (worker !== null)
worker.terminate(); worker.terminate();
worker = new Worker('worker.js'); worker = new Worker('worker.js');
worker.addEventListener('message', function(msg) { worker.addEventListener('message', function (msg) {
var data = msg.data; var data = msg.data;
switch (data.cmd) { switch (data.cmd) {
case 'versionLoaded': case 'versionLoaded':
...@@ -144,15 +144,15 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -144,15 +144,15 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
break; break;
}; };
}); });
worker.onerror = function(msg) { console.log(msg.data); }; worker.onerror = function (msg) { console.log(msg.data); };
worker.addEventListener('error', function(msg) { console.log(msg.data); }); worker.addEventListener('error', function (msg) { console.log(msg.data); });
compileJSON = function(source, optimize) { compileJSON = function (source, optimize) {
worker.postMessage({cmd: 'compile', source: source, optimize: optimize}); worker.postMessage({cmd: 'compile', source: source, optimize: optimize});
}; };
worker.postMessage({cmd: 'loadVersion', data: 'https://ethereum.github.io/solc-bin/bin/' + version}); worker.postMessage({cmd: 'loadVersion', data: 'https://ethereum.github.io/solc-bin/bin/' + version});
}; };
function gatherImports(files, importHints, cb) { function gatherImports (files, importHints, cb) {
importHints = importHints || []; importHints = importHints || [];
if (!compilerAcceptsMultipleFiles) if (!compilerAcceptsMultipleFiles)
{ {
...@@ -182,7 +182,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -182,7 +182,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
files[m] = cachedRemoteFiles[m]; files[m] = cachedRemoteFiles[m];
reloop = true; reloop = true;
} else if (githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m)) { } else if (githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m)) {
handleGithubCall(githubMatch[3], githubMatch[4], function(result) { handleGithubCall(githubMatch[3], githubMatch[4], function (result) {
if ('content' in result) if ('content' in result)
{ {
var content = Base64.decode(result.content); var content = Base64.decode(result.content);
...@@ -192,7 +192,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -192,7 +192,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
} }
else else
cb(null, 'Unable to import "' + m + '"'); cb(null, 'Unable to import "' + m + '"');
}).fail(function(){ }).fail(function () {
cb(null, 'Unable to import "' + m + '"'); cb(null, 'Unable to import "' + m + '"');
}); });
return; return;
...@@ -202,7 +202,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) ...@@ -202,7 +202,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
} }
} }
} while (reloop); } while (reloop);
cb(JSON.stringify({'sources':files})); cb(JSON.stringify({ 'sources': files }));
} }
} }
......
...@@ -3,9 +3,9 @@ var utils = require('./utils'); ...@@ -3,9 +3,9 @@ var utils = require('./utils');
var ace = require('brace'); var ace = require('brace');
require('../mode-solidity.js'); require('../mode-solidity.js');
function Editor(loadingFromGist) { function Editor (loadingFromGist) {
this.newFile = function() { this.newFile = function () {
untitledCount = ''; untitledCount = '';
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount]) while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount])
untitledCount = (untitledCount - 0) + 1; untitledCount = (untitledCount - 0) + 1;
...@@ -14,40 +14,40 @@ function Editor(loadingFromGist) { ...@@ -14,40 +14,40 @@ function Editor(loadingFromGist) {
this.setCacheFileContent(''); this.setCacheFileContent('');
}; };
this.setCacheFileContent = function(content) { this.setCacheFileContent = function (content) {
window.localStorage.setItem(SOL_CACHE_FILE, content); window.localStorage.setItem(SOL_CACHE_FILE, content);
}; };
this.setCacheFile = function(cacheFile) { this.setCacheFile = function (cacheFile) {
SOL_CACHE_FILE = utils.fileKey(cacheFile); SOL_CACHE_FILE = utils.fileKey(cacheFile);
}; };
this.getCacheFile = function() { this.getCacheFile = function () {
return utils.fileNameFromKey(SOL_CACHE_FILE); return utils.fileNameFromKey(SOL_CACHE_FILE);
}; };
this.cacheFileIsPresent = function() { this.cacheFileIsPresent = function () {
return !!SOL_CACHE_FILE; return !!SOL_CACHE_FILE;
}; };
this.setNextFile = function(fileKey) { this.setNextFile = function (fileKey) {
var index = this.getFiles().indexOf( fileKey ); var index = this.getFiles().indexOf(fileKey);
this.setCacheFile(this.getFiles()[ Math.max(0, index - 1)]); this.setCacheFile(this.getFiles()[ Math.max(0, index - 1) ]);
}; };
this.resetSession = function() { this.resetSession = function () {
editor.setSession( sessions[SOL_CACHE_FILE] ); editor.setSession(sessions[SOL_CACHE_FILE]);
editor.focus(); editor.focus();
}; };
this.hasFile = function(name) { this.hasFile = function (name) {
return this.getFiles().indexOf(utils.fileKey(name)) !== -1 return this.getFiles().indexOf(utils.fileKey(name)) !== -1
}; };
this.getFiles = function() { this.getFiles = function () {
var files = []; var files = [];
for (var f in localStorage ) { for (var f in localStorage) {
if (f.indexOf( utils.getCacheFilePrefix(), 0 ) === 0) { if (f.indexOf(utils.getCacheFilePrefix(), 0) === 0) {
files.push(f); files.push(f);
if (!sessions[f]) sessions[f] = newEditorSession(f); if (!sessions[f]) sessions[f] = newEditorSession(f);
} }
...@@ -55,7 +55,7 @@ function Editor(loadingFromGist) { ...@@ -55,7 +55,7 @@ function Editor(loadingFromGist) {
return files; return files;
} }
this.packageFiles = function() { this.packageFiles = function () {
var files = {}; var files = {};
var filesArr = this.getFiles(); var filesArr = this.getFiles();
...@@ -67,46 +67,46 @@ function Editor(loadingFromGist) { ...@@ -67,46 +67,46 @@ function Editor(loadingFromGist) {
return files; return files;
}; };
this.resize = function() { this.resize = function () {
editor.resize(); editor.resize();
var session = editor.getSession(); var session = editor.getSession();
session.setUseWrapMode(document.querySelector('#editorWrap').checked); session.setUseWrapMode(document.querySelector('#editorWrap').checked);
if(session.getUseWrapMode()) { if (session.getUseWrapMode()) {
var characterWidth = editor.renderer.characterWidth; var characterWidth = editor.renderer.characterWidth;
var contentWidth = editor.container.ownerDocument.getElementsByClassName('ace_scroller')[0].clientWidth; var contentWidth = editor.container.ownerDocument.getElementsByClassName('ace_scroller')[0].clientWidth;
if(contentWidth > 0) { if (contentWidth > 0) {
session.setWrapLimit(parseInt(contentWidth / characterWidth, 10)); session.setWrapLimit(parseInt(contentWidth / characterWidth, 10));
} }
} }
}; };
this.getValue = function() { this.getValue = function () {
return editor.getValue(); return editor.getValue();
}; };
this.clearAnnotations = function() { this.clearAnnotations = function () {
editor.getSession().clearAnnotations(); editor.getSession().clearAnnotations();
}; };
this.setAnnotations = function(sourceAnnotations) { this.setAnnotations = function (sourceAnnotations) {
editor.getSession().setAnnotations(sourceAnnotations); editor.getSession().setAnnotations(sourceAnnotations);
}; };
this.onChangeSetup = function(onChange) { this.onChangeSetup = function (onChange) {
editor.getSession().on('change', onChange); editor.getSession().on('change', onChange);
editor.on('changeSession', function(){ editor.on('changeSession', function () {
editor.getSession().on('change', onChange); editor.getSession().on('change', onChange);
onChange(); onChange();
}) })
}; };
this.handleErrorClick = function(errLine, errCol) { this.handleErrorClick = function (errLine, errCol) {
editor.focus(); editor.focus();
editor.gotoLine(errLine + 1, errCol - 1, true); editor.gotoLine(errLine + 1, errCol - 1, true);
}; };
function newEditorSession(filekey) { function newEditorSession (filekey) {
var s = new ace.EditSession(window.localStorage[filekey], 'ace/mode/javascript') var s = new ace.EditSession(window.localStorage[filekey], 'ace/mode/javascript')
s.setUndoManager(new ace.UndoManager()); s.setUndoManager(new ace.UndoManager());
s.setTabSize(4); s.setTabSize(4);
...@@ -115,10 +115,10 @@ function Editor(loadingFromGist) { ...@@ -115,10 +115,10 @@ function Editor(loadingFromGist) {
return s; return s;
} }
function setupStuff(files) { function setupStuff (files) {
var untitledCount = ''; var untitledCount = '';
if (!files.length || window.localStorage['sol-cache']) { if (!files.length || window.localStorage['sol-cache']) {
if(loadingFromGist) return; if (loadingFromGist) return;
// Backwards-compatibility // Backwards-compatibility
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount]) while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount])
untitledCount = (untitledCount - 0) + 1; untitledCount = (untitledCount - 0) + 1;
...@@ -133,7 +133,7 @@ function Editor(loadingFromGist) { ...@@ -133,7 +133,7 @@ function Editor(loadingFromGist) {
sessions[files[x]] = newEditorSession(files[x]) sessions[files[x]] = newEditorSession(files[x])
} }
editor.setSession( sessions[SOL_CACHE_FILE] ); editor.setSession(sessions[SOL_CACHE_FILE]);
editor.resize(true); editor.resize(true);
} }
......
var queryParams = require('./query-params'); var queryParams = require('./query-params');
function handleLoad(cb) { function handleLoad (cb) {
var params = queryParams.get(); var params = queryParams.get();
var loadingFromGist = false; var loadingFromGist = false;
if (typeof params['gist'] !== undefined) { if (typeof params['gist'] !== undefined) {
...@@ -8,7 +8,7 @@ function handleLoad(cb) { ...@@ -8,7 +8,7 @@ function handleLoad(cb) {
if (params['gist'] === '') { if (params['gist'] === '') {
var str = prompt('Enter the URL or ID of the Gist you would like to load.'); var str = prompt('Enter the URL or ID of the Gist you would like to load.');
if (str !== '') { if (str !== '') {
gistId = getGistId( str ); gistId = getGistId(str);
loadingFromGist = !!gistId; loadingFromGist = !!gistId;
} }
} else { } else {
...@@ -20,7 +20,7 @@ function handleLoad(cb) { ...@@ -20,7 +20,7 @@ function handleLoad(cb) {
return loadingFromGist; return loadingFromGist;
} }
function getGistId(str) { function getGistId (str) {
var idr = /[0-9A-Fa-f]{8,}/; var idr = /[0-9A-Fa-f]{8,}/;
var match = idr.exec(str); var match = idr.exec(str);
return match ? match[0] : null; return match ? match[0] : null;
......
function getQueryParams() { function getQueryParams () {
var qs = window.location.hash.substr(1); var qs = window.location.hash.substr(1);
if (window.location.search.length > 0) { if (window.location.search.length > 0) {
...@@ -16,7 +16,7 @@ function getQueryParams() { ...@@ -16,7 +16,7 @@ function getQueryParams() {
return params; return params;
} }
function updateQueryParams(params) { function updateQueryParams (params) {
var currentParams = getQueryParams(); var currentParams = getQueryParams();
var keys = Object.keys(params); var keys = Object.keys(params);
for (var x in keys) { for (var x in keys) {
...@@ -24,7 +24,7 @@ function updateQueryParams(params) { ...@@ -24,7 +24,7 @@ function updateQueryParams(params) {
} }
var queryString = '#'; var queryString = '#';
var updatedKeys = Object.keys(currentParams); var updatedKeys = Object.keys(currentParams);
for( var y in updatedKeys) { for (var y in updatedKeys) {
queryString += updatedKeys[y] + '=' + currentParams[updatedKeys[y]] + '&'; queryString += updatedKeys[y] + '=' + currentParams[updatedKeys[y]] + '&';
} }
window.location.hash = queryString.slice(0, -1); window.location.hash = queryString.slice(0, -1);
......
This diff is collapsed.
var utils = require('./utils'); var utils = require('./utils');
function StorageHandler(updateFiles) { function StorageHandler (updateFiles) {
this.sync = function() { this.sync = function () {
if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) return; if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) return;
...@@ -11,20 +11,20 @@ function StorageHandler(updateFiles) { ...@@ -11,20 +11,20 @@ function StorageHandler(updateFiles) {
var count = 0 var count = 0
var dont = 0; var dont = 0;
function check(key){ function check (key) {
chrome.storage.sync.get( key, function(resp){ chrome.storage.sync.get(key, function (resp) {
console.log('comparing to cloud', key, 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.')) { 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 ); console.log('Overwriting', key);
localStorage.setItem( key, resp[key] ); localStorage.setItem(key, resp[key]);
updateFiles(); updateFiles();
} else { } else {
console.log( 'add to obj', obj, key); console.log('add to obj', obj, key);
obj[key] = localStorage[key]; obj[key] = localStorage[key];
} }
done++; done++;
if (done >= count) chrome.storage.sync.set( obj, function(){ if (done >= count) chrome.storage.sync.set(obj, function () {
console.log( 'updated cloud files with: ', obj, this, arguments); console.log('updated cloud files with: ', obj, this, arguments);
}) })
}) })
} }
......
var SOL_CACHE_FILE_PREFIX = 'sol-cache-file-'; var SOL_CACHE_FILE_PREFIX = 'sol-cache-file-';
function getCacheFilePrefix() { function getCacheFilePrefix () {
return SOL_CACHE_FILE_PREFIX; return SOL_CACHE_FILE_PREFIX;
} }
function fileKey( name ) { function fileKey (name) {
return getCacheFilePrefix() + name; return getCacheFilePrefix() + name;
} }
function fileNameFromKey(key) { function fileNameFromKey (key) {
return key.replace( getCacheFilePrefix(), '' ); return key.replace(getCacheFilePrefix(), '');
} }
function errortype(message) { function errortype (message) {
return message.match(/^.*:[0-9]*:[0-9]* Warning: /) ? 'warning' : 'error'; return message.match(/^.*:[0-9]*:[0-9]* Warning: /) ? 'warning' : 'error';
} }
......
...@@ -2,4 +2,4 @@ require('es6-shim'); ...@@ -2,4 +2,4 @@ require('es6-shim');
var app = require('./app.js'); var app = require('./app.js');
var $ = require('jquery'); var $ = require('jquery');
$(document).ready(function() { app.run(); }); $(document).ready(function () { app.run(); });
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
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