Skip to content

Instantly share code, notes, and snippets.

@jviereck
Created March 30, 2010 10:58
Show Gist options
  • Select an option

  • Save jviereck/349005 to your computer and use it in GitHub Desktop.

Select an option

Save jviereck/349005 to your computer and use it in GitHub Desktop.
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Bespin.
-
- The Initial Developer of the Original Code is
- Mozilla.
- Portions created by the Initial Developer are Copyright (C) 2009
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<!DOCTYPE html>
<html>
<head>
<title>Titanium Bespin</title>
<link rel="stylesheet" type="text/css" href="BespinEmbedded.css">
<script type="text/javascript" src="BespinEmbedded.js"></script>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<style type="text/css">
#editor {
position: relative;
}
#menu {
position: absolute;
width: 56px;
right: 40px;
top: 8px;
border: 1px solid black;
-webkit-border-bottom-left-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
background-color: #444444;
opacity: 0.6;
}
</style>
<script type="text/javascript">
var bespin;
var currentFile = null;
function setupIcon(elm, iconName, clickFunc) {
$(elm).click(clickFunc).hover(function() {
$(this).attr('src', 'icon/' + iconName +'_on.png');
}, function() {
$(this).attr('src', 'icon/' + iconName + '.png')
});
}
function resizeWindow() {
$('#editor').height($(window).height() - 18);
}
window.onBespinLoad = function() {
bespin = $('#editor').get(0).bespin;
setupIcon('#buLoadFile', 'open', function() {
Titanium.UI.openFileChooserDialog(function(file) {
if (file[0]) {
currentFile = file[0];
var fs = Titanium.Filesystem.getFileStream(file[0]);
fs.open(fs.MODE_OPEN);
bespin.set('value', fs.read().toString());
var filename = file[0].split("/");
Titanium.UI.getWindows()[0].setTitle("Titanium Bespin - " + filename[filename.length - 1])
}
});
});
setupIcon('#buSaveFile', 'save', function() {
var fs = Titanium.Filesystem.getFileStream(currentFile);
fs.open(fs.MODE_WRITE);
fs.write(bespin.get('value'));
fs.close();
});
setTimeout(resizeWindow, 50);
$(window).resize(resizeWindow);
}
</script>
</head>
<body>
<div id="editor" class="bespin" data-bespinoptions='{ "stealFocus": true, "syntax": "html", "tabstop": 4 }'><h1>Titanium Bespin</h1>
</div>
<div id="menu">
<img id="buLoadFile" src="icon/open.png">
<img id="buSaveFile" src="icon/save.png">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment