change-mode.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Chnage mode - Editor.md examples</title>
  6. <link rel="stylesheet" href="css/style.css" />
  7. <link rel="stylesheet" href="../css/editormd.css" />
  8. <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
  9. <style>
  10. #codes textarea {display: none;}
  11. </style>
  12. </head>
  13. <body>
  14. <div id="layout">
  15. <header>
  16. <h1>Chnage mode</h1>
  17. <p>Become to the code editor</p>
  18. <p>Modes : <select id="modes">
  19. <option value="">select modes</option>
  20. </select>&nbsp;&nbsp;Themes :
  21. <select id="themes">
  22. <option selected="selected" value="">select themes</option>
  23. </select>
  24. </p>
  25. </header>
  26. <div class="btns">
  27. <button id="get-code-btn">Get code source</button>
  28. <button id="fullscreen-btn">Fullscreen (Press F11 into, ESC exit)</button>
  29. </div>
  30. <div id="codes">
  31. <textarea id="html-code">&lt;!DOCTYPE html&gt;
  32. &lt;html lang="zh"&gt;
  33. &lt;head&gt;
  34. &lt;meta charset="utf-8" /&gt;
  35. &lt;title&gt;Chnage mode - Editor.md examples&lt;/title&gt;
  36. &lt;link rel="stylesheet" href="css/style.css" /&gt;
  37. &lt;link rel="stylesheet" href="../css/editormd.css" /&gt;
  38. &lt;link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" /&gt;
  39. &lt;/head&gt;
  40. &lt;body&gt;
  41. &lt;div id="layout"&gt;
  42. &lt;header&gt;
  43. &lt;h1&gt;Chnage mode&lt;/h1&gt;
  44. &lt;/header&gt;
  45. &lt;div id="test-editormd"&gt;
  46. &lt;textarea style="display:none;"&gt;&lt;/textarea&gt;
  47. &lt;/div&gt;
  48. &lt;/div&gt;
  49. &lt;script src="js/jquery.min.js"&gt;&lt;/script&gt;
  50. &lt;script src="../editormd.js"&gt;&lt;/script&gt;
  51. &lt;script type="text/javascript"&gt;
  52. $(function() {
  53. var testEditor = editormd("test-editormd", {
  54. width : "90%",
  55. height : 720,
  56. watch : false,
  57. toolbar : false,
  58. codeFold : true,
  59. searchReplace : true,
  60. placeholder : "Enjoy coding!",
  61. value : (localStorage.mode) ? $("#"+localStorage.mode.replace("text/", "")+"-code").val() : $("#html-code").val(),
  62. theme : (localStorage.theme) ? localStorage.theme : "default",
  63. mode : (localStorage.mode) ? localStorage.mode : "text/html",
  64. path : '../lib/'
  65. });
  66. });
  67. &lt;/script&gt;
  68. &lt;/body&gt;
  69. &lt;/html&gt;</textarea>
  70. <textarea id="javascript-code">$(function() {
  71. var testEditor = editormd("test-editormd", {
  72. width : "90%",
  73. height : 720,
  74. watch : false,
  75. toolbar : false,
  76. codeFold : true,
  77. searchReplace : true,
  78. placeholder : "Enjoy coding!",
  79. value : (localStorage.mode) ? $("#"+localStorage.mode.replace("text/", "")+"-code").val() : $("#html-code").val(),
  80. theme : (localStorage.theme) ? localStorage.theme : "default",
  81. mode : (localStorage.mode) ? localStorage.mode : "text/html",
  82. path : '../lib/'
  83. });
  84. });</textarea>
  85. <textarea id="xml-code">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  86. &lt;root&gt;
  87. &lt;photo url="https://pandao.github.io/editor.md/examples/images/7.jpg"&gt;
  88. &lt;title&gt;李健首张专辑《似水流年》封面&lt;/title&gt;
  89. &lt;width&gt;360&lt;/width&gt;
  90. &lt;height&gt;360&lt;/height&gt;
  91. &lt;/photo&gt;
  92. &lt;photo url="https://pandao.github.io/editor.md/examples/images/7.jpg"&gt;
  93. &lt;title&gt;李健首张专辑《似水流年》封面&lt;/title&gt;
  94. &lt;width&gt;360&lt;/width&gt;
  95. &lt;height&gt;360&lt;/height&gt;
  96. &lt;/photo&gt;
  97. &lt;photo url="https://pandao.github.io/editor.md/examples/images/7.jpg"&gt;
  98. &lt;title&gt;李健首张专辑《似水流年》封面&lt;/title&gt;
  99. &lt;width&gt;360&lt;/width&gt;
  100. &lt;height&gt;360&lt;/height&gt;
  101. &lt;/photo&gt;
  102. &lt;/root&gt;</textarea>
  103. <textarea id="ruby-code">#!/usr/bin/ruby
  104. puts "Hello World!";
  105. # Ruby knows what you
  106. # mean, even if you
  107. # want to do math on
  108. # an entire Array
  109. cities = %w[ London
  110. Oslo
  111. Paris
  112. Amsterdam
  113. Berlin ]
  114. visited = %w[Berlin Oslo]
  115. puts "I still need " +
  116. "to visit the " +
  117. "following cities:",
  118. cities - visited</textarea>
  119. <textarea id="json-code">{
  120. "employees": [
  121. {
  122. "firstName" : "Bill",
  123. "lastName" : "Gates"
  124. },
  125. {
  126. "firstName" : "George",
  127. "lastName" : "Bush"
  128. },
  129. {
  130. "firstName" : "Thomas",
  131. "lastName" : "Carter"
  132. }
  133. ],
  134. "employees": [
  135. {
  136. "firstName" : "Bill",
  137. "lastName" : "Gates"
  138. },
  139. {
  140. "firstName" : "George",
  141. "lastName" : "Bush"
  142. },
  143. {
  144. "firstName" : "Thomas",
  145. "lastName" : "Carter"
  146. }
  147. ],
  148. }</textarea>
  149. <textarea id="php-code">&lt;?php
  150. $app = new Phalcon\Mvc\Micro();
  151. //Set a route with the name "show-post"
  152. $app->get('/blog/{year}/{title}', function ($year, $title) use ($app) {
  153. //.. show the post here
  154. return $year.$title;
  155. })->setName('show-post');
  156. $app->get('/', function () {
  157. echo "<h1>Welcome !</h1>";
  158. echo $app->url->get(array(
  159. 'for' => 'show-post',
  160. 'title' => 'php-is-a-great-framework',
  161. 'year' => 2012
  162. ));
  163. });
  164. $app->get('/posts/{year:[0-9]+}/{title:[a-zA-Z\-]+}', function ($year, $title) {
  165. echo "<h1>Title: $title</h1>";
  166. echo "<h2>Year: $year</h2>";
  167. });
  168. //Requiring another file
  169. $app->get('/show/results', function () {
  170. require 'views/results.php';
  171. });
  172. //Returning a JSON
  173. $app->get('/get/some-json', function () {
  174. echo json_encode(array("some", "important", "data"));
  175. });
  176. //This route makes a redirection to another route
  177. $app->post('/old/welcome', function () use ($app) {
  178. $app->response->redirect("new/welcome");
  179. });
  180. $app->post('/new/welcome', function () use ($app) {
  181. echo 'This is the new Welcome';
  182. });
  183. /*
  184. //Matches if the HTTP method is POST
  185. $app->post('/api/products/add', "add_product");
  186. //Matches if the HTTP method is PUT
  187. $app->put('/api/products/update/{id}', "update_product");
  188. //Matches if the HTTP method is DELETE
  189. $app->put('/api/products/remove/{id}', "delete_product");
  190. //Matches if the HTTP method is GET or POST
  191. $app->map('/repos/store/refs')->via(array('GET', 'POST'));
  192. */
  193. $app->handle();
  194. ?&gt;</textarea>
  195. <textarea id="cpp-code">#include "dialog.h"
  196. #include <QApplication>
  197. int main(int argc, char *argv[])
  198. {
  199. QApplication a(argc, argv);
  200. Dialog w;
  201. w.show();
  202. return a.exec();
  203. }</textarea>
  204. <textarea id="java-code">package com.demo.blog;
  205. import com.jfinal.aop.Before;
  206. import com.jfinal.core.Controller;
  207. @Before(BlogInterceptor.class)
  208. public class BlogController extends Controller {
  209. public void index() {
  210. setAttr("blogPage", Blog.me.paginate(getParaToInt(0, 1), 10));
  211. render("blog.html");
  212. }
  213. public void add() {
  214. }
  215. @Before(BlogValidator.class)
  216. public void save() {
  217. getModel(Blog.class).save();
  218. redirect("/blog");
  219. }
  220. public void edit() {
  221. setAttr("blog", Blog.me.findById(getParaToInt()));
  222. }
  223. @Before(BlogValidator.class)
  224. public void update() {
  225. getModel(Blog.class).update();
  226. redirect("/blog");
  227. }
  228. public void delete() {
  229. Blog.me.deleteById(getParaToInt());
  230. redirect("/blog");
  231. }
  232. }
  233. </textarea>
  234. <textarea id="actionscript-code">package com.flite
  235. {
  236. import flash.net.*;
  237. import flash.events.*;
  238. import flash.display.*;
  239. /**
  240. * @package com.flite
  241. * @class XMLLoader
  242. * @author pandao pandao@vip.qq.com
  243. */
  244. public class XMLLoder
  245. {
  246. public var xml:XML;
  247. public var url:String;
  248. public var list:XMLList;
  249. public var percent:Number = 0;
  250. public var onload:Function;
  251. public var onerror:Function;
  252. public var onpreload:Function;
  253. public var onprogress:Function;
  254. private var loader:URLLoader;
  255. public function XMLLoder(url:String) : void
  256. {
  257. this.url = url;
  258. xml = new XML();
  259. xml.ignoreWhite = true;
  260. loader = new URLLoader();
  261. loader.load(new URLRequest(url));
  262. loader.addEventListener(Event.OPEN, preloadHandler);
  263. loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
  264. loader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  265. loader.addEventListener(Event.COMPLETE, loadedHandler);
  266. }
  267. private function preloadHandler(event:Event) : void
  268. {
  269. onpreload = onpreload || new Function;
  270. onpreload(event);
  271. }
  272. private function errorHandler(event:IOErrorEvent) : void
  273. {
  274. onerror = onerror || new Function;
  275. onerror(event);
  276. }
  277. private function progressHandler(event:ProgressEvent) : void
  278. {
  279. percent = Math.round((event.bytesLoaded / event.bytesTotal) * 100);
  280. onprogress = onprogress || new Function;
  281. onprogress(event, percent);
  282. }
  283. private function loadedHandler(event:Event) : void
  284. {
  285. xml = XML(loader.data);
  286. onload = onload || new Function;
  287. onload(xml);
  288. }
  289. }
  290. }</textarea><textarea id="perl-code">#!/usr/bin/perl
  291. use strict;
  292. use warnings;
  293. print "Hello, World...\n";
  294. </textarea>
  295. <textarea id="go-code">package main
  296. import (
  297. "github.com/astaxie/beego"
  298. )
  299. type MainController struct {
  300. beego.Controller
  301. }
  302. func (this *MainController) Get() {
  303. this.Ctx.WriteString("hello world")
  304. }
  305. func main() {
  306. beego.Router("/", &MainController{})
  307. beego.Run()
  308. }</textarea><textarea id="python-code">#!/usr/bin/env python
  309. from flask import Flask
  310. app = Flask(__name__)
  311. @app.route('/')
  312. def hello_world():
  313. return 'Hello World!'
  314. if __name__ == '__main__':
  315. app.run()</textarea>
  316. <textarea id="css-code"> body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,
  317. th,td,hr,button,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
  318. margin:0;padding:0;
  319. }
  320. article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary {
  321. display: block;
  322. }
  323. audio, canvas, video {
  324. display: inline-block;
  325. }
  326. body, button, input, select, textarea {
  327. font:12px/1.5 Tahoma, "Hiragino Sans GB", "Microsoft Yahei", Arial;
  328. }
  329. body {
  330. font-size:12px;
  331. color:#666;
  332. background:#fff url(../images/) no-repeat left top;
  333. }
  334. a {
  335. color:#444;
  336. text-decoration: none;
  337. }
  338. a:hover {
  339. color:#065BC2;
  340. text-decoration: none;
  341. }
  342. .clear {
  343. zoom:1;
  344. }
  345. .clear:after {
  346. content:"";
  347. height:0;
  348. visibility:hidden;
  349. clear:both;
  350. display:block;
  351. }
  352. img {
  353. border:none;
  354. vertical-align: middle;
  355. }
  356. ul {
  357. list-style: none;
  358. }</textarea></div>
  359. <div id="test-editormd">
  360. <textarea style="display:none;"></textarea>
  361. </div>
  362. </div>
  363. <script src="js/jquery.min.js"></script>
  364. <script src="../editormd.js"></script>
  365. <script type="text/javascript">
  366. var testEditor;
  367. function getCodeValue() {
  368. return (localStorage.modeName) ? $("#"+localStorage.modeName.replace("text/", "").replace("c/c++", "cpp")+"-code").val() : $("#html-code").val();
  369. }
  370. $(function() {
  371. testEditor = editormd("test-editormd", {
  372. width : "90%",
  373. height : 720,
  374. watch : false,
  375. toolbar : false,
  376. codeFold : true,
  377. searchReplace : true,
  378. placeholder : "Enjoy coding!",
  379. value : getCodeValue(),
  380. theme : (localStorage.theme) ? localStorage.theme : "default",
  381. mode : (localStorage.mode) ? localStorage.mode : "text/html",
  382. path : '../lib/'
  383. });
  384. $("#get-code-btn").bind("click", function() {
  385. alert(testEditor.getValue());
  386. });
  387. $("#fullscreen-btn").bind("click", function() {
  388. testEditor.fullscreen();
  389. });
  390. var select = $("#themes");
  391. for (var i = 0, len = editormd.themes.length; i < len; i ++)
  392. {
  393. var theme = editormd.themes[i];
  394. var selected = (localStorage.theme == theme) ? " selected=\"selected\"" : "";
  395. select.append("<option value=\"" + theme + "\"" + selected + ">" + theme + "</option>");
  396. }
  397. select.change(function(){
  398. var theme = $(this).val();
  399. if (theme == "")
  400. {
  401. alert("theme == \"\"");
  402. return false;
  403. }
  404. localStorage.theme = theme;
  405. testEditor.setTheme(theme);
  406. });
  407. var modesSelect = $("#modes");
  408. var modeNames = ["text/html", "javascript", "php", "text/xml", "text/json", "java", "actionscript", "perl", "go", "python", "c/c++", "css", "ruby"];
  409. var modes = ["text/html", "javascript", "php", "text/xml", "text/json", "clike", "javascript", "perl", "go", "python", "clike", "css", "ruby"];
  410. for (var i = 0, len = modes.length; i < len; i ++)
  411. {
  412. var mode = modes[i];
  413. var selected = (localStorage.modeName == modeNames[i]) ? " selected=\"selected\"" : "";
  414. modesSelect.append("<option value=\"" + mode + "\"" + selected + " name=\"" + modeNames[i] + "\"" + selected + ">" + modeNames[i] + "</option>");
  415. }
  416. modesSelect.change(function(){
  417. var mode = $(this).val();
  418. var modeName = $(this).find("option:selected").attr("name");
  419. if (mode == "")
  420. {
  421. alert("mode == \"\"");
  422. return false;
  423. }
  424. localStorage.mode = mode;
  425. localStorage.modeName = modeName;
  426. var code = getCodeValue();
  427. testEditor.setCodeMirrorOption("mode", mode);
  428. //testEditor.setCodeMirrorOption("value", code);
  429. testEditor.setValue(code);
  430. });
  431. });
  432. </script>
  433. </body>
  434. </html>