-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modularized dialog creation library #97
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,67 @@ | ||
(function(){ | ||
|
||
function createDialog(cfg){ | ||
var header = ""; | ||
for(var i=0; i<cfg.header.length; i++) | ||
header +="<th>"+cfg.header[i]+"</th>"; | ||
|
||
new Dialog({ | ||
npp: Editor, | ||
html: "<table id='results' onMouseOver='Dialog.cfg.onMOver(window.event);' onMouseOut='Dialog.cfg.onMOut(window.event);' onclick='Dialog.cfg.onClick(window.event, Dialog);' onkeypress='Dialog.cfg.onKeyDown(window.event, Dialog);'><tr>"+header+"</tr></table>", | ||
height: 300, | ||
width: 500, | ||
title: cfg.title, | ||
css: "body{overflow:auto;} .highlight{background-color:#eee;} #results{ font-size:12px; border-collapse:collapse} td{cursor:pointer;} td,th{border: 1px solid #d8d8d8; padding: 2px 10px} th{ background-color: #d8d8d8; padding-top:5px; text-align: center; vertical-align: middle;} i.warning{ background-position:-16px 0;} i.warning,i.error{width:16px; height:16px; background-repeat: no-repeat; background-image: URL(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAQCAYAAAB3AH1ZAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAABOtJREFUSMe1lFtsVGUQx3/zfefs2XN2l25b1ra0dqEtLQ1CUVJRlAApjddQjGg0Jj6oiQmXqEFj4oPigxGiRAM8eHsxUSNCYor64IUYIyFAQwoFbexFKKYV2tKL2+6lu3s+HxbxQtEn53Fm/jO/b+bLwL/YJ044/pHtVPE/mlwr8Dro+1fefM7PpDI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Zdn+kqk3V34IJXIfY4xg6yQ2WAWVQugGTLYaZGH7PUVTiTLtyOAgg+7V6fEOl/55lA3OBuIYFHtTVwGBf4RUNi6H3HPSNQ28WbMjnhHeO6Ec2kftoeq+04BTtUjW3N+m6lYinwVagBfIGsj4mmSffdwT/58OnyExuC20xhwCsklBRLLttbzY9lUcXBxA7KBJ1DI4rUhMCX5ncVFKkIYGpSBvTnDL+eB4Z+8lUnthdQyZBaIs5lHpnchv9X2z1U7+0SWUjEosjXjEmOY4ZGcAMdsNQV7uCPe7l5gDysWK1Rh4QY5IWIhpjlEjhDogRDL4PykfMDJgcyEwh6iYNX2yCL4EgULJ6AXXP3MOdi6tpnhuh0Q1QnprhwmiC7h/O07F9P9+fvMgAMAxMALnfARodxAmP18qUAAAAAElFTkSuQmCC)}", | ||
|
||
oncreate: function(){ | ||
var el = this.getElementById("results"); | ||
|
||
var log=""; | ||
for (i=0, len=cfg.arr.length; i < len; i++){ | ||
var row = el.insertRow(); | ||
this.Dialog.cfg.cell(row, cfg.getCells( cfg.arr[i] )); | ||
} | ||
|
||
}, | ||
cell:function(r, arr){ | ||
for(var i=0,c=arr.length; i<c; i++) | ||
r.insertCell().innerHTML = arr[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh SHIT, I dislike this code, it feels like a vulnr. |
||
}, | ||
parent:function(el,name){ | ||
if (el.tagName == name) | ||
return el; | ||
return this.parent(el.parentNode, name); | ||
}, | ||
onMOver:function(evt){ | ||
var target = evt.srcElement || evt.target; | ||
var row = this.parent(target, "TR"); | ||
row.className = "highlight"; | ||
}, | ||
onMOut:function(evt){ | ||
var target = evt.srcElement || evt.target; | ||
var row = this.parent(target, "TR"); | ||
row.className = ""; | ||
}, | ||
onClick:function(evt, d){ | ||
if (typeof(cfg.onRowClick)!="function") | ||
return; | ||
|
||
var target = evt.srcElement || evt.target; | ||
var row = this.parent(target, "TR"); | ||
|
||
cfg.onRowClick(row, target); | ||
}, | ||
onKeyDown: function(evt, dialog) { | ||
var target = evt.srcElement || evt.target, | ||
keycode = evt.keyCode || evt.which; | ||
|
||
if (keycode == 27 || keycode == 13) { | ||
dialog.hide(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function getCSSLint(){ | ||
if (typeof(CSSLint) != "undefined") | ||
return CSSLint; | ||
|
@@ -30,7 +92,7 @@ var settings = GlobalSettings.get("CSSLint") || {}; | |
var CSSLintMenuCfg = { | ||
text:"CSS Lint", | ||
oninitpopup:function(){ | ||
this.verifyMenuItem.disabled = !/\.css/i.test(currentView.files[currentView.file]); | ||
this.verifyMenuItem.disabled = !/\.(css|php|html)/i.test(currentView.files[currentView.file]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the csslint work also on php and html files properly? Maybe it is worth to make it part of settings or control it via (un)check in the menu? |
||
} | ||
|
||
}; | ||
|
@@ -51,55 +113,29 @@ CSSLintMenuCfg.verifyMenuItem = CSSLintMenu.addItem({ | |
allowed[rules[i].id] = 1; | ||
} | ||
|
||
var results = csslint.verify(currentView.text, allowed); | ||
var messages = []; | ||
for(var i=0; i<results.messages.length; i++) | ||
messages.push(this.getCells(results.messages[i])); | ||
|
||
var results = csslint.verify(currentView.selection||currentView.text, allowed); | ||
var messages = results.messages; | ||
//alert(JSON.stringify(messages)); | ||
this.showDialog(messages); | ||
}, | ||
|
||
getCells:function(m){ | ||
return ["<i class='"+m.type+"'/>",m.line,m.col,m.rule.name,m.message]; | ||
}, | ||
css: "i.warning{ background-position:-16px 0;} i.warning,i.error{width:16px; height:16px; background-repeat: no-repeat; background-image: URL(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAQCAYAAAB3AH1ZAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAABOtJREFUSMe1lFtsVGUQx3/zfefs2XN2l25b1ra0dqEtLQ1CUVJRlAApjddQjGg0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4+4bA6t2IrdeXsE3pM6jShuQaD0SroCQBufycAMCIY2EK5BoPaq0AVLnCzrA2g32koj1od3ZDeeABUCxC6kUdk8fRD2YAxRHIDMNQ4ZA6wzLuuT9lzNmkeVwkMSZdn+kqk3V34IJXIfY4xg6yQ2WAWVQugGTLYaZGH7PUVTiTLtyOAgg+7V6fEOl/55lA3OBuIYFHtTVwGBf4RUNi6H3HPSNQ28WbMjnhHeO6Ec2kftoeq+04BTtUjW3N+m6lYinwVagBfIGsj4mmSffdwT/58OnyExuC20xhwCsklBRLLttbzY9lUcXBxA7KBJ1DI4rUhMCX5ncVFKkIYGpSBvTnDL+eB4Z+8lUnthdQyZBaIs5lHpnchv9X2z1U7+0SWUjEosjXjEmOY4ZGcAMdsNQV7uCPe7l5gDysWK1Rh4QY5IWIhpjlEjhDogRDL4PykfMDJgcyEwh6iYNX2yCL4EgULJ6AXXP3MOdi6tpnhuh0Q1QnprhwmiC7h/O07F9P9+fvMgAMAxMALnfARodxAmP18qUAAAAAElFTkSuQmCC)}", | ||
header: ["","Line", "Col", "Title","Description"], | ||
dockable:{name:"CSSLint", docking:"bottom"}, | ||
|
||
showDialog:function(messages){ | ||
var dialCfg = new Dialog.Grid({ | ||
view: Editor.currentView, | ||
|
||
dockable:this.dockable, | ||
rows:messages, | ||
title:"Results", | ||
header: this.header, | ||
css: this.css, | ||
onRowClick:function(cell, target){ | ||
var row = cell.parentNode; | ||
createGridViewDialog({ | ||
arr:messages, | ||
title:"CSSLint - Results", | ||
header: ["","Line", "Col", "Title","Description"], | ||
getCells:function(m){ | ||
return ["<i class='"+m.type+"'/>",m.line,m.col,m.rule.name,m.message]; | ||
}, | ||
|
||
onRowClick:function(row){ | ||
var line = row.cells[1].innerText; | ||
var col = row.cells[2].innerText; | ||
|
||
var lnNr = 1*line -1; | ||
|
||
// scroll to the line | ||
this.view.line = lnNr; | ||
|
||
//set current column | ||
var lineObj = this.view.lines.get(lnNr); | ||
|
||
var posNr = lineObj.start + col*1 -1; | ||
this.view.pos = posNr; | ||
this.view.anchor = posNr; | ||
|
||
// aktivate view | ||
MenuCmds.VIEW_SWITCHTO_OTHER_VIEW(); | ||
if (this.view != Editor.currentView) | ||
MenuCmds.VIEW_SWITCHTO_OTHER_VIEW(); | ||
var col = row.cells[2].innerText; | ||
Editor.currentView.line = 1*line -1; | ||
//this.npp.currentView.column = 1*col -1; | ||
|
||
} | ||
}); | ||
|
||
new Dialog(dialCfg); | ||
} | ||
}) | ||
|
||
|
@@ -110,28 +146,20 @@ CSSLintMenu.addItem({ | |
text:"Settings", | ||
cmd:function(){ | ||
var rules = getCSSLint().getRules(); | ||
var rows = []; | ||
for(var i=0,c=rules.length; i<c; i++){ | ||
rows.push(this.getCells(rules[i])); | ||
} | ||
|
||
this.showDialog(rows); | ||
}, | ||
getCells:function(rule){ | ||
var checked = settings[rule.id] != 1 ? ' checked="checked"' : ''; // negative logic, if exists then not selected | ||
return ['<input type="checkbox"' + checked + ' name="' + rule.id + '">', rule.name, rule.desc]; | ||
this.showDialog(rules); | ||
}, | ||
|
||
showDialog:function(rules){ | ||
var dialCfg = new Dialog.Grid({ | ||
title : "CSSLint - Settings", | ||
rows : rules, | ||
createGridViewDialog({ | ||
arr:rules, | ||
title:"CSSLint - Settings", | ||
header: ["","Title","Description"], | ||
clientHeight: 200, | ||
clientWidth: 400, | ||
onRowClick:function(cell, target){ | ||
var row = cell.parentNode; | ||
|
||
getCells:function(rule){ | ||
var checked = settings[rule.id] != 1?"checked=''":""; // negative logic, if exists then not selected | ||
return ["<input type='checkbox' "+checked+" name='"+rule.id+"'>",rule.name,rule.desc]; | ||
}, | ||
|
||
onRowClick:function(row, target){ | ||
var line = row.cells[1].innerText; | ||
if (target.tagName != "INPUT"){ | ||
target = row.cells[0].firstChild; | ||
this.toggle(target); | ||
|
@@ -148,8 +176,6 @@ CSSLintMenu.addItem({ | |
checkbox.checked = !checkbox.checked; | ||
} | ||
}); | ||
|
||
new Dialog(dialCfg); | ||
} | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this one too. Should definitely try to improve this. But I don't remember currently why don't I use DOM API here and if it is possible at allmor not. In fact I have modularized that very long ago.