home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 December
/
PCWorld_2006-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-1-2.exe
/
chrome
/
browser.jar
/
content
/
browser
/
addHeadlines.js
< prev
next >
Wrap
Text File
|
2006-01-06
|
6KB
|
174 lines
// addHeadlines.js
var m_URI;
var m_Title;
function init(aEvent)
{
if (window.arguments && window.arguments.length >= 2) {
m_URI = window.arguments[0];
m_Title = window.arguments[1];
} else if (window.arguments.length == 1){
m_URI = m_Title = window.arguments[0];
} else {
window.close();
return false;
}
document.getElementById("tbTitle").setAttribute("value",m_Title);
buildTree();
}
function uninit(aEvent)
{
if (aEvent.target != document)
return;
}
function doOK()
{
var myIndex = document.getElementById('toolbarPicker').currentIndex;
if (myIndex == -1) return false;
var myID = tbView.visibleData[myIndex][1];
if (myID.indexOf("|") > -1 ) {
var mytbIndex = myID.substr(myID.indexOf("|") +1);
var mytb = myID.substr(0,myID.indexOf("|"));
// dump("attempting addLivemark("+m_URI+","+m_URI+","+m_Title+","+mytb+","+mytbIndex+")\n");
window.opener.spui.addLivemark(m_URI,m_URI,m_Title,mytb,mytbIndex);
} else {
// dump("attempting addLivemark("+m_URI+","+m_URI+","+m_Title+","+myID+")\n");
window.opener.spui.addLivemark(m_URI,m_URI,m_Title,myID);
}
return true;
}
function doCancel()
{
return true;
}
function buildTree()
{
var toolbox = window.opener.document.getElementById('navigator-toolbox');
if (!toolbox) return;
var mySelect = -1;
for (var i = toolbox.firstChild; i; i = i.nextSibling) {
if (i.localName == 'toolbar') {
// dump('toolbar found, name = '+ i.getAttribute("toolbarname") + " id = " + i.id + "\n");
tbView.visibleData[tbView.visibleData.length] = [ i.getAttribute("toolbarname"), i.id, false, false, 0 ];
} else if (i.localName == 'multibar') {
// dump('multibar found, name = '+ i.getAttribute("toolbarname") + " id = " + i.id + "\n");
tbView.visibleData[tbView.visibleData.length] = [ i.getAttribute("toolbarname"), i.id, true, true, 0 ];
tbView.childData[i.id] = [ ];
var mcount = 0;
var mSelect = i.getAttribute("multibarselected");
// dump("mSelect = "+mSelect+"\n");
var curSet = i.getAttribute("currentset");
// dump("curSet = "+curSet+"\n");
var curBar = curSet.split(/;/);
// dump("curBar = "+curBar+"\n");
if (curBar.length > mSelect) {
var curBarName = curBar[mSelect].split(/:/)[0]
} else {
var curBarName = null;
}
// dump("curBarName = "+curBarName+"\n");
for (var j=i.firstChild;j;mcount++,j=j.nextSibling) {
if (j.localName == "multibartray") {
// dump("multibartray found, name = " + j.getAttribute("toolbarname") + " id = " + j.id + "\n");
tbView.childData[i.id][tbView.childData[i.id].length] = [j.getAttribute("toolbarname"), i.id + "|" + mcount];
tbView.visibleData[tbView.visibleData.length] = [ j.getAttribute("toolbarname"), i.id + "|" + mcount, false, false, 1 ];
if (curBarName == j.getAttribute("toolbarname")) mySelect = tbView.visibleData.length - 1;
}
}
}
}
document.getElementById("toolbarPicker").view = tbView;
if (mySelect > -1) document.getElementById("toolbarPicker").view.selection.select(mySelect);
}
var tbView = {
// childData[<id of parent>] = [ <label>, <id> ];
childData : { },
// visibleData[<index>] = [ <label>, <id>, <isContainer>, <isOpen>, <level> ]
visibleData : [ ],
treeBox: null,
selection: null,
get rowCount() { return this.visibleData.length; },
setTree: function(treeBox) { this.treeBox = treeBox; },
getCellText: function(idx, column) { return this.visibleData[idx][0]; },
isContainer: function(idx) { return this.visibleData[idx][2]; },
isContainerOpen: function(idx) { return this.visibleData[idx][3]; },
getLevel: function(idx) { return this.visibleData[idx][4]; },
isContainerEmpty: function(idx) { return false; },
isSeparator: function(idx) { return false; },
isSorted: function() { return false; },
isEditable: function(idx, column) { return false; },
getParentIndex: function(idx) {
if (this.isContainer(idx)) return -1;
for (var t = idx - 1; t >= 0 ; t--) {
if (this.isContainer(t)) return t;
}
return -1;
},
hasNextSibling: function(idx, after) {
var thisLevel = this.getLevel(idx);
for (var t = idx + 1; t < this.visibleData.length; t++) {
var nextLevel = this.getLevel(t)
if (nextLevel == thisLevel) return true;
else if (nextLevel < thisLevel) return false;
}
return false;
},
toggleOpenState: function(idx) {
var item = this.visibleData[idx];
if (!item[2]) return;
if (item[3]) {
item[3] = false;
var thisLevel = this.getLevel(idx);
var deletecount = 0;
for (var t = idx + 1; t < this.visibleData.length; t++) {
if (this.getLevel(t) > thisLevel) deletecount++;
else break;
}
if (deletecount) {
this.visibleData.splice(idx + 1, deletecount);
this.treeBox.rowCountChanged(idx + 1, -deletecount);
}
}
else {
item[3] = true;
var label = this.visibleData[idx][1];
var toinsert = this.childData[label];
for (var i = 0; i < toinsert.length; i++) {
this.visibleData.splice(idx + i + 1, 0, [toinsert[i][0],toinsert[i][1], false, false, 1]);
}
this.treeBox.rowCountChanged(idx + 1, toinsert.length);
}
},
getImageSrc: function(idx, column) {
if (this.isContainer(idx)) return "chrome://browser/skin/tbtree_multibar.png";
else if (this.getLevel(idx) == 1) {
var diff = idx - this.getParentIndex(idx);
return "chrome://browser/skin/tbtree_multibartray"+diff+".png";
} else return "chrome://browser/skin/tbtree_toolbar.png";
},
getProgressMode : function(idx,column) {},
getCellValue: function(idx, column) {},
cycleHeader: function(col, elem) {},
selectionChanged: function() {},
cycleCell: function(idx, column) {},
performAction: function(action) {},
performActionOnCell: function(action, index, column) {},
getRowProperties: function(idx, column, prop) {},
getCellProperties: function(idx, column, prop) {},
getColumnProperties: function(column, element, prop) {},
};