add iPad demo
This commit is contained in:
parent
b0e6c5941c
commit
291306f699
4 changed files with 259 additions and 1 deletions
70
demo/ipad.js
Normal file
70
demo/ipad.js
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/* ***** 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 Mozilla Skywriter.
|
||||
*
|
||||
* 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):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var Dom = require("pilot/dom");
|
||||
var Event = require("pilot/event");
|
||||
|
||||
var Editor = require("ace/editor").Editor;
|
||||
var EditSession = require("ace/edit_session").EditSession;
|
||||
var UndoManager = require("ace/undomanager").UndoManager;
|
||||
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
|
||||
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||
|
||||
exports.launch = function(el, text) {
|
||||
if (typeof(el) == "string") {
|
||||
el = document.getElementById(el);
|
||||
}
|
||||
|
||||
var editor = new Editor(new Renderer(el, "ace/theme/twilight"));
|
||||
|
||||
var doc = new EditSession(text);
|
||||
doc.setMode(new JavaScriptMode());
|
||||
doc.setUndoManager(new UndoManager());
|
||||
editor.setSession(doc);
|
||||
|
||||
editor.resize();
|
||||
Event.addListener(window, "resize", function() {
|
||||
editor.resize();
|
||||
});
|
||||
|
||||
return editor;
|
||||
};
|
||||
|
||||
});
|
||||
64
ipad.html
Normal file
64
ipad.html
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="viewport" content="user-scalable=no, width=device-width">
|
||||
<meta name="author" content="Fabian Jakobs">
|
||||
|
||||
<title>Ace on iPad</title>
|
||||
|
||||
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
||||
|
||||
<style type="text/css" media="screen">
|
||||
body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#editor {
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
font-family: 'Droid Sans Mono';
|
||||
font-size: 14px;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="editor">
|
||||
</div>
|
||||
|
||||
</script>
|
||||
|
||||
<script src="demo/require.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script>
|
||||
|
||||
require({
|
||||
paths: {
|
||||
demo: "../demo",
|
||||
ace: "../lib/ace",
|
||||
pilot: "../support/pilot/lib/pilot"
|
||||
}
|
||||
});
|
||||
|
||||
require(["demo/ipad"], function(demo) {
|
||||
var text = 'function foo(items) {\n\
|
||||
for (var i=0; i<items.length; i++) {\n\
|
||||
alert(items[i] + "juhu");\n\
|
||||
}\n\
|
||||
}';
|
||||
for (var i=0; i<500; i++)
|
||||
text += "\njuhu " + i;
|
||||
|
||||
demo.launch("editor", text);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
124
lib/ace/touch_handler.js
Normal file
124
lib/ace/touch_handler.js
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/* ***** 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 Ajax.org Code Editor (ACE).
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ajax.org B.V.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
define(function(require, exports, module) {
|
||||
|
||||
var event = require("pilot/event");
|
||||
|
||||
var TouchHandler = function(editor) {
|
||||
this.editor = editor;
|
||||
event.addListener(editor.container, "click", function(e) {
|
||||
// does this only work on click?
|
||||
editor.focus();
|
||||
});
|
||||
var mouseTarget = editor.renderer.getMouseEventTarget();
|
||||
mouseTarget.ontouchstart = this.onTouchStart.bind(this);
|
||||
mouseTarget.ontouchmove = this.onTouchMove.bind(this);
|
||||
mouseTarget.ontouchend = this.onTouchEnd.bind(this);
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
||||
this.$scrollSpeed = 1;
|
||||
this.setScrollSpeed = function(speed) {
|
||||
this.$scrollSpeed = speed;
|
||||
};
|
||||
|
||||
this.getScrollSpeed = function() {
|
||||
return this.$scrollSpeed;
|
||||
};
|
||||
|
||||
this.onTouchMove = function(e) {
|
||||
e.preventDefault();
|
||||
if (e.touches.length == 1) {
|
||||
this.$moveCursor(e.touches[0]);
|
||||
}
|
||||
else if (e.touches.length == 2) {
|
||||
if (!this.$scroll)
|
||||
return;
|
||||
|
||||
var touch = e.touches[0];
|
||||
var diffX = this.$scroll.pageX - touch.pageX;
|
||||
var diffY = this.$scroll.pageY - touch.pageY;
|
||||
this.editor.renderer.scrollBy(diffX, diffY);
|
||||
|
||||
this.$scroll = {
|
||||
pageX: touch.pageX,
|
||||
pageY: touch.pageY,
|
||||
ts: new Date().getTime()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.$moveCursor = function(touch) {
|
||||
var pageX = touch.pageX;
|
||||
var pageY = touch.pageY;
|
||||
|
||||
var editor = this.editor;
|
||||
var pos = editor.renderer.screenToTextCoordinates(pageX, pageY);
|
||||
pos.row = Math.max(0, Math.min(pos.row, editor.session.getLength()-1));
|
||||
|
||||
editor.moveCursorToPosition(pos);
|
||||
editor.renderer.scrollCursorIntoView();
|
||||
};
|
||||
|
||||
this.onTouchEnd = function(e) {
|
||||
//if (e.touches.length == 1) {
|
||||
console.log("focus")
|
||||
editor.focus();
|
||||
//e.preventDefault();
|
||||
//}
|
||||
};
|
||||
|
||||
this.onTouchStart = function(e) {
|
||||
if (e.touches.length == 1) {
|
||||
this.$moveCursor(e.touches[0]);
|
||||
}
|
||||
else if (e.touches.length == 2) {
|
||||
e.preventDefault();
|
||||
var touch = e.touches[0];
|
||||
this.$scroll = {
|
||||
pageX: touch.pageX,
|
||||
pageY: touch.pageY
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}).call(TouchHandler.prototype);
|
||||
|
||||
exports.TouchHandler = TouchHandler;
|
||||
});
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 9e4505f43d57a27a60cd05c6f0d68d5ea31c8e33
|
||||
Subproject commit 67a380309e5b139a9603334ad9d9f917659f04bc
|
||||
Loading…
Add table
Add a link
Reference in a new issue