diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..052212a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+**/.DS_Store
+node_modules/*
+*.ep_initialized
+*.swp
+*.swo
diff --git a/ep.json b/ep.json
index c4185e2..1f2a130 100644
--- a/ep.json
+++ b/ep.json
@@ -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",
@@ -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"
}
diff --git a/package.json b/package.json
index 931b323..56bbcdf 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,9 @@
{
"author": {
- "name": ["Gedion Woldeselassie","Tenzin Tsetan"],
+ "name": [
+ "Gedion Woldeselassie",
+ "Tenzin Tsetan"
+ ],
"email": "gwy321@gmail.com"
},
"name": "ep_tables",
@@ -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": "ep_tables@0.1.1",
- "_engineSupported": true,
- "_npmVersion": "1.1.24",
- "_nodeVersion": "v0.6.16",
- "_defaultsLoaded": true,
- "_from": "ep_tables",
- "_npmUser": {
- "name": "gedion",
- "email": "gwy321@gmail.com"
- }
+ "devDependencies": {
+ "LiveScript": "1.1.x"
+ },
+ "optionalDependencies": {}
}
diff --git a/package.ls b/package.ls
new file mode 100644
index 0000000..8cee5ba
--- /dev/null
+++ b/package.ls
@@ -0,0 +1,20 @@
+author:
+ name: ['Gedion Woldeselassie', 'Tenzin Tsetan']
+ email: 'gwy321@gmail.com'
+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: {}
diff --git a/src/js/contentcollector.ls b/src/js/contentcollector.ls
new file mode 100644
index 0000000..c8d8b14
--- /dev/null
+++ b/src/js/contentcollector.ls
@@ -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
diff --git a/src/js/datatables-renderer.ls b/src/js/datatables-renderer.ls
new file mode 100644
index 0000000..e4684c7
--- /dev/null
+++ b/src/js/datatables-renderer.ls
@@ -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 = '
'
+ 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 += ''
+ preHeader = ''
+ if j is 0 then preHeader = '{\uF134payload\uF134:[[\uF134'
+ htmlTbl += '' + preHeader + ' '
+ 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 = '' + quoteAndComma + ' '
+ 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] + "/r/n "
+ else
+ cellsWithBr += tdText[k]
+ k++
+ htmlTbl += '' + cellsWithBr + ' ' + delimCell
+ else
+ htmlTbl += '' + tds[i] + '' + ' ' + delimCell
+ i++
+ bracketAndcomma = '\uF134]],\uF134tblId\uF134:\uF134' + tblId + '\uF134,\uF134tblClass\uF134:\uF134\uFFF9\uF134}'
+ htmlTbl += '' + bracketAndcomma + ' '
+ htmlTbl += ' '
+ j++
+ htmlTbl += '
'
+ 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
diff --git a/src/js/datatables-ui.ls b/src/js/datatables-ui.ls
new file mode 100644
index 0000000..dbb64c2
--- /dev/null
+++ b/src/js/datatables-ui.ls
@@ -0,0 +1,504 @@
+exports.aceInitInnerdocbodyHead = (hook_name, args, cb) ->
+ args.iframeHTML.push ' '
+
+exports.postAceInit = (hook, context) ->
+ $.createTableMenu = (init) ->
+ showTblPropPanel = ->
+ if not $.tblPropDialog
+ $.tblPropDialog = new YAHOO.widget.Dialog 'yui-tbl-prop-panel', {
+ width: '600px'
+ height: '450px'
+ close: true
+ visible: false
+ zindex: 1001
+ constraintoviewport: true
+ }
+ $.tblPropDialog.setBody $.getTblPropertiesHTML!
+ $.tblPropDialog.render!
+ $.alignMenu $.tblPropDialog, @id
+ initTableProperties!
+ $.tblPropDialog.show!
+ createColorPicker = ->
+ createOColorPicker = ->
+ $.oColorPicker = new YAHOO.widget.ColorPicker 'color-picker-menu', {
+ showhsvcontrols: false
+ showrgbcontrols: false
+ showwebsafe: false
+ showhexsummary: false
+ showhexcontrols: true
+ images: {
+ PICKER_THUMB: 'https://raw.github.com/yui/yui2/master/build/colorpicker/assets/picker_thumb.png'
+ HUE_THUMB: 'https://raw.github.com/yui/yui2/master/build/colorpicker/assets/hue_thumb.png'
+ }
+ }
+ $.oColorPicker.on 'rgbChange', colorPickerButtonClick
+ $.colorPickerAligned = true
+ handleColorPickerSubmit = -> colorPickerButtonClick $.oColorPicker.get 'hex'
+ handleDialogCancel = -> @cancel!
+ $.oColorPickerDialog = new YAHOO.widget.Dialog 'yui-picker-panel', {
+ width: '500px'
+ close: true
+ visible: false
+ zindex: 1002
+ constraintoviewport: true
+ buttons: [{
+ text: 'Exit'
+ handler: @handleDialogCancel
+ }]
+ }
+ $.oColorPickerDialog.renderEvent.subscribe (-> createOColorPicker! if not $.oColorPicker)
+ $.oColorPickerDialog.render!
+ $.oColorPickerDialog.show!
+ colorPickerButtonClick = (sColor) ->
+ if typeof sColor is 'string' and sColor? and (sColor.indexOf '#') is -1
+ sColor = '#' + sColor
+ else
+ if typeof sColor is 'object' then sColor = if not (@get 'hex')? then @get 'value' else '#' + @get 'hex'
+ selParams = {
+ borderWidth: null
+ tblPropertyChange: true
+ }
+ switch $.tblfocusedProperty
+ case 'tbl_border_color'
+ selParams.tblBorderColor = true
+ selParams.attrName = 'borderColor'
+ $.borderColorPickerButton.set 'value', sColor
+ ($ '#current-color').css 'backgroundColor', sColor
+ ($ '#current-color').innerHTML = 'Current color is ' + sColor
+ case 'tbl_cell_bg_color'
+ selParams.tblCellBgColor = true
+ selParams.attrName = 'bgColor'
+ $.cellBgColorPickerButton.set 'value', sColor
+ ($ '#current-cell-bg-color').css 'backgroundColor', sColor
+ ($ '#current-cell-bg-color').innerHTML = 'Current color is ' + sColor
+ case 'tbl_even_row_bg_color'
+ selParams.tblEvenRowBgColor = true
+ selParams.attrName = 'evenBgColor'
+ $.evenRowBgColorPickerButton.set 'value', sColor
+ ($ '#even-row-bg-color').css 'backgroundColor', sColor
+ ($ '#even-row-bg-color').innerHTML = 'Current color is ' + sColor
+ case 'tbl_odd_row_bg_color'
+ selParams.tblOddRowBgColor = true
+ selParams.attrName = 'oddBgColor'
+ $.oddRowBgColorPickerButton.set 'value', sColor
+ ($ '#odd-row-bg-color').css 'backgroundColor', sColor
+ ($ '#odd-row-bg-color').innerHTML = 'Current color is ' + sColor
+ case 'tbl_single_row_bg_color'
+ selParams.tblSingleRowBgColor = true
+ selParams.attrName = 'bgColor'
+ $.singleRowBgColorPickerButton.set 'value', sColor
+ ($ '#single-row-bg-color').css 'backgroundColor', sColor
+ ($ '#single-row-bg-color').innerHTML = 'Current color is ' + sColor
+ case 'tbl_single_col_bg_color'
+ selParams.tblSingleColBgColor = true
+ selParams.attrName = 'bgColor'
+ $.singleColBgColorPickerButton.set 'value', sColor
+ ($ '#single-col-bg-color').css 'backgroundColor', sColor
+ ($ '#single-col-bg-color').innerHTML = 'Current color is ' + sColor
+ selParams.attrValue = sColor
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true
+ top.templatesMenu.hide! if not (typeof top.templatesMenu is 'undefined')
+ if $.tblContextMenu
+ $.alignMenu $.tblContextMenu, 'tbl-menu'
+ $.tblContextMenu.show!
+ return
+ $.handleTableBorder = (selectValue) ->
+ selParams = {
+ tblBorderWidth: true
+ attrName: 'borderWidth'
+ attrValue: selectValue
+ tblPropertyChange: true
+ }
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true
+ $.getTblPropertiesHTML = ->
+ ' ' + ' ' + '' + '' + ' '
+ if typeof $.tblContextMenu is 'undefined'
+ initTableProperties = ->
+ colVAligns = [
+ 'Left'
+ 'Center'
+ 'Right'
+ ]
+ $.colVAlignsMenu = new YAHOO.widget.ContextMenu 'tbl_col_v_align_menu', {
+ iframe: true
+ zindex: 1003
+ shadow: false
+ position: 'dynamic'
+ keepopen: true
+ clicktohide: true
+ }
+ $.colVAlignsMenu.addItems colVAligns
+ $.colVAlignsMenu.render document.body
+ $.colVAlignsMenu.subscribe 'click', (p_sType, p_aArgs) ->
+ oEvent = p_aArgs.0
+ oMenuItem = p_aArgs.1
+ if oMenuItem
+ align = oMenuItem.cfg.getProperty 'text'
+ selParams = {
+ tblColVAlign: true
+ attrName: 'colVAlign'
+ attrValue: align
+ tblPropertyChange: true
+ }
+ $.colVAlignsMenuButton.set 'value', selParams.attrValue
+ ($ '#current-col-v-alignment').html align
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true
+ $.colVAlignsMenuButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Left '
+ container: 'tbl_col_v_align'
+ }
+ ($ '#tbl_col_v_align').click (->
+ aligned = false
+ $.alignMenu $.colVAlignsMenu, 'tbl_col_v_align' if not aligned
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ if $.oColorPickerDialog then $.oColorPickerDialog.hide!
+ $.colVAlignsMenu.show!
+ vAlignValue = $.colVAlignsMenuButton.get 'value'
+ if vAlignValue
+ selParams = {
+ tblColVAlign: true
+ attrName: 'colVAlign'
+ attrValue: vAlignValue
+ tblPropertyChange: true
+ }
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true)
+ rowVAligns = [
+ 'Top'
+ 'Center'
+ 'Bottom'
+ ]
+ $.rowVAlignsMenu = new YAHOO.widget.ContextMenu 'tbl_row_v_align_menu', {
+ iframe: true
+ zindex: 1003
+ shadow: false
+ position: 'dynamic'
+ keepopen: true
+ clicktohide: true
+ }
+ $.rowVAlignsMenu.addItems rowVAligns
+ $.rowVAlignsMenu.render document.body
+ $.rowVAlignsMenu.subscribe 'click', (p_sType, p_aArgs) ->
+ oEvent = p_aArgs.0
+ oMenuItem = p_aArgs.1
+ if oMenuItem
+ align = oMenuItem.cfg.getProperty 'text'
+ selParams = {
+ tblRowVAlign: true
+ attrName: 'rowVAlign'
+ attrValue: align
+ tblPropertyChange: true
+ }
+ $.rowVAlignsMenuButton.set 'value', selParams.attrValue
+ ($ '#current-v-alignment').html align
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true
+ $.rowVAlignsMenuButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Top '
+ container: 'tbl_row_v_align'
+ }
+ ($ '#tbl_row_v_align').click (->
+ aligned = false
+ $.alignMenu $.rowVAlignsMenu, 'tbl_row_v_align' if not aligned
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ if $.oColorPickerDialog then $.oColorPickerDialog.hide!
+ $.rowVAlignsMenu.show!
+ vAlignValue = $.rowVAlignsMenuButton.get 'value'
+ if vAlignValue
+ selParams = {
+ tblRowVAlign: true
+ attrName: 'rowVAlign'
+ attrValue: vAlignValue
+ tblPropertyChange: true
+ }
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true)
+ borderWidths = [
+ '0px'
+ '1px'
+ '2px'
+ '3px'
+ '4px'
+ '5px'
+ '6px'
+ '7px'
+ '8px'
+ ]
+ $.borderWidthsMenu = new YAHOO.widget.ContextMenu 'tbl_border_width_menu', {
+ iframe: true
+ zindex: 1003
+ shadow: false
+ position: 'dynamic'
+ keepopen: true
+ clicktohide: true
+ }
+ $.borderWidthsMenu.addItems borderWidths
+ $.borderWidthsMenu.render document.body
+ $.borderWidthsMenu.subscribe 'click', (p_sType, p_aArgs) ->
+ oEvent = p_aArgs.0
+ oMenuItem = p_aArgs.1
+ if oMenuItem
+ borderReq = oMenuItem.cfg.getProperty 'text'
+ selParams = {
+ tblBorderWidth: true
+ attrName: 'borderWidth'
+ attrValue: borderReq.substring 0, borderReq.indexOf 'px'
+ tblPropertyChange: true
+ }
+ $.borderWidthPickerButton.set 'value', selParams.attrValue
+ ($ '#current-width').html borderReq
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true
+ $.borderWidthPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: '1px '
+ container: 'tbl_border_width'
+ }
+ ($ '#tbl_border_width').click (->
+ aligned = false
+ $.alignMenu $.borderWidthsMenu, 'tbl_border_width' if not aligned
+ if $.oColorPickerDialog then $.oColorPickerDialog.hide!
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ $.borderWidthsMenu.show!
+ widthValue = $.borderWidthPickerButton.get 'value'
+ if widthValue
+ selParams = {
+ tblBorderWidth: true
+ attrName: 'borderWidth'
+ attrValue: widthValue
+ tblPropertyChange: true
+ }
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true)
+ $.tblfocusedProperty = ''
+ ($ '#tbl_properties').click (->
+ $.borderWidthsMenu.hide! if not (typeof $.borderWidthsMenu is 'undefined')
+ if not (typeof $.oColorPickerDialog is 'undefined') then $.oColorPickerDialog.hide!
+ if not (typeof $.rowVAlignsMenu is 'undefined') then $.rowVAlignsMenu.hide!)
+ $.colorPickerAligned = false
+ ($ '#tbl_border_color').click (->
+ createColorPicker! if not $.colorPickerAligned
+ $.alignMenu $.oColorPickerDialog, 'tbl_border_color'
+ $.tblfocusedProperty = 'tbl_border_color'
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ $.oColorPickerDialog.setHeader 'Please choose a color for: Table Border color'
+ $.oColorPickerDialog.show!
+ hexValue = $.borderColorPickerButton.get 'value'
+ if hexValue then colorPickerButtonClick hexValue)
+ $.borderColorPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Current color is #FFFFFF. '
+ container: 'tbl_border_color'
+ }
+ $.cellBgColorPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Current color is #FFFFFF. '
+ container: 'tbl_cell_bg_color'
+ }
+ ($ '#tbl_cell_bg_color').click (->
+ createColorPicker! if not $.colorPickerAligned
+ $.alignMenu $.oColorPickerDialog, 'tbl_cell_bg_color'
+ $.tblfocusedProperty = 'tbl_cell_bg_color'
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ $.oColorPickerDialog.setHeader 'Please choose a color for: Cell Background color'
+ $.oColorPickerDialog.show!
+ hexValue = $.cellBgColorPickerButton.get 'value'
+ if hexValue then colorPickerButtonClick hexValue)
+ $.evenRowBgColorPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Current color is #FFFFFF. '
+ container: 'tbl_even_row_bg_color'
+ }
+ ($ '#tbl_even_row_bg_color').click (->
+ createColorPicker! if not $.colorPickerAligned
+ $.alignMenu $.oColorPickerDialog, 'tbl_even_row_bg_color'
+ $.tblfocusedProperty = 'tbl_even_row_bg_color'
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ $.oColorPickerDialog.setHeader 'Please choose a color for: Even Row Background color'
+ $.oColorPickerDialog.show!
+ hexValue = $.evenRowBgColorPickerButton.get 'value'
+ if hexValue then colorPickerButtonClick hexValue)
+ $.oddRowBgColorPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Current color is #FFFFFF. '
+ container: 'tbl_odd_row_bg_color'
+ }
+ ($ '#tbl_odd_row_bg_color').click (->
+ createColorPicker! if not $.colorPickerAligned
+ $.alignMenu $.oColorPickerDialog, 'tbl_odd_row_bg_color'
+ $.tblfocusedProperty = 'tbl_odd_row_bg_color'
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ $.oColorPickerDialog.setHeader 'Please choose a color for: Odd Row Background color'
+ $.oColorPickerDialog.show!
+ hexValue = $.oddRowBgColorPickerButton.get 'value'
+ if hexValue then colorPickerButtonClick hexValue)
+ $.singleRowBgColorPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Current color is #FFFFFF. '
+ container: 'tbl_single_row_bg_color'
+ }
+ ($ '#tbl_single_row_bg_color').click (->
+ createColorPicker! if not $.colorPickerAligned
+ $.alignMenu $.oColorPickerDialog, 'tbl_single_row_bg_color'
+ $.tblfocusedProperty = 'tbl_single_row_bg_color'
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ $.oColorPickerDialog.setHeader 'Please choose a color for: Single Row Background color'
+ $.oColorPickerDialog.show!
+ hexValue = $.singleRowBgColorPickerButton.get 'value'
+ if hexValue then colorPickerButtonClick hexValue)
+ $.singleColBgColorPickerButton = new YAHOO.widget.Button {
+ disabled: false
+ type: 'split'
+ label: 'Current color is #FFFFFF. '
+ container: 'tbl_single_col_bg_color'
+ }
+ ($ '#tbl_single_col_bg_color').click (->
+ createColorPicker! if not $.colorPickerAligned
+ $.alignMenu $.oColorPickerDialog, 'tbl_single_col_bg_color'
+ $.tblfocusedProperty = 'tbl_single_col_bg_color'
+ if $.rowVAlignsMenu then $.rowVAlignsMenu.hide!
+ if $.borderWidthsMenu then $.borderWidthsMenu.hide!
+ $.oColorPickerDialog.setHeader 'Please choose a color for: Single Column Background color'
+ $.oColorPickerDialog.show!
+ hexValue = $.singleColBgColorPickerButton.get 'value'
+ if hexValue then colorPickerButtonClick hexValue)
+ ($ '.text-input').change (->
+ selParams = {tblPropertyChange: true}
+ if @id is 'tbl_width'
+ selParams.tblWidth = true
+ selParams.attrName = 'width'
+ else
+ if @id is 'tbl_height'
+ selParams.tblHeight = true
+ selParams.attrName = 'height'
+ else
+ if @id is 'tbl_col_width'
+ selParams.tblColWidth = true
+ selParams.attrName = 'width'
+ else
+ if @id is 'tbl_row_height'
+ selParams.tblCellHeight = true
+ selParams.attrName = 'height'
+ else
+ if @id is 'tbl_cell_padding'
+ selParams.tblCellPadding = true
+ selParams.attrName = 'padding'
+ else
+ if @id is 'tbl_cell_font_size'
+ selParams.tblCellFontSize = true
+ selParams.attrName = 'fontSize'
+ else
+ if @id is 'img_width'
+ selParams.imgWidth = true
+ selParams.attrName = 'width'
+ else
+ if @id is 'img_height'
+ selParams.imgHeight = true
+ selParams.attrName = 'height'
+ selParams.attrValue = @value
+ @value = ''
+ ($ '#text_input_message').text 'Ok'
+ ($ '#text_input_message').removeAttr 'style'
+ ($ '#text_input_message').fadeOut 'slow'
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions selParams), 'tblOptions', true)
+ matrixTable = ''
+ $.tblContextMenu = new YAHOO.widget.ContextMenu 'tbl_context_menu', {
+ iframe: true
+ zindex: 500
+ shadow: false
+ position: 'dynamic'
+ clicktohide: true
+ }
+ $.tblContextMenu.addItems [
+ [{
+ text: 'Insert Table'
+ submenu: {
+ id: 'tbl_insert'
+ itemData: ['0 X 0
']
+ }
+ }]
+ [
+ 'Insert Row Above'
+ 'Insert Row Below'
+ 'Insert Column Right'
+ 'Insert Column Left'
+ ]
+ [
+ 'Delete Row'
+ 'Delete Column'
+ 'Delete Table'
+ ]
+ ]
+ subMenus = $.tblContextMenu.getSubmenus!
+ subMenus.0.setFooter matrixTable
+ $.tblContextMenu.render document.body
+ $.alignMenu = (menu, id, addX, addY, scrollY) ->
+ region = YAHOO.util.Dom.getRegion id
+ if typeof id is 'string' and (id is 'tbl-menu' or id is 'upload_image_cont')
+ menu.cfg.setProperty 'xy', [region.left, region.bottom]
+ else
+ if typeof id is 'string' then menu.cfg.setProperty 'xy', [region.right, region.top] else menu.cfg.setProperty 'xy', [30 + addX, 36 + addY - scrollY]
+ ($ 'table td').hover (->
+ x = 0
+ while x <= ($ this).index!
+ y = 0
+ while y <= ($ this).parent!.index!
+ ((($ this).parent!.parent!.children!.eq y).children!.eq x).addClass 'selected'
+ y++
+ x++), -> ($ 'table td').removeClass 'selected'
+ ($ 'table td').hover (->
+ xVal = @getAttribute 'value'
+ yVal = (($ this).closest 'tr').0.getAttribute 'value'
+ ($ '#select_matrix').html xVal + ' X ' + yVal)
+ ($ 'td', '#matrix_table').click ((e) ->
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions 'addTbl', 'addTblX' + ($ '#select_matrix').text!), 'tblOptions', true
+ $.tblContextMenu.hide!
+ false)
+ $.tblContextMenu.subscribe 'click', (p_sType, p_aArgs) ->
+ oEvent = p_aArgs.0
+ oMenuItem = p_aArgs.1
+ if oMenuItem
+ tblReq = oMenuItem.cfg.getProperty 'text'
+ disabled = oMenuItem.cfg.getProperty 'disabled'
+ return if disabled
+ id = ''
+ switch tblReq
+ case 'Insert Table'
+ id = 'addTbl'
+ case 'Insert Row Above'
+ id = 'addTblRowA'
+ case 'Insert Row Below'
+ id = 'addTblRowB'
+ case 'Insert Column Left'
+ id = 'addTblColL'
+ case 'Insert Column Right'
+ id = 'addTblColR'
+ case 'Delete Table'
+ id = 'delTbl'
+ case 'Delete Image'
+ id = 'delImg'
+ case 'Delete Row'
+ id = 'delTblRow'
+ case 'Delete Column'
+ id = 'delTblCol'
+ context.ace.callWithAce ((ace) -> ace.ace_doDatatableOptions id), 'tblOptions', true
+ $.tblContextMenu.hide!
+ false
+ if not init
+ $.alignMenu $.tblContextMenu, 'tbl-menu'
+ $.tblContextMenu.show!
+ ($ '#tbl-menu').click $.createTableMenu
+ YAHOO.util.Dom.addClass document.body, 'yui-skin-sam'
+ ($ 'body').append $ '' + '
Please choose a color:
' + '
' + '\t' + '
' + '
' + '
'
+ ($ 'body').append $ '' + '
Table/Image Properties
' + '
' + '
' + '
'
+ $.createTableMenu true
diff --git a/src/js/datatables.ls b/src/js/datatables.ls
new file mode 100644
index 0000000..6d44e4b
--- /dev/null
+++ b/src/js/datatables.ls
@@ -0,0 +1,974 @@
+_ = require 'ep_etherpad-lite/static/js/underscore'
+
+if not (typeof require is 'undefined')
+ Ace2Common = require 'ep_etherpad-lite/static/js/ace2_common' if typeof Ace2Common is 'undefined'
+ if typeof Changeset is 'undefined' then Changeset = require 'ep_etherpad-lite/static/js/Changeset'
+
+escapedJSON = ->
+ ret = JSON.stringify it
+ .replace /\\u(....)|\\(.)/g (_, _1, _2) ->
+ if _1
+ String.fromCharCode parseInt _1, 16
+ else
+ "\\"+_2.charCodeAt(0)+\;
+ .replace /"/g '\uF134'
+ .replace /\\(\d+);/g (_, _1) -> "\\"+String.fromCharCode(_1)
+ #console.log ret
+ #console.trace ret
+ ret
+
+fromEscapedJSON = ->
+ ret = JSON.parse it.replace(/(\\|")/g, '\\$1').replace(/\uF134/g, '"')
+ #console.log ret
+ #console.trace \fromEscape
+ ret
+
+exports.aceInitialized = (hook, context) ->
+ editorInfo = context.editorInfo
+ editorInfo.ace_doDatatableOptions = (_ Datatables.doDatatableOptions).bind context
+
+exports.acePostWriteDomLineHTML = (hook_name, {node}, cb) ->
+ lineText = $(node)text!
+ if lineText and (lineText.indexOf '\uFFF9') isnt -1
+ dtAttrs = if typeof exports.Datatables isnt 'undefined' then exports.Datatables.attributes else null
+ dtAttrs = dtAttrs or ''
+ code = fromEscapedJSON lineText
+ DatatablesRenderer.render {}, node, code, dtAttrs
+ exports.Datatables.lastTblId >?= code.tblId
+ exports.Datatables.attributes = null
+
+exports.eejsBlock_scripts = (hook_name, args, cb) ->
+ args.content = args.content + (require 'ep_etherpad-lite/node/eejs/').require 'ep_tables/templates/datatablesScripts.ejs'
+
+exports.eejsBlock_editbarMenuLeft = (hook_name, args, cb) ->
+ args.content = args.content + (require 'ep_etherpad-lite/node/eejs/').require 'ep_tables/templates/datatablesEditbarButtons.ejs'
+
+exports.eejsBlock_styles = (hook_name, args, cb) ->
+ args.content = ((require 'ep_etherpad-lite/node/eejs/').require 'ep_tables/templates/styles.ejs') + args.content
+
+exports.aceAttribsToClasses = (hook, context) ->
+ Datatables.attributes = null
+ if context.key is 'tblProp'
+ Datatables.attributes = context.value
+ ['tblProp:' + context.value]
+
+exports.aceStartLineAndCharForPoint = (hook, context) ->
+ selStart = null
+ try
+ Datatables.context = context
+ selStart = Datatables.getLineAndCharForPoint! if Datatables.isFocused!
+ catch error
+ top.console.log 'error ' + error
+ top.console.log 'context rep' + Datatables.context.rep
+ selStart
+
+_stylesDisabled = false
+
+enableStyles = ->
+ return unless _stylesDisabled
+ $(\#editbar)find('li[data-key]')each ->
+ el = $ @
+ key = el.data \keyOrig
+ el.data(\key, key).attr('data-key', key)
+ _stylesDisabled := false
+
+disableStyles = ->
+ return if _stylesDisabled
+ # note that pad_editbar.js uses attr, so just clearing data('key') doesn't work
+ $(\#editbar)find('li[data-key]')each ->
+ el = $ @
+ key = el.data \key
+ el.data(\keyOrig, key)data(\key, null)attr('data-key', '')
+ _stylesDisabled := true
+
+exports.aceEndLineAndCharForPoint = (hook, context) ->
+ selEndLine = null
+ try
+ Datatables.context = context
+ if Datatables.isFocused!
+ disableStyles!
+ selEndLine = Datatables.getLineAndCharForPoint!
+ else
+ enableStyles!
+ catch error
+ top.console.log 'error ' + error
+ top.console.log 'context rep' + Datatables.context.rep
+ selEndLine
+
+exports.aceKeyEvent = (hook, context) ->
+ specialHandled = false
+ try
+ Datatables.context = context
+ if Datatables.isFocused!
+ evt = context.evt
+ type = evt.type
+ keyCode = evt.keyCode
+ isTypeForSpecialKey = if Ace2Common.browser.msie or Ace2Common.browser.safari then type is 'keydown' else type is 'keypress'
+ isTypeForCmdKey = if Ace2Common.browser.msie or Ace2Common.browser.safari then type is 'keydown' else type is 'keypress'
+ which = evt.which
+ if not specialHandled and isTypeForSpecialKey and keyCode is 9 and not (evt.metaKey or evt.ctrlKey)
+ context.editorInfo.ace_fastIncorp 5
+ evt.preventDefault!
+ Datatables.performDocumentTableTabKey!
+ specialHandled = true
+ if not specialHandled and isTypeForSpecialKey and keyCode is 13
+ context.editorInfo.ace_fastIncorp 5
+ evt.preventDefault!
+ Datatables.doReturnKey!
+ specialHandled = true
+ if not specialHandled and isTypeForSpecialKey and (keyCode is Datatables.vars.JS_KEY_CODE_DEL or keyCode is Datatables.vars.JS_KEY_CODE_BS or (String.fromCharCode which).toLowerCase! is 'h' and evt.ctrlKey)
+ context.editorInfo.ace_fastIncorp 20
+ evt.preventDefault!
+ specialHandled = true
+ Datatables.doDeleteKey! if Datatables.isCellDeleteOk keyCode
+ catch
+ specialHandled
+
+class Datatables
+ nodeText = ({childNodes}) ->
+ excluded = do
+ noscript: 'noscript'
+ script: 'script'
+ text = for el in childNodes
+ if el.nodeType is 1 and el.tagName.toLowerCase! not of excluded
+ nodeText el
+ else if el.nodeType is 3
+ el.data
+ text.join ''
+ @lastTblId = 0
+ @defaults= {tblProps: {
+ borderWidth: '1'
+ cellAttrs: []
+ width: '6'
+ rowAttrs: {}
+ colAttrs: []
+ authors: {}
+ }}
+ @config= {}
+ @vars= {
+ OVERHEAD_LEN_PRE: '{\uF134payload\uF134:[[\uF134'.length
+ OVERHEAD_LEN_MID: '\uF134,\uF134'.length
+ OVERHEAD_LEN_ROW_START: '[\uF134'.length
+ OVERHEAD_LEN_ROW_END: '\uF134],'.length
+ JS_KEY_CODE_BS: 8
+ JS_KEY_CODE_DEL: 46
+ TBL_OPTIONS: [
+ 'addTbl'
+ 'addTblRowA'
+ 'addTblRowB'
+ 'addTblColL'
+ 'addTblColR'
+ 'delTbl'
+ 'delTblRow'
+ 'delTblCol'
+ 'delImg'
+ ]
+ }
+ @context= null
+ @isFocused = ->
+ return false if not @context.rep.selStart or not @context.rep.selEnd
+ line = try @context.rep.lines.atIndex @context.rep.selStart.0
+ if not line then return false
+ currLineText = line.text or ''
+ if (currLineText.indexOf '\uFFF9') is -1 then return false
+ true
+ @_getRowEndOffset = (rowStartOffset, tds) ->
+ rowEndOffset = rowStartOffset + @vars.OVERHEAD_LEN_ROW_START
+ i = 0
+ len = tds.length
+ while i < len
+ overHeadLen = @vars.OVERHEAD_LEN_MID
+ overHeadLen = @vars.OVERHEAD_LEN_ROW_END if i is len - 1
+ rowEndOffset += tds[i].length + overHeadLen
+ i++
+ rowEndOffset
+ @getFocusedTdInfo = (payload, colStart) ->
+ payloadOffset = colStart - @vars.OVERHEAD_LEN_PRE
+ rowStartOffset = 0
+ payloadSum = 0
+ rIndex = 0
+ rLen = payload.length
+ while rIndex < rLen
+ tds = payload[rIndex]
+ tIndex = 0
+ tLen = tds.length
+ while tIndex < tLen
+ overHeadLen = @vars.OVERHEAD_LEN_MID
+ overHeadLen = @vars.OVERHEAD_LEN_ROW_END if tIndex is tLen - 1
+ payloadSum += tds[tIndex].length + overHeadLen
+ if payloadSum >= payloadOffset
+ tIndex++ if payloadSum is payloadOffset
+ leftOverTdTxtLen = if payloadSum - payloadOffset is 0 then payload[rIndex][tIndex].length + @vars.OVERHEAD_LEN_MID else payloadSum - payloadOffset
+ cellCaretPos = tds[tIndex].length - leftOverTdTxtLen - overHeadLen
+ rowEndOffset = @_getRowEndOffset rowStartOffset, tds
+ return {
+ row: rIndex
+ td: tIndex
+ leftOverTdTxtLen: leftOverTdTxtLen
+ rowStartOffset: rowStartOffset
+ rowEndOffset: rowEndOffset
+ cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen
+ cellEndOffset: payloadSum
+ cellCaretPos: cellCaretPos
+ }
+ tIndex++
+ rowStartOffset = payloadSum
+ payloadSum += @vars.OVERHEAD_LEN_ROW_START
+ rIndex++
+ @printCaretPos = (start, end) ->
+ top.console.log JSON.stringify start
+ top.console.log JSON.stringify end
+ @doDatatableOptions = (cmd, xByY) ->
+ Datatables.context = this
+ if typeof cmd is 'object' and cmd.tblPropertyChange
+ Datatables.updateTableProperties cmd
+ else
+ switch cmd
+ case Datatables.vars.TBL_OPTIONS.0
+ Datatables.addTable xByY
+ case Datatables.vars.TBL_OPTIONS.1
+ Datatables.insertTblRow 'addA'
+ case Datatables.vars.TBL_OPTIONS.2
+ Datatables.insertTblRow 'addB'
+ case Datatables.vars.TBL_OPTIONS.3
+ Datatables.insertTblColumn 'addL'
+ case Datatables.vars.TBL_OPTIONS.4
+ Datatables.insertTblColumn 'addR'
+ case Datatables.vars.TBL_OPTIONS.5
+ Datatables.deleteTable!
+ case Datatables.vars.TBL_OPTIONS.6
+ Datatables.deleteTblRow!
+ case Datatables.vars.TBL_OPTIONS.7
+ Datatables.deleteTblColumn!
+ @addTable = (tableObj) ->
+ rep = @context.rep
+ start = rep.selStart
+ end = rep.selEnd
+ line = rep.lines.atIndex rep.selStart.0
+ hasMoreRows = null
+ isRowAddition = null
+ if tableObj
+ hasMoreRows = tableObj.hasMoreRows
+ isRowAddition = tableObj.isRowAddition
+ if isRowAddition
+ table = fromEscapedJSON tableObj.tblString
+ insertTblRowBelow 0, table
+ performDocApplyTblAttrToRow rep.selStart, JSON.stringify table.tblProperties
+ return
+ if line
+ currLineText = line.text
+ if currLineText.indexOf('\uFFF9') isnt -1
+ do
+ rep.selStart.0 = rep.selStart.0 + 1
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ while currLineText.indexOf('\uFFF9') isnt -1
+ rep.selEnd.1 = rep.selStart.1 = currLineText.length
+ @context.editorInfo.ace_doReturnKey!
+ @context.editorInfo.ace_doReturnKey!
+ else
+ rep.selEnd.1 = rep.selStart.1 = currLineText.length
+ @context.editorInfo.ace_doReturnKey!
+ if not tableObj?
+ authors = {}
+ @insertTblRowBelow 3
+ @performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties!
+ @insertTblRowBelow 3
+ @performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties authors
+ @insertTblRowBelow 3
+ @performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties authors
+ @context.editorInfo.ace_doReturnKey!
+ @updateAuthorAndCaretPos rep.selStart.0 - 3
+ return
+ xByYSelect = if typeof tableObj is 'object' then null else tableObj.split 'X'
+ if xByYSelect? and xByYSelect.length is 3
+ cols = parseInt xByYSelect.1
+ rows = parseInt xByYSelect.2
+ jsoStrTblProp = JSON.stringify @createDefaultTblProperties!
+ authors = {}
+ i = 0
+ table = {}
+ while i < rows
+ @insertTblRowBelow cols, table
+ if i is 0 then @performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties! else @performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties authors
+ i++
+ @updateAuthorAndCaretPos rep.selStart.0 - rows + 1
+ return
+ newText
+ @insertTblRow = (aboveOrBelow) ->
+ func = 'insertTblRow()'
+ rep = @context.rep
+ try
+ newText = ''
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ {payload,tblId} = (fromEscapedJSON currLineText)
+ currTdInfo = @getFocusedTdInfo payload, rep.selStart.1
+ currRow = currTdInfo.row
+ lastRowOffSet = 0
+ start = []
+ end = []
+ start.0 = rep.selStart.0
+ start.1 = rep.selStart.1
+ end.0 = rep.selStart.0
+ end.1 = rep.selStart.1
+ if aboveOrBelow is 'addA'
+ rep.selStart.0 = rep.selEnd.0 = rep.selStart.0 - 1
+ @insertTblRowBelow payload.0.length, {tblId}
+ else
+ @insertTblRowBelow payload.0.length, {tblId}
+ @context.editorInfo.ace_performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties!
+ @updateAuthorAndCaretPos rep.selStart.0
+ updateEvenOddBgColor = true
+ @sanitizeTblProperties rep.selStart, updateEvenOddBgColor
+ catch
+ @deleteTable = ->
+ rep = @context.rep
+ func = 'deleteTable()'
+ start = rep.seStart
+ end = rep.seEnd
+ try
+ line = rep.selStart.0 - 1
+ numOfLinesAbove = 0
+ numOfLinesBelow = 0
+ while not (((rep.lines.atIndex line).text.indexOf '\uFFF9') is -1)
+ numOfLinesAbove++
+ line--
+ line = rep.selEnd.0 + 1
+ while not (((rep.lines.atIndex line).text.indexOf '\uFFF9') is -1)
+ numOfLinesBelow++
+ line++
+ rep.selStart.1 = 0
+ rep.selStart.0 = rep.selStart.0 - numOfLinesAbove
+ rep.selEnd.0 = rep.selEnd.0 + numOfLinesBelow
+ rep.selEnd.1 = (rep.lines.atIndex rep.selEnd.0).text.length
+ @context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ catch
+ @deleteTblRow = ->
+ func = 'deleteTblRow()'
+ rep = @context.rep
+ try
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ return if (currLineText.indexOf '\uFFF9') is -1
+ rep.selEnd.0 = rep.selStart.0 + 1
+ rep.selStart.1 = 0
+ rep.selEnd.1 = 0
+ @context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ if (currLineText.indexOf '\uFFF9') is -1 then return
+ @updateAuthorAndCaretPos rep.selStart.0, 0, 0
+ updateEvenOddBgColor = true
+ @sanitizeTblProperties rep.selStart, updateEvenOddBgColor
+ catch
+ @updateTableProperties = (props) ->
+ rep = @context.rep
+ currTd = null
+ if props.tblColWidth or props.tblSingleColBgColor or props.tblColVAlign
+ currLine = rep.lines.atIndex rep.selStart.0
+ currLineText = currLine.text
+ tblJSONObj = fromEscapedJSON currLineText
+ payload = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo payload, rep.selStart.1
+ currTd = currTdInfo.td
+ if props.tblWidth or props.tblHeight or props.tblBorderWidth or props.tblBorderColor or props.tblColWidth or props.tblSingleColBgColor or props.tblEvenRowBgColor or props.tblOddRowBgColor or props.tblColVAlign
+ start = []
+ start.0 = rep.selStart.0
+ start.1 = rep.selStart.1
+ numOfLinesAbove = @getTblAboveRowsFromCurFocus start
+ tempStart = []
+ tempStart.0 = start.0 - numOfLinesAbove
+ tempStart.1 = start.1
+ while tempStart.0 < rep.lines.length! and ((rep.lines.atIndex tempStart.0).text.indexOf '\uFFF9') isnt -1
+ if props.tblEvenRowBgColor and tempStart.0 % 2 isnt 0
+ tempStart.0 = tempStart.0 + 1
+ continue
+ else
+ if props.tblOddRowBgColor and tempStart.0 % 2 is 0
+ tempStart.0 = tempStart.0 + 1
+ continue
+ @updateTablePropertiesHelper props, tempStart, currTd
+ tempStart.0 = tempStart.0 + 1
+ else
+ start = []
+ start.0 = rep.selStart.0
+ start.1 = rep.selStart.1
+ @updateTablePropertiesHelper props, start, currTd
+ @addCellAttr = (start, tblJSONObj, tblProperties, attrName, attrValue) ->
+ rep = @context.rep
+ payload = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo payload, start.1
+ currRow = currTdInfo.row
+ currTd = currTdInfo.td
+ cellAttrs = tblProperties.cellAttrs
+ row = cellAttrs[currRow]
+ row = [] if not row? or typeof row is 'undefined'
+ cell = row[currTd]
+ if not cell? or typeof cell is 'undefined' then cell = {}
+ if attrName is 'fontWeight' or attrName is 'fontStyle' or attrName is 'textDecoration' then attrValue = '' if cell[attrName] is attrValue else if cell[attrName] is attrValue then return false
+ cell[attrName] = attrValue
+ row[currTd] = cell
+ cellAttrs[currRow] = row
+ tblProperties.cellAttrs = cellAttrs
+ tblProperties
+ @addRowAttr = (tblJSONObj, tblProperties, attrName, attrValue) ->
+ rep = @context.rep
+ rowAttrs = tblProperties.rowAttrs
+ if attrName is 'bgColor'
+ payload = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo payload, rep.selStart.1
+ currRow = currTdInfo.row
+ singleRowAttrs = rowAttrs.singleRowAttrs
+ singleRowAttrs = [] if not singleRowAttrs? or typeof singleRowAttrs is 'undefined'
+ if not singleRowAttrs[currRow]? or typeof singleRowAttrs[currRow] is 'undefined' then singleRowAttrs[currRow] = {} else if singleRowAttrs[currRow][attrName] is attrValue then return false
+ singleRowAttrs[currRow][attrName] = attrValue
+ rowAttrs.singleRowAttrs = singleRowAttrs
+ else
+ return false if rowAttrs[attrName] is attrValue
+ rowAttrs[attrName] = attrValue
+ tblProperties.rowAttrs = rowAttrs
+ tblProperties
+ @addColumnAttr = (start, tblJSONObj, tblProperties, attrName, attrValue, currTd) ->
+ payload = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo payload, start.1
+ colAttrs = tblProperties.colAttrs
+ colAttrs = [] if not colAttrs? or typeof colAttrs is 'undefined'
+ if not colAttrs[currTd]? or typeof colAttrs[currTd] is 'undefined' then colAttrs[currTd] = {} else if colAttrs[currTd][attrName] is attrValue then return false
+ colAttrs[currTd][attrName] = attrValue
+ tblProperties.colAttrs = colAttrs
+ tblProperties
+ @updateTablePropertiesHelper = (props, start, currTd) ->
+ rep = @context.rep
+ lastTblPropertyUsed = 'updateTableProperties'
+ start = start or rep.selStart
+ return if not start
+ currLine = rep.lines.atIndex start.0
+ currLineText = currLine.text
+ if (currLineText.indexOf '\uFFF9') is -1 then return true
+ (try
+ tblJSONObj = fromEscapedJSON currLineText
+ tblProperties = @getLineTableProperty start.0
+ update = false
+ if props.tblWidth or props.tblHeight or props.tblBorderWidth or props.tblBorderColor
+ currAttrValue = tblProperties[props.attrName]
+ if props.attrValue? and (typeof currAttrValue is 'undefined' or currAttrValue isnt props.attrValue)
+ tblProperties[props.attrName] = props.attrValue
+ update = true
+ if props.tblCellFontWeight or props.tblCellFontStyle or props.tblCellTextDecoration
+ tblProps = @addCellAttr start, tblJSONObj, tblProperties, props.attrName, props.attrValue
+ if tblProps
+ tblProperties = tblProps
+ update = true
+ if props.tblCellFontSize or props.tblCellBgColor or props.tblCellHeight or props.tblCellPadding or props.tblcellVAlign
+ tblProps = @addCellAttr start, tblJSONObj, tblProperties, props.attrName, props.attrValue
+ if tblProps
+ tblProperties = tblProps
+ update = true
+ if props.tblEvenRowBgColor or props.tblOddRowBgColor
+ tblProps = @addRowAttr tblJSONObj, tblProperties, props.attrName, props.attrValue
+ if tblProps
+ tblProperties = tblProps
+ update = true
+ if props.tblSingleRowBgColor or props.tblRowVAlign
+ tblProps = @addRowAttr tblJSONObj, tblProperties, props.attrName, props.attrValue
+ if tblProps
+ tblProperties = tblProps
+ update = true
+ if props.tblColWidth or props.tblSingleColBgColor or props.tblColVAlign
+ tblProps = @addColumnAttr start, tblJSONObj, tblProperties, props.attrName, props.attrValue, currTd
+ if tblProps
+ tblProperties = tblProps
+ update = true
+ if update then @updateTblPropInAPool -1, -1, tblProperties, start
+ catch)
+ @updateAuthorAndCaretPos = (magicDomLineNum, tblRowNum, tblColNum) ->
+ rep = @context.rep
+ rep.selStart.1 = rep.selEnd.1 = @vars.OVERHEAD_LEN_PRE
+ rep.selStart.0 = rep.selEnd.0 = magicDomLineNum
+ row = if typeof tblRowNum is 'undefined' or not tblRowNum? then 0 else tblRowNum
+ col = if typeof tblColNum is 'undefined' or not tblRowNum? then 0 else tblColNum
+ @updateTblPropInAPool row, col, null, rep.selStart
+ rep.selStart.1 = rep.selEnd.1 = @vars.OVERHEAD_LEN_PRE
+ @context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ @createDefaultTblProperties = (authors) ->
+ rep = @context.rep
+ defTblProp = {
+ borderWidth: '1'
+ cellAttrs: []
+ width: '6'
+ rowAttrs: {}
+ colAttrs: []
+ authors: {}
+ }
+ defTblProp.'authors' = authors if authors
+ prevLine = rep.lines.atIndex rep.selEnd.0 - 1
+ jsoTblProp = null
+ if prevLine
+ prevLineText = prevLine.text
+ jsoTblProp = @getLineTableProperty rep.selStart.0 - 1 if not ((prevLineText.indexOf '\uFFF9') is -1)
+ if not jsoTblProp
+ nextLine = rep.lines.atIndex rep.selEnd.0 - 1
+ if nextLine
+ nextLineText = nextLine.text
+ jsoTblProp = @getLineTableProperty rep.selStart.0 + 1 if not ((nextLineText.indexOf '\uFFF9') is -1)
+ if jsoTblProp
+ defTblProp.borderWidth = jsoTblProp.borderWidth
+ defTblProp.borderColor = jsoTblProp.borderColor
+ defTblProp.width = jsoTblProp.width
+ defTblProp.height = jsoTblProp.height
+ defTblProp.colAttrs = jsoTblProp.colAttrs
+ jsoStrTblProp = JSON.stringify defTblProp
+ jsoStrTblProp
+ @performDocApplyTblAttrToRow = (start, jsoStrTblProp) ->
+ tempStart = []
+ tempEnd = []
+ tempStart.0 = start.0
+ tempEnd.0 = start.0
+ tempStart.1 = 0
+ tempEnd.1 = (@context.rep.lines.atIndex start.0).text.length
+ @context.editorInfo.ace_performDocumentApplyAttributesToRange tempStart, tempEnd, [['tblProp', jsoStrTblProp]]
+ @performDocumentTableTabKey = ->
+ try
+ context = @context
+ rep = context.rep
+ currLine = rep.lines.atIndex rep.selStart.0
+ currLineText = currLine.text
+ tblJSONObj = fromEscapedJSON currLineText
+ payload = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo payload, rep.selStart.1
+ leftOverTdTxtLen = currTdInfo.leftOverTdTxtLen
+ currRow = currTdInfo.row
+ currTd = currTdInfo.td
+ if typeof payload[currRow][currTd + 1] is 'undefined'
+ currRow += 1
+ nextLine = rep.lines.atIndex rep.selStart.0 + 1
+ nextLineText = nextLine.text
+ updateEvenOddBgColor = false
+ if not nextLineText? or nextLineText is '' or (nextLineText.indexOf '\uFFF9') is -1
+ @insertTblRowBelow null, {tblJSONObj.tblId}
+ @performDocApplyTblAttrToRow rep.selStart, @createDefaultTblProperties!
+ rep.selEnd.1 = rep.selStart.1 = @vars.OVERHEAD_LEN_PRE
+ updateEvenOddBgColor = true
+ else
+ currTd = -1
+ rep.selStart.0 = rep.selEnd.0 = rep.selStart.0 + 1
+ tblJSONObj = fromEscapedJSON nextLineText
+ payload = tblJSONObj.payload
+ leftOverTdTxtLen = payload.0.0.length
+ rep.selEnd.1 = rep.selStart.1 = @vars.OVERHEAD_LEN_PRE + leftOverTdTxtLen
+ context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ start = []
+ start.0 = rep.selStart.0
+ start.1 = rep.selStart.1
+ @updateTblCellAuthor 0, 0, null, start, updateEvenOddBgColor
+ else
+ nextTdTxtLen = if typeof payload[currRow] is 'undefined' then -leftOverTdTxtLen else payload[currRow][currTd + 1].length
+ payload = tblJSONObj.payload
+ rep.selStart.1 = rep.selEnd.1 = rep.selEnd.1 + nextTdTxtLen + leftOverTdTxtLen
+ context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ @updateTblPropInAPool currRow, currTd + 1, null, rep.selStart
+ catch
+ @getTdInfo = (payload, tdIndex) ->
+ rep = @context.rep
+ startOffset = @vars.OVERHEAD_LEN_PRE
+ rowStartOffset = startOffset
+ payloadSum = startOffset
+ tds = payload.0
+ tIndex = 0
+ tLen = tds.length
+ while tIndex < tLen
+ overHeadLen = @vars.OVERHEAD_LEN_MID
+ overHeadLen = @vars.OVERHEAD_LEN_ROW_END if tIndex is tLen - 1
+ payloadSum += tds[tIndex].length + overHeadLen
+ if tIndex >= tdIndex
+ return {
+ cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen
+ cellEndOffset: payloadSum
+ }
+ tIndex++
+ @getNextTdInfo = (payload, currTdInfo) ->
+ rep = @context.rep
+ startOffset = currTdInfo.rowEndOffset
+ rowStartOffset = startOffset
+ payloadSum = startOffset
+ tds = payload[currTdInfo.row]
+ tIndex = 0
+ tLen = tds.length
+ while tIndex < tLen
+ overHeadLen = @vars.OVERHEAD_LEN_MID
+ overHeadLen = @vars.OVERHEAD_LEN_ROW_END if tIndex is tLen - 1
+ payloadSum += tds[tIndex].length + overHeadLen
+ if tIndex >= currTdInfo.td
+ leftOverTdTxtLen = if payloadSum - startOffset is 0 then payload[currTdInfo.row + 1][tIndex].length + @vars.OVERHEAD_LEN_MID else payloadSum - startOffset
+ rowEndOffset = @_getRowEndOffset rowStartOffset, tds
+ tdInfo = {
+ row: currTdInfo.row + 1
+ td: tIndex
+ leftOverTdTxtLen: leftOverTdTxtLen
+ rowStartOffset: rowStartOffset
+ rowEndOffset: rowEndOffset
+ cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen
+ cellEndOffset: payloadSum
+ }
+ return tdInfo
+ tIndex++
+ @insertTblColumn = (leftOrRight, start, end) ->
+ rep = @context.rep
+ func = 'insertTblColumn()'
+ try
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ tblJSONObj = fromEscapedJSON currLineText
+ payload = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo payload, rep.selStart.1
+ currTd = currTdInfo.td
+ start = []
+ end = []
+ start.0 = rep.selStart.0
+ start.1 = rep.selStart.1
+ end.0 = rep.selEnd.0
+ end.1 = rep.selEnd.1
+ currTd -= 1 if leftOrRight is 'addL'
+ numOfLinesAbove = @getTblAboveRowsFromCurFocus start
+ rep.selEnd.0 = rep.selStart.0 = rep.selStart.0 - numOfLinesAbove
+ while rep.selStart.0 < rep.lines.length! and ((rep.lines.atIndex rep.selStart.0).text.indexOf '\uFFF9') isnt -1
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ tblJSONObj = fromEscapedJSON currLineText
+ payload = tblJSONObj.payload
+ cellPos = (@getTdInfo payload, currTd).cellEndOffset
+ newText = '\uF134 \uF134,'
+ if currTd is payload.0.length - 1
+ rep.selStart.1 = rep.selEnd.1 = cellPos - @vars.OVERHEAD_LEN_ROW_END + 1
+ newText = ',\uF134 \uF134'
+ else
+ if currTd is -1 then rep.selStart.1 = rep.selEnd.1 = @vars.OVERHEAD_LEN_PRE - 1 else rep.selStart.1 = rep.selEnd.1 = cellPos - 1
+ @context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, newText
+ rep.selEnd.0 = rep.selStart.0 = rep.selStart.0 + 1
+ rep.selStart = start
+ rep.selEnd = end
+ if leftOrRight is 'addL'
+ rep.selStart.1 = rep.selEnd.1 = @vars.OVERHEAD_LEN_PRE
+ rep.selStart.0 = rep.selEnd.0 = rep.selStart.0
+ @updateTblPropInAPool 0, 0, null, rep.selStart
+ rep.selStart.1 = rep.selEnd.1 = @vars.OVERHEAD_LEN_PRE
+ currTd++
+ updateEvenOddBgColor = false
+ updateColAttrs = true
+ @sanitizeTblProperties start, updateEvenOddBgColor, updateColAttrs, currTd, 'add'
+ @context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ catch
+ @deleteTblColumn = ->
+ func = 'deleteTblColumn()'
+ rep = @context.rep
+ try
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ tblJSONObj = fromEscapedJSON currLineText
+ payload = tblJSONObj.payload
+ deleteTable! if payload.0.length is 1
+ currTdInfo = @getFocusedTdInfo payload, rep.selStart.1
+ currTd = currTdInfo.td
+ start = []
+ end = []
+ start.0 = rep.selStart.0
+ start.1 = rep.selStart.1
+ end.0 = rep.selEnd.0
+ end.1 = rep.selEnd.1
+ numOfLinesAbove = @getTblAboveRowsFromCurFocus start
+ rep.selEnd.0 = rep.selStart.0 = rep.selStart.0 - numOfLinesAbove
+ while rep.selStart.0 < rep.lines.length! and ((rep.lines.atIndex rep.selStart.0).text.indexOf '\uFFF9') isnt -1
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ tblJSONObj = fromEscapedJSON currLineText
+ payload = tblJSONObj.payload
+ cellTdInfo = @getTdInfo payload, currTd
+ newText = '\uF134 \uF134,'
+ if currTd is payload.0.length - 1
+ rep.selStart.1 = cellTdInfo.cellStartOffset - 2
+ rep.selEnd.1 = cellTdInfo.cellEndOffset - 2
+ else
+ if currTd is 0
+ rep.selStart.1 = @vars.OVERHEAD_LEN_PRE - 1
+ rep.selEnd.1 = cellTdInfo.cellEndOffset - 1
+ else
+ rep.selStart.1 = cellTdInfo.cellStartOffset - 1
+ rep.selEnd.1 = cellTdInfo.cellEndOffset - 1
+ @context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ rep.selEnd.0 = rep.selStart.0 = rep.selStart.0 + 1
+ rep.selStart = start
+ rep.selEnd = end
+ updateEvenOddBgColor = false
+ updateColAttrs = true
+ @sanitizeTblProperties start, updateEvenOddBgColor, updateColAttrs, currTd, 'del'
+ @updateAuthorAndCaretPos rep.selStart.0, 0, 0
+ catch
+ @insertTblRowBelow = (numOfRows, table) ->
+ context = @context
+ rep = context.rep
+ currLineText = (rep.lines.atIndex rep.selStart.0).text
+ payload = [[]]
+ if not numOfRows and numOfRows isnt 0
+ tblPayload = (fromEscapedJSON currLineText).payload
+ numOfRows = tblPayload.0.length
+ tblRows = new Array numOfRows
+ if not (numOfRows is 0)
+ i = 0
+ while i < tblRows.length
+ tblRows[i] = ' '
+ i++
+ payload = table?payload ? [tblRows]
+ tblId = table?tblId ? @getNewTblId!
+ tableObj = {
+ payload
+ tblId
+ tblClass: '\uFFF9'
+ trClass: 'alst'
+ tdClass: 'hide-el'
+ }
+ table?tblId = tblId
+ rep.selEnd.1 = rep.selStart.1 = currLineText.length
+ @context.editorInfo.ace_inCallStackIfNecessary 'newline', @context.editorInfo.ace_doReturnKey
+ context.editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, escapedJSON tableObj
+ @getNewTblId = ->
+ ++@lastTblId
+ @doReturnKey = ->
+ context = @context
+ rep = context.rep
+ start = rep.seStart
+ end = rep.selEnd
+ lastTblPropertyUsed = 'doTableReturnKey'
+ currLine = rep.lines.atIndex rep.selStart.0
+ currLineText = currLine.text
+ if currLineText.indexOf('\uFFF9') isnt -1
+ func = 'doTableReturnKey()'
+ try
+ currCarretPos = rep.selStart.1
+ if (currLineText.substring currCarretPos - 1, currCarretPos + 2) is '\uF134,\uF134'
+ return true
+ else
+ if (currLineText.substring currCarretPos - 2, currCarretPos + 1) is '\uF134,\uF134'
+ return true
+ else
+ if currCarretPos < @vars.OVERHEAD_LEN_PRE then return true else if currCarretPos > currLineText.length then return true
+ start = rep.selStart
+ end = rep.selEnd
+ newText = ' /r/n '
+ start.1 = currCarretPos
+ end.1 = currCarretPos
+ (try
+ jsonObj = fromEscapedJSON (currLineText.substring 0, start.1) + newText + currLineText.substring start.1
+ payloadStr = escapedJSON jsonObj.payload
+ return true if currCarretPos > payloadStr.length + @vars.OVERHEAD_LEN_PRE - 2
+ catch error
+ return true)
+ context.editorInfo.ace_performDocumentReplaceRange start, end, newText
+ catch
+ true
+ @isCellDeleteOk = (keyCode) ->
+ {selStart:start}:rep = @context.rep
+ {text:currLineText} = rep.lines.atIndex start.0
+ return true if (currLineText.indexOf '\uFFF9') is -1
+ isDeleteAccepted = false
+ try
+ tblJSONObj = fromEscapedJSON currLineText
+ table = tblJSONObj.payload
+ currTdInfo = @getFocusedTdInfo table, start.1
+ cellEntryLen = table[currTdInfo.row][currTdInfo.td].length
+ currCarretPos = start.1
+ if (currLineText.substring currCarretPos - 1, currCarretPos + 2) is '\uF134,\uF134'
+ return false
+ else
+ if (currLineText.substring currCarretPos - 2, currCarretPos + 1) is '\uF134,\uF134'
+ return false
+ switch keyCode
+ case @vars.JS_KEY_CODE_BS
+ isDeleteAccepted = true if cellEntryLen > 0 and cellEntryLen > currTdInfo.leftOverTdTxtLen - @vars.OVERHEAD_LEN_MID
+ case @vars.JS_KEY_CODE_DEL
+ return false # still buggy and can corrupt table structure
+ isDeleteAccepted = true if cellEntryLen > 0 and currTdInfo.leftOverTdTxtLen - @vars.OVERHEAD_LEN_MID > 0
+ default
+ isDeleteAccepted = true if cellEntryLen > 1 and cellEntryLen > currTdInfo.leftOverTdTxtLen - @vars.OVERHEAD_LEN_MID
+ catch error
+ isDeleteAccepted = false
+ isDeleteAccepted
+ @nodeTextPlain = (n) -> n.innerText or n.textContent or n.nodeValue or ''
+ @toString = -> 'ep_tables'
+ @getLineAndCharForPoint = ->
+ context = @context
+ point = context.point
+ root = context.root
+ if point.node is root
+ if point.index is 0
+ [0, 0]
+ else
+ N = @context.rep.lines.length!
+ ln = @context.rep.lines.atIndex N - 1
+ [N - 1, ln.text.length]
+ else
+ n = point.node
+ col = 0
+ col = point.index if (nodeText n) or point.index > 0
+ parNode = void
+ prevSib = void
+ while (parNode = n.parentNode) isnt root
+ if prevSib = n.previousSibling
+ n = prevSib
+ textLen = nodeText(n).length or @nodeTextPlain(n).length
+ col += textLen
+ else
+ n = parNode
+ if n.id is '' then console.debug 'BAD'
+ if n.firstChild and context.editorInfo.ace_isBlockElement n.firstChild then col += 1
+ lineEntry = @context.rep.lines.atKey n.id
+ lineNum = @context.rep.lines.indexOfEntry lineEntry
+ [lineNum, col]
+ @doDeleteKey = ->
+ context = @context
+ evt = context.evt or {}
+ handled = false
+ rep = @context.rep
+ editorInfo = context.editorInfo
+ if rep.selStart
+ if editorInfo.ace_isCaret!
+ lineNum = editorInfo.ace_caretLine!
+ col = editorInfo.ace_caretColumn!
+ lineEntry = rep.lines.atIndex lineNum
+ lineText = lineEntry.text
+ lineMarker = lineEntry.lineMarker
+ if /^ +$/.exec lineText.substring lineMarker, col
+ col2 = col - lineMarker
+ tabSize = ''.length
+ toDelete = (col2 - 1) % tabSize + 1
+ editorInfo.ace_performDocumentReplaceRange [lineNum, col - toDelete], [lineNum, col], ''
+ handled = true
+ if not handled
+ if editorInfo.ace_isCaret!
+ theLine = editorInfo.ace_caretLine!
+ lineEntry = rep.lines.atIndex theLine
+ if editorInfo.ace_caretColumn! <= lineEntry.lineMarker
+ action = 'delete_newline'
+ prevLineListType = if theLine > 0 then editorInfo.ace_getLineListType theLine - 1 else ''
+ thisLineListType = editorInfo.ace_getLineListType theLine
+ prevLineEntry = theLine > 0 and rep.lines.atIndex theLine - 1
+ prevLineBlank = prevLineEntry and prevLineEntry.text.length is prevLineEntry.lineMarker
+ if thisLineListType
+ if prevLineBlank and not prevLineListType
+ editorInfo.ace_performDocumentReplaceRange [theLine - 1, prevLineEntry.text.length], [theLine, 0], ''
+ else
+ editorInfo.ace_performDocumentReplaceRange [theLine, 0], [theLine, lineEntry.lineMarker], ''
+ else
+ if theLine > 0
+ editorInfo.ace_performDocumentReplaceRange [theLine - 1, prevLineEntry.text.length], [theLine, 0], ''
+ else
+ docChar = editorInfo.ace_caretDocChar!
+ if docChar > 0
+ if evt.metaKey or evt.ctrlKey or evt.altKey
+ deleteBackTo = docChar - 1
+ while deleteBackTo > lineEntry.lineMarker and editorInfo.ace_isWordChar rep.alltext.charAt deleteBackTo - 1
+ deleteBackTo--
+ editorInfo.ace_performDocumentReplaceCharRange deleteBackTo, docChar, ''
+ else
+ returnKeyWitinTblOffset = 0
+ returnKeyWitinTblOffset = 4 if (lineText.substring col - 5, col) is '/r/n '
+ editorInfo.ace_performDocumentReplaceCharRange docChar - 1 - returnKeyWitinTblOffset, docChar, ''
+ else
+ editorInfo.ace_performDocumentReplaceRange rep.selStart, rep.selEnd, ''
+ line = editorInfo.ace_caretLine!
+ if line isnt -1 and (editorInfo.ace_renumberList line + 1) is null then editorInfo.ace_renumberList line
+ @getLineTableProperty = (lineNum) ->
+ rep = @context.rep
+ aline = rep.alines[lineNum]
+ if aline
+ opIter = Changeset.opIterator aline
+ if opIter.hasNext!
+ tblJSString = Changeset.opAttributeValue opIter.next!, 'tblProp', rep.apool
+ try
+ return JSON.parse tblJSString
+ catch error
+ return @defaults.tblProps
+ @defaults.tblProps
+ @getCurrTblOddEvenRowBgColor = (startRowNum, currRowNum) ->
+ rowBgColors = {
+ oddBgColor: null
+ evenBgColor: null
+ }
+ if not (startRowNum is currRowNum)
+ jsoTblProp1 = @getLineTableProperty startRowNum
+ jsoTblProp2 = @getLineTableProperty startRowNum + 1
+ rowBgColors.evenBgColor = jsoTblProp1.'rowAttrs'.'evenBgColor' or jsoTblProp2.'rowAttrs'.'evenBgColor'
+ rowBgColors.oddBgColor = jsoTblProp1.'rowAttrs'.'oddBgColor' or jsoTblProp2.'rowAttrs'.'oddBgColor'
+ rowBgColors
+ @getTblAboveRowsFromCurFocus = (start) ->
+ rep = @context.rep
+ numOfLinesAbove = -1
+ line = start.0
+ tblId = null
+ while text = rep.lines.atIndex(line).text
+ break unless text is /\uFFF9/
+ curr = fromEscapedJSON(text).tblId
+ tblId ?= curr
+ break if curr != tblId
+ numOfLinesAbove++
+ line--
+ numOfLinesAbove
+ @updateTableIndices = (tblProperties, currTd, addOrDel) ->
+ cellAttrs = tblProperties.cellAttrs
+ rIndex = 0
+ rLen = cellAttrs.length
+ while rIndex < rLen
+ cellAttr = cellAttrs[rIndex]
+ if addOrDel is 'add' then cellAttr.splice currTd, 0, null if cellAttr else cellAttr.splice currTd, 1 if cellAttr
+ rIndex++
+ colAttrs = tblProperties.colAttrs
+ if addOrDel is 'add' then colAttrs.splice currTd, 0, null if colAttrs else colAttrs.splice currTd, 1 if colAttrs
+ tblProperties
+ @sanitizeTblProperties = (start, updateEvenOddBgColor, updateColAttrs, currTd, addOrDel) ->
+ rep = @context.rep
+ editorInfo = @context.editorInfo
+ thisAuthor = editorInfo.ace_getAuthor!
+ numOfLinesAbove = @getTblAboveRowsFromCurFocus start
+ tempStart = []
+ tempStart.0 = start.0 - numOfLinesAbove
+ evenOddRowBgColors = {}
+ updateEvenOddBgColor
+ while tempStart.0 < rep.lines.length! and ((rep.lines.atIndex tempStart.0).text.indexOf '\uFFF9') isnt -1
+ jsoTblProp = @getLineTableProperty tempStart.0
+ update = false
+ if tempStart.0 isnt start.0 and jsoTblProp.'authors' and jsoTblProp.'authors'[thisAuthor]
+ delete jsoTblProp.'authors'[thisAuthor]
+ update = true
+ if updateColAttrs
+ jsoTblProp = @updateTableIndices jsoTblProp, currTd, addOrDel
+ update = true
+ if tempStart.0 isnt start.0 and updateEvenOddBgColor
+ delete jsoTblProp.'rowAttrs'.'oddBgColor'
+ delete jsoTblProp.'rowAttrs'.'evenBgColor'
+ update = true
+ if update then @updateTblPropInAPool -1, -1, jsoTblProp, tempStart
+ tempStart.0 = tempStart.0 + 1
+ @updateTblPropInAPool = (row, td, jsoTblProp, start) ->
+ try
+ rep = @context.rep
+ editorInfo = @context.editorInfo
+ thisAuthor = editorInfo.ace_getAuthor!
+ authorInfos = editorInfo.ace_getAuthorInfos!
+ tblProps = void
+ jsoTblProp = @getLineTableProperty start.0 if typeof jsoTblProp is 'undefined' or not jsoTblProp?
+ if row isnt -1 and td isnt -1
+ jsoTblProp.'authors'[thisAuthor] = {
+ row: row
+ cell: td
+ colorId: authorInfos[thisAuthor].bgcolor
+ }
+ jsoStrTblProp = JSON.stringify jsoTblProp
+ attrStart = []
+ attrEnd = []
+ attrStart.0 = start.0
+ attrStart.1 = 0
+ attrEnd.0 = start.0
+ attrEnd.1 = (rep.lines.atIndex start.0).text.length
+ editorInfo.ace_performDocumentApplyAttributesToRange attrStart, attrEnd, [['tblProp', jsoStrTblProp]]
+ catch
+ @updateTblCellAuthor = (row, td, tblProperties, start, updateEvenOddBgColor) ->
+ try
+ @updateTblPropInAPool row, td, tblProperties, start
+ tempStart = []
+ tempStart.0 = start.0
+ tempStart.1 = start.1
+ @sanitizeTblProperties tempStart, updateEvenOddBgColor
+
+exports?Datatables = Datatables
diff --git a/src/js/linestylefilter.ls b/src/js/linestylefilter.ls
new file mode 100644
index 0000000..f9d229f
--- /dev/null
+++ b/src/js/linestylefilter.ls
@@ -0,0 +1,5 @@
+exports.disableAuthorColorsForThisLine = (hook, context) ->
+ lineText = context.text
+ disableLineColors = false
+ disableLineColors = true if lineText and (lineText.indexOf '\uFFF9') isnt -1
+ disableLineColors
diff --git a/static/css/dataTables.css b/static/css/dataTables.css
index 65b2e6f..0f9a41e 100644
--- a/static/css/dataTables.css
+++ b/static/css/dataTables.css
@@ -1,5 +1,8 @@
.hide-el{
display:none;
+ *position: absolute;
+ *top: -10000px;
+ *display: block;
}
.tblBreak{
display:block;
diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js
index a3d7b1b..6f6d4c3 100644
--- a/static/js/contentcollector.js
+++ b/static/js/contentcollector.js
@@ -1,35 +1,42 @@
-exports.collectContentLineBreak = function (hook, context) {
- var tvalue = context.tvalue;
- var breakLine = true;
- if (tvalue && tvalue == 'tblBreak') {
- breakLine = false;
- }
- return breakLine;
-};
-exports.collectContentLineText= function (hook, context) {
- var n = context.node;
- var txt = context.text;
- if (txt) {
- while (n) {
- if (n.tagName == 'TD') {
- var elementName = n.getAttribute("name");
- if (elementName == 'tData') {
- txt = txt.replace(/\\/g, "|");
- txt = txt.replace(/"/g, "'");
- break;
- } else if (elementName == 'delimCell') {
- txt = '","';
- break;
- } else if (elementName == 'payload') {
- txt = "{\"payload\":[[\"";
- break;
- } else if (elementName == 'bracketAndcomma') {
- txt = "\"]],\"tblId\":\"1\",\"tblClass\":\"data-tables\"}";
- break;
- }
- }
- n = n.parentNode;
- }
- }
- return txt;
-};
+exports.collectContentLineBreak = function(hook, context){
+ var tvalue, breakLine;
+ tvalue = context.tvalue;
+ breakLine = true;
+ if (tvalue && tvalue === 'tblBreak') {
+ breakLine = false;
+ }
+ return breakLine;
+};
+exports.collectContentLineText = function(hook, context){
+ var n, txt, tblId, elementName;
+ n = context.node;
+ txt = context.text;
+ tblId = 1;
+ if (txt) {
+ while (n) {
+ if (n.tagName === 'TD') {
+ elementName = n.getAttribute('name');
+ if (elementName === 'tData') {
+ break;
+ } else {
+ if (elementName === 'delimCell') {
+ txt = '\uF134,\uF134';
+ break;
+ } else {
+ if (elementName === 'payload') {
+ txt = '{\uF134payload\uF134:[[\uF134';
+ break;
+ } else {
+ if (elementName === 'bracketAndcomma') {
+ txt = "\uF134]],\uF134tblId\uF134:\uF134" + tblId + "\uF134,\uF134tblClass\uF134:\uF134\uFFF9\uF134}";
+ break;
+ }
+ }
+ }
+ }
+ }
+ n = n.parentNode;
+ }
+ }
+ return txt;
+};
\ No newline at end of file
diff --git a/static/js/datatables-renderer.js b/static/js/datatables-renderer.js
index fe2add0..224556e 100644
--- a/static/js/datatables-renderer.js
+++ b/static/js/datatables-renderer.js
@@ -1,187 +1,243 @@
-if (typeof (DatatablesRenderer) == 'undefined') var DatatablesRenderer = function () {
- var dRenderer = {
- render: function (params, element, attributes) {
- var renderer = new DatatablesRenderer.Renderer();
- if (element.innerText) code = element.innerText;
- else code = element.textContent;
- element.innerHTML = renderer.getHtml(code, attributes);
- }
- }; // end of dRenderer
- dRenderer.Renderer = function () {
- //
- };
- dRenderer.Renderer.prototype = {
- createDefaultTblProperties: function (authors) {
- return {
- borderWidth: "1",
- cellAttrs: [],
- width: "6",
- rowAttrs: {},
- colAttrs: [],
- authors: {}
- };
- },
- buildTabularData: function (tblJSONObj, tblPropsJSString) {
- var htmlTbl = "";
- var tblId = tblJSONObj.tblId;
- var tblClass = tblJSONObj.tblClass;
- var tdClass = tblJSONObj.tdClass;
- var trClass = tblJSONObj.trClass;
- var payload = tblJSONObj.payload;
- var tblProperties = {};
- try {
- tblProperties = JSON.parse(tblPropsJSString);
- } catch (error) {
- tblProperties = this.createDefaultTblProperties();
- }
- var rowAttrs = tblProperties.rowAttrs;
- var singleRowAttrs = rowAttrs.singleRowAttrs;
- var cellAttrs = tblProperties.cellAttrs;
- var colAttrs = tblProperties.colAttrs;
- var tblWidth = typeof (tblProperties) == 'undefined' || tblProperties == null ? "1" : tblProperties.width || "1";
- tblWidth = this.getAttrInInch(tblWidth);
- var tblHeight = typeof (tblProperties) == 'undefined' || tblProperties == null ? ".1" : tblProperties.height || ".1";
- tblHeight = this.getAttrInInch(tblHeight);
- var tblBorderWidth = typeof (tblProperties) == 'undefined' || tblProperties == null ? 0 : tblProperties.borderWidth || 0;
- var tblBorderColor = typeof (tblProperties) == 'undefined' || tblProperties == null ? "#000000" : tblProperties.borderColor || "#000000";
- var currRow = tblProperties.currRowAuthorIdx;
- var currCell = tblProperties.currCellAuthorIdx;
- var authors = tblProperties.authors;
- var printViewTBlStyles = "table-layout:fixed !important;border-collapse:collapse!important;font-family:Trebuchet MS!important;";
- var printViewTblTDStyles = "font-size: 1em!important;line-height: 1em!important;padding: 3px 7px 2px!important;word-wrap: break-word!important;"
- var htmlTbl = "";
- var borders = "border-bottom:" + tblBorderWidth + "px solid " + tblBorderColor;
- var rowVAlign = typeof (rowAttrs) == 'undefined' || rowAttrs == null ? "left" : rowAttrs.rowVAlign || "left";
- var rows = tblJSONObj.payload;
- var evenRowBgColor = typeof (rowAttrs) == 'undefined' || rowAttrs == null ? "#FFFFFF" : rowAttrs.evenBgColor || "#FFFFFF";
- var oddRowBgColor = typeof (rowAttrs) == 'undefined' || rowAttrs == null ? null : rowAttrs.oddBgColor || null;
- for (var j = 0, rl = rows.length; j < rl; j++) {
- var tds = rows[j];
- var rowBgColor = oddRowBgColor;
- if (!rowBgColor) {
- rowBgColor = evenRowBgColor;
- }
- htmlTbl += "";
- var preHeader = "";
- if (j == 0) {
- preHeader = "{\"payload\":[[\"";
- }
- htmlTbl += "" + preHeader + " ";
- var singleRowAttr = typeof (singleRowAttrs) == 'undefined' || singleRowAttrs == null ? null : singleRowAttrs[j];
- for (var i = 0, tl = tds.length; i < tl; i++) {
- var cellAttr = typeof (cellAttrs[j]) == 'undefined' || cellAttrs[j] == null ? null : cellAttrs[j][i];
- var cellStyles = this.getCellAttrs(singleRowAttr, cellAttr, colAttrs[i], authors, i, j);
-
- var authorBorderColor = this.getCellAuthorColors(authors, i, j, tblBorderWidth) + "!important;";
- var borderTop = "";
- if (tblBorderWidth == 0) {
- borderTop = " border-top: 0px solid white !important;";
- }
- //col vAlign
- var colVAlign = typeof (colAttrs[i]) == 'undefined' || colAttrs[i] == null ? "" : "align='" + colAttrs[i].colVAlign + "'" || "";
- var quoteAndComma = "\",\"";
- var cellDel = "";
- var delimCell = "" + quoteAndComma + " ";
- var lastCellBorder = "";
- if (i == tl - 1) {
- delimCell = "";
- lastCellBorder = "border-right:" + tblBorderWidth + "px solid " + tblBorderColor + "!important;";
- quoteAndComma = "";
- }
- if (tds[i].indexOf('/r/n') != -1) {
- cellsWithBr = "";
- var tdText = tds[i].split('/r/n');
- for (var k = 0; k < tdText.length; k++) {
- if (k < tdText.length - 1) {
- cellsWithBr += tdText[k] + "/r/n ";
- } else cellsWithBr += tdText[k];
- }
- htmlTbl += "" + cellsWithBr +
- " " + delimCell;
- } else {
- htmlTbl += "" + tds[i] + "" + " " + delimCell
- }
- }
- var bracketAndcomma = "\"]],\"tblId\":\"1\",\"tblClass\":\"data-tables\"}";
- htmlTbl += "" + bracketAndcomma + " ";
- htmlTbl += " ";
- }
- htmlTbl += "
";
- return htmlTbl;
- },
- getCellAuthorColors: function (authors, cell, row, tblBorderWidth) {
- var cellBorderColor = null;
- if (typeof (authors) != 'undefined' && authors != null) {
- for (var authorId in authors) {
- author = authors[authorId];
- if (typeof (author) != 'undefined' && author != null && author.cell == cell && author.row == row) {
- cellBorderColor = author.colorId;
- }
- }
- }
- var borderWidth = tblBorderWidth != 0 ? tblBorderWidth : 1;
- cellBorderColor = cellBorderColor == null ? "" : ";border:" + borderWidth + "px solid " + cellBorderColor;
- return cellBorderColor;
- },
- getCellAttrs: function (singleRowAttr, cellAttr, colAttr, authors, cell, row) {
- var attrsJSO = {};
- var colWidth = typeof (colAttr) == 'undefined' || colAttr == null ? "1" : colAttr.width || "1";
- attrsJSO['width'] = this.getAttrInInch(colWidth) + 'px';
- var cellBgColor = "";
- //row highlight
- if (typeof (singleRowAttr) != 'undefined' && singleRowAttr != null) {
- var bgColor = singleRowAttr.bgColor;
- if (typeof (bgColor) != 'undefined' && bgColor != null && bgColor != '#FFFFFF') {
- cellBgColor = bgColor;
- }
- }
- //col highlight
- if (typeof (colAttr) != 'undefined' && colAttr != null) {
- var bgColor = colAttr.bgColor;
- if (typeof (bgColor) != 'undefined' && bgColor != null && bgColor != '#FFFFFF') {
- cellBgColor = bgColor;
- }
- }
- cellBgColor = typeof (cellAttr) == 'undefined' || cellAttr == null ? cellBgColor : cellAttr.bgColor || cellBgColor;
- attrsJSO['background-color'] = cellBgColor;
- var cellHeight = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.height || "";
- attrsJSO['height'] = this.getAttrInInch(cellHeight) + 'px';
- var cellPadding = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.padding || "";
- attrsJSO['padding-top'] = attrsJSO['padding-bottom'] = attrsJSO['padding-left'] = attrsJSO['padding-right'] = this.getAttrInInch(cellPadding) + 'px';
- var cellVAlign = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.vAlign || "";
- attrsJSO['vertical-align'] = cellVAlign;
- var cellFontSize = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.fontSize || "";
- attrsJSO['font-size'] = cellFontSize + 'px';
- var cellFontWeight = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.fontWeight || "";
- attrsJSO['font-weight'] = cellFontWeight;
- var cellFontStyle = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.fontStyle || "";
- attrsJSO['font-style'] = cellFontStyle;
- var cellTextDecoration = typeof (cellAttr) == 'undefined' || cellAttr == null ? "" : cellAttr.textDecoration || "";
- attrsJSO['text-decoration'] = cellTextDecoration;
- var attrsString = "";
- for (var attrName in attrsJSO) {
- if (attrName && attrsJSO[attrName] != "" && attrsJSO[attrName] != "NaNpx" && attrsJSO[attrName] != "px") attrsString += attrName + ":" + attrsJSO[attrName] + " !important;";
- }
- return attrsString;
- },
- getAttrInInch: function (attrValue) {
- var intAttrValue = 0;
- intAttrValue = parseFloat(attrValue);
- attrValue = isNaN(intAttrValue) ? parseFloat(attrValue) : intAttrValue;
- return 96 * attrValue - 1;
- },
- getHtml: function (code, attributes) {
- var JSONCode = "";
- var html = "";
- try {
- JSONCode = JSON.parse(code);
- html = this.buildTabularData(JSONCode, attributes);
- } catch (error) {}
- return html;
- },
- };
- return dRenderer;
- }(); // end of anonymous function
-// CommonJS
-typeof (exports) != 'undefined' ? exports.DatatablesRenderer = DatatablesRenderer : null;
+var DatatablesRenderer;
+DatatablesRenderer = {};
+DatatablesRenderer = (function(){
+ DatatablesRenderer.displayName = 'DatatablesRenderer';
+ var Renderer, prototype = DatatablesRenderer.prototype, constructor = DatatablesRenderer;
+ DatatablesRenderer.render = function(params, element, code, attributes){
+ var renderer;
+ renderer = new DatatablesRenderer.Renderer;
+ return element.innerHTML = renderer.getHtml(code, attributes);
+ };
+ DatatablesRenderer.Renderer = Renderer = (function(){
+ Renderer.displayName = 'Renderer';
+ var prototype = Renderer.prototype, constructor = Renderer;
+ function Renderer(){}
+ prototype.createDefaultTblProperties = function(authors){
+ return {
+ borderWidth: '1',
+ cellAttrs: [],
+ width: '6',
+ rowAttrs: {},
+ colAttrs: [],
+ authors: {}
+ };
+ };
+ prototype.buildTabularData = function(tblJSONObj, tblPropsJSString){
+ var htmlTbl, tblId, tblClass, tdClass, trClass, payload, tblProperties, error, rowAttrs, singleRowAttrs, cellAttrs, colAttrs, tblWidth, tblHeight, tblBorderWidth, tblBorderColor, currRow, currCell, authors, printViewTBlStyles, printViewTblTDStyles, borders, rowVAlign, rows, evenRowBgColor, oddRowBgColor, j, rl, tds, rowBgColor, preHeader, singleRowAttr, i, tl, cellAttr, cellStyles, authorBorderColor, borderTop, colVAlign, quoteAndComma, cellDel, delimCell, lastCellBorder, cellsWithBr, tdText, k, bracketAndcomma;
+ htmlTbl = '';
+ tblId = tblJSONObj.tblId;
+ tblClass = tblJSONObj.tblClass;
+ tdClass = tblJSONObj.tdClass;
+ trClass = tblJSONObj.trClass;
+ payload = tblJSONObj.payload;
+ tblProperties = {};
+ try {
+ tblProperties = JSON.parse(tblPropsJSString);
+ } catch (e$) {
+ error = e$;
+ tblProperties = this.createDefaultTblProperties();
+ }
+ rowAttrs = tblProperties.rowAttrs;
+ singleRowAttrs = rowAttrs.singleRowAttrs;
+ cellAttrs = tblProperties.cellAttrs;
+ colAttrs = tblProperties.colAttrs;
+ tblWidth = typeof tblProperties === 'undefined' || tblProperties == null
+ ? '1'
+ : tblProperties.width || '1';
+ tblWidth = this.getAttrInInch(tblWidth);
+ tblHeight = typeof tblProperties === 'undefined' || tblProperties == null
+ ? '.1'
+ : tblProperties.height || '.1';
+ tblHeight = this.getAttrInInch(tblHeight);
+ tblBorderWidth = typeof tblProperties === 'undefined' || tblProperties == null
+ ? 0
+ : tblProperties.borderWidth || 0;
+ tblBorderColor = typeof tblProperties === 'undefined' || tblProperties == null
+ ? '#000000'
+ : tblProperties.borderColor || '#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 = '';
+ borders = 'border-bottom:' + tblBorderWidth + 'px solid ' + tblBorderColor;
+ rowVAlign = typeof rowAttrs === 'undefined' || rowAttrs == null
+ ? 'left'
+ : rowAttrs.rowVAlign || 'left';
+ rows = tblJSONObj.payload;
+ evenRowBgColor = typeof rowAttrs === 'undefined' || rowAttrs == null
+ ? '#FFFFFF'
+ : rowAttrs.evenBgColor || '#FFFFFF';
+ oddRowBgColor = typeof rowAttrs === 'undefined' || rowAttrs == null
+ ? null
+ : rowAttrs.oddBgColor || null;
+ j = 0;
+ rl = rows.length;
+ while (j < rl) {
+ tds = rows[j];
+ rowBgColor = oddRowBgColor;
+ if (!rowBgColor) {
+ rowBgColor = evenRowBgColor;
+ }
+ htmlTbl += '';
+ preHeader = '';
+ if (j === 0) {
+ preHeader = '{\uF134payload\uF134:[[\uF134';
+ }
+ htmlTbl += '' + preHeader + ' ';
+ singleRowAttr = typeof singleRowAttrs === 'undefined' || singleRowAttrs == null
+ ? null
+ : singleRowAttrs[j];
+ i = 0;
+ tl = tds.length;
+ while (i < tl) {
+ cellAttr = typeof cellAttrs[j] === 'undefined' || cellAttrs[j] == null
+ ? null
+ : cellAttrs[j][i];
+ cellStyles = this.getCellAttrs(singleRowAttr, cellAttr, colAttrs[i], authors, i, j);
+ authorBorderColor = this.getCellAuthorColors(authors, i, j, tblBorderWidth) + '!important;';
+ borderTop = '';
+ if (tblBorderWidth === 0) {
+ borderTop = ' border-top: 0px solid white !important;';
+ }
+ colVAlign = typeof colAttrs[i] === 'undefined' || colAttrs[i] == null
+ ? ''
+ : 'align=\'' + colAttrs[i].colVAlign + '\'' || '';
+ quoteAndComma = '\uF134,\uF134';
+ cellDel = '';
+ delimCell = '' + quoteAndComma + ' ';
+ lastCellBorder = '';
+ if (i === tl - 1) {
+ delimCell = '';
+ lastCellBorder = 'border-right:' + tblBorderWidth + 'px solid ' + tblBorderColor + '!important;';
+ quoteAndComma = '';
+ }
+ if (!(tds[i].indexOf('/r/n') === -1)) {
+ cellsWithBr = '';
+ tdText = tds[i].split('/r/n');
+ k = 0;
+ while (k < tdText.length) {
+ if (k < tdText.length - 1) {
+ cellsWithBr += tdText[k] + ("/r/n ");
+ } else {
+ cellsWithBr += tdText[k];
+ }
+ k++;
+ }
+ htmlTbl += '' + cellsWithBr + ' ' + delimCell;
+ } else {
+ htmlTbl += '' + tds[i] + '' + ' ' + delimCell;
+ }
+ i++;
+ }
+ bracketAndcomma = '\uF134]],\uF134tblId\uF134:\uF134' + tblId + '\uF134,\uF134tblClass\uF134:\uF134\uFFF9\uF134}';
+ htmlTbl += '' + bracketAndcomma + ' ';
+ htmlTbl += ' ';
+ j++;
+ }
+ htmlTbl += '
';
+ return htmlTbl;
+ };
+ prototype.getCellAuthorColors = function(authors, cell, row, tblBorderWidth){
+ var cellBorderColor, authorId, author, borderWidth;
+ cellBorderColor = null;
+ if (typeof authors !== 'undefined' && authors != null) {
+ for (authorId in authors) {
+ author = authors[authorId];
+ if (typeof author !== 'undefined' && author != null && author.cell === cell && author.row === row) {
+ cellBorderColor = author.colorId;
+ }
+ }
+ }
+ borderWidth = tblBorderWidth !== 0 ? tblBorderWidth : 1;
+ cellBorderColor = cellBorderColor == null
+ ? ''
+ : ';border:' + borderWidth + 'px solid ' + cellBorderColor;
+ return cellBorderColor;
+ };
+ prototype.getCellAttrs = function(singleRowAttr, cellAttr, colAttr, authors, cell, row){
+ var attrsJSO, colWidth, cellBgColor, bgColor, cellHeight, cellPadding, cellVAlign, cellFontSize, cellFontWeight, cellFontStyle, cellTextDecoration, attrsString, attrName;
+ attrsJSO = {};
+ colWidth = typeof colAttr === 'undefined' || colAttr == null
+ ? '1'
+ : colAttr.width || '1';
+ attrsJSO['width'] = this.getAttrInInch(colWidth) + 'px';
+ cellBgColor = '';
+ if (typeof singleRowAttr !== 'undefined' && singleRowAttr != null) {
+ bgColor = singleRowAttr.bgColor;
+ if (typeof bgColor !== 'undefined' && bgColor != null && bgColor !== '#FFFFFF') {
+ cellBgColor = bgColor;
+ }
+ }
+ if (typeof colAttr !== 'undefined' && colAttr != null) {
+ bgColor = colAttr.bgColor;
+ if (typeof bgColor !== 'undefined' && bgColor != null && bgColor !== '#FFFFFF') {
+ cellBgColor = bgColor;
+ }
+ }
+ cellBgColor = typeof cellAttr === 'undefined' || cellAttr == null
+ ? cellBgColor
+ : cellAttr.bgColor || cellBgColor;
+ attrsJSO['background-color'] = cellBgColor;
+ cellHeight = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.height || '';
+ attrsJSO['height'] = this.getAttrInInch(cellHeight) + 'px';
+ cellPadding = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.padding || '';
+ attrsJSO['padding-top'] = attrsJSO['padding-bottom'] = attrsJSO['padding-left'] = attrsJSO['padding-right'] = this.getAttrInInch(cellPadding) + 'px';
+ cellVAlign = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.vAlign || '';
+ attrsJSO['vertical-align'] = cellVAlign;
+ cellFontSize = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.fontSize || '';
+ attrsJSO['font-size'] = cellFontSize + 'px';
+ cellFontWeight = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.fontWeight || '';
+ attrsJSO['font-weight'] = cellFontWeight;
+ cellFontStyle = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.fontStyle || '';
+ attrsJSO['font-style'] = cellFontStyle;
+ cellTextDecoration = typeof cellAttr === 'undefined' || cellAttr == null
+ ? ''
+ : cellAttr.textDecoration || '';
+ attrsJSO['text-decoration'] = cellTextDecoration;
+ attrsString = '';
+ for (attrName in attrsJSO) {
+ if (attrName && attrsJSO[attrName] !== '' && attrsJSO[attrName] !== 'NaNpx' && attrsJSO[attrName] !== 'px') {
+ attrsString += attrName + ':' + attrsJSO[attrName] + ' !important;';
+ }
+ }
+ return attrsString;
+ };
+ prototype.getAttrInInch = function(attrValue){
+ var intAttrValue;
+ intAttrValue = 0;
+ intAttrValue = parseFloat(attrValue);
+ attrValue = isNaN(intAttrValue) ? parseFloat(attrValue) : intAttrValue;
+ return 96 * attrValue - 1;
+ };
+ prototype.getHtml = function(JSONCode, attributes){
+ var html, e;
+ html = '';
+ try {
+ html = this.buildTabularData(JSONCode, attributes);
+ } catch (e$) {
+ e = e$;
+ }
+ return html;
+ };
+ return Renderer;
+ }());
+ function DatatablesRenderer(){}
+ return DatatablesRenderer;
+}());
+if (typeof exports != 'undefined' && exports !== null) {
+ exports.DatatablesRenderer = DatatablesRenderer;
+}
\ No newline at end of file
diff --git a/static/js/datatables-ui.js b/static/js/datatables-ui.js
new file mode 100644
index 0000000..ede09eb
--- /dev/null
+++ b/static/js/datatables-ui.js
@@ -0,0 +1,684 @@
+exports.aceInitInnerdocbodyHead = function(hook_name, args, cb){
+ return args.iframeHTML.push(' ');
+};
+exports.postAceInit = function(hook, context){
+ $.createTableMenu = function(init){
+ var showTblPropPanel, createColorPicker, colorPickerButtonClick, initTableProperties, matrixTable, subMenus;
+ showTblPropPanel = function(){
+ if (!$.tblPropDialog) {
+ $.tblPropDialog = new YAHOO.widget.Dialog('yui-tbl-prop-panel', {
+ width: '600px',
+ height: '450px',
+ close: true,
+ visible: false,
+ zindex: 1001,
+ constraintoviewport: true
+ });
+ $.tblPropDialog.setBody($.getTblPropertiesHTML());
+ $.tblPropDialog.render();
+ $.alignMenu($.tblPropDialog, this.id);
+ initTableProperties();
+ }
+ return $.tblPropDialog.show();
+ };
+ createColorPicker = function(){
+ var createOColorPicker, handleColorPickerSubmit, handleDialogCancel;
+ createOColorPicker = function(){
+ $.oColorPicker = new YAHOO.widget.ColorPicker('color-picker-menu', {
+ showhsvcontrols: false,
+ showrgbcontrols: false,
+ showwebsafe: false,
+ showhexsummary: false,
+ showhexcontrols: true,
+ images: {
+ PICKER_THUMB: 'https://raw.github.com/yui/yui2/master/build/colorpicker/assets/picker_thumb.png',
+ HUE_THUMB: 'https://raw.github.com/yui/yui2/master/build/colorpicker/assets/hue_thumb.png'
+ }
+ });
+ $.oColorPicker.on('rgbChange', colorPickerButtonClick);
+ return $.colorPickerAligned = true;
+ };
+ handleColorPickerSubmit = function(){
+ return colorPickerButtonClick($.oColorPicker.get('hex'));
+ };
+ handleDialogCancel = function(){
+ return this.cancel();
+ };
+ $.oColorPickerDialog = new YAHOO.widget.Dialog('yui-picker-panel', {
+ width: '500px',
+ close: true,
+ visible: false,
+ zindex: 1002,
+ constraintoviewport: true,
+ buttons: [{
+ text: 'Exit',
+ handler: this.handleDialogCancel
+ }]
+ });
+ $.oColorPickerDialog.renderEvent.subscribe(function(){
+ if (!$.oColorPicker) {
+ return createOColorPicker();
+ }
+ });
+ $.oColorPickerDialog.render();
+ return $.oColorPickerDialog.show();
+ };
+ colorPickerButtonClick = function(sColor){
+ var selParams;
+ if (typeof sColor === 'string' && sColor != null && sColor.indexOf('#') === -1) {
+ sColor = '#' + sColor;
+ } else {
+ if (typeof sColor === 'object') {
+ sColor = this.get('hex') == null
+ ? this.get('value')
+ : '#' + this.get('hex');
+ }
+ }
+ selParams = {
+ borderWidth: null,
+ tblPropertyChange: true
+ };
+ switch ($.tblfocusedProperty) {
+ case 'tbl_border_color':
+ selParams.tblBorderColor = true;
+ selParams.attrName = 'borderColor';
+ $.borderColorPickerButton.set('value', sColor);
+ $('#current-color').css('backgroundColor', sColor);
+ $('#current-color').innerHTML = 'Current color is ' + sColor;
+ break;
+ case 'tbl_cell_bg_color':
+ selParams.tblCellBgColor = true;
+ selParams.attrName = 'bgColor';
+ $.cellBgColorPickerButton.set('value', sColor);
+ $('#current-cell-bg-color').css('backgroundColor', sColor);
+ $('#current-cell-bg-color').innerHTML = 'Current color is ' + sColor;
+ break;
+ case 'tbl_even_row_bg_color':
+ selParams.tblEvenRowBgColor = true;
+ selParams.attrName = 'evenBgColor';
+ $.evenRowBgColorPickerButton.set('value', sColor);
+ $('#even-row-bg-color').css('backgroundColor', sColor);
+ $('#even-row-bg-color').innerHTML = 'Current color is ' + sColor;
+ break;
+ case 'tbl_odd_row_bg_color':
+ selParams.tblOddRowBgColor = true;
+ selParams.attrName = 'oddBgColor';
+ $.oddRowBgColorPickerButton.set('value', sColor);
+ $('#odd-row-bg-color').css('backgroundColor', sColor);
+ $('#odd-row-bg-color').innerHTML = 'Current color is ' + sColor;
+ break;
+ case 'tbl_single_row_bg_color':
+ selParams.tblSingleRowBgColor = true;
+ selParams.attrName = 'bgColor';
+ $.singleRowBgColorPickerButton.set('value', sColor);
+ $('#single-row-bg-color').css('backgroundColor', sColor);
+ $('#single-row-bg-color').innerHTML = 'Current color is ' + sColor;
+ break;
+ case 'tbl_single_col_bg_color':
+ selParams.tblSingleColBgColor = true;
+ selParams.attrName = 'bgColor';
+ $.singleColBgColorPickerButton.set('value', sColor);
+ $('#single-col-bg-color').css('backgroundColor', sColor);
+ $('#single-col-bg-color').innerHTML = 'Current color is ' + sColor;
+ }
+ selParams.attrValue = sColor;
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ };
+ if (!(typeof top.templatesMenu === 'undefined')) {
+ top.templatesMenu.hide();
+ }
+ if ($.tblContextMenu) {
+ $.alignMenu($.tblContextMenu, 'tbl-menu');
+ $.tblContextMenu.show();
+ return;
+ }
+ $.handleTableBorder = function(selectValue){
+ var selParams;
+ selParams = {
+ tblBorderWidth: true,
+ attrName: 'borderWidth',
+ attrValue: selectValue,
+ tblPropertyChange: true
+ };
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ };
+ $.getTblPropertiesHTML = function(){
+ return ' ' + ' ' + '' + '' + ' ';
+ };
+ if (typeof $.tblContextMenu === 'undefined') {
+ initTableProperties = function(){
+ var colVAligns, rowVAligns, borderWidths;
+ colVAligns = ['Left', 'Center', 'Right'];
+ $.colVAlignsMenu = new YAHOO.widget.ContextMenu('tbl_col_v_align_menu', {
+ iframe: true,
+ zindex: 1003,
+ shadow: false,
+ position: 'dynamic',
+ keepopen: true,
+ clicktohide: true
+ });
+ $.colVAlignsMenu.addItems(colVAligns);
+ $.colVAlignsMenu.render(document.body);
+ $.colVAlignsMenu.subscribe('click', function(p_sType, p_aArgs){
+ var oEvent, oMenuItem, align, selParams;
+ oEvent = p_aArgs[0];
+ oMenuItem = p_aArgs[1];
+ if (oMenuItem) {
+ align = oMenuItem.cfg.getProperty('text');
+ selParams = {
+ tblColVAlign: true,
+ attrName: 'colVAlign',
+ attrValue: align,
+ tblPropertyChange: true
+ };
+ $.colVAlignsMenuButton.set('value', selParams.attrValue);
+ $('#current-col-v-alignment').html(align);
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ }
+ });
+ $.colVAlignsMenuButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Left ',
+ container: 'tbl_col_v_align'
+ });
+ $('#tbl_col_v_align').click(function(){
+ var aligned, vAlignValue, selParams;
+ aligned = false;
+ if (!aligned) {
+ $.alignMenu($.colVAlignsMenu, 'tbl_col_v_align');
+ }
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ if ($.oColorPickerDialog) {
+ $.oColorPickerDialog.hide();
+ }
+ $.colVAlignsMenu.show();
+ vAlignValue = $.colVAlignsMenuButton.get('value');
+ if (vAlignValue) {
+ selParams = {
+ tblColVAlign: true,
+ attrName: 'colVAlign',
+ attrValue: vAlignValue,
+ tblPropertyChange: true
+ };
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ }
+ });
+ rowVAligns = ['Top', 'Center', 'Bottom'];
+ $.rowVAlignsMenu = new YAHOO.widget.ContextMenu('tbl_row_v_align_menu', {
+ iframe: true,
+ zindex: 1003,
+ shadow: false,
+ position: 'dynamic',
+ keepopen: true,
+ clicktohide: true
+ });
+ $.rowVAlignsMenu.addItems(rowVAligns);
+ $.rowVAlignsMenu.render(document.body);
+ $.rowVAlignsMenu.subscribe('click', function(p_sType, p_aArgs){
+ var oEvent, oMenuItem, align, selParams;
+ oEvent = p_aArgs[0];
+ oMenuItem = p_aArgs[1];
+ if (oMenuItem) {
+ align = oMenuItem.cfg.getProperty('text');
+ selParams = {
+ tblRowVAlign: true,
+ attrName: 'rowVAlign',
+ attrValue: align,
+ tblPropertyChange: true
+ };
+ $.rowVAlignsMenuButton.set('value', selParams.attrValue);
+ $('#current-v-alignment').html(align);
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ }
+ });
+ $.rowVAlignsMenuButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Top ',
+ container: 'tbl_row_v_align'
+ });
+ $('#tbl_row_v_align').click(function(){
+ var aligned, vAlignValue, selParams;
+ aligned = false;
+ if (!aligned) {
+ $.alignMenu($.rowVAlignsMenu, 'tbl_row_v_align');
+ }
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ if ($.oColorPickerDialog) {
+ $.oColorPickerDialog.hide();
+ }
+ $.rowVAlignsMenu.show();
+ vAlignValue = $.rowVAlignsMenuButton.get('value');
+ if (vAlignValue) {
+ selParams = {
+ tblRowVAlign: true,
+ attrName: 'rowVAlign',
+ attrValue: vAlignValue,
+ tblPropertyChange: true
+ };
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ }
+ });
+ borderWidths = ['0px', '1px', '2px', '3px', '4px', '5px', '6px', '7px', '8px'];
+ $.borderWidthsMenu = new YAHOO.widget.ContextMenu('tbl_border_width_menu', {
+ iframe: true,
+ zindex: 1003,
+ shadow: false,
+ position: 'dynamic',
+ keepopen: true,
+ clicktohide: true
+ });
+ $.borderWidthsMenu.addItems(borderWidths);
+ $.borderWidthsMenu.render(document.body);
+ $.borderWidthsMenu.subscribe('click', function(p_sType, p_aArgs){
+ var oEvent, oMenuItem, borderReq, selParams;
+ oEvent = p_aArgs[0];
+ oMenuItem = p_aArgs[1];
+ if (oMenuItem) {
+ borderReq = oMenuItem.cfg.getProperty('text');
+ selParams = {
+ tblBorderWidth: true,
+ attrName: 'borderWidth',
+ attrValue: borderReq.substring(0, borderReq.indexOf('px')),
+ tblPropertyChange: true
+ };
+ $.borderWidthPickerButton.set('value', selParams.attrValue);
+ $('#current-width').html(borderReq);
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ }
+ });
+ $.borderWidthPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: '1px ',
+ container: 'tbl_border_width'
+ });
+ $('#tbl_border_width').click(function(){
+ var aligned, widthValue, selParams;
+ aligned = false;
+ if (!aligned) {
+ $.alignMenu($.borderWidthsMenu, 'tbl_border_width');
+ }
+ if ($.oColorPickerDialog) {
+ $.oColorPickerDialog.hide();
+ }
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ $.borderWidthsMenu.show();
+ widthValue = $.borderWidthPickerButton.get('value');
+ if (widthValue) {
+ selParams = {
+ tblBorderWidth: true,
+ attrName: 'borderWidth',
+ attrValue: widthValue,
+ tblPropertyChange: true
+ };
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ }
+ });
+ $.tblfocusedProperty = '';
+ $('#tbl_properties').click(function(){
+ if (!(typeof $.borderWidthsMenu === 'undefined')) {
+ $.borderWidthsMenu.hide();
+ }
+ if (!(typeof $.oColorPickerDialog === 'undefined')) {
+ $.oColorPickerDialog.hide();
+ }
+ if (!(typeof $.rowVAlignsMenu === 'undefined')) {
+ return $.rowVAlignsMenu.hide();
+ }
+ });
+ $.colorPickerAligned = false;
+ $('#tbl_border_color').click(function(){
+ var hexValue;
+ if (!$.colorPickerAligned) {
+ createColorPicker();
+ }
+ $.alignMenu($.oColorPickerDialog, 'tbl_border_color');
+ $.tblfocusedProperty = 'tbl_border_color';
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ $.oColorPickerDialog.setHeader('Please choose a color for: Table Border color');
+ $.oColorPickerDialog.show();
+ hexValue = $.borderColorPickerButton.get('value');
+ if (hexValue) {
+ return colorPickerButtonClick(hexValue);
+ }
+ });
+ $.borderColorPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Current color is #FFFFFF. ',
+ container: 'tbl_border_color'
+ });
+ $.cellBgColorPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Current color is #FFFFFF. ',
+ container: 'tbl_cell_bg_color'
+ });
+ $('#tbl_cell_bg_color').click(function(){
+ var hexValue;
+ if (!$.colorPickerAligned) {
+ createColorPicker();
+ }
+ $.alignMenu($.oColorPickerDialog, 'tbl_cell_bg_color');
+ $.tblfocusedProperty = 'tbl_cell_bg_color';
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ $.oColorPickerDialog.setHeader('Please choose a color for: Cell Background color');
+ $.oColorPickerDialog.show();
+ hexValue = $.cellBgColorPickerButton.get('value');
+ if (hexValue) {
+ return colorPickerButtonClick(hexValue);
+ }
+ });
+ $.evenRowBgColorPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Current color is #FFFFFF. ',
+ container: 'tbl_even_row_bg_color'
+ });
+ $('#tbl_even_row_bg_color').click(function(){
+ var hexValue;
+ if (!$.colorPickerAligned) {
+ createColorPicker();
+ }
+ $.alignMenu($.oColorPickerDialog, 'tbl_even_row_bg_color');
+ $.tblfocusedProperty = 'tbl_even_row_bg_color';
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ $.oColorPickerDialog.setHeader('Please choose a color for: Even Row Background color');
+ $.oColorPickerDialog.show();
+ hexValue = $.evenRowBgColorPickerButton.get('value');
+ if (hexValue) {
+ return colorPickerButtonClick(hexValue);
+ }
+ });
+ $.oddRowBgColorPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Current color is #FFFFFF. ',
+ container: 'tbl_odd_row_bg_color'
+ });
+ $('#tbl_odd_row_bg_color').click(function(){
+ var hexValue;
+ if (!$.colorPickerAligned) {
+ createColorPicker();
+ }
+ $.alignMenu($.oColorPickerDialog, 'tbl_odd_row_bg_color');
+ $.tblfocusedProperty = 'tbl_odd_row_bg_color';
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ $.oColorPickerDialog.setHeader('Please choose a color for: Odd Row Background color');
+ $.oColorPickerDialog.show();
+ hexValue = $.oddRowBgColorPickerButton.get('value');
+ if (hexValue) {
+ return colorPickerButtonClick(hexValue);
+ }
+ });
+ $.singleRowBgColorPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Current color is #FFFFFF. ',
+ container: 'tbl_single_row_bg_color'
+ });
+ $('#tbl_single_row_bg_color').click(function(){
+ var hexValue;
+ if (!$.colorPickerAligned) {
+ createColorPicker();
+ }
+ $.alignMenu($.oColorPickerDialog, 'tbl_single_row_bg_color');
+ $.tblfocusedProperty = 'tbl_single_row_bg_color';
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ $.oColorPickerDialog.setHeader('Please choose a color for: Single Row Background color');
+ $.oColorPickerDialog.show();
+ hexValue = $.singleRowBgColorPickerButton.get('value');
+ if (hexValue) {
+ return colorPickerButtonClick(hexValue);
+ }
+ });
+ $.singleColBgColorPickerButton = new YAHOO.widget.Button({
+ disabled: false,
+ type: 'split',
+ label: 'Current color is #FFFFFF. ',
+ container: 'tbl_single_col_bg_color'
+ });
+ $('#tbl_single_col_bg_color').click(function(){
+ var hexValue;
+ if (!$.colorPickerAligned) {
+ createColorPicker();
+ }
+ $.alignMenu($.oColorPickerDialog, 'tbl_single_col_bg_color');
+ $.tblfocusedProperty = 'tbl_single_col_bg_color';
+ if ($.rowVAlignsMenu) {
+ $.rowVAlignsMenu.hide();
+ }
+ if ($.borderWidthsMenu) {
+ $.borderWidthsMenu.hide();
+ }
+ $.oColorPickerDialog.setHeader('Please choose a color for: Single Column Background color');
+ $.oColorPickerDialog.show();
+ hexValue = $.singleColBgColorPickerButton.get('value');
+ if (hexValue) {
+ return colorPickerButtonClick(hexValue);
+ }
+ });
+ return $('.text-input').change(function(){
+ var selParams;
+ selParams = {
+ tblPropertyChange: true
+ };
+ if (this.id === 'tbl_width') {
+ selParams.tblWidth = true;
+ selParams.attrName = 'width';
+ } else {
+ if (this.id === 'tbl_height') {
+ selParams.tblHeight = true;
+ selParams.attrName = 'height';
+ } else {
+ if (this.id === 'tbl_col_width') {
+ selParams.tblColWidth = true;
+ selParams.attrName = 'width';
+ } else {
+ if (this.id === 'tbl_row_height') {
+ selParams.tblCellHeight = true;
+ selParams.attrName = 'height';
+ } else {
+ if (this.id === 'tbl_cell_padding') {
+ selParams.tblCellPadding = true;
+ selParams.attrName = 'padding';
+ } else {
+ if (this.id === 'tbl_cell_font_size') {
+ selParams.tblCellFontSize = true;
+ selParams.attrName = 'fontSize';
+ } else {
+ if (this.id === 'img_width') {
+ selParams.imgWidth = true;
+ selParams.attrName = 'width';
+ } else {
+ if (this.id === 'img_height') {
+ selParams.imgHeight = true;
+ selParams.attrName = 'height';
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ selParams.attrValue = this.value;
+ this.value = '';
+ $('#text_input_message').text('Ok');
+ $('#text_input_message').removeAttr('style');
+ $('#text_input_message').fadeOut('slow');
+ return context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(selParams);
+ }, 'tblOptions', true);
+ });
+ };
+ matrixTable = '';
+ $.tblContextMenu = new YAHOO.widget.ContextMenu('tbl_context_menu', {
+ iframe: true,
+ zindex: 500,
+ shadow: false,
+ position: 'dynamic',
+ clicktohide: true
+ });
+ $.tblContextMenu.addItems([
+ [{
+ text: 'Insert Table',
+ submenu: {
+ id: 'tbl_insert',
+ itemData: ['0 X 0
']
+ }
+ }], ['Insert Row Above', 'Insert Row Below', 'Insert Column Right', 'Insert Column Left'], ['Delete Row', 'Delete Column', 'Delete Table']
+ ]);
+ subMenus = $.tblContextMenu.getSubmenus();
+ subMenus[0].setFooter(matrixTable);
+ $.tblContextMenu.render(document.body);
+ $.alignMenu = function(menu, id, addX, addY, scrollY){
+ var region;
+ region = YAHOO.util.Dom.getRegion(id);
+ if (typeof id === 'string' && (id === 'tbl-menu' || id === 'upload_image_cont')) {
+ return menu.cfg.setProperty('xy', [region.left, region.bottom]);
+ } else {
+ if (typeof id === 'string') {
+ return menu.cfg.setProperty('xy', [region.right, region.top]);
+ } else {
+ return menu.cfg.setProperty('xy', [30 + addX, 36 + addY - scrollY]);
+ }
+ }
+ };
+ $('table td').hover(function(){
+ var x, lresult$, y, results$ = [];
+ x = 0;
+ while (x <= $(this).index()) {
+ lresult$ = [];
+ y = 0;
+ while (y <= $(this).parent().index()) {
+ $(this).parent().parent().children().eq(y).children().eq(x).addClass('selected');
+ y++;
+ }
+ lresult$.push(x++);
+ results$.push(lresult$);
+ }
+ return results$;
+ }, function(){
+ return $('table td').removeClass('selected');
+ });
+ $('table td').hover(function(){
+ var xVal, yVal;
+ xVal = this.getAttribute('value');
+ yVal = $(this).closest('tr')[0].getAttribute('value');
+ return $('#select_matrix').html(xVal + ' X ' + yVal);
+ });
+ $('td', '#matrix_table').click(function(e){
+ context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions('addTbl', 'addTblX' + $('#select_matrix').text());
+ }, 'tblOptions', true);
+ $.tblContextMenu.hide();
+ return false;
+ });
+ $.tblContextMenu.subscribe('click', function(p_sType, p_aArgs){
+ var oEvent, oMenuItem, tblReq, disabled, id;
+ oEvent = p_aArgs[0];
+ oMenuItem = p_aArgs[1];
+ if (oMenuItem) {
+ tblReq = oMenuItem.cfg.getProperty('text');
+ disabled = oMenuItem.cfg.getProperty('disabled');
+ if (disabled) {
+ return;
+ }
+ id = '';
+ switch (tblReq) {
+ case 'Insert Table':
+ id = 'addTbl';
+ break;
+ case 'Insert Row Above':
+ id = 'addTblRowA';
+ break;
+ case 'Insert Row Below':
+ id = 'addTblRowB';
+ break;
+ case 'Insert Column Left':
+ id = 'addTblColL';
+ break;
+ case 'Insert Column Right':
+ id = 'addTblColR';
+ break;
+ case 'Delete Table':
+ id = 'delTbl';
+ break;
+ case 'Delete Image':
+ id = 'delImg';
+ break;
+ case 'Delete Row':
+ id = 'delTblRow';
+ break;
+ case 'Delete Column':
+ id = 'delTblCol';
+ }
+ context.ace.callWithAce(function(ace){
+ return ace.ace_doDatatableOptions(id);
+ }, 'tblOptions', true);
+ $.tblContextMenu.hide();
+ return false;
+ }
+ });
+ }
+ if (!init) {
+ $.alignMenu($.tblContextMenu, 'tbl-menu');
+ return $.tblContextMenu.show();
+ }
+ };
+ $('#tbl-menu').click($.createTableMenu);
+ YAHOO.util.Dom.addClass(document.body, 'yui-skin-sam');
+ $('body').append($('' + '
Please choose a color:
' + '
' + '\t' + '
' + '
' + '
'));
+ $('body').append($('' + '
Table/Image Properties
' + '
' + '
' + '
'));
+ return $.createTableMenu(true);
+};
\ No newline at end of file
diff --git a/static/js/datatables.js b/static/js/datatables.js
index 06f83f6..767c9f7 100644
--- a/static/js/datatables.js
+++ b/static/js/datatables.js
@@ -1,1927 +1,1342 @@
-var _ = require('ep_etherpad-lite/static/js/underscore');
-// CommonJS
-if (typeof (require) != 'undefined') {
- if (typeof (Ace2Common) == 'undefined') {
- Ace2Common = require('ep_etherpad-lite/static/js/ace2_common');
- }
- if (typeof (Changeset) == 'undefined') {
- Changeset = require('ep_etherpad-lite/static/js/Changeset');
- }
-}
-exports.aceInitInnerdocbodyHead = function (hook_name, args, cb) {
- args.iframeHTML.push(' ');
-}
-// Bind the event handler to the toolbar buttons
-exports.postAceInit = function (hook, context) {
- $.createTableMenu = function (init) {
- if (typeof (top.templatesMenu) != 'undefined') {
- top.templatesMenu.hide();
- }
- if ($.tblContextMenu) {
- $.alignMenu($.tblContextMenu, 'tbl-menu');
- $.tblContextMenu.show();
- return;
- }
-
- function showTblPropPanel() {
- if (!$.tblPropDialog) {
- $.tblPropDialog = new YAHOO.widget.Dialog("yui-tbl-prop-panel", {
- width: "600px",
- height: "450px",
- close: true,
- visible: false,
- zindex: 1001,
- constraintoviewport: true
- });
- $.tblPropDialog.setBody($.getTblPropertiesHTML());
- $.tblPropDialog.render();
- $.alignMenu($.tblPropDialog, this.id);
- initTableProperties();
- }
- $.tblPropDialog.show();
- }
-
- function createColorPicker() {
- handleColorPickerSubmit = function () {
- colorPickerButtonClick($.oColorPicker.get('hex'));
- }
- handleDialogCancel = function () {
- this.cancel();
- }
- $.oColorPickerDialog = new YAHOO.widget.Dialog("yui-picker-panel", {
- width: "500px",
- close: true,
- visible: false,
- zindex: 1002,
- constraintoviewport: true,
- buttons: [{
- text: "Exit",
- handler: this.handleDialogCancel
- }]
- });
- $.oColorPickerDialog.renderEvent.subscribe(function () {
- if (!$.oColorPicker) { //make sure that we haven't already created our Color Picker
- createOColorPicker();
- }
- });
- $.oColorPickerDialog.render();
- $.oColorPickerDialog.show();
-
- function createOColorPicker() {
- $.oColorPicker = new YAHOO.widget.ColorPicker('color-picker-menu', {
- showhsvcontrols: false,
- showrgbcontrols: false,
- showwebsafe: false,
- showhexsummary: false,
- showhexcontrols: true,
- images: {
- PICKER_THUMB: "http://yui.yahooapis.com/2.9.0/build/colorpicker/assets/picker_thumb.png",
- HUE_THUMB: "http://yui.yahooapis.com/2.9.0/build/colorpicker/assets/hue_thumb.png"
- }
- });
- $.oColorPicker.on("rgbChange", colorPickerButtonClick);
- $.colorPickerAligned = true;
- }
- }
-
- function colorPickerButtonClick(sColor) {
- if (typeof (sColor) == 'string' && sColor != null && sColor.indexOf("#") == -1) {
- sColor = "#" + sColor;
- } else if (typeof (sColor) == "object") {
- sColor = this.get("hex") == null ? this.get("value") : "#" + this.get("hex");
- }
- var selParams = {
- borderWidth: null,
- tblPropertyChange: true
- };
- switch ($.tblfocusedProperty) {
- case "tbl_border_color":
- selParams.tblBorderColor = true;
- selParams.attrName = "borderColor";
- $.borderColorPickerButton.set("value", sColor);
- $("#current-color").css("backgroundColor", sColor);
- $("#current-color").innerHTML = "Current color is " + sColor;
- break;
- case 'tbl_cell_bg_color':
- selParams.tblCellBgColor = true;
- selParams.attrName = "bgColor";
- $.cellBgColorPickerButton.set("value", sColor);
- $("#current-cell-bg-color").css("backgroundColor", sColor);
- $("#current-cell-bg-color").innerHTML = "Current color is " + sColor;
- break;
- case "tbl_even_row_bg_color":
- selParams.tblEvenRowBgColor = true;
- selParams.attrName = "evenBgColor";
- $.evenRowBgColorPickerButton.set("value", sColor);
- $("#even-row-bg-color").css("backgroundColor", sColor);
- $("#even-row-bg-color").innerHTML = "Current color is " + sColor;
- break;
- case "tbl_odd_row_bg_color":
- selParams.tblOddRowBgColor = true;
- selParams.attrName = "oddBgColor";
- $.oddRowBgColorPickerButton.set("value", sColor);
- $("#odd-row-bg-color").css("backgroundColor", sColor);
- $("#odd-row-bg-color").innerHTML = "Current color is " + sColor;
- break;
- case "tbl_single_row_bg_color":
- selParams.tblSingleRowBgColor = true;
- selParams.attrName = "bgColor";
- $.singleRowBgColorPickerButton.set("value", sColor);
- $("#single-row-bg-color").css("backgroundColor", sColor);
- $("#single-row-bg-color").innerHTML = "Current color is " + sColor;
- break;
- case "tbl_single_col_bg_color":
- selParams.tblSingleColBgColor = true;
- selParams.attrName = "bgColor";
- $.singleColBgColorPickerButton.set("value", sColor);
- $("#single-col-bg-color").css("backgroundColor", sColor);
- $("#single-col-bg-color").innerHTML = "Current color is " + sColor;
- break;
- }
- selParams.attrValue = sColor;
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- $.handleTableBorder = function (selectValue) {
- var selParams = {
- tblBorderWidth: true,
- attrName: 'borderWidth',
- attrValue: selectValue,
- tblPropertyChange: true
- };
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- $.getTblPropertiesHTML = function () {
- return " " + " " + "" + "" + " ";
- }
- //initilizer
- if (typeof ($.tblContextMenu) == 'undefined') {
- var matrixTable = "";
- $.tblContextMenu = new YAHOO.widget.ContextMenu("tbl_context_menu", {
- iframe: true,
- zindex: 500,
- shadow: false,
- position: "dynamic",
- keepopen: true,
- clicktohide: true
- });
- $.tblContextMenu.addItems([
- [{
- text: "Insert Table",
- submenu: {
- id: 'tbl_insert',
- itemData: ["0 X 0
"]
- }
- }],
- ["Insert Row Above", "Insert Row Below", "Insert Column Right", "Insert Column Left"],
- ["Delete Row", "Delete Column", "Delete Table"],
- [{
- id: 'tbl_prop_menu_item',
- text: "Table Properties",
- onclick: {
- fn: showTblPropPanel
- }
- }]
- ]);
- var subMenus = $.tblContextMenu.getSubmenus();
- subMenus[0].setFooter(matrixTable);
- $.tblContextMenu.render(document.body);
- $.alignMenu = function (menu, id, addX, addY, scrollY) {
- var region = YAHOO.util.Dom.getRegion(id);
- if (typeof (id) == 'string' && (id == 'tbl-menu' || id == 'upload_image_cont')) {
- menu.cfg.setProperty("xy", [region.left, region.bottom]);
- } else if (typeof (id) == 'string') {
- menu.cfg.setProperty("xy", [region.right, region.top]);
- } else {
- menu.cfg.setProperty("xy", [30 + addX, 36 + addY - scrollY]);
- }
- }
- $('table td').hover(function () {
- for (var x = 0; x <= $(this).index(); x++) {
- for (var y = 0; y <= $(this).parent().index(); y++) {
- $(this).parent().parent().children().eq(y).children().eq(x).addClass('selected');
- }
- }
- }, function () {
- $('table td').removeClass('selected');
- });
- $('table td').hover(function () {
- xVal = this.getAttribute('value')
- yVal = $(this).closest("tr")[0].getAttribute("value");
- $("#select_matrix").html(xVal + " X " + yVal);
- });
- $("td", "#matrix_table").click(function (e) {
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions('addTbl', 'addTblX' + $("#select_matrix").text());
- }, 'tblOptions', true);
- return false;
- });
- $.tblContextMenu.subscribe("click", function (p_sType, p_aArgs) {
- var oEvent = p_aArgs[0],
- oMenuItem = p_aArgs[1]; // YAHOO.widget.MenuItem instance
- if (oMenuItem) {
- tblReq = oMenuItem.cfg.getProperty("text");
- disabled = oMenuItem.cfg.getProperty("disabled");
- if (disabled) return;
- var id = "";
- switch (tblReq) {
- case "Insert Table":
- id = 'addTbl';
- break;
- case "Insert Row Above":
- id = 'addTblRowA';
- break;
- case "Insert Row Below":
- id = 'addTblRowB';
- break;
- case "Insert Column Left":
- id = 'addTblColL';
- break;
- case "Insert Column Right":
- id = 'addTblColR';
- break;
- case "Delete Table":
- id = 'delTbl';
- break;
- case "Delete Image":
- id = 'delImg';
- break;
- case "Delete Row":
- id = 'delTblRow';
- break;
- case "Delete Column":
- id = 'delTblCol';
- break;
- }
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(id);
- }, 'tblOptions', true);
- return false;
- }
- });
-
- function initTableProperties() {
- //tbl col horizontal align
- var colVAligns = ['Left', 'Center', 'Right'];
- $.colVAlignsMenu = new YAHOO.widget.ContextMenu("tbl_col_v_align_menu", {
- iframe: true,
- zindex: 1003,
- shadow: false,
- position: "dynamic",
- keepopen: true,
- clicktohide: true
- });
- $.colVAlignsMenu.addItems(colVAligns);
- $.colVAlignsMenu.render(document.body);
- $.colVAlignsMenu.subscribe("click", function (p_sType, p_aArgs) {
- var oEvent = p_aArgs[0],
- oMenuItem = p_aArgs[1]; // YAHOO.widget.MenuItem instance
- if (oMenuItem) {
- align = oMenuItem.cfg.getProperty("text");
- var selParams = {
- tblColVAlign: true,
- attrName: 'colVAlign',
- attrValue: align,
- tblPropertyChange: true
- };
- $.colVAlignsMenuButton.set("value", selParams.attrValue);
- $("#current-col-v-alignment").html(align);
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- });
- $.colVAlignsMenuButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Left ",
- container: "tbl_col_v_align"
- });
- $('#tbl_col_v_align').click(function () {
- var aligned = false;
- if (!aligned) {
- $.alignMenu($.colVAlignsMenu, 'tbl_col_v_align');
- }
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- if ($.oColorPickerDialog) $.oColorPickerDialog.hide();
- $.colVAlignsMenu.show();
- var vAlignValue = $.colVAlignsMenuButton.get("value");
- if (vAlignValue) {
- var selParams = {
- tblColVAlign: true,
- attrName: 'colVAlign',
- attrValue: vAlignValue,
- tblPropertyChange: true
- };
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- });
- //tbl row vertical align
- var rowVAligns = ['Top', 'Center', 'Bottom'];
- $.rowVAlignsMenu = new YAHOO.widget.ContextMenu("tbl_row_v_align_menu", {
- iframe: true,
- zindex: 1003,
- shadow: false,
- position: "dynamic",
- keepopen: true,
- clicktohide: true
- });
- $.rowVAlignsMenu.addItems(rowVAligns);
- $.rowVAlignsMenu.render(document.body);
- $.rowVAlignsMenu.subscribe("click", function (p_sType, p_aArgs) {
- var oEvent = p_aArgs[0],
- oMenuItem = p_aArgs[1]; // YAHOO.widget.MenuItem instance
- if (oMenuItem) {
- align = oMenuItem.cfg.getProperty("text");
- var selParams = {
- tblRowVAlign: true,
- attrName: 'rowVAlign',
- attrValue: align,
- tblPropertyChange: true
- };
- $.rowVAlignsMenuButton.set("value", selParams.attrValue);
- $("#current-v-alignment").html(align);
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- });
- $.rowVAlignsMenuButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Top ",
- container: "tbl_row_v_align"
- });
- $('#tbl_row_v_align').click(function () {
- var aligned = false;
- if (!aligned) {
- $.alignMenu($.rowVAlignsMenu, 'tbl_row_v_align');
- }
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- if ($.oColorPickerDialog) $.oColorPickerDialog.hide();
- $.rowVAlignsMenu.show();
- var vAlignValue = $.rowVAlignsMenuButton.get("value");
- if (vAlignValue) {
- var selParams = {
- tblRowVAlign: true,
- attrName: 'rowVAlign',
- attrValue: vAlignValue,
- tblPropertyChange: true
- };
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- });
- //tbl border width
- var borderWidths = ['0px', '1px', '2px', '3px', '4px', '5px', '6px', '7px', '8px'];
- $.borderWidthsMenu = new YAHOO.widget.ContextMenu("tbl_border_width_menu", {
- iframe: true,
- zindex: 1003,
- shadow: false,
- position: "dynamic",
- keepopen: true,
- clicktohide: true
- });
- $.borderWidthsMenu.addItems(borderWidths);
- $.borderWidthsMenu.render(document.body);
- $.borderWidthsMenu.subscribe("click", function (p_sType, p_aArgs) {
- var oEvent = p_aArgs[0],
- oMenuItem = p_aArgs[1]; // YAHOO.widget.MenuItem instance
- if (oMenuItem) {
- borderReq = oMenuItem.cfg.getProperty("text");
- var selParams = {
- tblBorderWidth: true,
- attrName: 'borderWidth',
- attrValue: borderReq.substring(0, borderReq.indexOf("px")),
- tblPropertyChange: true
- };
- $.borderWidthPickerButton.set("value", selParams.attrValue);
- $("#current-width").html(borderReq);
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- });
- $.borderWidthPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "1px ",
- container: "tbl_border_width"
- });
- $('#tbl_border_width').click(function () {
- var aligned = false;
- if (!aligned) {
- $.alignMenu($.borderWidthsMenu, 'tbl_border_width');
- }
- if ($.oColorPickerDialog) $.oColorPickerDialog.hide();
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- $.borderWidthsMenu.show();
- var widthValue = $.borderWidthPickerButton.get("value");
- if (widthValue) {
- var selParams = {
- tblBorderWidth: true,
- attrName: 'borderWidth',
- attrValue: widthValue,
- tblPropertyChange: true
- };
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- }
- });
- $.tblfocusedProperty = "";
- $('#tbl_properties').click(function () {
- if (typeof ($.borderWidthsMenu) != 'undefined') $.borderWidthsMenu.hide();
- if (typeof ($.oColorPickerDialog) != 'undefined') $.oColorPickerDialog.hide();
- if (typeof ($.rowVAlignsMenu) != 'undefined') $.rowVAlignsMenu.hide();
- });
- $.colorPickerAligned = false;
- $('#tbl_border_color').click(function () {
- if (!$.colorPickerAligned) {
- createColorPicker();
- }
- $.alignMenu($.oColorPickerDialog, 'tbl_border_color');
- $.tblfocusedProperty = "tbl_border_color";
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- $.oColorPickerDialog.setHeader("Please choose a color for: Table Border color");
- $.oColorPickerDialog.show();
- var hexValue = $.borderColorPickerButton.get("value");
- if (hexValue) {
- colorPickerButtonClick(hexValue);
- }
- });
- $.borderColorPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Current color is #FFFFFF. ",
- container: "tbl_border_color"
- });
- //tbl cell bg color
- $.cellBgColorPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Current color is #FFFFFF. ",
- container: "tbl_cell_bg_color"
- });
- $('#tbl_cell_bg_color').click(function () {
- if (!$.colorPickerAligned) {
- createColorPicker();
- }
- $.alignMenu($.oColorPickerDialog, 'tbl_cell_bg_color');
- $.tblfocusedProperty = "tbl_cell_bg_color";
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- $.oColorPickerDialog.setHeader("Please choose a color for: Cell Background color");
- $.oColorPickerDialog.show();
- var hexValue = $.cellBgColorPickerButton.get("value");
- if (hexValue) {
- colorPickerButtonClick(hexValue);
- }
- });
- //tbl even rows bg color
- $.evenRowBgColorPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Current color is #FFFFFF. ",
- container: "tbl_even_row_bg_color"
- });
- $('#tbl_even_row_bg_color').click(function () {
- if (!$.colorPickerAligned) {
- createColorPicker();
- }
- $.alignMenu($.oColorPickerDialog, 'tbl_even_row_bg_color');
- $.tblfocusedProperty = "tbl_even_row_bg_color";
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- $.oColorPickerDialog.setHeader("Please choose a color for: Even Row Background color");
- $.oColorPickerDialog.show();
- var hexValue = $.evenRowBgColorPickerButton.get("value");
- if (hexValue) {
- colorPickerButtonClick(hexValue);
- }
- });
- //tbl odd rows bg color
- $.oddRowBgColorPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Current color is #FFFFFF. ",
- container: "tbl_odd_row_bg_color"
- });
- $('#tbl_odd_row_bg_color').click(function () {
- if (!$.colorPickerAligned) {
- createColorPicker();
- }
- $.alignMenu($.oColorPickerDialog, 'tbl_odd_row_bg_color');
- $.tblfocusedProperty = "tbl_odd_row_bg_color";
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- $.oColorPickerDialog.setHeader("Please choose a color for: Odd Row Background color");
- $.oColorPickerDialog.show();
- var hexValue = $.oddRowBgColorPickerButton.get("value");
- if (hexValue) {
- colorPickerButtonClick(hexValue);
- }
- });
- //tbl single row bg color
- $.singleRowBgColorPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Current color is #FFFFFF. ",
- container: "tbl_single_row_bg_color"
- });
- $('#tbl_single_row_bg_color').click(function () {
- if (!$.colorPickerAligned) {
- createColorPicker();
- }
- $.alignMenu($.oColorPickerDialog, 'tbl_single_row_bg_color');
- $.tblfocusedProperty = "tbl_single_row_bg_color";
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- $.oColorPickerDialog.setHeader("Please choose a color for: Single Row Background color");
- $.oColorPickerDialog.show();
- var hexValue = $.singleRowBgColorPickerButton.get("value");
- if (hexValue) {
- colorPickerButtonClick(hexValue);
- }
- });
- //tbl single col bg color
- $.singleColBgColorPickerButton = new YAHOO.widget.Button({
- disabled: false,
- type: "split",
- label: "Current color is #FFFFFF. ",
- container: "tbl_single_col_bg_color"
- });
- $('#tbl_single_col_bg_color').click(function () {
- if (!$.colorPickerAligned) {
- createColorPicker();
- }
- $.alignMenu($.oColorPickerDialog, 'tbl_single_col_bg_color');
- $.tblfocusedProperty = "tbl_single_col_bg_color";
- if ($.rowVAlignsMenu) $.rowVAlignsMenu.hide();
- if ($.borderWidthsMenu) $.borderWidthsMenu.hide();
- $.oColorPickerDialog.setHeader("Please choose a color for: Single Column Background color");
- $.oColorPickerDialog.show();
- var hexValue = $.singleColBgColorPickerButton.get("value");
- if (hexValue) {
- colorPickerButtonClick(hexValue);
- }
- });
- //tbl property text inputs
- $('.text-input').change(function () {
- var selParams = {
- tblPropertyChange: true
- };
- if (this.id == "tbl_width") {
- selParams.tblWidth = true;
- selParams.attrName = "width";
- } else if (this.id == "tbl_height") {
- selParams.tblHeight = true;
- selParams.attrName = "height";
- } else if (this.id == "tbl_col_width") {
- selParams.tblColWidth = true;
- selParams.attrName = "width";
- } else if (this.id == "tbl_row_height") {
- selParams.tblCellHeight = true;
- selParams.attrName = "height";
- } else if (this.id == "tbl_cell_padding") {
- selParams.tblCellPadding = true;
- selParams.attrName = "padding";
- } else if (this.id == "tbl_cell_font_size") {
- selParams.tblCellFontSize = true;
- selParams.attrName = "fontSize";
- } //image attrs
- else if (this.id == "img_width") {
- selParams.imgWidth = true;
- selParams.attrName = "width";
- } else if (this.id == "img_height") {
- selParams.imgHeight = true;
- selParams.attrName = "height";
- }
- selParams.attrValue = this.value;
- this.value = '';
- $('#text_input_message').text("Ok");
- $('#text_input_message').removeAttr('style');
- $('#text_input_message').fadeOut("slow");
- context.ace.callWithAce(function (ace) {
- ace.ace_doDatatableOptions(selParams);
- }, 'tblOptions', true);
- });
- }
- }
- if (!init) {
- $.alignMenu($.tblContextMenu, 'tbl-menu');
- $.tblContextMenu.show();
- }
- };
- $('#tbl-menu').click($.createTableMenu);
- YAHOO.util.Dom.addClass(document.body, 'yui-skin-sam');
- $("body").append($('' + '
Please choose a color:
' + '
' + ' ' + '
' + '
' + '
'));
- $("body").append($('' + '
Table/Image Properties
' + '
' + '
' + '
'));
- $.createTableMenu(true);
-};
-// Once ace is initialized, we set ace_doDatatableOptions and bind it to the context
-exports.aceInitialized = function (hook, context) {
- var editorInfo = context.editorInfo;
- editorInfo.ace_doDatatableOptions = _(Datatables.doDatatableOptions).bind(context);
-};
-exports.acePostWriteDomLineHTML = function (hook_name, args, cb) {
- // Iterate through the child nodes (spans) and point SyntaxHighlighter at them
- var children = args.node.children;
- for (var i = 0; i < children.length; i++) {
- if (args.node.children[i].className.indexOf("list") != -1 || args.node.children[i].className.indexOf("tag") != -1 || args.node.children[i].className.indexOf("url") != -1) continue;
- var lineText = "";
- if (args.node.children[i].innerText) lineText = args.node.children[i].innerText;
- else lineText = args.node.children[i].textContent;
- if (lineText && lineText.indexOf("data-tables") != -1) {
- var dtAttrs = typeof (exports.Datatables) != 'undefined' ? exports.Datatables.attributes : null;
- dtAttrs = dtAttrs || "";
- DatatablesRenderer.render({}, args.node.children[i], dtAttrs);
- exports.Datatables.attributes = null;
- }
- }
-}
-exports.eejsBlock_scripts = function (hook_name, args, cb) {
- args.content = args.content + require('ep_etherpad-lite/node/eejs/').require("ep_tables/templates/datatablesScripts.ejs");
-}
-exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {
- args.content = args.content + require('ep_etherpad-lite/node/eejs/').require("ep_tables/templates/datatablesEditbarButtons.ejs");
-}
-exports.eejsBlock_styles = function (hook_name, args, cb) {
- args.content = require('ep_etherpad-lite/node/eejs/').require("ep_tables/templates/styles.ejs") + args.content;
-}
-// Our heading attribute will result in a heaading:h1... :h6 class
-exports.aceAttribsToClasses = function (hook, context) {
- Datatables.attributes = null;
- if (context.key == 'tblProp') {
- Datatables.attributes = context.value;
- return ['tblProp:' + context.value];
- }
-}
-exports.aceStartLineAndCharForPoint = function (hook, context) {
- var selStart = null;
- try {
- Datatables.context = context;
- if (Datatables.isFocused()) {
- selStart = Datatables.getLineAndCharForPoint();
- }
- } catch (error) {
- top.console.log('error ' + error);
- top.console.log('context rep' + Datatables.context.rep);
- }
- return selStart;
-};
-
-exports.aceEndLineAndCharForPoint = function (hook, context) {
- var selEndLine = null;
- try {
- Datatables.context = context;
- if (Datatables.isFocused()) {
- selEndLine = Datatables.getLineAndCharForPoint();
- }
- } catch (error) {
- top.console.log('error ' + error);
- top.console.log('context rep' + Datatables.context.rep);
- }
- return selEndLine;
-};
-exports.aceKeyEvent = function (hook, context) {
-
- var specialHandled = false;
- try {
- Datatables.context = context;
- if (Datatables.isFocused()) {
- var evt = context.evt;
- var type = evt.type;
- var keyCode = evt.keyCode;
- var isTypeForSpecialKey = ((Ace2Common.browser.msie || Ace2Common.browser.safari) ? (type == "keydown") : (type == "keypress"));
- var isTypeForCmdKey = ((Ace2Common.browser.msie || Ace2Common.browser.safari) ? (type == "keydown") : (type == "keypress"));
- var which = evt.which;
- if ((!specialHandled) && isTypeForSpecialKey && keyCode == 9 && !(evt.metaKey || evt.ctrlKey)) {
- context.editorInfo.ace_fastIncorp(5);
- evt.preventDefault();
- Datatables.performDocumentTableTabKey();
- specialHandled = true;
- }
- if ((!specialHandled) && isTypeForSpecialKey && keyCode == 13) {
- // return key, handle specially;
- context.editorInfo.ace_fastIncorp(5);
- evt.preventDefault();
- Datatables.doReturnKey();
- specialHandled = true;
- }
- if ((!specialHandled) && isTypeForSpecialKey && (keyCode == Datatables.vars.JS_KEY_CODE_DEL || keyCode == Datatables.vars.JS_KEY_CODE_BS || (String.fromCharCode(which).toLowerCase() == "h" && (evt.ctrlKey)))) {
- context.editorInfo.ace_fastIncorp(20);
- evt.preventDefault();
- specialHandled = true;
- if (Datatables.isCellDeleteOk(keyCode)) {
- Datatables.doDeleteKey();
- }
- }
- }
- } catch (error) {}
- //console.log(' ace key evt specialHandled ',specialHandled);
- return specialHandled;
-};
-if (typeof (Datatables) == 'undefined') var Datatables = function () {
- // Get the text within an element
- // Doesn't do any normalising, returns a string
- // of text as found.
- function nodeText(n) {
- var text = [];
- var self = arguments.callee;
- var el, els = n.childNodes;
- var excluded = {
- 'noscript': 'noscript',
- 'script': 'script',
- };
- for (var i = 0, iLen = els.length; i < iLen; i++) {
- el = els[i];
- // May need to add other node types here
- if (el.nodeType == 1 && !(el.tagName.toLowerCase() in excluded)) {
- text.push(self(el));
- // If working with XML, add nodeType 4 to get text from CDATA nodes
- } else if (el.nodeType == 3) {
- // Deal with extra whitespace and returns in text here.
- text.push(el.data);
- }
- }
- return text.join('');
- }
- var dt = {
- defaults: {
- tblProps: {
- borderWidth: "1",
- cellAttrs: [],
- width: "6",
- rowAttrs: {},
- colAttrs: [],
- authors: {}
- }
- },
- config: {},
- /** Internal 'global' variables. */
- vars: {
- OVERHEAD_LEN_PRE: '{"payload":[["'.length,
- OVERHEAD_LEN_MID: '","'.length,
- OVERHEAD_LEN_ROW_START: '["'.length,
- OVERHEAD_LEN_ROW_END: '"],'.length,
- JS_KEY_CODE_BS: 8,
- JS_KEY_CODE_DEL: 46,
- TBL_OPTIONS: ['addTbl', 'addTblRowA', 'addTblRowB', 'addTblColL', 'addTblColR', 'delTbl', 'delTblRow', 'delTblCol', 'delImg']
- },
- /* passed parameters */
- context: null
- }; // end of dt
- dt.isFocused = function () {
- if (!this.context.rep.selStart || !this.context.rep.selEnd) return false;
- var line = this.context.rep.lines.atIndex(this.context.rep.selStart[0]);
- if (!line) return false;
- var currLineText = line.text || '';
- if (currLineText.indexOf("data-tables") == -1) {
- return false;
- }
- return true;
- };
- /* Helper function. not meant to be used as a standalone function
-
- requires rowStartOffset
-
- */
- dt._getRowEndOffset = function (rowStartOffset, tds) {
- var rowEndOffset = rowStartOffset + this.vars.OVERHEAD_LEN_ROW_START;
- for (var i = 0, len = tds.length; i < len; i++) {
- var overHeadLen = this.vars.OVERHEAD_LEN_MID;
- if (i == len - 1) {
- overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
- }
- rowEndOffset += tds[i].length + overHeadLen;
- }
- return rowEndOffset;
- }
- /**
-
- current row index,
-
- td index ,
-
- the length of leftover text of the current cell,
-
- current row start offset,
-
- current row end offset,
-
- current td start offset,
-
- current td end offset,
-
- and cellCaretPos
-
- */
- dt.getFocusedTdInfo = function (payload, colStart) {
- var payloadOffset = colStart - this.vars.OVERHEAD_LEN_PRE;
- var rowStartOffset = 0;
- var payloadSum = 0;
- for (var rIndex = 0, rLen = payload.length; rIndex < rLen; rIndex++) {
- var tds = payload[rIndex];
- for (var tIndex = 0, tLen = tds.length; tIndex < tLen; tIndex++) {
- var overHeadLen = this.vars.OVERHEAD_LEN_MID;
- if (tIndex == tLen - 1) {
- overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
- }
- payloadSum += tds[tIndex].length + overHeadLen;
- if (payloadSum >= payloadOffset) {
- if (payloadSum == payloadOffset) {
- tIndex++;
- }
- var leftOverTdTxtLen = payloadSum - payloadOffset == 0 ? payload[rIndex][tIndex].length + this.vars.OVERHEAD_LEN_MID : payloadSum - payloadOffset;
- var cellCaretPos = tds[tIndex].length - (leftOverTdTxtLen - overHeadLen);
- var rowEndOffset = this._getRowEndOffset(rowStartOffset, tds);
- return {
- row: rIndex,
- td: tIndex,
- leftOverTdTxtLen: leftOverTdTxtLen,
- rowStartOffset: rowStartOffset,
- rowEndOffset: rowEndOffset,
- cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen,
- cellEndOffset: payloadSum,
- cellCaretPos: cellCaretPos
- };
- }
- }
- rowStartOffset = payloadSum;
- payloadSum += this.vars.OVERHEAD_LEN_ROW_START;
- }
- };
- dt.printCaretPos = function (start, end) {
- top.console.log(JSON.stringify(start));
- top.console.log(JSON.stringify(end));
- };
- dt.doDatatableOptions = function (cmd, xByY) {
- Datatables.context = this; // the scope is still ep lite and not DataTables because of the binding we have to do in exports.aceInitialized
- if ((typeof (cmd) == 'object' && cmd.tblPropertyChange)) {
- Datatables.updateTableProperties(cmd);
- } else {
- switch (cmd) {
- case Datatables.vars.TBL_OPTIONS[0]:
- Datatables.addTable(xByY);
- break;
- case Datatables.vars.TBL_OPTIONS[1]:
- Datatables.insertTblRow("addA");
- break;
- case Datatables.vars.TBL_OPTIONS[2]:
- Datatables.insertTblRow("addB");
- break;
- case Datatables.vars.TBL_OPTIONS[3]:
- Datatables.insertTblColumn("addL");
- break;
- case Datatables.vars.TBL_OPTIONS[4]:
- Datatables.insertTblColumn("addR");
- break;
- case Datatables.vars.TBL_OPTIONS[5]:
- Datatables.deleteTable();
- break;
- case Datatables.vars.TBL_OPTIONS[6]:
- Datatables.deleteTblRow();
- break;
- case Datatables.vars.TBL_OPTIONS[7]:
- Datatables.deleteTblColumn();
- break;
- }
- }
- };
- dt.addTable = function (tableObj) {
- var rep = this.context.rep;
- var start = rep.selStart;
- var end = rep.selEnd;
- var line = rep.lines.atIndex(rep.selStart[0]);
- var hasMoreRows = null;
- var isRowAddition = null;
- if (tableObj) {
- hasMoreRows = tableObj.hasMoreRows;
- isRowAddition = tableObj.isRowAddition;
- }
- if (isRowAddition) {
- var table = JSON.parse(tableObj.tblString);
- insertTblRowBelow(0, table);
- performDocApplyTblAttrToRow(rep.selStart, JSON.stringify(table.tblProperties));
- return;
- }
- //if the carret is within a table, add the new table at the bottom
- if (line) {
- var currLineText = line.text;
- if (currLineText.indexOf("data-tables") != -1) {
- do {
- rep.selStart[0] = rep.selStart[0] + 1
- currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- } while (currLineText.indexOf("data-tables") != -1);
- rep.selEnd[1] = rep.selStart[1] = currLineText.length;
- this.context.editorInfo.ace_doReturnKey();
- this.context.editorInfo.ace_doReturnKey();
- } else {
- rep.selEnd[1] = rep.selStart[1] = currLineText.length;
- this.context.editorInfo.ace_doReturnKey();
- // this.context.editorInfo.ace_inCallStackIfNecessary ('newline',this.context.editorInfo.ace_doReturnKey);
- }
- }
- //if no col/row specified, create a default 3X3 empty table
- if (tableObj == null) {
- var authors = {};
- this.insertTblRowBelow(3);
- this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
- this.insertTblRowBelow(3);
- this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties(authors));
- this.insertTblRowBelow(3);
- this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties(authors));
- this.context.editorInfo.ace_doReturnKey();
- //this.context.editorInfo.ace_inCallStackIfNecessary ('newline',this.context.editorInfo.ace_doReturnKey);
- this.updateAuthorAndCaretPos(rep.selStart[0] - 3);
- return;
- }
- //xbyy cols and rows have been specified or an actual payload object is present, for the former, create x rows of magicdom lines that contain a row
- //per table.
- xByYSelect = typeof (tableObj) == "object" ? null : tableObj.split("X");
- if (xByYSelect != null && xByYSelect.length == 3) {
- var cols = parseInt(xByYSelect[1]);
- var rows = parseInt(xByYSelect[2]);
- var jsoStrTblProp = JSON.stringify(this.createDefaultTblProperties());
- var authors = {};
- for (var i = 0; i < rows; i++) {
- this.insertTblRowBelow(cols);
- if (i == 0) {
- this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
- } else {
- this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties(authors));
- }
- }
- this.updateAuthorAndCaretPos(rep.selStart[0] - rows + 1);
- return;
- }
- return newText;
- };
- //insert a row
- dt.insertTblRow = function (aboveOrBelow) {
- var func = 'insertTblRow()';
- var rep = this.context.rep;
- try {
- var newText = "";
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var payload = JSON.parse(currLineText).payload;
- var currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
- var currRow = currTdInfo.row;
- var lastRowOffSet = 0;
- var start = [],
- end = [];
- start[0] = rep.selStart[0], start[1] = rep.selStart[1];
- end[0] = rep.selStart[0], end[1] = rep.selStart[1];
- if (aboveOrBelow == 'addA') {
- rep.selStart[0] = rep.selEnd[0] = rep.selStart[0] - 1;
- this.insertTblRowBelow(payload[0].length);
- } else { //below curr row ( aboveOrBelow = 'addB')
- this.insertTblRowBelow(payload[0].length);
- }
- this.context.editorInfo.ace_performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
- this.updateAuthorAndCaretPos(rep.selStart[0]);
- var updateEvenOddBgColor = true;
- this.sanitizeTblProperties(rep.selStart, updateEvenOddBgColor);
- } catch (error) {
- //domline.createErrorState(start,end,'insertTblRow',rep.lines.atIndex(rep.selStart[0]).text,rep.selStart,rep.selEnd,newText,error);
- }
- };
- //delete a table, also removes table overhead
- dt.deleteTable = function () {
- var rep = this.context.rep;
- var func = 'deleteTable()';
- var start = rep.seStart;
- var end = rep.seEnd;
- try {
- var line = rep.selStart[0] - 1;
- var numOfLinesAbove = 0;
- var numOfLinesBelow = 0;
- while (rep.lines.atIndex(line).text.indexOf('data-tables') != -1) { //count num of rows above current pos
- numOfLinesAbove++;
- line--;
- }
- line = rep.selEnd[0] + 1;
- while (rep.lines.atIndex(line).text.indexOf('data-tables') != -1) { //count num of rows below current pos
- numOfLinesBelow++;
- line++;
- }
- rep.selStart[1] = 0;
- rep.selStart[0] = rep.selStart[0] - numOfLinesAbove;
- rep.selEnd[0] = rep.selEnd[0] + numOfLinesBelow;
- rep.selEnd[1] = rep.lines.atIndex(rep.selEnd[0]).text.length;
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- } catch (error) {
- //domline.createErrorState(start,end,func,rep.lines.atIndex(rep.selStart[0]).text,rep.selStart,rep.selEnd,"",error);
- }
- };
- //delete a row
- dt.deleteTblRow = function () {
- var func = 'deleteTblRow()';
- var rep = this.context.rep;
- try {
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- if (currLineText.indexOf('data-tables') == -1) return;
- rep.selEnd[0] = rep.selStart[0] + 1;
- rep.selStart[1] = 0;
- rep.selEnd[1] = 0;
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- if (currLineText.indexOf('data-tables') == -1) return;
- this.updateAuthorAndCaretPos(rep.selStart[0], 0, 0);
- updateEvenOddBgColor = true;
- this.sanitizeTblProperties(rep.selStart, updateEvenOddBgColor);
- } catch (error) {
- //domline.createErrorState(start,end,'deleteTblRow',rep.lines.atIndex(rep.selStart[0]).text,rep.selStart,rep.selEnd,"",error);
- }
- };
- dt.updateTableProperties = function (props) {
- var rep = this.context.rep;
- var currTd = null;
- if (props.tblColWidth || props.tblSingleColBgColor || props.tblColVAlign) {
- var currLine = rep.lines.atIndex(rep.selStart[0]);
- var currLineText = currLine.text;
- var tblJSONObj = JSON.parse(currLineText);
- var payload = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
- currTd = currTdInfo.td;
- }
- if (props.tblWidth || props.tblHeight || props.tblBorderWidth || props.tblBorderColor || props.tblColWidth || props.tblSingleColBgColor || props.tblEvenRowBgColor || props.tblOddRowBgColor || props.tblColVAlign) {
- var start = [];
- start[0] = rep.selStart[0], start[1] = rep.selStart[1];
- var numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
- var tempStart = [];
- tempStart[0] = start[0] - numOfLinesAbove;
- tempStart[1] = start[1];
- while (tempStart[0] < rep.lines.length() && rep.lines.atIndex(tempStart[0]).text.indexOf('data-tables') != -1) { //start from top of a table
- if (props.tblEvenRowBgColor && tempStart[0] % 2 != 0) {
- tempStart[0] = tempStart[0] + 1;
- continue;
- } else if (props.tblOddRowBgColor && tempStart[0] % 2 == 0) {
- tempStart[0] = tempStart[0] + 1;
- continue;
- }
- this.updateTablePropertiesHelper(props, tempStart, currTd);
- tempStart[0] = tempStart[0] + 1;
- }
- } else {
- var start = [];
- start[0] = rep.selStart[0];
- start[1] = rep.selStart[1];
- this.updateTablePropertiesHelper(props, start, currTd);
- }
- };
- dt.addCellAttr = function (start, tblJSONObj, tblProperties, attrName, attrValue) {
- var rep = this.context.rep;
- var payload = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(payload, start[1]);
- var currRow = currTdInfo.row;
- var currTd = currTdInfo.td;
- var cellAttrs = tblProperties.cellAttrs;
- var row = cellAttrs[currRow];
- if (row == null || typeof (row) == 'undefined') {
- row = [];
- }
- cell = row[currTd];
- if (cell == null || typeof (cell) == 'undefined') {
- cell = {};
- }
- //toggle these attributes
- if (attrName == 'fontWeight' || attrName == 'fontStyle' || attrName == 'textDecoration') {
- if (cell[attrName] == attrValue) {
- attrValue = '';
- }
- } else if (cell[attrName] == attrValue) return false; //other wise no need to update
- cell[attrName] = attrValue;
- row[currTd] = cell;
- cellAttrs[currRow] = row;
- tblProperties.cellAttrs = cellAttrs;
- return tblProperties;
- };
- //returns false if no chanage to tblProperties
- dt.addRowAttr = function (tblJSONObj, tblProperties, attrName, attrValue) {
- var rep = this.context.rep;
- var rowAttrs = tblProperties.rowAttrs;
- if (attrName == 'bgColor') { //specific single row property
- var payload = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
- var currRow = currTdInfo.row;
- var singleRowAttrs = rowAttrs.singleRowAttrs;
- if (singleRowAttrs == null || typeof (singleRowAttrs) == 'undefined') {
- singleRowAttrs = [];
- }
- if (singleRowAttrs[currRow] == null || typeof (singleRowAttrs[currRow]) == 'undefined') {
- singleRowAttrs[currRow] = {};
- } else if (singleRowAttrs[currRow][attrName] == attrValue) {
- return false;
- }
- singleRowAttrs[currRow][attrName] = attrValue;
- rowAttrs.singleRowAttrs = singleRowAttrs;
- } else { //even-odd rows properties,rowAlign
- if (rowAttrs[attrName] == attrValue) return false;
- rowAttrs[attrName] = attrValue;
- }
- tblProperties.rowAttrs = rowAttrs;
- return tblProperties;
- };
- //returns false if no chanage to tblProperties
- dt.addColumnAttr = function (start, tblJSONObj, tblProperties, attrName, attrValue, currTd) {
- var payload = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(payload, start[1]);
- var colAttrs = tblProperties.colAttrs;
- if (colAttrs == null || typeof (colAttrs) == 'undefined') {
- colAttrs = [];
- }
- if (colAttrs[currTd] == null || typeof (colAttrs[currTd]) == 'undefined') {
- colAttrs[currTd] = {};
- } else if (colAttrs[currTd][attrName] == attrValue) {
- return false;
- }
- colAttrs[currTd][attrName] = attrValue;
- tblProperties.colAttrs = colAttrs;
- return tblProperties;
- };
- dt.updateTablePropertiesHelper = function (props, start, currTd) {
- var rep = this.context.rep;
- lastTblPropertyUsed = 'updateTableProperties';
- start = start || rep.selStart;
- if (!(start)) return;
- var currLine = rep.lines.atIndex(start[0]);
- var currLineText = currLine.text;
- if (currLineText.indexOf('data-tables') == -1) return true;
- try {
- var tblJSONObj = JSON.parse(currLineText);
- var tblProperties = this.getLineTableProperty(start[0]);
- var update = false;
- //table width , height , border width and tbl color
- if (props.tblWidth || props.tblHeight || props.tblBorderWidth || props.tblBorderColor) {
- var currAttrValue = tblProperties[props.attrName];
- if (props.attrValue != null && (typeof (currAttrValue) == 'undefined' || currAttrValue != props.attrValue)) {
- tblProperties[props.attrName] = props.attrValue;
- update = true;
- }
- }
- /*
-
- set or unset table cells attrs
-
- bold , italic , line-through/underline;
-
- */
- if (props.tblCellFontWeight || props.tblCellFontStyle || props.tblCellTextDecoration) {
- var tblProps = this.addCellAttr(start, tblJSONObj, tblProperties, props.attrName, props.attrValue);
- if (tblProps) {
- tblProperties = tblProps;
- update = true;
- }
- }
- //cell background color, height, and padding, cell font size
- if (props.tblCellFontSize || props.tblCellBgColor || props.tblCellHeight || props.tblCellPadding || props.tblcellVAlign) {
- var tblProps = this.addCellAttr(start, tblJSONObj, tblProperties, props.attrName, props.attrValue);
- if (tblProps) {
- tblProperties = tblProps;
- update = true;
- }
- }
- //even/odd row background color
- if (props.tblEvenRowBgColor || props.tblOddRowBgColor) {
- var tblProps = this.addRowAttr(tblJSONObj, tblProperties, props.attrName, props.attrValue);
- if (tblProps) {
- tblProperties = tblProps;
- update = true;
- }
- }
- //single row background color, rowVAlign
- if (props.tblSingleRowBgColor || props.tblRowVAlign) {
- var tblProps = this.addRowAttr(tblJSONObj, tblProperties, props.attrName, props.attrValue);
- if (tblProps) {
- tblProperties = tblProps;
- update = true;
- }
- }
- // col width, col bgColor, colVAlign
- if (props.tblColWidth || props.tblSingleColBgColor || props.tblColVAlign) {
- var tblProps = this.addColumnAttr(start, tblJSONObj, tblProperties, props.attrName, props.attrValue, currTd);
- if (tblProps) {
- tblProperties = tblProps;
- update = true;
- }
- }
- //only update if there is a change
- if (update) {
- this.updateTblPropInAPool(-1, -1, tblProperties, start);
- }
- } catch (error) {
- // domline.createErrorState(start,end,'updateTableProperties',rep.lines.atIndex(rep.selStart[0]).text,rep.selStart,rep.selEnd,"",error);
- }
- };
- dt.updateAuthorAndCaretPos = function (magicDomLineNum, tblRowNum, tblColNum) {
- var rep = this.context.rep;
- rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
- rep.selStart[0] = rep.selEnd[0] = magicDomLineNum;
- var row = typeof (tblRowNum) == 'undefined' || tblRowNum == null ? 0 : tblRowNum;
- var col = typeof (tblColNum) == 'undefined' || tblRowNum == null ? 0 : tblColNum;
- this.updateTblPropInAPool(row, col, null, rep.selStart);
- rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
- }
- dt.insertTblRowBelow = function (numOfRows, table) {
- var rep = this.rep;
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var payload = [
- []
- ];
- if (!numOfRows && numOfRows != 0) {
- var tblPayload = JSON.parse(currLineText).payload;
- numOfRows = tblPayload[0].length;
- }
- var tblRows = new Array(numOfRows);
- if (numOfRows != 0) {
- for (var i = 0; i < tblRows.length; i++) {
- tblRows[i] = " ";
- }
- }
- payload = [tblRows];
- if (table) {
- payload = table.payload;
- }
- tableObj = {
- "payload": payload,
- "tblId": 1,
- "tblClass": "data-tables",
- "trClass": "alst",
- "tdClass": "hide-el"
- }
- rep.selEnd[1] = rep.selStart[1] = currLineText.length;
- this.context.editorInfo.ace_doReturnKey();
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, JSON.stringify(tableObj));
- };
- dt.createDefaultTblProperties = function (authors) {
- var rep = this.context.rep;
- var defTblProp = {
- borderWidth: "1",
- cellAttrs: [],
- width: "6",
- rowAttrs: {},
- colAttrs: [],
- authors: {}
- };
- if (authors) {
- defTblProp['authors'] = authors;
- }
- //from existing Table tableborder,tbl_border_width,table_width and table_height
- var prevLine = rep.lines.atIndex(rep.selEnd[0] - 1);
- var jsoTblProp = null;
- if (prevLine) {
- var prevLineText = prevLine.text;
- if (prevLineText.indexOf("data-tables") != -1) {
- jsoTblProp = this.getLineTableProperty(rep.selStart[0] - 1);
- }
- }
- if (!jsoTblProp) {
- var nextLine = rep.lines.atIndex(rep.selEnd[0] - 1);
- if (nextLine) {
- var nextLineText = nextLine.text;
- if (nextLineText.indexOf("data-tables") != -1) {
- jsoTblProp = this.getLineTableProperty(rep.selStart[0] + 1);
- }
- }
- }
- if (jsoTblProp) {
- defTblProp.borderWidth = jsoTblProp.borderWidth;
- defTblProp.borderColor = jsoTblProp.borderColor;
- defTblProp.width = jsoTblProp.width;
- defTblProp.height = jsoTblProp.height;
- defTblProp.colAttrs = jsoTblProp.colAttrs;
- }
- var jsoStrTblProp = JSON.stringify(defTblProp);
- return jsoStrTblProp;
- }
- dt.performDocApplyTblAttrToRow = function (start, jsoStrTblProp) {
- var tempStart = [],
- tempEnd = [];
- tempStart[0] = start[0], tempEnd[0] = start[0];
- tempStart[1] = 0, tempEnd[1] = this.context.rep.lines.atIndex(start[0]).text.length;
- this.context.editorInfo.ace_performDocumentApplyAttributesToRange(tempStart, tempEnd, [
- ["tblProp", jsoStrTblProp]
- ]);
- }
- /* handles tab key within a table */
- dt.performDocumentTableTabKey = function () {
- try {
- var context = this.context;
- var rep = context.rep;
- var currLine = rep.lines.atIndex(rep.selStart[0]);
- var currLineText = currLine.text;
- var tblJSONObj = JSON.parse(currLineText);
- var payload = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
- var leftOverTdTxtLen = currTdInfo.leftOverTdTxtLen;
- var currRow = currTdInfo.row;
- var currTd = currTdInfo.td;
- if (typeof (payload[currRow][currTd + 1]) == "undefined") { //next row
- currRow += 1;
- var nextLine = rep.lines.atIndex(rep.selStart[0] + 1);
- var nextLineText = nextLine.text;
- var updateEvenOddBgColor = false;
- if (nextLineText == null || nextLineText == '' || nextLineText.indexOf('data-tables') == -1) { //create new row and move caret to this new row
- this.insertTblRowBelow(null, null);
- this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
- rep.selEnd[1] = rep.selStart[1] = this.vars.OVERHEAD_LEN_PRE;
- updateEvenOddBgColor = true;
- } else { //just move caret to existing next row
- currTd = -1;
- rep.selStart[0] = rep.selEnd[0] = rep.selStart[0] + 1;
- var tblJSONObj = JSON.parse(nextLineText);
- var payload = tblJSONObj.payload;
- leftOverTdTxtLen = payload[0][0].length;
- rep.selEnd[1] = rep.selStart[1] = this.vars.OVERHEAD_LEN_PRE + leftOverTdTxtLen;
- }
- context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- var start = [];
- start[0] = rep.selStart[0];
- start[1] = rep.selStart[1];
- dt.updateTblCellAuthor(0, 0, null, start, updateEvenOddBgColor); //this requires removing potential user color in a differnt row(although it should only check the previous row)
- } else { //tab to the next col and update cell user color
- var nextTdTxtLen = typeof (payload[currRow]) == 'undefined' ? -leftOverTdTxtLen : payload[currRow][currTd + 1].length;
- payload = tblJSONObj.payload;
- rep.selStart[1] = rep.selEnd[1] = rep.selEnd[1] + nextTdTxtLen + leftOverTdTxtLen;
- context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- // debugger;
- dt.updateTblPropInAPool(currRow, currTd + 1, null, rep.selStart); //this need not to update entire table of color setting
- }
- } catch (error) {}
- };
- dt.getTdInfo = function (payload, tdIndex) {
- var rep = this.context.rep;
- var startOffset = this.vars.OVERHEAD_LEN_PRE;
- var rowStartOffset = startOffset;
- var payloadSum = startOffset;
- var tds = payload[0];
- for (var tIndex = 0, tLen = tds.length; tIndex < tLen; tIndex++) {
- var overHeadLen = this.vars.OVERHEAD_LEN_MID;
- if (tIndex == tLen - 1) {
- overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
- }
- payloadSum += tds[tIndex].length + overHeadLen;
- if (tIndex >= tdIndex) {
- return {
- cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen,
- cellEndOffset: payloadSum
- }
- }
- }
- };
- dt.getNextTdInfo = function (payload, currTdInfo) {
- var rep = this.context.rep;
- var startOffset = currTdInfo.rowEndOffset;
- var rowStartOffset = startOffset;
- var payloadSum = startOffset;
- var tds = payload[currTdInfo.row];
- for (var tIndex = 0, tLen = tds.length; tIndex < tLen; tIndex++) {
- var overHeadLen = this.vars.OVERHEAD_LEN_MID;
- if (tIndex == tLen - 1) {
- overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
- }
- payloadSum += tds[tIndex].length + overHeadLen;
- if (tIndex >= currTdInfo.td) {
- var leftOverTdTxtLen = payloadSum - startOffset == 0 ? payload[currTdInfo.row + 1][tIndex].length + this.vars.OVERHEAD_LEN_MID : payloadSum - startOffset;
- var rowEndOffset = this._getRowEndOffset(rowStartOffset, tds);
- var tdInfo = {
- row: currTdInfo.row + 1,
- td: tIndex,
- leftOverTdTxtLen: leftOverTdTxtLen,
- rowStartOffset: rowStartOffset,
- rowEndOffset: rowEndOffset,
- cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen,
- cellEndOffset: payloadSum
- };
- return tdInfo;
- }
- }
- };
- //insert a column.
- dt.insertTblColumn = function (leftOrRight, start, end) {
- var rep = this.context.rep;
- var func = 'insertTblColumn()';
- try {
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var tblJSONObj = JSON.parse(currLineText);
- var payload = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
- var currTd = currTdInfo.td;
- start = [], end = [];
- start[0] = rep.selStart[0];
- start[1] = rep.selStart[1];
- end[0] = rep.selEnd[0];
- end[1] = rep.selEnd[1];
- if (leftOrRight == "addL") {
- currTd -= 1;
- }
- var numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
- rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] - numOfLinesAbove;
- while (rep.selStart[0] < rep.lines.length() && rep.lines.atIndex(rep.selStart[0]).text.indexOf('data-tables') != -1) { //count num of rows above current pos
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var tblJSONObj = JSON.parse(currLineText);
- var payload = tblJSONObj.payload;
- var cellPos = this.getTdInfo(payload, currTd).cellEndOffset;
- var newText = '" ",';
- if (currTd == payload[0].length - 1) { //add to the most right
- rep.selStart[1] = rep.selEnd[1] = cellPos - this.vars.OVERHEAD_LEN_ROW_END + 1;
- newText = '," "';
- } else if (currTd == -1) { //add to most left
- rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE - 1;
- } else {
- rep.selStart[1] = rep.selEnd[1] = cellPos - 1;
- }
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, newText);
- rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] + 1;
- }
- rep.selStart = start;
- rep.selEnd = end;
- if (leftOrRight == "addL") {
- rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
- rep.selStart[0] = rep.selEnd[0] = rep.selStart[0];
- this.updateTblPropInAPool(0, 0, null, rep.selStart);
- rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
- }
- currTd++;
- var updateEvenOddBgColor = false;
- var updateColAttrs = true;
- this.sanitizeTblProperties(start, updateEvenOddBgColor, updateColAttrs, currTd, "add")
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- } catch (error) {
- //domline.createErrorState(start,end,'insertTblColumn',rep.lines.atIndex(rep.selStart[0]).text,rep.selStart,rep.selEnd,"",error);
- }
- };
- dt.deleteTblColumn = function () {
- var func = 'deleteTblColumn()';
- var rep = this.context.rep;
- try {
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var tblJSONObj = JSON.parse(currLineText);
- var payload = tblJSONObj.payload;
- if (payload[0].length == 1) {
- deleteTable();
- }
- var currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
- var currTd = currTdInfo.td;
- var start = [],
- end = [];
- start[0] = rep.selStart[0];
- start[1] = rep.selStart[1];
- end[0] = rep.selEnd[0];
- end[1] = rep.selEnd[1];
- var numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
- rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] - numOfLinesAbove;
- while (rep.selStart[0] < rep.lines.length() && rep.lines.atIndex(rep.selStart[0]).text.indexOf('data-tables') != -1) { //count num of rows above current pos
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var tblJSONObj = JSON.parse(currLineText);
- var payload = tblJSONObj.payload;
- var cellTdInfo = this.getTdInfo(payload, currTd);
- var newText = '" ",';
- if (currTd == payload[0].length - 1) { //remove most right col
- rep.selStart[1] = cellTdInfo.cellStartOffset - 2;
- rep.selEnd[1] = cellTdInfo.cellEndOffset - 2;
- } else if (currTd == 0) { //remove most left col
- rep.selStart[1] = this.vars.OVERHEAD_LEN_PRE - 1;
- rep.selEnd[1] = cellTdInfo.cellEndOffset - 1;
- } else {
- rep.selStart[1] = cellTdInfo.cellStartOffset - 1
- rep.selEnd[1] = cellTdInfo.cellEndOffset - 1;
- }
- this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] + 1;
- }
- rep.selStart = start;
- rep.selEnd = end;
- var updateEvenOddBgColor = false;
- var updateColAttrs = true;
- this.sanitizeTblProperties(start, updateEvenOddBgColor, updateColAttrs, currTd, "del")
- this.updateAuthorAndCaretPos(rep.selStart[0], 0, 0);
- } catch (error) {
- //domline.createErrorState(start,end,'deleteTblColumn',rep.lines.atIndex(rep.selStart[0]).text,rep.selStart,rep.selEnd,"",error);
- }
- }
- dt.insertTblRowBelow = function (numOfRows, table) {
- var context = this.context;
- var rep = context.rep;
- var currLineText = rep.lines.atIndex(rep.selStart[0]).text;
- var payload = [
- []
- ];
- if (!numOfRows && numOfRows != 0) {
- var tblPayload = JSON.parse(currLineText).payload;
- numOfRows = tblPayload[0].length;
- }
- var tblRows = new Array(numOfRows);
- if (numOfRows != 0) {
- for (var i = 0; i < tblRows.length; i++) {
- tblRows[i] = " ";
- }
- }
- payload = [tblRows];
- if (table) {
- payload = table.payload;
- }
- tableObj = {
- "payload": payload,
- "tblId": 1,
- "tblClass": "data-tables",
- "trClass": "alst",
- "tdClass": "hide-el"
- }
- rep.selEnd[1] = rep.selStart[1] = currLineText.length;
- this.context.editorInfo.ace_inCallStackIfNecessary('newline', this.context.editorInfo.ace_doReturnKey);
- context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, JSON.stringify(tableObj));
- };
- dt.doReturnKey = function () {
- var context = this.context;
- var rep = context.rep;
- var start = rep.seStart;
- var end = rep.selEnd;
- lastTblPropertyUsed = 'doTableReturnKey';
- var currLine = rep.lines.atIndex(rep.selStart[0]);
- var currLineText = currLine.text;
- if (currLineText.indexOf('data-tables') == -1) return false;
- else {
- var func = 'doTableReturnKey()';
- try {
- var currCarretPos = rep.selStart[1];
- if (currLineText.substring(currCarretPos - 1, currCarretPos + 2) == '","') return true;
- else if (currLineText.substring(currCarretPos - 2, currCarretPos + 1) == '","') return true;
- else if (currCarretPos < this.vars.OVERHEAD_LEN_PRE) return true;
- else if (currCarretPos > currLineText.length) return true;
- var start = rep.selStart,
- end = rep.selEnd;
- newText = " /r/n ";
- start[1] = currCarretPos;
- end[1] = currCarretPos;
- try {
- var jsonObj = JSON.parse(currLineText.substring(0, start[1]) + newText + currLineText.substring(start[1]));
- payloadStr = JSON.stringify(jsonObj.payload);
- if (currCarretPos > payloadStr.length + this.vars.OVERHEAD_LEN_PRE - 2) {
- return true;
- }
- } catch (error) {
- return true;
- }
- context.editorInfo.ace_performDocumentReplaceRange(start, end, newText);
- } catch (error) {}
- return true;
- }
- };
- dt.isCellDeleteOk = function (keyCode) {
- var context = this.context;
- var rep = context.rep;
- var start = rep.selStart;
- var end = rep.selEnd;
- var currLine = rep.lines.atIndex(rep.selStart[0]);
- var currLineText = currLine.text;
- if (currLineText.indexOf('data-tables') == -1) return true;
- var isDeleteAccepted = false;
- try {
- var tblJSONObj = JSON.parse(currLineText);
- var table = tblJSONObj.payload;
- var currTdInfo = this.getFocusedTdInfo(table, rep.selStart[1]);
- cellEntryLen = table[currTdInfo.row][currTdInfo.td].length;
- var currCarretPos = rep.selStart[1];
- if (currLineText.substring(currCarretPos - 1, currCarretPos + 2) == '","') return false;
- else if (currLineText.substring(currCarretPos - 2, currCarretPos + 1) == '","') return false;
- switch (keyCode) {
- case this.vars.JS_KEY_CODE_BS:
- if (cellEntryLen != 0 && cellEntryLen > (currTdInfo.leftOverTdTxtLen - this.vars.OVERHEAD_LEN_MID)) {
- isDeleteAccepted = true;
- }
- break;
- case this.vars.JS_KEY_CODE_DEL:
- return false; //disabled for the moment
- if (cellEntryLen != 0 && currTdInfo.leftOverTdTxtLen - this.vars.OVERHEAD_LEN_MID > 0) {
- isDeleteAccepted = true;
- }
- break;
- default:
- // cntrl H
- if (cellEntryLen != 0 && cellEntryLen > (currTdInfo.leftOverTdTxtLen - this.vars.OVERHEAD_LEN_MID)) {
- isDeleteAccepted = true;
- }
- break;
- }
- } catch (error) {
- isDeleteAccepted = false;
- }
- return isDeleteAccepted;
- };
- dt.nodeTextPlain = function (n) {
- return n.innerText || n.textContent || n.nodeValue || '';
- }
- // Get the text within an element
- // Doesn't do any normalising, returns a string
- // of text as found.
- dt.toString = function () {
- return "ep_tables";
- };
- dt.getLineAndCharForPoint = function () {
- var context = this.context;
- var point = context.point;
- var root = context.root;
- // Turn DOM node selection into [line,char] selection.
- // This method has to work when the DOM is not pristine,
- // assuming the point is not in a dirty node.
- if (point.node == root) {
- if (point.index == 0) {
- return [0, 0];
- } else {
- var N = this.context.rep.lines.length();
- var ln = this.context.rep.lines.atIndex(N - 1);
- return [N - 1, ln.text.length];
- }
- } else {
- var n = point.node;
- var col = 0;
- // if this part fails, it probably means the selection node
- // was dirty, and we didn't see it when collecting dirty nodes.
- if (nodeText(n) || point.index > 0) {
- col = point.index;
- }
- var parNode, prevSib;
- while ((parNode = n.parentNode) != root) {
- if ((prevSib = n.previousSibling)) {
- n = prevSib;
- var textLen = nodeText(n).length == 0 ? this.nodeTextPlain(n).length : nodeText(n).length;
- col += textLen;
- } else {
- n = parNode;
- }
- }
- if (n.id == "") console.debug("BAD");
- if (n.firstChild && context.editorInfo.ace_isBlockElement(n.firstChild)) {
- col += 1; // lineMarker
- }
- var lineEntry = this.context.rep.lines.atKey(n.id);
- var lineNum = this.context.rep.lines.indexOfEntry(lineEntry);
- return [lineNum, col];
- }
- };
- dt.doDeleteKey = function () {
- var context = this.context;
- var evt = context.evt || {};
- var handled = false;
- var rep = this.context.rep;
- var editorInfo = context.editorInfo;
- if (rep.selStart) {
- //end tbl-mod-by-wlos
- if (editorInfo.ace_isCaret()) {
- var lineNum = editorInfo.ace_caretLine();
- var col = editorInfo.ace_caretColumn();
- var lineEntry = rep.lines.atIndex(lineNum);
- var lineText = lineEntry.text;
- var lineMarker = lineEntry.lineMarker;
- if (/^ +$/.exec(lineText.substring(lineMarker, col))) {
- var col2 = col - lineMarker;
- var tabSize = ''.length; // zero for now, tabs are not supported within tables
- var toDelete = ((col2 - 1) % tabSize) + 1;
- editorInfo.ace_performDocumentReplaceRange([lineNum, col - toDelete], [lineNum, col], '');
- //scrollSelectionIntoView();
- handled = true;
- }
- }
- if (!handled) {
- if (editorInfo.ace_isCaret()) {
- var theLine = editorInfo.ace_caretLine();
- var lineEntry = rep.lines.atIndex(theLine);
- if (editorInfo.ace_caretColumn() <= lineEntry.lineMarker) {
- // delete at beginning of line
- var action = 'delete_newline';
- var prevLineListType = (theLine > 0 ? editorInfo.ace_getLineListType(theLine - 1) : '');
- var thisLineListType = editorInfo.ace_getLineListType(theLine);
- var prevLineEntry = (theLine > 0 && rep.lines.atIndex(theLine - 1));
- var prevLineBlank = (prevLineEntry && prevLineEntry.text.length == prevLineEntry.lineMarker);
- if (thisLineListType) {
- // this line is a list
- if (prevLineBlank && !prevLineListType) {
- // previous line is blank, remove it
- editorInfo.ace_performDocumentReplaceRange([theLine - 1, prevLineEntry.text.length], [theLine, 0], '');
- } else {
- // delistify
- editorInfo.ace_performDocumentReplaceRange([theLine, 0], [theLine, lineEntry.lineMarker], '');
- }
- } else if (theLine > 0) {
- // remove newline
- editorInfo.ace_performDocumentReplaceRange([theLine - 1, prevLineEntry.text.length], [theLine, 0], '');
- }
- } else {
- var docChar = editorInfo.ace_caretDocChar();
- if (docChar > 0) {
- if (evt.metaKey || evt.ctrlKey || evt.altKey) {
- // delete as many unicode "letters or digits" in a row as possible;
- // always delete one char, delete further even if that first char
- // isn't actually a word char.
- var deleteBackTo = docChar - 1;
- while (deleteBackTo > lineEntry.lineMarker && editorInfo.ace_isWordChar(rep.alltext.charAt(deleteBackTo - 1))) {
- deleteBackTo--;
- }
- editorInfo.ace_performDocumentReplaceCharRange(deleteBackTo, docChar, '');
- } else {
- var returnKeyWitinTblOffset = 0;
- if (lineText.substring(col - 5, col) == '/r/n ') {
- returnKeyWitinTblOffset = 4;
- }
- // normal or table return key delete
- editorInfo.ace_performDocumentReplaceCharRange(docChar - 1 - returnKeyWitinTblOffset, docChar, '');
- }
- }
- }
- } else {
- editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, "");
- }
- }
- }
- //if the list has been removed, it is necessary to renumber
- //starting from the *next* line because the list may have been
- //separated. If it returns null, it means that the list was not cut, try
- //from the current one.
- var line = editorInfo.ace_caretLine();
- if (line != -1 && editorInfo.ace_renumberList(line + 1) === null) {
- editorInfo.ace_renumberList(line);
- }
- };
- dt.getLineTableProperty = function (lineNum) {
- var rep = this.context.rep;
- // get "tblProp" attribute of first char of line
- var aline = rep.alines[lineNum];
- if (aline) {
- var opIter = Changeset.opIterator(aline);
- if (opIter.hasNext()) {
- var tblJSString = Changeset.opAttributeValue(opIter.next(), 'tblProp', rep.apool);
- try {
- return JSON.parse(tblJSString);
- } catch (error) {
- return this.defaults.tblProps;
- }
- }
- }
- return this.defaults.tblProps;
- };
- dt.updateTblPropInAPool = function (row, td, jsoTblProp, start) {
- try {
- var rep = this.context.rep;
- var tblProps;
- var editorInfo = this.context.editorInfo;
- var thisAuthor = editorInfo.ace_getAuthor();
- var authorInfos = editorInfo.ace_getAuthorInfos();
- if (typeof (jsoTblProp) == 'undefined' || jsoTblProp == null) {
- jsoTblProp = this.getLineTableProperty(start[0]);
- }
- if (row != -1 && td != -1) {
- jsoTblProp['authors'][thisAuthor] = {
- row: row,
- cell: td,
- colorId: authorInfos[thisAuthor].bgcolor
- };
- }
- var jsoStrTblProp = JSON.stringify(jsoTblProp);
- var attrStart = [],
- attrEnd = [];
- attrStart[0] = start[0], attrStart[1] = 0;
- attrEnd[0] = start[0], attrEnd[1] = rep.lines.atIndex(start[0]).text.length;
- editorInfo.ace_performDocumentApplyAttributesToRange(attrStart, attrEnd, [
- ["tblProp", jsoStrTblProp]
- ]);
- } catch (error) {
- //createErrorState(start, start, 'updateTblPropInAPool', rep.lines.atIndex(start[0]).text, [row,td], [row,td], "", error);
- }
- };
- dt.getCurrTblOddEvenRowBgColor = function (startRowNum, currRowNum) {
- var rowBgColors = {
- oddBgColor: null,
- evenBgColor: null
- };
- if (startRowNum != currRowNum) {
- var jsoTblProp1 = this.getLineTableProperty(startRowNum);
- var jsoTblProp2 = this.getLineTableProperty(startRowNum + 1);
- rowBgColors.evenBgColor = jsoTblProp1['rowAttrs']['evenBgColor'] || jsoTblProp2['rowAttrs']['evenBgColor'];
- rowBgColors.oddBgColor = jsoTblProp1['rowAttrs']['oddBgColor'] || jsoTblProp2['rowAttrs']['oddBgColor'];
- }
- return rowBgColors;
- };
- dt.getTblAboveRowsFromCurFocus = function (start) {
- var rep = this.context.rep;
- var numOfLinesAbove = 0;
- var line = start[0] - 1;
- while (rep.lines.atIndex(line).text.indexOf('data-tables') != -1) { //count num of rows above current pos
- numOfLinesAbove++;
- line--;
- }
- return numOfLinesAbove;
- }
- dt.updateTableIndices = function (tblProperties, currTd, addOrDel) {
- cellAttrs = tblProperties.cellAttrs;
- for (var rIndex = 0, rLen = cellAttrs.length; rIndex < rLen; rIndex++) {
- var cellAttr = cellAttrs[rIndex];
- if (addOrDel == 'add') { //insert column
- if (cellAttr) {
- cellAttr.splice(currTd, 0, null);
- }
- } else { //remove column
- if (cellAttr) {
- cellAttr.splice(currTd, 1);
- }
- }
- }
- //col attrs
- colAttrs = tblProperties.colAttrs;
- if (addOrDel == 'add') { //insert column
- if (colAttrs) {
- colAttrs.splice(currTd, 0, null);
- }
- } else { //remove column
- if (colAttrs) {
- colAttrs.splice(currTd, 1);
- }
- }
- return tblProperties;
- };
- dt.sanitizeTblProperties = function (start, updateEvenOddBgColor, updateColAttrs, currTd, addOrDel) {
- var rep = this.context.rep;
- var editorInfo = this.context.editorInfo;
- var thisAuthor = editorInfo.ace_getAuthor();
- var numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
- var tempStart = [];
- tempStart[0] = start[0] - numOfLinesAbove;
- var evenOddRowBgColors = {};
- if (updateEvenOddBgColor) {
- //evenOddRowBgColors=getCurrTblOddEvenRowBgColor(tempStart[0],start[0]);
- }
- while (tempStart[0] < rep.lines.length() && rep.lines.atIndex(tempStart[0]).text.indexOf('data-tables') != -1) { //start from top of a table
- var jsoTblProp = this.getLineTableProperty(tempStart[0]);
- var update = false;
- if (tempStart[0] != start[0] && jsoTblProp['authors'] && jsoTblProp['authors'][thisAuthor]) {
- delete jsoTblProp['authors'][thisAuthor];
- update = true;
- }
- if (updateColAttrs) {
- jsoTblProp = this.updateTableIndices(jsoTblProp, currTd, addOrDel);
- update = true;
- }
- if (tempStart[0] != start[0] && updateEvenOddBgColor) {
- delete jsoTblProp['rowAttrs']['oddBgColor'];
- delete jsoTblProp['rowAttrs']['evenBgColor'];
- update = true;
- }
- if (update) {
- this.updateTblPropInAPool(-1, -1, jsoTblProp, tempStart);
- }
- tempStart[0] = tempStart[0] + 1;
- }
- };
- dt.updateTblPropInAPool = function (row, td, jsoTblProp, start) {
- try {
- var rep = this.context.rep;
- var editorInfo = this.context.editorInfo;
- var thisAuthor = editorInfo.ace_getAuthor();
- var authorInfos = editorInfo.ace_getAuthorInfos();
- var tblProps;
- if (typeof (jsoTblProp) == 'undefined' || jsoTblProp == null) {
- jsoTblProp = this.getLineTableProperty(start[0]);
- }
- if (row != -1 && td != -1) {
- jsoTblProp['authors'][thisAuthor] = {
- row: row,
- cell: td,
- colorId: authorInfos[thisAuthor].bgcolor
- };
- }
- var jsoStrTblProp = JSON.stringify(jsoTblProp);
- var attrStart = [],
- attrEnd = [];
- attrStart[0] = start[0], attrStart[1] = 0;
- attrEnd[0] = start[0], attrEnd[1] = rep.lines.atIndex(start[0]).text.length;
- editorInfo.ace_performDocumentApplyAttributesToRange(attrStart, attrEnd, [
- ["tblProp", jsoStrTblProp]
- ]);
- } catch (error) {
- //createErrorState(start, start, 'updateTblPropInAPool', rep.lines.atIndex(start[0]).text, [row,td], [row,td], "", error);
- }
- };
- dt.updateTblCellAuthor = function (row, td, tblProperties, start, updateEvenOddBgColor) {
- try {
- this.updateTblPropInAPool(row, td, tblProperties, start);
- var tempStart = [];
- tempStart[0] = start[0];
- tempStart[1] = start[1];
- this.sanitizeTblProperties(tempStart, updateEvenOddBgColor);
- } catch (error) {
- //createErrorState(start, end, 'updateTblCellAuthor', rep.lines.atIndex(start).text, rep.selStart, rep.selEnd, "", error);
- }
- }
- return dt;
- }(); // end of anonymous function
-typeof (exports) != 'undefined' ? exports.Datatables = Datatables : null;
+var _, Ace2Common, Changeset, escapedJSON, fromEscapedJSON, _stylesDisabled, enableStyles, disableStyles, Datatables;
+_ = require('ep_etherpad-lite/static/js/underscore');
+if (!(typeof require === 'undefined')) {
+ if (typeof Ace2Common === 'undefined') {
+ Ace2Common = require('ep_etherpad-lite/static/js/ace2_common');
+ }
+ if (typeof Changeset === 'undefined') {
+ Changeset = require('ep_etherpad-lite/static/js/Changeset');
+ }
+}
+escapedJSON = function(it){
+ var ret;
+ ret = JSON.stringify(it).replace(/\\u(....)|\\(.)/g, function(_, _1, _2){
+ if (_1) {
+ return String.fromCharCode(parseInt(_1, 16));
+ } else {
+ return "\\" + _2.charCodeAt(0) + ';';
+ }
+ }).replace(/"/g, '\uF134').replace(/\\(\d+);/g, function(_, _1){
+ return "\\" + String.fromCharCode(_1);
+ });
+ return ret;
+};
+fromEscapedJSON = function(it){
+ var ret;
+ ret = JSON.parse(it.replace(/(\\|")/g, '\\$1').replace(/\uF134/g, '"'));
+ return ret;
+};
+exports.aceInitialized = function(hook, context){
+ var editorInfo;
+ editorInfo = context.editorInfo;
+ return editorInfo.ace_doDatatableOptions = _(Datatables.doDatatableOptions).bind(context);
+};
+exports.acePostWriteDomLineHTML = function(hook_name, arg$, cb){
+ var node, lineText, dtAttrs, code, ref$, ref1$;
+ node = arg$.node;
+ lineText = $(node).text();
+ if (lineText && lineText.indexOf('\uFFF9') !== -1) {
+ dtAttrs = typeof exports.Datatables !== 'undefined' ? exports.Datatables.attributes : null;
+ dtAttrs = dtAttrs || '';
+ code = fromEscapedJSON(lineText);
+ DatatablesRenderer.render({}, node, code, dtAttrs);
+ (ref$ = exports.Datatables).lastTblId >= (ref1$ = code.tblId) || (ref$.lastTblId = ref1$);
+ return exports.Datatables.attributes = null;
+ }
+};
+exports.eejsBlock_scripts = function(hook_name, args, cb){
+ return args.content = args.content + require('ep_etherpad-lite/node/eejs/').require('ep_tables/templates/datatablesScripts.ejs');
+};
+exports.eejsBlock_editbarMenuLeft = function(hook_name, args, cb){
+ return args.content = args.content + require('ep_etherpad-lite/node/eejs/').require('ep_tables/templates/datatablesEditbarButtons.ejs');
+};
+exports.eejsBlock_styles = function(hook_name, args, cb){
+ return args.content = require('ep_etherpad-lite/node/eejs/').require('ep_tables/templates/styles.ejs') + args.content;
+};
+exports.aceAttribsToClasses = function(hook, context){
+ Datatables.attributes = null;
+ if (context.key === 'tblProp') {
+ Datatables.attributes = context.value;
+ return ['tblProp:' + context.value];
+ }
+};
+exports.aceStartLineAndCharForPoint = function(hook, context){
+ var selStart, error;
+ selStart = null;
+ try {
+ Datatables.context = context;
+ if (Datatables.isFocused()) {
+ selStart = Datatables.getLineAndCharForPoint();
+ }
+ } catch (e$) {
+ error = e$;
+ top.console.log('error ' + error);
+ top.console.log('context rep' + Datatables.context.rep);
+ }
+ return selStart;
+};
+_stylesDisabled = false;
+enableStyles = function(){
+ if (!_stylesDisabled) {
+ return;
+ }
+ $('#editbar').find('li[data-key]').each(function(){
+ var el, key;
+ el = $(this);
+ key = el.data('keyOrig');
+ return el.data('key', key).attr('data-key', key);
+ });
+ return _stylesDisabled = false;
+};
+disableStyles = function(){
+ if (_stylesDisabled) {
+ return;
+ }
+ $('#editbar').find('li[data-key]').each(function(){
+ var el, key;
+ el = $(this);
+ key = el.data('key');
+ return el.data('keyOrig', key).data('key', null).attr('data-key', '');
+ });
+ return _stylesDisabled = true;
+};
+exports.aceEndLineAndCharForPoint = function(hook, context){
+ var selEndLine, error;
+ selEndLine = null;
+ try {
+ Datatables.context = context;
+ if (Datatables.isFocused()) {
+ disableStyles();
+ selEndLine = Datatables.getLineAndCharForPoint();
+ } else {
+ enableStyles();
+ }
+ } catch (e$) {
+ error = e$;
+ top.console.log('error ' + error);
+ top.console.log('context rep' + Datatables.context.rep);
+ }
+ return selEndLine;
+};
+exports.aceKeyEvent = function(hook, context){
+ var specialHandled, evt, type, keyCode, isTypeForSpecialKey, isTypeForCmdKey, which, e;
+ specialHandled = false;
+ try {
+ Datatables.context = context;
+ if (Datatables.isFocused()) {
+ evt = context.evt;
+ type = evt.type;
+ keyCode = evt.keyCode;
+ isTypeForSpecialKey = Ace2Common.browser.msie || Ace2Common.browser.safari
+ ? type === 'keydown'
+ : type === 'keypress';
+ isTypeForCmdKey = Ace2Common.browser.msie || Ace2Common.browser.safari
+ ? type === 'keydown'
+ : type === 'keypress';
+ which = evt.which;
+ if (!specialHandled && isTypeForSpecialKey && keyCode === 9 && !(evt.metaKey || evt.ctrlKey)) {
+ context.editorInfo.ace_fastIncorp(5);
+ evt.preventDefault();
+ Datatables.performDocumentTableTabKey();
+ specialHandled = true;
+ }
+ if (!specialHandled && isTypeForSpecialKey && keyCode === 13) {
+ context.editorInfo.ace_fastIncorp(5);
+ evt.preventDefault();
+ Datatables.doReturnKey();
+ specialHandled = true;
+ }
+ if (!specialHandled && isTypeForSpecialKey && (keyCode === Datatables.vars.JS_KEY_CODE_DEL || keyCode === Datatables.vars.JS_KEY_CODE_BS || String.fromCharCode(which).toLowerCase() === 'h' && evt.ctrlKey)) {
+ context.editorInfo.ace_fastIncorp(20);
+ evt.preventDefault();
+ specialHandled = true;
+ if (Datatables.isCellDeleteOk(keyCode)) {
+ Datatables.doDeleteKey();
+ }
+ }
+ }
+ } catch (e$) {
+ e = e$;
+ }
+ return specialHandled;
+};
+Datatables = (function(){
+ Datatables.displayName = 'Datatables';
+ var nodeText, prototype = Datatables.prototype, constructor = Datatables;
+ nodeText = function(arg$){
+ var childNodes, excluded, text, res$, i$, len$, el;
+ childNodes = arg$.childNodes;
+ excluded = {
+ noscript: 'noscript',
+ script: 'script'
+ };
+ res$ = [];
+ for (i$ = 0, len$ = childNodes.length; i$ < len$; ++i$) {
+ el = childNodes[i$];
+ if (el.nodeType === 1 && !(el.tagName.toLowerCase() in excluded)) {
+ res$.push(nodeText(el));
+ } else if (el.nodeType === 3) {
+ res$.push(el.data);
+ }
+ }
+ text = res$;
+ return text.join('');
+ };
+ Datatables.lastTblId = 0;
+ Datatables.defaults = {
+ tblProps: {
+ borderWidth: '1',
+ cellAttrs: [],
+ width: '6',
+ rowAttrs: {},
+ colAttrs: [],
+ authors: {}
+ }
+ };
+ Datatables.config = {};
+ Datatables.vars = {
+ OVERHEAD_LEN_PRE: '{\uF134payload\uF134:[[\uF134'.length,
+ OVERHEAD_LEN_MID: '\uF134,\uF134'.length,
+ OVERHEAD_LEN_ROW_START: '[\uF134'.length,
+ OVERHEAD_LEN_ROW_END: '\uF134],'.length,
+ JS_KEY_CODE_BS: 8,
+ JS_KEY_CODE_DEL: 46,
+ TBL_OPTIONS: ['addTbl', 'addTblRowA', 'addTblRowB', 'addTblColL', 'addTblColR', 'delTbl', 'delTblRow', 'delTblCol', 'delImg']
+ };
+ Datatables.context = null;
+ Datatables.isFocused = function(){
+ var line, currLineText;
+ if (!this.context.rep.selStart || !this.context.rep.selEnd) {
+ return false;
+ }
+ line = (function(){
+ try {
+ return this.context.rep.lines.atIndex(this.context.rep.selStart[0]);
+ } catch (e$) {}
+ }.call(this));
+ if (!line) {
+ return false;
+ }
+ currLineText = line.text || '';
+ if (currLineText.indexOf('\uFFF9') === -1) {
+ return false;
+ }
+ return true;
+ };
+ Datatables._getRowEndOffset = function(rowStartOffset, tds){
+ var rowEndOffset, i, len, overHeadLen;
+ rowEndOffset = rowStartOffset + this.vars.OVERHEAD_LEN_ROW_START;
+ i = 0;
+ len = tds.length;
+ while (i < len) {
+ overHeadLen = this.vars.OVERHEAD_LEN_MID;
+ if (i === len - 1) {
+ overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
+ }
+ rowEndOffset += tds[i].length + overHeadLen;
+ i++;
+ }
+ return rowEndOffset;
+ };
+ Datatables.getFocusedTdInfo = function(payload, colStart){
+ var payloadOffset, rowStartOffset, payloadSum, rIndex, rLen, tds, tIndex, tLen, overHeadLen, leftOverTdTxtLen, cellCaretPos, rowEndOffset;
+ payloadOffset = colStart - this.vars.OVERHEAD_LEN_PRE;
+ rowStartOffset = 0;
+ payloadSum = 0;
+ rIndex = 0;
+ rLen = payload.length;
+ while (rIndex < rLen) {
+ tds = payload[rIndex];
+ tIndex = 0;
+ tLen = tds.length;
+ while (tIndex < tLen) {
+ overHeadLen = this.vars.OVERHEAD_LEN_MID;
+ if (tIndex === tLen - 1) {
+ overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
+ }
+ payloadSum += tds[tIndex].length + overHeadLen;
+ if (payloadSum >= payloadOffset) {
+ if (payloadSum === payloadOffset) {
+ tIndex++;
+ }
+ leftOverTdTxtLen = payloadSum - payloadOffset === 0
+ ? payload[rIndex][tIndex].length + this.vars.OVERHEAD_LEN_MID
+ : payloadSum - payloadOffset;
+ cellCaretPos = tds[tIndex].length - leftOverTdTxtLen - overHeadLen;
+ rowEndOffset = this._getRowEndOffset(rowStartOffset, tds);
+ return {
+ row: rIndex,
+ td: tIndex,
+ leftOverTdTxtLen: leftOverTdTxtLen,
+ rowStartOffset: rowStartOffset,
+ rowEndOffset: rowEndOffset,
+ cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen,
+ cellEndOffset: payloadSum,
+ cellCaretPos: cellCaretPos
+ };
+ }
+ tIndex++;
+ }
+ rowStartOffset = payloadSum;
+ payloadSum += this.vars.OVERHEAD_LEN_ROW_START;
+ rIndex++;
+ }
+ };
+ Datatables.printCaretPos = function(start, end){
+ top.console.log(JSON.stringify(start));
+ return top.console.log(JSON.stringify(end));
+ };
+ Datatables.doDatatableOptions = function(cmd, xByY){
+ Datatables.context = this;
+ if (typeof cmd === 'object' && cmd.tblPropertyChange) {
+ return Datatables.updateTableProperties(cmd);
+ } else {
+ switch (cmd) {
+ case Datatables.vars.TBL_OPTIONS[0]:
+ return Datatables.addTable(xByY);
+ case Datatables.vars.TBL_OPTIONS[1]:
+ return Datatables.insertTblRow('addA');
+ case Datatables.vars.TBL_OPTIONS[2]:
+ return Datatables.insertTblRow('addB');
+ case Datatables.vars.TBL_OPTIONS[3]:
+ return Datatables.insertTblColumn('addL');
+ case Datatables.vars.TBL_OPTIONS[4]:
+ return Datatables.insertTblColumn('addR');
+ case Datatables.vars.TBL_OPTIONS[5]:
+ return Datatables.deleteTable();
+ case Datatables.vars.TBL_OPTIONS[6]:
+ return Datatables.deleteTblRow();
+ case Datatables.vars.TBL_OPTIONS[7]:
+ return Datatables.deleteTblColumn();
+ }
+ }
+ };
+ Datatables.addTable = function(tableObj){
+ var rep, start, end, line, hasMoreRows, isRowAddition, table, currLineText, authors, xByYSelect, cols, rows, jsoStrTblProp, i;
+ rep = this.context.rep;
+ start = rep.selStart;
+ end = rep.selEnd;
+ line = rep.lines.atIndex(rep.selStart[0]);
+ hasMoreRows = null;
+ isRowAddition = null;
+ if (tableObj) {
+ hasMoreRows = tableObj.hasMoreRows;
+ isRowAddition = tableObj.isRowAddition;
+ }
+ if (isRowAddition) {
+ table = fromEscapedJSON(tableObj.tblString);
+ insertTblRowBelow(0, table);
+ performDocApplyTblAttrToRow(rep.selStart, JSON.stringify(table.tblProperties));
+ return;
+ }
+ if (line) {
+ currLineText = line.text;
+ if (currLineText.indexOf('\uFFF9') !== -1) {
+ do {
+ rep.selStart[0] = rep.selStart[0] + 1;
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ } while (currLineText.indexOf('\uFFF9') !== -1);
+ rep.selEnd[1] = rep.selStart[1] = currLineText.length;
+ this.context.editorInfo.ace_doReturnKey();
+ this.context.editorInfo.ace_doReturnKey();
+ } else {
+ rep.selEnd[1] = rep.selStart[1] = currLineText.length;
+ this.context.editorInfo.ace_doReturnKey();
+ }
+ }
+ if (tableObj == null) {
+ authors = {};
+ this.insertTblRowBelow(3);
+ this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
+ this.insertTblRowBelow(3);
+ this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties(authors));
+ this.insertTblRowBelow(3);
+ this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties(authors));
+ this.context.editorInfo.ace_doReturnKey();
+ this.updateAuthorAndCaretPos(rep.selStart[0] - 3);
+ return;
+ }
+ xByYSelect = typeof tableObj === 'object'
+ ? null
+ : tableObj.split('X');
+ if (xByYSelect != null && xByYSelect.length === 3) {
+ cols = parseInt(xByYSelect[1]);
+ rows = parseInt(xByYSelect[2]);
+ jsoStrTblProp = JSON.stringify(this.createDefaultTblProperties());
+ authors = {};
+ i = 0;
+ table = {};
+ while (i < rows) {
+ this.insertTblRowBelow(cols, table);
+ if (i === 0) {
+ this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
+ } else {
+ this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties(authors));
+ }
+ i++;
+ }
+ this.updateAuthorAndCaretPos(rep.selStart[0] - rows + 1);
+ return;
+ }
+ return newText;
+ };
+ Datatables.insertTblRow = function(aboveOrBelow){
+ var func, rep, newText, currLineText, ref$, payload, tblId, currTdInfo, currRow, lastRowOffSet, start, end, updateEvenOddBgColor, e;
+ func = 'insertTblRow()';
+ rep = this.context.rep;
+ try {
+ newText = '';
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ ref$ = fromEscapedJSON(currLineText), payload = ref$.payload, tblId = ref$.tblId;
+ currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
+ currRow = currTdInfo.row;
+ lastRowOffSet = 0;
+ start = [];
+ end = [];
+ start[0] = rep.selStart[0];
+ start[1] = rep.selStart[1];
+ end[0] = rep.selStart[0];
+ end[1] = rep.selStart[1];
+ if (aboveOrBelow === 'addA') {
+ rep.selStart[0] = rep.selEnd[0] = rep.selStart[0] - 1;
+ this.insertTblRowBelow(payload[0].length, {
+ tblId: tblId
+ });
+ } else {
+ this.insertTblRowBelow(payload[0].length, {
+ tblId: tblId
+ });
+ }
+ this.context.editorInfo.ace_performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
+ this.updateAuthorAndCaretPos(rep.selStart[0]);
+ updateEvenOddBgColor = true;
+ return this.sanitizeTblProperties(rep.selStart, updateEvenOddBgColor);
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.deleteTable = function(){
+ var rep, func, start, end, line, numOfLinesAbove, numOfLinesBelow, e;
+ rep = this.context.rep;
+ func = 'deleteTable()';
+ start = rep.seStart;
+ end = rep.seEnd;
+ try {
+ line = rep.selStart[0] - 1;
+ numOfLinesAbove = 0;
+ numOfLinesBelow = 0;
+ while (!(rep.lines.atIndex(line).text.indexOf('\uFFF9') === -1)) {
+ numOfLinesAbove++;
+ line--;
+ }
+ line = rep.selEnd[0] + 1;
+ while (!(rep.lines.atIndex(line).text.indexOf('\uFFF9') === -1)) {
+ numOfLinesBelow++;
+ line++;
+ }
+ rep.selStart[1] = 0;
+ rep.selStart[0] = rep.selStart[0] - numOfLinesAbove;
+ rep.selEnd[0] = rep.selEnd[0] + numOfLinesBelow;
+ rep.selEnd[1] = rep.lines.atIndex(rep.selEnd[0]).text.length;
+ return this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.deleteTblRow = function(){
+ var func, rep, currLineText, updateEvenOddBgColor, e;
+ func = 'deleteTblRow()';
+ rep = this.context.rep;
+ try {
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ if (currLineText.indexOf('\uFFF9') === -1) {
+ return;
+ }
+ rep.selEnd[0] = rep.selStart[0] + 1;
+ rep.selStart[1] = 0;
+ rep.selEnd[1] = 0;
+ this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ if (currLineText.indexOf('\uFFF9') === -1) {
+ return;
+ }
+ this.updateAuthorAndCaretPos(rep.selStart[0], 0, 0);
+ updateEvenOddBgColor = true;
+ return this.sanitizeTblProperties(rep.selStart, updateEvenOddBgColor);
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.updateTableProperties = function(props){
+ var rep, currTd, currLine, currLineText, tblJSONObj, payload, currTdInfo, start, numOfLinesAbove, tempStart, results$ = [];
+ rep = this.context.rep;
+ currTd = null;
+ if (props.tblColWidth || props.tblSingleColBgColor || props.tblColVAlign) {
+ currLine = rep.lines.atIndex(rep.selStart[0]);
+ currLineText = currLine.text;
+ tblJSONObj = fromEscapedJSON(currLineText);
+ payload = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
+ currTd = currTdInfo.td;
+ }
+ if (props.tblWidth || props.tblHeight || props.tblBorderWidth || props.tblBorderColor || props.tblColWidth || props.tblSingleColBgColor || props.tblEvenRowBgColor || props.tblOddRowBgColor || props.tblColVAlign) {
+ start = [];
+ start[0] = rep.selStart[0];
+ start[1] = rep.selStart[1];
+ numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
+ tempStart = [];
+ tempStart[0] = start[0] - numOfLinesAbove;
+ tempStart[1] = start[1];
+ while (tempStart[0] < rep.lines.length() && rep.lines.atIndex(tempStart[0]).text.indexOf('\uFFF9') !== -1) {
+ if (props.tblEvenRowBgColor && tempStart[0] % 2 !== 0) {
+ tempStart[0] = tempStart[0] + 1;
+ continue;
+ } else {
+ if (props.tblOddRowBgColor && tempStart[0] % 2 === 0) {
+ tempStart[0] = tempStart[0] + 1;
+ continue;
+ }
+ }
+ this.updateTablePropertiesHelper(props, tempStart, currTd);
+ results$.push(tempStart[0] = tempStart[0] + 1);
+ }
+ return results$;
+ } else {
+ start = [];
+ start[0] = rep.selStart[0];
+ start[1] = rep.selStart[1];
+ return this.updateTablePropertiesHelper(props, start, currTd);
+ }
+ };
+ Datatables.addCellAttr = function(start, tblJSONObj, tblProperties, attrName, attrValue){
+ var rep, payload, currTdInfo, currRow, currTd, cellAttrs, row, cell;
+ rep = this.context.rep;
+ payload = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(payload, start[1]);
+ currRow = currTdInfo.row;
+ currTd = currTdInfo.td;
+ cellAttrs = tblProperties.cellAttrs;
+ row = cellAttrs[currRow];
+ if (row == null || typeof row === 'undefined') {
+ row = [];
+ }
+ cell = row[currTd];
+ if (cell == null || typeof cell === 'undefined') {
+ cell = {};
+ }
+ if (attrName === 'fontWeight' || attrName === 'fontStyle' || attrName === 'textDecoration') {
+ if (cell[attrName] === attrValue) {
+ attrValue = '';
+ }
+ } else if (cell[attrName] === attrValue) {
+ return false;
+ }
+ cell[attrName] = attrValue;
+ row[currTd] = cell;
+ cellAttrs[currRow] = row;
+ tblProperties.cellAttrs = cellAttrs;
+ return tblProperties;
+ };
+ Datatables.addRowAttr = function(tblJSONObj, tblProperties, attrName, attrValue){
+ var rep, rowAttrs, payload, currTdInfo, currRow, singleRowAttrs;
+ rep = this.context.rep;
+ rowAttrs = tblProperties.rowAttrs;
+ if (attrName === 'bgColor') {
+ payload = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
+ currRow = currTdInfo.row;
+ singleRowAttrs = rowAttrs.singleRowAttrs;
+ if (singleRowAttrs == null || typeof singleRowAttrs === 'undefined') {
+ singleRowAttrs = [];
+ }
+ if (singleRowAttrs[currRow] == null || typeof singleRowAttrs[currRow] === 'undefined') {
+ singleRowAttrs[currRow] = {};
+ } else if (singleRowAttrs[currRow][attrName] === attrValue) {
+ return false;
+ }
+ singleRowAttrs[currRow][attrName] = attrValue;
+ rowAttrs.singleRowAttrs = singleRowAttrs;
+ } else {
+ if (rowAttrs[attrName] === attrValue) {
+ return false;
+ }
+ rowAttrs[attrName] = attrValue;
+ }
+ tblProperties.rowAttrs = rowAttrs;
+ return tblProperties;
+ };
+ Datatables.addColumnAttr = function(start, tblJSONObj, tblProperties, attrName, attrValue, currTd){
+ var payload, currTdInfo, colAttrs;
+ payload = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(payload, start[1]);
+ colAttrs = tblProperties.colAttrs;
+ if (colAttrs == null || typeof colAttrs === 'undefined') {
+ colAttrs = [];
+ }
+ if (colAttrs[currTd] == null || typeof colAttrs[currTd] === 'undefined') {
+ colAttrs[currTd] = {};
+ } else if (colAttrs[currTd][attrName] === attrValue) {
+ return false;
+ }
+ colAttrs[currTd][attrName] = attrValue;
+ tblProperties.colAttrs = colAttrs;
+ return tblProperties;
+ };
+ Datatables.updateTablePropertiesHelper = function(props, start, currTd){
+ var rep, lastTblPropertyUsed, currLine, currLineText, tblJSONObj, tblProperties, update, currAttrValue, tblProps, e;
+ rep = this.context.rep;
+ lastTblPropertyUsed = 'updateTableProperties';
+ start = start || rep.selStart;
+ if (!start) {
+ return;
+ }
+ currLine = rep.lines.atIndex(start[0]);
+ currLineText = currLine.text;
+ if (currLineText.indexOf('\uFFF9') === -1) {
+ return true;
+ }
+ try {
+ tblJSONObj = fromEscapedJSON(currLineText);
+ tblProperties = this.getLineTableProperty(start[0]);
+ update = false;
+ if (props.tblWidth || props.tblHeight || props.tblBorderWidth || props.tblBorderColor) {
+ currAttrValue = tblProperties[props.attrName];
+ if (props.attrValue != null && (typeof currAttrValue === 'undefined' || currAttrValue !== props.attrValue)) {
+ tblProperties[props.attrName] = props.attrValue;
+ update = true;
+ }
+ }
+ if (props.tblCellFontWeight || props.tblCellFontStyle || props.tblCellTextDecoration) {
+ tblProps = this.addCellAttr(start, tblJSONObj, tblProperties, props.attrName, props.attrValue);
+ if (tblProps) {
+ tblProperties = tblProps;
+ update = true;
+ }
+ }
+ if (props.tblCellFontSize || props.tblCellBgColor || props.tblCellHeight || props.tblCellPadding || props.tblcellVAlign) {
+ tblProps = this.addCellAttr(start, tblJSONObj, tblProperties, props.attrName, props.attrValue);
+ if (tblProps) {
+ tblProperties = tblProps;
+ update = true;
+ }
+ }
+ if (props.tblEvenRowBgColor || props.tblOddRowBgColor) {
+ tblProps = this.addRowAttr(tblJSONObj, tblProperties, props.attrName, props.attrValue);
+ if (tblProps) {
+ tblProperties = tblProps;
+ update = true;
+ }
+ }
+ if (props.tblSingleRowBgColor || props.tblRowVAlign) {
+ tblProps = this.addRowAttr(tblJSONObj, tblProperties, props.attrName, props.attrValue);
+ if (tblProps) {
+ tblProperties = tblProps;
+ update = true;
+ }
+ }
+ if (props.tblColWidth || props.tblSingleColBgColor || props.tblColVAlign) {
+ tblProps = this.addColumnAttr(start, tblJSONObj, tblProperties, props.attrName, props.attrValue, currTd);
+ if (tblProps) {
+ tblProperties = tblProps;
+ update = true;
+ }
+ }
+ if (update) {
+ return this.updateTblPropInAPool(-1, -1, tblProperties, start);
+ }
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.updateAuthorAndCaretPos = function(magicDomLineNum, tblRowNum, tblColNum){
+ var rep, row, col;
+ rep = this.context.rep;
+ rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
+ rep.selStart[0] = rep.selEnd[0] = magicDomLineNum;
+ row = typeof tblRowNum === 'undefined' || tblRowNum == null ? 0 : tblRowNum;
+ col = typeof tblColNum === 'undefined' || tblRowNum == null ? 0 : tblColNum;
+ this.updateTblPropInAPool(row, col, null, rep.selStart);
+ rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
+ return this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ };
+ Datatables.createDefaultTblProperties = function(authors){
+ var rep, defTblProp, prevLine, jsoTblProp, prevLineText, nextLine, nextLineText, jsoStrTblProp;
+ rep = this.context.rep;
+ defTblProp = {
+ borderWidth: '1',
+ cellAttrs: [],
+ width: '6',
+ rowAttrs: {},
+ colAttrs: [],
+ authors: {}
+ };
+ if (authors) {
+ defTblProp['authors'] = authors;
+ }
+ prevLine = rep.lines.atIndex(rep.selEnd[0] - 1);
+ jsoTblProp = null;
+ if (prevLine) {
+ prevLineText = prevLine.text;
+ if (!(prevLineText.indexOf('\uFFF9') === -1)) {
+ jsoTblProp = this.getLineTableProperty(rep.selStart[0] - 1);
+ }
+ }
+ if (!jsoTblProp) {
+ nextLine = rep.lines.atIndex(rep.selEnd[0] - 1);
+ if (nextLine) {
+ nextLineText = nextLine.text;
+ if (!(nextLineText.indexOf('\uFFF9') === -1)) {
+ jsoTblProp = this.getLineTableProperty(rep.selStart[0] + 1);
+ }
+ }
+ }
+ if (jsoTblProp) {
+ defTblProp.borderWidth = jsoTblProp.borderWidth;
+ defTblProp.borderColor = jsoTblProp.borderColor;
+ defTblProp.width = jsoTblProp.width;
+ defTblProp.height = jsoTblProp.height;
+ defTblProp.colAttrs = jsoTblProp.colAttrs;
+ }
+ jsoStrTblProp = JSON.stringify(defTblProp);
+ return jsoStrTblProp;
+ };
+ Datatables.performDocApplyTblAttrToRow = function(start, jsoStrTblProp){
+ var tempStart, tempEnd;
+ tempStart = [];
+ tempEnd = [];
+ tempStart[0] = start[0];
+ tempEnd[0] = start[0];
+ tempStart[1] = 0;
+ tempEnd[1] = this.context.rep.lines.atIndex(start[0]).text.length;
+ return this.context.editorInfo.ace_performDocumentApplyAttributesToRange(tempStart, tempEnd, [['tblProp', jsoStrTblProp]]);
+ };
+ Datatables.performDocumentTableTabKey = function(){
+ var context, rep, currLine, currLineText, tblJSONObj, payload, currTdInfo, leftOverTdTxtLen, currRow, currTd, nextLine, nextLineText, updateEvenOddBgColor, start, nextTdTxtLen, e;
+ try {
+ context = this.context;
+ rep = context.rep;
+ currLine = rep.lines.atIndex(rep.selStart[0]);
+ currLineText = currLine.text;
+ tblJSONObj = fromEscapedJSON(currLineText);
+ payload = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
+ leftOverTdTxtLen = currTdInfo.leftOverTdTxtLen;
+ currRow = currTdInfo.row;
+ currTd = currTdInfo.td;
+ if (typeof payload[currRow][currTd + 1] === 'undefined') {
+ currRow += 1;
+ nextLine = rep.lines.atIndex(rep.selStart[0] + 1);
+ nextLineText = nextLine.text;
+ updateEvenOddBgColor = false;
+ if (nextLineText == null || nextLineText === '' || nextLineText.indexOf('\uFFF9') === -1) {
+ this.insertTblRowBelow(null, {
+ tblId: tblJSONObj.tblId
+ });
+ this.performDocApplyTblAttrToRow(rep.selStart, this.createDefaultTblProperties());
+ rep.selEnd[1] = rep.selStart[1] = this.vars.OVERHEAD_LEN_PRE;
+ updateEvenOddBgColor = true;
+ } else {
+ currTd = -1;
+ rep.selStart[0] = rep.selEnd[0] = rep.selStart[0] + 1;
+ tblJSONObj = fromEscapedJSON(nextLineText);
+ payload = tblJSONObj.payload;
+ leftOverTdTxtLen = payload[0][0].length;
+ rep.selEnd[1] = rep.selStart[1] = this.vars.OVERHEAD_LEN_PRE + leftOverTdTxtLen;
+ }
+ context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ start = [];
+ start[0] = rep.selStart[0];
+ start[1] = rep.selStart[1];
+ return this.updateTblCellAuthor(0, 0, null, start, updateEvenOddBgColor);
+ } else {
+ nextTdTxtLen = typeof payload[currRow] === 'undefined'
+ ? -leftOverTdTxtLen
+ : payload[currRow][currTd + 1].length;
+ payload = tblJSONObj.payload;
+ rep.selStart[1] = rep.selEnd[1] = rep.selEnd[1] + nextTdTxtLen + leftOverTdTxtLen;
+ context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ return this.updateTblPropInAPool(currRow, currTd + 1, null, rep.selStart);
+ }
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.getTdInfo = function(payload, tdIndex){
+ var rep, startOffset, rowStartOffset, payloadSum, tds, tIndex, tLen, overHeadLen;
+ rep = this.context.rep;
+ startOffset = this.vars.OVERHEAD_LEN_PRE;
+ rowStartOffset = startOffset;
+ payloadSum = startOffset;
+ tds = payload[0];
+ tIndex = 0;
+ tLen = tds.length;
+ while (tIndex < tLen) {
+ overHeadLen = this.vars.OVERHEAD_LEN_MID;
+ if (tIndex === tLen - 1) {
+ overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
+ }
+ payloadSum += tds[tIndex].length + overHeadLen;
+ if (tIndex >= tdIndex) {
+ return {
+ cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen,
+ cellEndOffset: payloadSum
+ };
+ }
+ tIndex++;
+ }
+ };
+ Datatables.getNextTdInfo = function(payload, currTdInfo){
+ var rep, startOffset, rowStartOffset, payloadSum, tds, tIndex, tLen, overHeadLen, leftOverTdTxtLen, rowEndOffset, tdInfo;
+ rep = this.context.rep;
+ startOffset = currTdInfo.rowEndOffset;
+ rowStartOffset = startOffset;
+ payloadSum = startOffset;
+ tds = payload[currTdInfo.row];
+ tIndex = 0;
+ tLen = tds.length;
+ while (tIndex < tLen) {
+ overHeadLen = this.vars.OVERHEAD_LEN_MID;
+ if (tIndex === tLen - 1) {
+ overHeadLen = this.vars.OVERHEAD_LEN_ROW_END;
+ }
+ payloadSum += tds[tIndex].length + overHeadLen;
+ if (tIndex >= currTdInfo.td) {
+ leftOverTdTxtLen = payloadSum - startOffset === 0
+ ? payload[currTdInfo.row + 1][tIndex].length + this.vars.OVERHEAD_LEN_MID
+ : payloadSum - startOffset;
+ rowEndOffset = this._getRowEndOffset(rowStartOffset, tds);
+ tdInfo = {
+ row: currTdInfo.row + 1,
+ td: tIndex,
+ leftOverTdTxtLen: leftOverTdTxtLen,
+ rowStartOffset: rowStartOffset,
+ rowEndOffset: rowEndOffset,
+ cellStartOffset: payloadSum - tds[tIndex].length - overHeadLen,
+ cellEndOffset: payloadSum
+ };
+ return tdInfo;
+ }
+ tIndex++;
+ }
+ };
+ Datatables.insertTblColumn = function(leftOrRight, start, end){
+ var rep, func, currLineText, tblJSONObj, payload, currTdInfo, currTd, numOfLinesAbove, cellPos, newText, updateEvenOddBgColor, updateColAttrs, e;
+ rep = this.context.rep;
+ func = 'insertTblColumn()';
+ try {
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ tblJSONObj = fromEscapedJSON(currLineText);
+ payload = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
+ currTd = currTdInfo.td;
+ start = [];
+ end = [];
+ start[0] = rep.selStart[0];
+ start[1] = rep.selStart[1];
+ end[0] = rep.selEnd[0];
+ end[1] = rep.selEnd[1];
+ if (leftOrRight === 'addL') {
+ currTd -= 1;
+ }
+ numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
+ rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] - numOfLinesAbove;
+ while (rep.selStart[0] < rep.lines.length() && rep.lines.atIndex(rep.selStart[0]).text.indexOf('\uFFF9') !== -1) {
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ tblJSONObj = fromEscapedJSON(currLineText);
+ payload = tblJSONObj.payload;
+ cellPos = this.getTdInfo(payload, currTd).cellEndOffset;
+ newText = '\uF134 \uF134,';
+ if (currTd === payload[0].length - 1) {
+ rep.selStart[1] = rep.selEnd[1] = cellPos - this.vars.OVERHEAD_LEN_ROW_END + 1;
+ newText = ',\uF134 \uF134';
+ } else {
+ if (currTd === -1) {
+ rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE - 1;
+ } else {
+ rep.selStart[1] = rep.selEnd[1] = cellPos - 1;
+ }
+ }
+ this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, newText);
+ rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] + 1;
+ }
+ rep.selStart = start;
+ rep.selEnd = end;
+ if (leftOrRight === 'addL') {
+ rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
+ rep.selStart[0] = rep.selEnd[0] = rep.selStart[0];
+ this.updateTblPropInAPool(0, 0, null, rep.selStart);
+ rep.selStart[1] = rep.selEnd[1] = this.vars.OVERHEAD_LEN_PRE;
+ }
+ currTd++;
+ updateEvenOddBgColor = false;
+ updateColAttrs = true;
+ this.sanitizeTblProperties(start, updateEvenOddBgColor, updateColAttrs, currTd, 'add');
+ return this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.deleteTblColumn = function(){
+ var func, rep, currLineText, tblJSONObj, payload, currTdInfo, currTd, start, end, numOfLinesAbove, cellTdInfo, newText, updateEvenOddBgColor, updateColAttrs, e;
+ func = 'deleteTblColumn()';
+ rep = this.context.rep;
+ try {
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ tblJSONObj = fromEscapedJSON(currLineText);
+ payload = tblJSONObj.payload;
+ if (payload[0].length === 1) {
+ deleteTable();
+ }
+ currTdInfo = this.getFocusedTdInfo(payload, rep.selStart[1]);
+ currTd = currTdInfo.td;
+ start = [];
+ end = [];
+ start[0] = rep.selStart[0];
+ start[1] = rep.selStart[1];
+ end[0] = rep.selEnd[0];
+ end[1] = rep.selEnd[1];
+ numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
+ rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] - numOfLinesAbove;
+ while (rep.selStart[0] < rep.lines.length() && rep.lines.atIndex(rep.selStart[0]).text.indexOf('\uFFF9') !== -1) {
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ tblJSONObj = fromEscapedJSON(currLineText);
+ payload = tblJSONObj.payload;
+ cellTdInfo = this.getTdInfo(payload, currTd);
+ newText = '\uF134 \uF134,';
+ if (currTd === payload[0].length - 1) {
+ rep.selStart[1] = cellTdInfo.cellStartOffset - 2;
+ rep.selEnd[1] = cellTdInfo.cellEndOffset - 2;
+ } else {
+ if (currTd === 0) {
+ rep.selStart[1] = this.vars.OVERHEAD_LEN_PRE - 1;
+ rep.selEnd[1] = cellTdInfo.cellEndOffset - 1;
+ } else {
+ rep.selStart[1] = cellTdInfo.cellStartOffset - 1;
+ rep.selEnd[1] = cellTdInfo.cellEndOffset - 1;
+ }
+ }
+ this.context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ rep.selEnd[0] = rep.selStart[0] = rep.selStart[0] + 1;
+ }
+ rep.selStart = start;
+ rep.selEnd = end;
+ updateEvenOddBgColor = false;
+ updateColAttrs = true;
+ this.sanitizeTblProperties(start, updateEvenOddBgColor, updateColAttrs, currTd, 'del');
+ return this.updateAuthorAndCaretPos(rep.selStart[0], 0, 0);
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.insertTblRowBelow = function(numOfRows, table){
+ var context, rep, currLineText, payload, tblPayload, tblRows, i, ref$, tblId, tableObj;
+ context = this.context;
+ rep = context.rep;
+ currLineText = rep.lines.atIndex(rep.selStart[0]).text;
+ payload = [[]];
+ if (!numOfRows && numOfRows !== 0) {
+ tblPayload = fromEscapedJSON(currLineText).payload;
+ numOfRows = tblPayload[0].length;
+ }
+ tblRows = new Array(numOfRows);
+ if (!(numOfRows === 0)) {
+ i = 0;
+ while (i < tblRows.length) {
+ tblRows[i] = ' ';
+ i++;
+ }
+ }
+ payload = (ref$ = table != null ? table.payload : void 8) != null
+ ? ref$
+ : [tblRows];
+ tblId = (ref$ = table != null ? table.tblId : void 8) != null
+ ? ref$
+ : this.getNewTblId();
+ tableObj = {
+ payload: payload,
+ tblId: tblId,
+ tblClass: '\uFFF9',
+ trClass: 'alst',
+ tdClass: 'hide-el'
+ };
+ if (table != null) {
+ table.tblId = tblId;
+ }
+ rep.selEnd[1] = rep.selStart[1] = currLineText.length;
+ this.context.editorInfo.ace_inCallStackIfNecessary('newline', this.context.editorInfo.ace_doReturnKey);
+ return context.editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, escapedJSON(tableObj));
+ };
+ Datatables.getNewTblId = function(){
+ return ++this.lastTblId;
+ };
+ Datatables.doReturnKey = function(){
+ var context, rep, start, end, lastTblPropertyUsed, currLine, currLineText, func, currCarretPos, newText, jsonObj, payloadStr, error, e;
+ context = this.context;
+ rep = context.rep;
+ start = rep.seStart;
+ end = rep.selEnd;
+ lastTblPropertyUsed = 'doTableReturnKey';
+ currLine = rep.lines.atIndex(rep.selStart[0]);
+ currLineText = currLine.text;
+ if (currLineText.indexOf('\uFFF9') !== -1) {
+ func = 'doTableReturnKey()';
+ try {
+ currCarretPos = rep.selStart[1];
+ if (currLineText.substring(currCarretPos - 1, currCarretPos + 2) === '\uF134,\uF134') {
+ return true;
+ } else {
+ if (currLineText.substring(currCarretPos - 2, currCarretPos + 1) === '\uF134,\uF134') {
+ return true;
+ } else {
+ if (currCarretPos < this.vars.OVERHEAD_LEN_PRE) {
+ return true;
+ } else if (currCarretPos > currLineText.length) {
+ return true;
+ }
+ }
+ }
+ start = rep.selStart;
+ end = rep.selEnd;
+ newText = ' /r/n ';
+ start[1] = currCarretPos;
+ end[1] = currCarretPos;
+ try {
+ jsonObj = fromEscapedJSON(currLineText.substring(0, start[1]) + newText + currLineText.substring(start[1]));
+ payloadStr = escapedJSON(jsonObj.payload);
+ if (currCarretPos > payloadStr.length + this.vars.OVERHEAD_LEN_PRE - 2) {
+ return true;
+ }
+ } catch (e$) {
+ error = e$;
+ return true;
+ }
+ context.editorInfo.ace_performDocumentReplaceRange(start, end, newText);
+ } catch (e$) {
+ e = e$;
+ }
+ return true;
+ }
+ };
+ Datatables.isCellDeleteOk = function(keyCode){
+ var rep, start, currLineText, isDeleteAccepted, tblJSONObj, table, currTdInfo, cellEntryLen, currCarretPos, error;
+ rep = this.context.rep, start = rep.selStart;
+ currLineText = rep.lines.atIndex(start[0]).text;
+ if (currLineText.indexOf('\uFFF9') === -1) {
+ return true;
+ }
+ isDeleteAccepted = false;
+ try {
+ tblJSONObj = fromEscapedJSON(currLineText);
+ table = tblJSONObj.payload;
+ currTdInfo = this.getFocusedTdInfo(table, start[1]);
+ cellEntryLen = table[currTdInfo.row][currTdInfo.td].length;
+ currCarretPos = start[1];
+ if (currLineText.substring(currCarretPos - 1, currCarretPos + 2) === '\uF134,\uF134') {
+ return false;
+ } else {
+ if (currLineText.substring(currCarretPos - 2, currCarretPos + 1) === '\uF134,\uF134') {
+ return false;
+ }
+ }
+ switch (keyCode) {
+ case this.vars.JS_KEY_CODE_BS:
+ if (cellEntryLen > 0 && cellEntryLen > currTdInfo.leftOverTdTxtLen - this.vars.OVERHEAD_LEN_MID) {
+ isDeleteAccepted = true;
+ }
+ break;
+ case this.vars.JS_KEY_CODE_DEL:
+ return false;
+ if (cellEntryLen > 0 && currTdInfo.leftOverTdTxtLen - this.vars.OVERHEAD_LEN_MID > 0) {
+ isDeleteAccepted = true;
+ }
+ break;
+ default:
+ if (cellEntryLen > 1 && cellEntryLen > currTdInfo.leftOverTdTxtLen - this.vars.OVERHEAD_LEN_MID) {
+ isDeleteAccepted = true;
+ }
+ }
+ } catch (e$) {
+ error = e$;
+ isDeleteAccepted = false;
+ }
+ return isDeleteAccepted;
+ };
+ Datatables.nodeTextPlain = function(n){
+ return n.innerText || n.textContent || n.nodeValue || '';
+ };
+ Datatables.toString = function(){
+ return 'ep_tables';
+ };
+ Datatables.getLineAndCharForPoint = function(){
+ var context, point, root, N, ln, n, col, parNode, prevSib, textLen, lineEntry, lineNum;
+ context = this.context;
+ point = context.point;
+ root = context.root;
+ if (point.node === root) {
+ if (point.index === 0) {
+ return [0, 0];
+ } else {
+ N = this.context.rep.lines.length();
+ ln = this.context.rep.lines.atIndex(N - 1);
+ return [N - 1, ln.text.length];
+ }
+ } else {
+ n = point.node;
+ col = 0;
+ if (nodeText(n) || point.index > 0) {
+ col = point.index;
+ }
+ parNode = void 8;
+ prevSib = void 8;
+ while ((parNode = n.parentNode) !== root) {
+ if (prevSib = n.previousSibling) {
+ n = prevSib;
+ textLen = nodeText(n).length || this.nodeTextPlain(n).length;
+ col += textLen;
+ } else {
+ n = parNode;
+ }
+ }
+ if (n.id === '') {
+ console.debug('BAD');
+ }
+ if (n.firstChild && context.editorInfo.ace_isBlockElement(n.firstChild)) {
+ col += 1;
+ }
+ lineEntry = this.context.rep.lines.atKey(n.id);
+ lineNum = this.context.rep.lines.indexOfEntry(lineEntry);
+ return [lineNum, col];
+ }
+ };
+ Datatables.doDeleteKey = function(){
+ var context, evt, handled, rep, editorInfo, lineNum, col, lineEntry, lineText, lineMarker, col2, tabSize, toDelete, theLine, action, prevLineListType, thisLineListType, prevLineEntry, prevLineBlank, docChar, deleteBackTo, returnKeyWitinTblOffset, line;
+ context = this.context;
+ evt = context.evt || {};
+ handled = false;
+ rep = this.context.rep;
+ editorInfo = context.editorInfo;
+ if (rep.selStart) {
+ if (editorInfo.ace_isCaret()) {
+ lineNum = editorInfo.ace_caretLine();
+ col = editorInfo.ace_caretColumn();
+ lineEntry = rep.lines.atIndex(lineNum);
+ lineText = lineEntry.text;
+ lineMarker = lineEntry.lineMarker;
+ if (/^ +$/.exec(lineText.substring(lineMarker, col))) {
+ col2 = col - lineMarker;
+ tabSize = ''.length;
+ toDelete = (col2 - 1) % tabSize + 1;
+ editorInfo.ace_performDocumentReplaceRange([lineNum, col - toDelete], [lineNum, col], '');
+ handled = true;
+ }
+ }
+ if (!handled) {
+ if (editorInfo.ace_isCaret()) {
+ theLine = editorInfo.ace_caretLine();
+ lineEntry = rep.lines.atIndex(theLine);
+ if (editorInfo.ace_caretColumn() <= lineEntry.lineMarker) {
+ action = 'delete_newline';
+ prevLineListType = theLine > 0 ? editorInfo.ace_getLineListType(theLine - 1) : '';
+ thisLineListType = editorInfo.ace_getLineListType(theLine);
+ prevLineEntry = theLine > 0 && rep.lines.atIndex(theLine - 1);
+ prevLineBlank = prevLineEntry && prevLineEntry.text.length === prevLineEntry.lineMarker;
+ if (thisLineListType) {
+ if (prevLineBlank && !prevLineListType) {
+ editorInfo.ace_performDocumentReplaceRange([theLine - 1, prevLineEntry.text.length], [theLine, 0], '');
+ } else {
+ editorInfo.ace_performDocumentReplaceRange([theLine, 0], [theLine, lineEntry.lineMarker], '');
+ }
+ } else {
+ if (theLine > 0) {
+ editorInfo.ace_performDocumentReplaceRange([theLine - 1, prevLineEntry.text.length], [theLine, 0], '');
+ }
+ }
+ } else {
+ docChar = editorInfo.ace_caretDocChar();
+ if (docChar > 0) {
+ if (evt.metaKey || evt.ctrlKey || evt.altKey) {
+ deleteBackTo = docChar - 1;
+ while (deleteBackTo > lineEntry.lineMarker && editorInfo.ace_isWordChar(rep.alltext.charAt(deleteBackTo - 1))) {
+ deleteBackTo--;
+ }
+ editorInfo.ace_performDocumentReplaceCharRange(deleteBackTo, docChar, '');
+ } else {
+ returnKeyWitinTblOffset = 0;
+ if (lineText.substring(col - 5, col) === '/r/n ') {
+ returnKeyWitinTblOffset = 4;
+ }
+ editorInfo.ace_performDocumentReplaceCharRange(docChar - 1 - returnKeyWitinTblOffset, docChar, '');
+ }
+ }
+ }
+ } else {
+ editorInfo.ace_performDocumentReplaceRange(rep.selStart, rep.selEnd, '');
+ }
+ }
+ }
+ line = editorInfo.ace_caretLine();
+ if (line !== -1 && editorInfo.ace_renumberList(line + 1) === null) {
+ return editorInfo.ace_renumberList(line);
+ }
+ };
+ Datatables.getLineTableProperty = function(lineNum){
+ var rep, aline, opIter, tblJSString, error;
+ rep = this.context.rep;
+ aline = rep.alines[lineNum];
+ if (aline) {
+ opIter = Changeset.opIterator(aline);
+ if (opIter.hasNext()) {
+ tblJSString = Changeset.opAttributeValue(opIter.next(), 'tblProp', rep.apool);
+ try {
+ return JSON.parse(tblJSString);
+ } catch (e$) {
+ error = e$;
+ return this.defaults.tblProps;
+ }
+ }
+ }
+ return this.defaults.tblProps;
+ };
+ Datatables.getCurrTblOddEvenRowBgColor = function(startRowNum, currRowNum){
+ var rowBgColors, jsoTblProp1, jsoTblProp2;
+ rowBgColors = {
+ oddBgColor: null,
+ evenBgColor: null
+ };
+ if (!(startRowNum === currRowNum)) {
+ jsoTblProp1 = this.getLineTableProperty(startRowNum);
+ jsoTblProp2 = this.getLineTableProperty(startRowNum + 1);
+ rowBgColors.evenBgColor = jsoTblProp1['rowAttrs']['evenBgColor'] || jsoTblProp2['rowAttrs']['evenBgColor'];
+ rowBgColors.oddBgColor = jsoTblProp1['rowAttrs']['oddBgColor'] || jsoTblProp2['rowAttrs']['oddBgColor'];
+ }
+ return rowBgColors;
+ };
+ Datatables.getTblAboveRowsFromCurFocus = function(start){
+ var rep, numOfLinesAbove, line, tblId, text, curr;
+ rep = this.context.rep;
+ numOfLinesAbove = -1;
+ line = start[0];
+ tblId = null;
+ while (text = rep.lines.atIndex(line).text) {
+ if (!/\uFFF9/.test(text)) {
+ break;
+ }
+ curr = fromEscapedJSON(text).tblId;
+ tblId == null && (tblId = curr);
+ if (curr !== tblId) {
+ break;
+ }
+ numOfLinesAbove++;
+ line--;
+ }
+ return numOfLinesAbove;
+ };
+ Datatables.updateTableIndices = function(tblProperties, currTd, addOrDel){
+ var cellAttrs, rIndex, rLen, cellAttr, colAttrs;
+ cellAttrs = tblProperties.cellAttrs;
+ rIndex = 0;
+ rLen = cellAttrs.length;
+ while (rIndex < rLen) {
+ cellAttr = cellAttrs[rIndex];
+ if (addOrDel === 'add') {
+ if (cellAttr) {
+ cellAttr.splice(currTd, 0, null);
+ }
+ } else {
+ if (cellAttr) {
+ cellAttr.splice(currTd, 1);
+ }
+ }
+ rIndex++;
+ }
+ colAttrs = tblProperties.colAttrs;
+ if (addOrDel === 'add') {
+ if (colAttrs) {
+ colAttrs.splice(currTd, 0, null);
+ }
+ } else {
+ if (colAttrs) {
+ colAttrs.splice(currTd, 1);
+ }
+ }
+ return tblProperties;
+ };
+ Datatables.sanitizeTblProperties = function(start, updateEvenOddBgColor, updateColAttrs, currTd, addOrDel){
+ var rep, editorInfo, thisAuthor, numOfLinesAbove, tempStart, evenOddRowBgColors, jsoTblProp, update, results$ = [];
+ rep = this.context.rep;
+ editorInfo = this.context.editorInfo;
+ thisAuthor = editorInfo.ace_getAuthor();
+ numOfLinesAbove = this.getTblAboveRowsFromCurFocus(start);
+ tempStart = [];
+ tempStart[0] = start[0] - numOfLinesAbove;
+ evenOddRowBgColors = {};
+ updateEvenOddBgColor;
+ while (tempStart[0] < rep.lines.length() && rep.lines.atIndex(tempStart[0]).text.indexOf('\uFFF9') !== -1) {
+ jsoTblProp = this.getLineTableProperty(tempStart[0]);
+ update = false;
+ if (tempStart[0] !== start[0] && jsoTblProp['authors'] && jsoTblProp['authors'][thisAuthor]) {
+ delete jsoTblProp['authors'][thisAuthor];
+ update = true;
+ }
+ if (updateColAttrs) {
+ jsoTblProp = this.updateTableIndices(jsoTblProp, currTd, addOrDel);
+ update = true;
+ }
+ if (tempStart[0] !== start[0] && updateEvenOddBgColor) {
+ delete jsoTblProp['rowAttrs']['oddBgColor'];
+ delete jsoTblProp['rowAttrs']['evenBgColor'];
+ update = true;
+ }
+ if (update) {
+ this.updateTblPropInAPool(-1, -1, jsoTblProp, tempStart);
+ }
+ results$.push(tempStart[0] = tempStart[0] + 1);
+ }
+ return results$;
+ };
+ Datatables.updateTblPropInAPool = function(row, td, jsoTblProp, start){
+ var rep, editorInfo, thisAuthor, authorInfos, tblProps, jsoStrTblProp, attrStart, attrEnd, e;
+ try {
+ rep = this.context.rep;
+ editorInfo = this.context.editorInfo;
+ thisAuthor = editorInfo.ace_getAuthor();
+ authorInfos = editorInfo.ace_getAuthorInfos();
+ tblProps = void 8;
+ if (typeof jsoTblProp === 'undefined' || jsoTblProp == null) {
+ jsoTblProp = this.getLineTableProperty(start[0]);
+ }
+ if (row !== -1 && td !== -1) {
+ jsoTblProp['authors'][thisAuthor] = {
+ row: row,
+ cell: td,
+ colorId: authorInfos[thisAuthor].bgcolor
+ };
+ }
+ jsoStrTblProp = JSON.stringify(jsoTblProp);
+ attrStart = [];
+ attrEnd = [];
+ attrStart[0] = start[0];
+ attrStart[1] = 0;
+ attrEnd[0] = start[0];
+ attrEnd[1] = rep.lines.atIndex(start[0]).text.length;
+ return editorInfo.ace_performDocumentApplyAttributesToRange(attrStart, attrEnd, [['tblProp', jsoStrTblProp]]);
+ } catch (e$) {
+ return e = e$;
+ }
+ };
+ Datatables.updateTblCellAuthor = function(row, td, tblProperties, start, updateEvenOddBgColor){
+ var tempStart;
+ try {
+ this.updateTblPropInAPool(row, td, tblProperties, start);
+ tempStart = [];
+ tempStart[0] = start[0];
+ tempStart[1] = start[1];
+ return this.sanitizeTblProperties(tempStart, updateEvenOddBgColor);
+ } catch (e$) {}
+ };
+ function Datatables(){}
+ return Datatables;
+}());
+if (typeof exports != 'undefined' && exports !== null) {
+ exports.Datatables = Datatables;
+}
\ No newline at end of file
diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js
index 381ce18..f688f29 100644
--- a/static/js/linestylefilter.js
+++ b/static/js/linestylefilter.js
@@ -1,8 +1,9 @@
-exports.disableAuthorColorsForThisLine = function (hook, context) {
- var lineText = context.text;
- var disableLineColors = false;
- if (lineText && lineText.indexOf('data-tables')!=-1) {
- disableLineColors = true;
- }
- return disableLineColors;
-};
+exports.disableAuthorColorsForThisLine = function(hook, context){
+ var lineText, disableLineColors;
+ lineText = context.text;
+ disableLineColors = false;
+ if (lineText && lineText.indexOf('\uFFF9') !== -1) {
+ disableLineColors = true;
+ }
+ return disableLineColors;
+};
\ No newline at end of file
diff --git a/templates/datatablesScripts.ejs b/templates/datatablesScripts.ejs
index f0bf40c..b11e0fc 100644
--- a/templates/datatablesScripts.ejs
+++ b/templates/datatablesScripts.ejs
@@ -1,17 +1,17 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/templates/styles.ejs b/templates/styles.ejs
index 1c669e1..eee1ec5 100644
--- a/templates/styles.ejs
+++ b/templates/styles.ejs
@@ -6,4 +6,4 @@
-
+