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