Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized js with coffee and created gh-pages #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.sass-cache
.coffeescript-cache

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
Binary file removed css/images/bg.jpg
Binary file not shown.
Binary file removed css/images/dlg-close.png
Binary file not shown.
50 changes: 0 additions & 50 deletions css/style.css

This file was deleted.

170 changes: 0 additions & 170 deletions css/topbox.css

This file was deleted.

159 changes: 159 additions & 0 deletions engine/coffeescripts/litelighter.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
(($) ->
$.litelighter = ($this, options) ->
@settings = $.extend({},
clone: false
style: "light"
language: "generic"
, options)
@code = $this
@enable()

$.extend $.litelighter::,
enable: ->
@codelite = @code.data("llcode", @code.text())
@codelite = $("<pre />").text(@code.text()).addClass("litelighter").insertAfter(@code.css("display", "none")) if @settings.clone is true
@settings.language = @code.data("lllanguage") if @code.data("lllanguage")
@settings.style = @code.data("llstyle") if @code.data("llstyle")
style = $.litelighter.styles[@settings.style]
lang = $.litelighter.languages[@settings.language]
txt = $.litelighter.highlight(@codelite.html(), style, lang)
@codelite.attr("style", style.code).html txt
@code

disable: ->
if @settings.clone
@codelite.remove()
return @code.css("display", "block")
@code.html("").text @code.data("llcode")

destroy: ->
@disable()
@code.removeData "litelighter"

option: (key, val) ->
if val isnt `undefined`
@code.data "ll" + key, val
@settings[key] = val
@disable()
return @enable()
this[key]

$.fn.extend litelighter: (o) ->
o = o or {}
tmp_args = Array::slice.call(arguments)
if typeof (o) is "string"
@each ->
inst = $(this).data("litelighter")
inst[o].apply inst, tmp_args.slice(1)
else
@each ->
$t = $(this)
$t.data "litelighter", new $.litelighter($t, o)

$.litelighter.highlight = (txt, style, lang) ->
sublangsi = 0
sublangs = []
for i of lang
if lang.hasOwnProperty(i) and lang[i].language isnt `undefined` and $.litelighter.languages[lang[i].language] isnt `undefined`
txt = txt.replace(lang[i].re, ($1, $2, $3) ->
sublangs[sublangsi++] = $.litelighter.highlight($2, style, $.litelighter.languages[lang[i].language])
$1.replace $2, "___subtmpl" + (sublangsi - 1) + "___"
)
for i of lang
txt = txt.replace(lang[i].re, "___" + i + "___$1___end" + i + "___") if lang.hasOwnProperty(i) and lang[i].language is `undefined`
lvls = []
txt = txt.replace(/___(?!subtmpl)\w+?___/g, ($0) ->
end = (if ($0.substr(3, 3) is "end") then true else false)
tag = (if not end then $0.substr(3) else $0.substr(6)).replace(/_/g, "")
lastTag = (if lvls.length > 0 then lvls[lvls.length - 1] else null)
if not end and (not lastTag? or tag is lastTag or (lastTag? and lang[lastTag].embed isnt `undefined` and $.inArray(tag, lang[lastTag].embed) >= 0))
lvls.push tag
return $0
else if end and tag is lastTag
lvls.pop()
return $0
""
)
for i of lang
txt = txt.replace(new RegExp("___end" + i + "___", "g"), "</span>").replace(new RegExp("___" + i + "___", "g"), "<span class='litelighterstyle' style='" + style[lang[i].style] + "'>") if lang.hasOwnProperty(i)
for i of lang
if lang.hasOwnProperty(i) and lang[i].language isnt `undefined` and $.litelighter.languages[lang[i].language] isnt `undefined`
txt = txt.replace(/___subtmpl\d+___/g, ($tmpl) ->
i = parseInt($tmpl.replace(/___subtmpl(\d+)___/, "$1"), 10)
sublangs[i]
)
txt

$.litelighter.styles =
light:
code: "background-color:#ffffff;color:#555;"
comment: "color:#999"
string: "color:#8F9657"
number: "color:#CF6745;"
keyword: "color:#6F87A8;"
operators: "color:#9e771e;"

dark:
code: "background-color:#141414;color:#ffffff;"
comment: "color:#999"
string: "color:#8F9657"
number: "color:#CF6745;"
keyword: "color:#6F87A8;"
operators: "color:#fee79e;"

$.litelighter.languages = generic:
comment:
re: /(\/\/.*|\/\*([\s\S]*?)\*\/)/g
style: "comment"

string:
re: /((\'.*?\')|(\".*?\"))/g
style: "string"

numbers:
re: /(\-?(\d+|\d+\.\d+|\.\d+))/g
style: "number"

regex:
re: /([^\/]\/[^\/].+\/(g|i|m)*)/g
style: "number"

keywords:
re: /(?:\b)(for|foreach|while|if|else|elseif|switch|break|as|return|this|class|self|default|var|false|true|null|undefined)(?:\b)/g
style: "keyword"

operators:
re: /(\+|\-|\/|\*|\%|\=|\&lt;|\&gt;|\||\?|\.)/g
style: "operators"

$.litelighter.languages.js = $.litelighter.languages.generic
$.litelighter.languages.css =
comment: $.litelighter.languages.generic.comment
string: $.litelighter.languages.generic.string
numbers:
re: /((\-?(\d+|\d+\.\d+|\.\d+)(\%|px|em|pt|in)?)|\#[0-9a-fA-F]{3}[0-9a-fA-F]{3})/g
style: "number"

keywords:
re: /(\@\w+|\:?\:\w+|[a-z\-]+\:)/g
style: "keyword"

$.litelighter.languages.html =
comment:
re: /(\&lt\;\!\-\-([\s\S]*?)\-\-\&gt\;)/g
style: "comment"

tag:
re: /(\&lt\;\/?\w(.|\n)*?\/?\&gt\;)/g
style: "keyword"
embed: [ "string" ]

string: $.litelighter.languages.generic.string
css:
re: /(?:\&lt;style.*?\&gt;)([\s\S]+?)(?:\&lt;\/style\&gt;)/g
language: "css"

script:
re: /(?:\&lt;script.*?\&gt;)([\s\S]+?)(?:\&lt;\/script\&gt;)/g
language: "js"
) jQuery
Loading