allow publishing gists and toggle rhp

pull/1/head
d11e9 9 years ago
parent 31ca4c4da4
commit e17ef151c2
  1. 61
      index.html
  2. 20
      stylesheets/browser-solidity.css

@ -54,6 +54,7 @@ THE SOFTWARE.
<div id="editor">
<div id="files">
<span class="newFile" title="New File">+</span>
<span class="toggleRHP" title="Toggle right hand panel"></span>
</div>
<div id="input"></div>
<div id="dragbar"></div>
@ -66,6 +67,7 @@ THE SOFTWARE.
<div class="info">
<p>Version: <span id="version">(loading)</span><br/>
Change to: <select id="versionSelector"></select><br/>
<button id="gist">Share</button>
<code>tx.origin = <span id="txorigin"/></code></p>
</div>
<div id="optimizeBox">
@ -139,6 +141,50 @@ THE SOFTWARE.
compile();
}
// ------------------ gist publish --------------
$('#gist').click(function(){
//Get Github Authorization Token with proper scope, print to console
var note = ((new Date()).toString() + Math.random().toString());
var description = "Ethereum Contracts Gist created using soleditor at: https://chriseth.github.io/browser-solidity";
$.ajax({
url: 'https://api.github.com/authorizations',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + "c29sZWRpdG9yOmRlY2VudHJhbGlzZWV2ZXJ5dGhpbmc=");
},
data: JSON.stringify({
scopes:["gist"],
note: note
})
}).done(function(response) {
//Create a Gist with token from above
var files = {};
files["00" + response.hashed_token] = { content: description + " at " + new Date() }
var filesArr = getFiles();
for(var f in filesArr) { files[fileNameFromKey(filesArr[f])] = { content: localStorage[filesArr[f]] } }
var data = JSON.stringify({
description: description,
public: true,
files: files
});
$.ajax({
url: 'https://api.github.com/gists',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "token " + response.token);
},
data: data
}).done(function(response) {
if (response.html_url && confirm("Created a gist at " + response.html_url + " Would you like to open it in a new window?")) {
window.open( response.html_url );
}
});
});
})
// ----------------- file selector-------------
@ -305,6 +351,10 @@ THE SOFTWARE.
onResize();
}
function getEditorSize(){
window.localStorage[EDITOR_SIZE_CACHE_KEY] = $('#righthand-panel').width();
}
$(document).mouseup(function(e){
if (dragging) {
var delta = $body.width() - e.pageX+2;
@ -319,6 +369,17 @@ THE SOFTWARE.
// set cached defaults
var cachedSize = window.localStorage.getItem(EDITOR_SIZE_CACHE_KEY);
if (cachedSize) setEditorSize(cachedSize);
else getEditorSize();
// ----------------- toggle right hand panel
var toggledRHP = false;
$('.toggleRHP').click(function(){
toggledRHP = !toggledRHP;
setEditorSize( toggledRHP ? 0 : window.localStorage[EDITOR_SIZE_CACHE_KEY] );
$('.toggleRHP').toggleClass('toggled', toggledRHP)
});
// ----------------- editor resize ---------------

@ -17,7 +17,7 @@ body {
height: 2.5em;
box-sizing: border-box;
line-height: 2em;
padding: 0.5em 0.5em 0;
padding: 0.5em 0 0;
}
#files .file,
@ -31,12 +31,28 @@ body {
position: relative;
}
#files .newFile {
#files .newFile,
#files .toggleRHP {
background-color: #B1EAC5;
font-weight: bold;
color: #4E775D;
}
#files .toggleRHP {
float: right;
cursor: pointer;
}
#files .toggleRHP:before {
content: ">>";
width: 2em;
padding: 0 0.6em;
box-sizing: border-box;
}
#files .toggleRHP.toggled:before {
content: "<<";
}
#files .file.active {
font-weight: bold;
border-bottom: 0 none;

Loading…
Cancel
Save