奇技淫巧之瀏覽器秒秒鐘變編輯器

奇技淫巧之瀏覽器秒秒鐘變編輯器javascript

  此文是翻譯來的,原文戳這裏php

由來css

  有時,我僅僅想輸入一些亂碼。僅僅想放空本身。用編輯器來輸入這些胡言亂語會使我很苦惱,由於這樣會弄亂我項目的工做區。(我很挑剔,我懂得)html

  因此我就這麼作。自從我生活在有瀏覽器的地方,我就只需打開新的標籤,而後在地址欄裏輸入下面的內容:java

data:text/html, <html contenteditable>

  瞧,瀏覽器記事本。python

爲何代碼會有效git

  你不須要記住它。它不是rocket science(哈哈,這裏不是火箭科學,更不是那部電影,此處指艱深的學問以及複雜傷身的工做)。咱們正在使用數據URI格式Data URI’s format而且告訴瀏覽器對html進行渲染(嘗試一下」javascript:alert(‘Bazinga’);」)。html所說的內容是一種帶有HTML的contenteditable(內容可編輯)的屬性的HTML line。這僅僅在能識別這種屬性的現代的瀏覽器上是有效的。點擊編輯吧!github

  以上就是翻譯的所有內容,原文戳這裏web

  效果圖:sql

More

  在做者發佈這個消息以後,有不少的大神開始開動腦筋,絞盡腦汁,開始創做了各類碉堡的瀏覽器編輯器。下面這一款我比較喜歡的:

1 data:text/html, <style type="text/css">.e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div class="e" id="editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("editor");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/java");</script>

  效果出衆,最重要的是支持多種語言想用其它的語言的話,僅僅須要把ace/mode/python用下面的換掉便可:

 1 Markdown -> `ace/mode/markdown`
 2 Python -> `ace/mode/ruby`
 3 C/C++ -> `ace/mode/c_cpp`
 4 Javscript -> `ace/mode/javascript`
 5 Java -> `ace/mode/java`
 6 Scala- -> `ace/mode/scala`
 7 CoffeeScript -> `ace/mode/coffee`
 8 and 
 9 css, html, php, latex, 
10 tex, sh, sql, lua, clojure, dart, typescript, go, groovy, json, jsp, less, lisp, 
11 lucene, perl, powershell, scss, textile, xml, yaml, xquery, liquid, diff and many more...

  更碉堡的是,主題也能夠換的,僅僅把ace/theme/monokai用下面的換掉便可:

1 Eclipse -> ace/theme/eclipse
2 GitHub -> ace/theme/github
3 TextMate -> ace/theme/textmate
4 and 
5 ambiance, dawn, chaos, chrome, dreamweaver, xcode, vibrant_ink, solarized_dark, solarized_light, tomorrow, tomorrow_night, tomorrow_night_blue, 
6 twilight, tomorrow_night_eighties, pastel_on_dark and many more..
View Code

  還有一個比較好玩的,是一個在編輯過程當中會變色的,你們能夠試試:

1 data:text/html, <html><head><link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'><style type="text/css"> html { font-family: "Open Sans" } * { -webkit-transition: all linear 1s; }</style><script>window.onload=function(){var e=false;var t=0;setInterval(function(){if(!e){t=Math.round(Math.max(0,t-Math.max(t/3,1)))}var n=(255-t*2).toString(16);document.body.style.backgroundColor="#ff"+n+""+n},1e3);var n=null;document.onkeydown=function(){t=Math.min(128,t+2);e=true;clearTimeout(n);n=setTimeout(function(){e=false},1500)}}</script></head><body contenteditable style="font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;">
View Code  

  另外我已經將代碼放在github上了,歡迎Fork。瀏覽器-編輯器

  最後附上一張Python編輯器的圖:

  以上。

 

 

  PS:本博客歡迎轉發,但請註明博客地址及做者,因本人水平有限,如有不對之處,歡迎指出,謝謝~

  博客地址:http://www.cnblogs.com/voidy/

  博客新址:http://voidy.net

  <。)#)))≦

相關文章
相關標籤/搜索