mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-27 03:10:18 +01:00
parent
3178676fba
commit
af9a71549b
5 changed files with 60 additions and 74 deletions
|
@ -166,9 +166,10 @@ haste.extensionMap = {
|
||||||
rb: 'ruby', py: 'python', pl: 'perl', php: 'php', scala: 'scala', go: 'go',
|
rb: 'ruby', py: 'python', pl: 'perl', php: 'php', scala: 'scala', go: 'go',
|
||||||
xml: 'xml', html: 'xml', htm: 'xml', css: 'css', js: 'javascript', vbs: 'vbscript',
|
xml: 'xml', html: 'xml', htm: 'xml', css: 'css', js: 'javascript', vbs: 'vbscript',
|
||||||
lua: 'lua', pas: 'delphi', java: 'java', cpp: 'cpp', cc: 'cpp', m: 'objectivec',
|
lua: 'lua', pas: 'delphi', java: 'java', cpp: 'cpp', cc: 'cpp', m: 'objectivec',
|
||||||
vala: 'vala', cs: 'cs', sql: 'sql', sm: 'smalltalk', lisp: 'lisp', ini: 'ini',
|
vala: 'vala', sql: 'sql', sm: 'smalltalk', lisp: 'lisp', ini: 'ini',
|
||||||
diff: 'diff', bash: 'bash', sh: 'bash', tex: 'tex', erl: 'erlang', hs: 'haskell',
|
diff: 'diff', bash: 'bash', sh: 'bash', tex: 'tex', erl: 'erlang', hs: 'haskell',
|
||||||
md: 'markdown', txt: '', coffee: 'coffee', json: 'javascript'
|
md: 'markdown', txt: '', coffee: 'coffee', json: 'javascript',
|
||||||
|
swift: 'swift'
|
||||||
};
|
};
|
||||||
|
|
||||||
// Look up the extension preferred for a type
|
// Look up the extension preferred for a type
|
||||||
|
|
2
static/application.min.js
vendored
2
static/application.min.js
vendored
|
@ -1 +1 @@
|
||||||
var haste_document=function(){this.locked=!1};haste_document.prototype.htmlEscape=function(e){return e.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<").replace(/"/g,""")},haste_document.prototype.load=function(e,t,n){var r=this;$.ajax("/documents/"+e,{type:"get",dataType:"json",success:function(i){r.locked=!0,r.key=e,r.data=i.data;try{var s;n==="txt"?s={value:r.htmlEscape(i.data)}:n?s=hljs.highlight(n,i.data):s=hljs.highlightAuto(i.data)}catch(o){s=hljs.highlightAuto(i.data)}t({value:s.value,key:e,language:s.language||n,lineCount:i.data.split("\n").length})},error:function(e){t(!1)}})},haste_document.prototype.save=function(e,t){if(this.locked)return!1;this.data=e;var n=this;$.ajax("/documents",{type:"post",data:e,dataType:"json",contentType:"application/json; charset=utf-8",success:function(r){n.locked=!0,n.key=r.key;var i=hljs.highlightAuto(e);t(null,{value:i.value,key:r.key,language:i.language,lineCount:e.split("\n").length})},error:function(e){try{t($.parseJSON(e.responseText))}catch(n){t({message:"Something went wrong!"})}}})};var haste=function(e,t){this.appName=e,this.$textarea=$("textarea"),this.$box=$("#box"),this.$code=$("#box code"),this.$linenos=$("#linenos"),this.options=t,this.configureShortcuts(),this.configureButtons(),t.twitter||$("#box2 .twitter").hide()};haste.prototype.setTitle=function(e){var t=e?this.appName+" - "+e:this.appName;document.title=t},haste.prototype.showMessage=function(e,t){var n=$('<li class="'+(t||"info")+'">'+e+"</li>");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n<e.length;n++)if(t.hasClass(e[n]))return t.addClass("enabled"),!0;t.removeClass("enabled")})},haste.prototype.newDocument=function(e){this.$box.hide(),this.doc=new haste_document,e||window.history.pushState(null,this.appName,"/"),this.setTitle(),this.lightKey(),this.$textarea.val("").show("fast",function(){this.focus()}),this.removeLineNumbers()},haste.extensionMap={rb:"ruby",py:"python",pl:"perl",php:"php",scala:"scala",go:"go",xml:"xml",html:"xml",htm:"xml",css:"css",js:"javascript",vbs:"vbscript",lua:"lua",pas:"delphi",java:"java",cpp:"cpp",cc:"cpp",m:"objectivec",vala:"vala",cs:"cs",sql:"sql",sm:"smalltalk",lisp:"lisp",ini:"ini",diff:"diff",bash:"bash",sh:"bash",tex:"tex",erl:"erlang",hs:"haskell",md:"markdown",txt:"",coffee:"coffee",json:"javascript"},haste.prototype.lookupExtensionByType=function(e){for(var t in haste.extensionMap)if(haste.extensionMap[t]===e)return t;return e},haste.prototype.lookupTypeByExtension=function(e){return haste.extensionMap[e]||e},haste.prototype.addLineNumbers=function(e){var t="";for(var n=0;n<e;n++)t+=(n+1).toString()+"<br/>";$("#linenos").html(t)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.$code.html(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount)):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.$code.html(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t<this.buttons.length;t++)this.configureButton(this.buttons[t])},haste.prototype.configureButton=function(e){e.$where.click(function(t){t.preventDefault(),!e.clickDisabled&&$(this).hasClass("enabled")&&e.action()}),e.$where.mouseenter(function(t){$("#box3 .label").text(e.label),$("#box3 .shortcut").text(e.shortcutDescription||""),$("#box3").show(),$(this).append($("#pointer").remove().show())}),e.$where.mouseleave(function(e){$("#box3").hide(),$("#pointer").hide()})},haste.prototype.configureShortcuts=function(){var e=this;$(document.body).keydown(function(t){var n;for(var r=0;r<e.buttons.length;r++){n=e.buttons[r];if(n.shortcut&&n.shortcut(t)){t.preventDefault(),n.action();return}}})},$(function(){$("textarea").keydown(function(e){if(e.keyCode===9){e.preventDefault();var t=" ";if(document.selection)this.focus(),sel=document.selection.createRange(),sel.text=t,this.focus();else if(this.selectionStart||this.selectionStart=="0"){var n=this.selectionStart,r=this.selectionEnd,i=this.scrollTop;this.value=this.value.substring(0,n)+t+this.value.substring(r,this.value.length),this.focus(),this.selectionStart=n+t.length,this.selectionEnd=n+t.length,this.scrollTop=i}else this.value+=t,this.focus()}})})
|
var haste_document=function(){this.locked=!1};haste_document.prototype.htmlEscape=function(e){return e.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<").replace(/"/g,""")},haste_document.prototype.load=function(e,t,n){var r=this;$.ajax("/documents/"+e,{type:"get",dataType:"json",success:function(i){r.locked=!0,r.key=e,r.data=i.data;try{var s;n==="txt"?s={value:r.htmlEscape(i.data)}:n?s=hljs.highlight(n,i.data):s=hljs.highlightAuto(i.data)}catch(o){s=hljs.highlightAuto(i.data)}t({value:s.value,key:e,language:s.language||n,lineCount:i.data.split("\n").length})},error:function(e){t(!1)}})},haste_document.prototype.save=function(e,t){if(this.locked)return!1;this.data=e;var n=this;$.ajax("/documents",{type:"post",data:e,dataType:"json",contentType:"application/json; charset=utf-8",success:function(r){n.locked=!0,n.key=r.key;var i=hljs.highlightAuto(e);t(null,{value:i.value,key:r.key,language:i.language,lineCount:e.split("\n").length})},error:function(e){try{t($.parseJSON(e.responseText))}catch(n){t({message:"Something went wrong!"})}}})};var haste=function(e,t){this.appName=e,this.$textarea=$("textarea"),this.$box=$("#box"),this.$code=$("#box code"),this.$linenos=$("#linenos"),this.options=t,this.configureShortcuts(),this.configureButtons(),t.twitter||$("#box2 .twitter").hide()};haste.prototype.setTitle=function(e){var t=e?this.appName+" - "+e:this.appName;document.title=t},haste.prototype.showMessage=function(e,t){var n=$('<li class="'+(t||"info")+'">'+e+"</li>");$("#messages").prepend(n),setTimeout(function(){n.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","raw"])},haste.prototype.configureKey=function(e){var t,n=0;$("#box2 .function").each(function(){t=$(this);for(n=0;n<e.length;n++)if(t.hasClass(e[n]))return t.addClass("enabled"),!0;t.removeClass("enabled")})},haste.prototype.newDocument=function(e){this.$box.hide(),this.doc=new haste_document,e||window.history.pushState(null,this.appName,"/"),this.setTitle(),this.lightKey(),this.$textarea.val("").show("fast",function(){this.focus()}),this.removeLineNumbers()},haste.extensionMap={rb:"ruby",py:"python",pl:"perl",php:"php",scala:"scala",go:"go",xml:"xml",html:"xml",htm:"xml",css:"css",js:"javascript",vbs:"vbscript",lua:"lua",pas:"delphi",java:"java",cpp:"cpp",cc:"cpp",m:"objectivec",vala:"vala",sql:"sql",sm:"smalltalk",lisp:"lisp",ini:"ini",diff:"diff",bash:"bash",sh:"bash",tex:"tex",erl:"erlang",hs:"haskell",md:"markdown",txt:"",coffee:"coffee",json:"javascript",swift:"swift"},haste.prototype.lookupExtensionByType=function(e){for(var t in haste.extensionMap)if(haste.extensionMap[t]===e)return t;return e},haste.prototype.lookupTypeByExtension=function(e){return haste.extensionMap[e]||e},haste.prototype.addLineNumbers=function(e){var t="";for(var n=0;n<e;n++)t+=(n+1).toString()+"<br/>";$("#linenos").html(t)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(e){var t=e.split(".",2),n=this;n.doc=new haste_document,n.doc.load(t[0],function(e){e?(n.$code.html(e.value),n.setTitle(e.key),n.fullKey(),n.$textarea.val("").hide(),n.$box.show().focus(),n.addLineNumbers(e.lineCount)):n.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){if(this.doc.locked){var e=this.doc.data;this.newDocument(),this.$textarea.val(e)}},haste.prototype.lockDocument=function(){var e=this;this.doc.save(this.$textarea.val(),function(t,n){if(t)e.showMessage(t.message,"error");else if(n){e.$code.html(n.value),e.setTitle(n.key);var r="/"+n.key;n.language&&(r+="."+e.lookupExtensionByType(n.language)),window.history.pushState(null,e.appName+"-"+n.key,r),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(n.lineCount)}})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcutDescription:"control + s",shortcut:function(e){return e.ctrlKey&&e.keyCode===83},action:function(){e.$textarea.val().replace(/^\s+|\s+$/g,"")!==""&&e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(e){return e.ctrlKey&&e.keyCode===78},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&t.keyCode===68},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(e){return e.ctrlKey&&e.shiftKey&&e.keyCode===82},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}},{$where:$("#box2 .twitter"),label:"Twitter",shortcut:function(t){return e.options.twitter&&e.doc.locked&&t.shiftKey&&t.ctrlKey&&t.keyCode==84},shortcutDescription:"control + shift + t",action:function(){window.open("https://twitter.com/share?url="+encodeURI(window.location.href))}}];for(var t=0;t<this.buttons.length;t++)this.configureButton(this.buttons[t])},haste.prototype.configureButton=function(e){e.$where.click(function(t){t.preventDefault(),!e.clickDisabled&&$(this).hasClass("enabled")&&e.action()}),e.$where.mouseenter(function(t){$("#box3 .label").text(e.label),$("#box3 .shortcut").text(e.shortcutDescription||""),$("#box3").show(),$(this).append($("#pointer").remove().show())}),e.$where.mouseleave(function(e){$("#box3").hide(),$("#pointer").hide()})},haste.prototype.configureShortcuts=function(){var e=this;$(document.body).keydown(function(t){var n;for(var r=0;r<e.buttons.length;r++){n=e.buttons[r];if(n.shortcut&&n.shortcut(t)){t.preventDefault(),n.action();return}}})},$(function(){$("textarea").keydown(function(e){if(e.keyCode===9){e.preventDefault();var t=" ";if(document.selection)this.focus(),sel=document.selection.createRange(),sel.text=t,this.focus();else if(this.selectionStart||this.selectionStart=="0"){var n=this.selectionStart,r=this.selectionEnd,i=this.scrollTop;this.value=this.value.substring(0,n)+t+this.value.substring(r,this.value.length),this.focus(),this.selectionStart=n+t.length,this.selectionEnd=n+t.length,this.scrollTop=i}else this.value+=t,this.focus()}})})
|
3
static/highlight.min.js
vendored
3
static/highlight.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -60,7 +60,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="linenos"></div>
|
<div id="linenos"></div>
|
||||||
<pre id="box" style="display:none;" tabindex="0"><code></code></pre>
|
<pre id="box" style="display:none;" class="hljs" tabindex="0"><code></code></pre>
|
||||||
<textarea spellcheck="false" style="display:none;"></textarea>
|
<textarea spellcheck="false" style="display:none;"></textarea>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -4,97 +4,81 @@ Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull <sourdrums@gmai
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pre code {
|
.hljs {
|
||||||
display: block; padding: 0.5em;
|
display: block;
|
||||||
background: #002b36; color: #92a0a0;
|
overflow-x: auto;
|
||||||
|
padding: 0.5em;
|
||||||
|
background: #002b36;
|
||||||
|
color: #839496;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .comment,
|
.hljs-comment,
|
||||||
pre .template_comment,
|
.hljs-quote {
|
||||||
pre .diff .header,
|
|
||||||
pre .doctype,
|
|
||||||
pre .lisp .string,
|
|
||||||
pre .javadoc {
|
|
||||||
color: #586e75;
|
color: #586e75;
|
||||||
font-style: italic;
|
|
||||||
display: inline-block;
|
|
||||||
line-height: 1em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .keyword,
|
/* Solarized Green */
|
||||||
pre .css .rule .keyword,
|
.hljs-keyword,
|
||||||
pre .winutils,
|
.hljs-selector-tag,
|
||||||
pre .javascript .title,
|
.hljs-addition {
|
||||||
pre .method,
|
|
||||||
pre .addition,
|
|
||||||
pre .css .tag,
|
|
||||||
pre .lisp .title {
|
|
||||||
color: #859900;
|
color: #859900;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .number,
|
/* Solarized Cyan */
|
||||||
pre .command,
|
.hljs-number,
|
||||||
pre .string,
|
.hljs-string,
|
||||||
pre .tag .value,
|
.hljs-meta .hljs-meta-string,
|
||||||
pre .phpdoc,
|
.hljs-literal,
|
||||||
pre .tex .formula,
|
.hljs-doctag,
|
||||||
pre .regexp,
|
.hljs-regexp {
|
||||||
pre .hexcolor {
|
|
||||||
color: #2aa198;
|
color: #2aa198;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .title,
|
/* Solarized Blue */
|
||||||
pre .localvars,
|
.hljs-title,
|
||||||
pre .function .title,
|
.hljs-section,
|
||||||
pre .chunk,
|
.hljs-name,
|
||||||
pre .decorator,
|
.hljs-selector-id,
|
||||||
pre .builtin,
|
.hljs-selector-class {
|
||||||
pre .built_in,
|
|
||||||
pre .lisp .title,
|
|
||||||
pre .identifier,
|
|
||||||
pre .title .keymethods,
|
|
||||||
pre .id,
|
|
||||||
pre .header {
|
|
||||||
color: #268bd2;
|
color: #268bd2;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .tag .title,
|
/* Solarized Yellow */
|
||||||
pre .rules .property,
|
.hljs-attribute,
|
||||||
pre .django .tag .keyword {
|
.hljs-attr,
|
||||||
font-weight: bold;
|
.hljs-variable,
|
||||||
}
|
.hljs-template-variable,
|
||||||
|
.hljs-class .hljs-title,
|
||||||
pre .attribute,
|
.hljs-type {
|
||||||
pre .variable,
|
|
||||||
pre .instancevar,
|
|
||||||
pre .lisp .body,
|
|
||||||
pre .smalltalk .number,
|
|
||||||
pre .constant,
|
|
||||||
pre .class .title,
|
|
||||||
pre .parent,
|
|
||||||
pre .haskell .label {
|
|
||||||
color: #b58900;
|
color: #b58900;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .preprocessor,
|
/* Solarized Orange */
|
||||||
pre .pi,
|
.hljs-symbol,
|
||||||
pre .shebang,
|
.hljs-bullet,
|
||||||
pre .symbol,
|
.hljs-subst,
|
||||||
pre .diff .change,
|
.hljs-meta,
|
||||||
pre .special,
|
.hljs-meta .hljs-keyword,
|
||||||
pre .keymethods,
|
.hljs-selector-attr,
|
||||||
pre .attr_selector,
|
.hljs-selector-pseudo,
|
||||||
pre .important,
|
.hljs-link {
|
||||||
pre .subst,
|
|
||||||
pre .cdata {
|
|
||||||
color: #cb4b16;
|
color: #cb4b16;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .deletion {
|
/* Solarized Red */
|
||||||
|
.hljs-built_in,
|
||||||
|
.hljs-deletion {
|
||||||
color: #dc322f;
|
color: #dc322f;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre .tex .formula,
|
.hljs-formula {
|
||||||
pre .code {
|
|
||||||
background: #073642;
|
background: #073642;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hljs-emphasis {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hljs-strong {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue