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

Porting to LiveScript, and fixing a few blocker bugs #6

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d5c656b
convert datatables to ls
clkao Oct 30, 2012
169963b
* package.ls
audreyt Oct 30, 2012
e7d81bf
* Do not emit npm-local package.ls
audreyt Oct 30, 2012
8bfa8b5
* Convert everything to livescript
audreyt Oct 30, 2012
d6b9e26
avoid arguments.callee
clkao Oct 30, 2012
97c4a47
use alternative json encoding that allows verbatim " and \\ in content
clkao Oct 30, 2012
fff0201
use \uFFF9 as tblclass rather than "data-tables"
clkao Oct 30, 2012
7a48223
modern class for DatatableRenderer
clkao Oct 30, 2012
934b8db
split menu hook into datatables-ui
clkao Oct 31, 2012
3361207
modernize the Datatables class
clkao Oct 31, 2012
15beb43
remove duplicated method: updateTblPropInAPool
clkao Oct 31, 2012
26c375e
fix remaining unescaped quotes
clkao Oct 31, 2012
33c2e2d
cleanup render call
clkao Oct 31, 2012
0658433
fix incorrect js2ls loop translation causing infinite loop
clkao Oct 31, 2012
add7561
less tangled logic
clkao Oct 31, 2012
d2a9b04
fix cursor jump due to js2ls error
clkao Oct 31, 2012
3dfc2ff
cleanup nodeText
clkao Nov 1, 2012
0122e04
fix backspace and prevent table payload leak
clkao Nov 1, 2012
bb6b224
simplify logic
clkao Nov 1, 2012
b051231
disable styling buttons when we are inside table. still need css to m…
clkao Nov 1, 2012
831e838
use relative path for css/js
clkao Nov 1, 2012
9a3e7fe
parse the whole line for table json, so intermediate elements like sp…
clkao Nov 5, 2012
474cd28
* Add a reaonsable .gitignore
audreyt Nov 6, 2012
3ca80a4
remove duplicated method insertTblRowBelow
clkao Nov 6, 2012
c88ffb2
use getNewTblId to get tblId
clkao Nov 6, 2012
3c438a4
maintain tblId across rows and use it to distinguish tables
clkao Nov 6, 2012
59aaa35
disable table options for now
clkao Nov 6, 2012
99e5ccd
Fix IE: use jquery to get textContent
clkao Nov 6, 2012
978463a
use interpolation
clkao Nov 6, 2012
041ad7d
wrap atIndex with try as it sometimes calls console.warn and breaks IE8
clkao Nov 6, 2012
0bd731c
IE7 compatibility
clkao Nov 6, 2012
33b28bd
* Only emit contenteditable=false for IE7
audreyt Nov 6, 2012
d5a5eb6
make the table menu more usable
clkao Nov 6, 2012
9ab35b7
* Point .js to https-hosted github
audreyt Nov 15, 2012
282f7d4
fix deleting the sole character in a column
clkao Nov 16, 2012
f8a65a3
fix escapedJSON
clkao Nov 16, 2012
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/.DS_Store
node_modules/*
*.ep_initialized
*.swp
*.swo
4 changes: 2 additions & 2 deletions ep.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

},
"client_hooks" : {
"aceInitInnerdocbodyHead": "ep_tables/static/js/datatables:aceInitInnerdocbodyHead",
"aceInitInnerdocbodyHead": "ep_tables/static/js/datatables-ui.js:aceInitInnerdocbodyHead",
"collectContentLineBreak": "ep_tables/static/js/contentcollector:collectContentLineBreak",
"collectContentLineText": "ep_tables/static/js/contentcollector:collectContentLineText",
"aceKeyEvent": "ep_tables/static/js/datatables.js:aceKeyEvent",
Expand All @@ -18,7 +18,7 @@
"aceAttribsToClasses": "ep_tables/static/js/datatables.js:aceAttribsToClasses",
"acePostWriteDomLineHTML": "ep_tables/static/js/datatables:acePostWriteDomLineHTML",
"aceInitialized": "ep_tables/static/js/datatables:aceInitialized",
"postAceInit": "ep_tables/static/js/datatables:postAceInit",
"postAceInit": "ep_tables/static/js/datatables-ui.js:postAceInit",
"disableAuthorColorsForThisLine": "ep_tables/static/js/linestylefilter:disableAuthorColorsForThisLine"

}
Expand Down
24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"author": {
"name": ["Gedion Woldeselassie","Tenzin Tsetan"],
"name": [
"Gedion Woldeselassie",
"Tenzin Tsetan"
],
"email": "[email protected]"
},
"name": "ep_tables",
Expand All @@ -10,20 +13,15 @@
"type": "git",
"url": "git://github.com/gedion/ep_tables.git"
},
"scripts": {
"prepublish": "./node_modules/.bin/livescript -j package.ls > package.tmp &&\nmv package.tmp package.json &&\n./node_modules/.bin/livescript -bc -o static/js src/js"
},
"engines": {
"node": "*"
},
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
"_id": "[email protected]",
"_engineSupported": true,
"_npmVersion": "1.1.24",
"_nodeVersion": "v0.6.16",
"_defaultsLoaded": true,
"_from": "ep_tables",
"_npmUser": {
"name": "gedion",
"email": "[email protected]"
}
"devDependencies": {
"LiveScript": "1.1.x"
},
"optionalDependencies": {}
}
20 changes: 20 additions & 0 deletions package.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
author:
name: ['Gedion Woldeselassie', 'Tenzin Tsetan']
email: '[email protected]'
name: 'ep_tables'
description: 'Adds tables to etherpad-lite'
version: '0.1.1'
repository:
type: 'git'
url: 'git://github.com/gedion/ep_tables.git'
scripts:
prepublish: """
./node_modules/.bin/livescript -j package.ls > package.tmp &&
mv package.tmp package.json &&
./node_modules/.bin/livescript -bc -o static/js src/js
"""
engines: {node: '*'}
dependencies: {}
devDependencies:
LiveScript: \1.1.x
optionalDependencies: {}
30 changes: 30 additions & 0 deletions src/js/contentcollector.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exports.collectContentLineBreak = (hook, context) ->
tvalue = context.tvalue
breakLine = true
breakLine = false if tvalue and tvalue is 'tblBreak'
breakLine

exports.collectContentLineText = (hook, context) ->
n = context.node
txt = context.text
tblId = 1
if txt
while n
if n.tagName is 'TD'
elementName = n.getAttribute 'name'
if elementName is 'tData'
break
else
if elementName is 'delimCell'
txt = '\uF134,\uF134'
break
else
if elementName is 'payload'
txt = '{\uF134payload\uF134:[[\uF134'
break
else
if elementName is 'bracketAndcomma'
txt = "\uF134]],\uF134tblId\uF134:\uF134#{tblId}\uF134,\uF134tblClass\uF134:\uF134\uFFF9\uF134}"
break
n = n.parentNode
txt
152 changes: 152 additions & 0 deletions src/js/datatables-renderer.ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
DatatablesRenderer = {}
class DatatablesRenderer
@render = (params, element, code, attributes) ->
renderer = new DatatablesRenderer.Renderer
element.innerHTML = renderer.getHtml code, attributes

class @Renderer
->
createDefaultTblProperties: (authors) ->
{
borderWidth: '1'
cellAttrs: []
width: '6'
rowAttrs: {}
colAttrs: []
authors: {}
}
buildTabularData: (tblJSONObj, tblPropsJSString) ->
htmlTbl = ''
tblId = tblJSONObj.tblId
tblClass = tblJSONObj.tblClass
tdClass = tblJSONObj.tdClass
trClass = tblJSONObj.trClass
payload = tblJSONObj.payload
tblProperties = {}
try
tblProperties = JSON.parse tblPropsJSString
catch error
tblProperties = @createDefaultTblProperties!
rowAttrs = tblProperties.rowAttrs
singleRowAttrs = rowAttrs.singleRowAttrs
cellAttrs = tblProperties.cellAttrs
colAttrs = tblProperties.colAttrs
tblWidth = if typeof tblProperties is 'undefined' or not tblProperties? then '1' else tblProperties.width or '1'
tblWidth = @getAttrInInch tblWidth
tblHeight = if typeof tblProperties is 'undefined' or not tblProperties? then '.1' else tblProperties.height or '.1'
tblHeight = @getAttrInInch tblHeight
tblBorderWidth = if typeof tblProperties is 'undefined' or not tblProperties? then 0 else tblProperties.borderWidth or 0
tblBorderColor = if typeof tblProperties is 'undefined' or not tblProperties? then '#000000' else tblProperties.borderColor or '#000000'
currRow = tblProperties.currRowAuthorIdx
currCell = tblProperties.currCellAuthorIdx
authors = tblProperties.authors
printViewTBlStyles = 'table-layout:fixed !important;border-collapse:collapse!important;font-family:Trebuchet MS!important;'
printViewTblTDStyles = 'font-size: 1em!important;line-height: 1em!important;padding: 3px 7px 2px!important;word-wrap: break-word!important;'
htmlTbl = '<table class=\'' + tblClass + '\' style=\'' + printViewTBlStyles + 'background-color:white;width:' + tblWidth + 'px!important;height:' + tblHeight + 'px!important; border-top: ' + tblBorderWidth + 'px solid ' + tblBorderColor + '!important;' + '\'><tbody>'
borders = 'border-bottom:' + tblBorderWidth + 'px solid ' + tblBorderColor
rowVAlign = if typeof rowAttrs is 'undefined' or not rowAttrs? then 'left' else rowAttrs.rowVAlign or 'left'
rows = tblJSONObj.payload
evenRowBgColor = if typeof rowAttrs is 'undefined' or not rowAttrs? then '#FFFFFF' else rowAttrs.evenBgColor or '#FFFFFF'
oddRowBgColor = if typeof rowAttrs is 'undefined' or not rowAttrs? then null else rowAttrs.oddBgColor or null
j = 0
rl = rows.length
while j < rl
tds = rows[j]
rowBgColor = oddRowBgColor
rowBgColor = evenRowBgColor if not rowBgColor
htmlTbl += '<tr style=\'vertical-align:' + rowVAlign + ';background-color:' + rowBgColor + '; ' + borders + '!important;\' class=\'' + trClass + '\'>'
preHeader = ''
if j is 0 then preHeader = '{\uF134payload\uF134:[[\uF134'
htmlTbl += '<td name=\'payload\' class=\'hide-el overhead\'>' + preHeader + '</td>'
singleRowAttr = if typeof singleRowAttrs is 'undefined' or not singleRowAttrs? then null else singleRowAttrs[j]
i = 0
tl = tds.length
while i < tl
cellAttr = if typeof cellAttrs[j] is 'undefined' or not cellAttrs[j]? then null else cellAttrs[j][i]
cellStyles = @getCellAttrs singleRowAttr, cellAttr, colAttrs[i], authors, i, j
authorBorderColor = (@getCellAuthorColors authors, i, j, tblBorderWidth) + '!important;'
borderTop = ''
borderTop = ' border-top: 0px solid white !important;' if tblBorderWidth is 0
colVAlign = if typeof colAttrs[i] is 'undefined' or not colAttrs[i]? then '' else 'align=\'' + colAttrs[i].colVAlign + '\'' or ''
quoteAndComma = '\uF134,\uF134'
cellDel = ''
delimCell = '<td name=\'delimCell\' id=\'' + '\' class=\'hide-el overhead\'>' + quoteAndComma + '</td>'
lastCellBorder = ''
if i is tl - 1
delimCell = ''
lastCellBorder = 'border-right:' + tblBorderWidth + 'px solid ' + tblBorderColor + '!important;'
quoteAndComma = ''
if not ((tds[i].indexOf '/r/n') is -1)
cellsWithBr = ''
tdText = tds[i].split '/r/n'
k = 0
while k < tdText.length
if k < tdText.length - 1
cellsWithBr += tdText[k] + "<span value='tblBreak'#{
if $.browser.msie and $.browser.version <= 7 then " contenteditable='false'" else ""
} class='hide-el'>/r/n</span><label class='tblBreak'></label>"
else
cellsWithBr += tdText[k]
k++
htmlTbl += '<td name=\'tData\' ' + colVAlign + ' style=\'' + printViewTblTDStyles + cellStyles + ' border-left:' + tblBorderWidth + 'px solid ' + tblBorderColor + authorBorderColor + borderTop + lastCellBorder + '\' >' + cellsWithBr + '<br value=\'tblBreak\'></td>' + delimCell
else
htmlTbl += '<td name=\'tData\' ' + colVAlign + ' style=\'' + printViewTblTDStyles + cellStyles + lastCellBorder + ' border-left:' + tblBorderWidth + 'px solid ' + tblBorderColor + authorBorderColor + borderTop + '\' >' + tds[i] + '' + '<br value=\'tblBreak\'></td>' + delimCell
i++
bracketAndcomma = '\uF134]],\uF134tblId\uF134:\uF134' + tblId + '\uF134,\uF134tblClass\uF134:\uF134\uFFF9\uF134}'
htmlTbl += '<td name=\'bracketAndcomma\' class=\' hide-el overhead\'>' + bracketAndcomma + '</td>'
htmlTbl += '</tr>'
j++
htmlTbl += '</tbody></table>'
htmlTbl
getCellAuthorColors: (authors, cell, row, tblBorderWidth) ->
cellBorderColor = null
if typeof authors isnt 'undefined' and authors?
for authorId of authors
author = authors[authorId]
cellBorderColor = author.colorId if typeof author isnt 'undefined' and author? and author.cell is cell and author.row is row
borderWidth = if tblBorderWidth isnt 0 then tblBorderWidth else 1
cellBorderColor = if not cellBorderColor? then '' else ';border:' + borderWidth + 'px solid ' + cellBorderColor
cellBorderColor
getCellAttrs: (singleRowAttr, cellAttr, colAttr, authors, cell, row) ->
attrsJSO = {}
colWidth = if typeof colAttr is 'undefined' or not colAttr? then '1' else colAttr.width or '1'
attrsJSO.'width' = (@getAttrInInch colWidth) + 'px'
cellBgColor = ''
if typeof singleRowAttr isnt 'undefined' and singleRowAttr?
bgColor = singleRowAttr.bgColor
cellBgColor = bgColor if typeof bgColor isnt 'undefined' and bgColor? and bgColor isnt '#FFFFFF'
if typeof colAttr isnt 'undefined' and colAttr?
bgColor = colAttr.bgColor
cellBgColor = bgColor if typeof bgColor isnt 'undefined' and bgColor? and bgColor isnt '#FFFFFF'
cellBgColor = if typeof cellAttr is 'undefined' or not cellAttr? then cellBgColor else cellAttr.bgColor or cellBgColor
attrsJSO.'background-color' = cellBgColor
cellHeight = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.height or ''
attrsJSO.'height' = (@getAttrInInch cellHeight) + 'px'
cellPadding = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.padding or ''
attrsJSO.'padding-top' = attrsJSO.'padding-bottom' = attrsJSO.'padding-left' = attrsJSO.'padding-right' = (@getAttrInInch cellPadding) + 'px'
cellVAlign = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.vAlign or ''
attrsJSO.'vertical-align' = cellVAlign
cellFontSize = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.fontSize or ''
attrsJSO.'font-size' = cellFontSize + 'px'
cellFontWeight = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.fontWeight or ''
attrsJSO.'font-weight' = cellFontWeight
cellFontStyle = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.fontStyle or ''
attrsJSO.'font-style' = cellFontStyle
cellTextDecoration = if typeof cellAttr is 'undefined' or not cellAttr? then '' else cellAttr.textDecoration or ''
attrsJSO.'text-decoration' = cellTextDecoration
attrsString = ''
[attrsString += attrName + ':' + attrsJSO[attrName] + ' !important;' if attrName and attrsJSO[attrName] isnt '' and attrsJSO[attrName] isnt 'NaNpx' and attrsJSO[attrName] isnt 'px' for attrName of attrsJSO]
attrsString
getAttrInInch: (attrValue) ->
intAttrValue = 0
intAttrValue = parseFloat attrValue
attrValue = if isNaN intAttrValue then parseFloat attrValue else intAttrValue
96 * attrValue - 1
getHtml: (JSONCode, attributes) ->
html = ''
try
html = @buildTabularData JSONCode, attributes
catch
html

exports?DatatablesRenderer = DatatablesRenderer
Loading