Permalink
Browse files

added tablesupport, this code is from Gedion Wolde

  • Loading branch information...
1 parent ddf1cd3 commit ca342b2c1da07e39edd1ed60281e76c7dda374ea @Pita Pita committed Jan 2, 2012
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -80,15 +80,19 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
};
var _blockElems = {
- "div": 1,
+ "div": 1,
"p": 1,
"pre": 1,
"li": 1
};
function isBlockElement(n)
- {
- return !!_blockElems[(dom.nodeTagName(n) || "").toLowerCase()];
+ {
+ /*tAttr = dom.nodeAttr(n,'value');
+ if(tAttr == null || tAttr!='tblBreak'){
+ return !!_blockElems[(dom.nodeTagName(n) || "").toLowerCase()];
+ }*/
+ return !!_blockElems[(dom.nodeTagName(n) || "").toLowerCase()];;
}
function textify(str)
@@ -430,9 +434,12 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
else
{
var tname = (dom.nodeTagName(node) || "").toLowerCase();
- if (tname == "br")
- {
+ if (tname == "br")
+ {
+ tAttr = dom.nodeAttr(node,'value');
+ if(tAttr == null || tAttr!='tblBreak'){
cc.startNewLine(state);
+ }
}
else if (tname == "script" || tname == "style")
{
View
@@ -164,14 +164,26 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
}
extraOpenTags = extraOpenTags + '<a href="' + href.replace(/\"/g, '&quot;') + '">';
extraCloseTags = '</a>' + extraCloseTags;
+ html.push('<span class="', cls || '', '">', extraOpenTags, perTextNodeProcess(domline.escapeHTML(txt)), extraCloseTags, '</span>');
}
- if (simpleTags)
+ else if(txt.indexOf("data-tables")!=-1){
+ try{
+ tblJSONObj = JSON.parse(txt);
+ var htmlTbl = buildText(tblJSONObj);
+ html.push('<span class="', cls || '', '">',htmlTbl, perTextNodeProcess(""), '</span>');
+ }catch(error){
+ html.push('<span class="', cls || '', '">',"hmm...something went wrong. ctrl-z is the best thing a man could have. Reporting it to WLOS developers is the 2nd best thing!", perTextNodeProcess(""), '</span>');
+ }
+ }
+ else if (simpleTags)
{
simpleTags.sort();
extraOpenTags = extraOpenTags + '<' + simpleTags.join('><') + '>';
simpleTags.reverse();
extraCloseTags = '</' + simpleTags.join('></') + '>' + extraCloseTags;
+ html.push('<span class="', cls || '', '">', extraOpenTags, perTextNodeProcess(domline.escapeHTML(txt)), extraCloseTags, '</span>');
}
+ else
html.push('<span class="', cls || '', '">', extraOpenTags, perTextNodeProcess(domline.escapeHTML(txt)), extraCloseTags, '</span>');
}
};
@@ -182,6 +194,63 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
result.lineMarker = 0;
};
+ function buildText(tblJSONObj){
+ var htmlTbl = "";
+ var tblId = tblJSONObj.tblId;
+ var tblClass = tblJSONObj.tblClass;
+ var tdClass = tblJSONObj.tdClass;
+ var trClass = tblJSONObj.trClass;
+ var payload = tblJSONObj.payload;
+ var cellAttr = tblJSONObj.cellAttr;
+ var htmlTbl = "<table id='" + tblId + "' class='" + tblClass + "'><tbody>";
+
+ var rows = tblJSONObj.payload;
+ for (var j = 0, rl = rows.length; j < rl; j++) {
+ var tds = rows[j];
+ trClassName = "";
+ if(j % 2 == 0){
+ trClassName = "alt";
+ }
+ htmlTbl += "<tr class='"+trClass+" "+trClassName+"'>";
+ var preHeader = "";
+ if(j==0){
+ preHeader = "{\"payload\":["
+ }
+ htmlTbl += "<td class='"+tdClass+" overhead'>" +preHeader+ "[\"" + "</td>";
+ for (var i = 0, tl = tds.length; i < tl; i++) {
+ var quoteAndComma = ",\"";
+ var bracketAndcomma = "";
+ if(i==tl-1){
+ quoteAndComma = "";
+ bracketAndcomma = "],";
+ if(j==rl-1){
+ bracketAndcomma = "]],\"tblId\":\""+tblId+"\",\"tblClass\":\""+tblClass+"\",\"trClass\":\""+trClass+"\",\"tdClass\":\""+tdClass+"\",\"cellAttr\":"+JSON.stringify(cellAttr)+"}";
+ }
+ }
+ var allCellAttrs = typeof(cellAttr[j])=='undefined'||cellAttr[j]==null?null:cellAttr[j][i];
+ if(allCellAttrs == null || typeof(allCellAttrs) == 'undefined'){
+ htmlTbl += "<td>" + domline.escapeHTML(tds[i]+"") + "<br value='tblBreak'></td><td class='"+tdClass+" overhead'>\"" + quoteAndComma + bracketAndcomma + "</td>";
+ }
+ else{
+ cellsWithBr = "";
+ var tdText = tds[i];
+ for(var k =0;k<tdText.length;k++){
+ var numOfBreaks = allCellAttrs.breaks[k];
+ if(numOfBreaks != null){
+ for(var brIndex = 0; brIndex < numOfBreaks; brIndex++){
+ cellsWithBr += "<br value='tblBreak'>";
+ }
+ }
+ cellsWithBr += domline.escapeHTML(tdText[k]+"");
+ }
+ htmlTbl += "<td>" + cellsWithBr + "<br value='tblBreak'></td><td class='"+tdClass+" overhead'>\"" + quoteAndComma + bracketAndcomma + "</td>";
+ }
+ }
+ htmlTbl += "</tr>";
+ }
+ htmlTbl += "</tbody></table>";
+ return htmlTbl;
+ };
function writeHTML()
{
var newHTML = perHtmlLineProcess(html.join(''));
@@ -156,18 +156,57 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
}
else if (txt)
{
- if (href)
+ if (href)
{
+ if(!~href.indexOf("http")) // if the url doesn't include http or https etc prefix it.
+ {
+ href = "http://"+href;
+ }
extraOpenTags = extraOpenTags + '<a href="' + href.replace(/\"/g, '&quot;') + '">';
extraCloseTags = '</a>' + extraCloseTags;
+ html.push('<span class="', cls || '', '">', extraOpenTags, perTextNodeProcess(domline.escapeHTML(txt)), extraCloseTags, '</span>');
+ }
+ else if (txt.indexOf("$")!=-1)
+ {
+ var delTr = "%";
+ var delTd = "$";
+ var htmlTbl = "<table class='data-tables'><tbody>";
+
+ var rows = txt.split(delTr);
+ for(var j=0;j<rows.length;j++){
+ var tds = rows[j].split(delTd);
+
+ htmlTbl += "<tr>";
+ for(var i =0;i<tds.length;i++){
+ if(tds[i]=="")continue;
+ htmlTbl += "<td>"+tds[i]+"</td><td class='hide-el'>"+delTd+"</td>";
+ }
+
+ htmlTbl += "</tr>";
+ htmlTbl += "<tr class='hide-el'><td>"+delTr+"</td></tr>";
+ }
+
+ htmlTbl += "</tbody></table>";
+ html.push('<span class="', cls || '', '">',htmlTbl, perTextNodeProcess(""), '</span>');
}
- if (simpleTags)
+ else if(txt.indexOf("data-tables")!=-1){
+ try{
+ tblJSONObj = JSON.parse(txt);
+ var htmlTbl = buildText(tblJSONObj);
+ html.push('<span class="', cls || '', '">',htmlTbl, perTextNodeProcess(""), '</span>');
+ }catch(error){
+ //failed to jsonfiy
+ }
+ }
+ else if (simpleTags)
{
simpleTags.sort();
extraOpenTags = extraOpenTags + '<' + simpleTags.join('><') + '>';
simpleTags.reverse();
extraCloseTags = '</' + simpleTags.join('></') + '>' + extraCloseTags;
+ html.push('<span class="', cls || '', '">', extraOpenTags, perTextNodeProcess(domline.escapeHTML(txt)), extraCloseTags, '</span>');
}
+ else
html.push('<span class="', cls || '', '">', extraOpenTags, perTextNodeProcess(domline.escapeHTML(txt)), extraCloseTags, '</span>');
}
};
@@ -177,7 +216,44 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
lineClass = ''; // non-null to cause update
result.lineMarker = 0;
};
-
+ function buildText(tblJSONObj){
+ var htmlTbl = "";
+ var tblId = tblJSONObj.tblId;
+ var tblClass = tblJSONObj.tblClass;
+ var tdClass = tblJSONObj.tdClass;
+ var trClass = tblJSONObj.trClass;
+ var payload = tblJSONObj.payload;
+ var htmlTbl = "<table id='" + tblId + "' class='" + tblClass + "'><tbody>";
+ var rows = tblJSONObj.payload;
+ for (var j = 0, rl = rows.length; j < rl; j++) {
+ var tds = rows[j];
+ trClassName = "";
+ if(j % 2 == 0){
+ trClassName = "alt";
+ }
+ htmlTbl += "<tr class='"+trClass+" "+trClassName+"'>";
+ var preHeader = "";
+ if(j==0){
+ preHeader = "{\"payload\":["
+ }
+ htmlTbl += "<td class='"+tdClass+" overhead'>" +preHeader+ "[\"" + "</td>";
+ for (var i = 0, tl = tds.length; i < tl; i++) {
+ var quoteAndComma = ",\"";
+ var bracketAndcomma = "";
+ if(i==tl-1){
+ quoteAndComma = "";
+ bracketAndcomma = "],";
+ if(j==rl-1){
+ bracketAndcomma = "]],\"tblId\":\""+tblId+"\",\"tblClass\":\""+tblClass+"\",\"trClass\":\""+trClass+"\",\"tdClass\":\""+tdClass+"\"}";
+ }
+ }
+ htmlTbl += "<td>" + domline.escapeHTML(tds[i]+"") + "</td><td class='"+tdClass+" overhead'>\"" + quoteAndComma + bracketAndcomma + "</td>";
+ }
+ htmlTbl += "</tr>";
+ }
+ htmlTbl += "</tbody></table>";
+ return htmlTbl;
+ };
function writeHTML()
{
var newHTML = perHtmlLineProcess(html.join(''));
@@ -143,7 +143,8 @@ linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFun
// prevent infinite loop if something funny's going on
return nextAfterAuthorColors(txt, cls);
}
- var spanSize = txt.length;
+ var spanSize = leftInAuthor = txt.length;
+ //var spanSize = txt.length;
if (spanSize > leftInAuthor)
{
spanSize = leftInAuthor;
@@ -141,7 +141,8 @@ linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFun
// prevent infinite loop if something funny's going on
return nextAfterAuthorColors(txt, cls);
}
- var spanSize = txt.length;
+ var spanSize = leftInAuthor = txt.length;
+ //var spanSize = txt.length;
if (spanSize > leftInAuthor)
{
spanSize = leftInAuthor;
View
@@ -658,6 +658,9 @@ var pad = {
padeditbar.toolbarClick(cmd);
}
},
+ isFocusWithinTbl:function (){
+ padeditbar.toolbarClick('isFocusWithinTbl');
+ },
dmesg: function(m)
{
if (pad.getIsDebugEnabled())
View
@@ -96,6 +96,7 @@ var padeditbar = (function()
{
$("#editbar").addClass('disabledtoolbar').removeClass("enabledtoolbar");
},
+
toolbarClick: function(cmd)
{
if (self.isEnabled())
@@ -123,8 +124,19 @@ var padeditbar = (function()
{
padeditor.ace.callWithAce(function(ace)
{
- if (cmd == 'bold' || cmd == 'italic' || cmd == 'underline' || cmd == 'strikethrough') ace.ace_toggleAttributeOnSelection(cmd);
+ var OPTIONS_TBL = ['addTbl','addTblRowA','addTblRowB','addTblColL','addTblColR','delTbl','delTblRow','delTblCol'];
+ if(typeof(cmd.payload)!='undefined'){ace.ace_addTable(cmd);}
+ else if (cmd == 'bold' || cmd == 'italic' || cmd == 'underline' || cmd == 'strikethrough') ace.ace_toggleAttributeOnSelection(cmd);
else if (cmd == 'undo' || cmd == 'redo') ace.ace_doUndoRedo(cmd);
+ else if (cmd == 'isFocusWithinTbl'){ padeditor.isFocusWithinTbl = ace.ace_isFocusWithinTbl();}
+ else if (cmd !=null){
+ if($.inArray(cmd,OPTIONS_TBL) != -1){
+ ace.ace_doInsertOrDeleteTableRowCol(cmd);
+ }
+ else if(cmd.indexOf('addTbl') != -1){
+ ace.ace_doInsertOrDeleteTableRowCol('addTbl',cmd);
+ }
+ }
else if (cmd == 'insertunorderedlist') ace.ace_doInsertUnorderedList();
else if (cmd == 'indent')
{
View
@@ -146,7 +146,10 @@ var padeditor = (function()
{
pad.addHistoricalAuthors(dataFromServer.historicalAuthorData);
self.ace.importAText(dataFromServer.atext, dataFromServer.apool, true);
- }
+ },
+ hideTblContextMenu:function(){
+ $.tblContextMenu.hide();
+ }
};
return self;
}());
Oops, something went wrong.

0 comments on commit ca342b2

Please sign in to comment.