Skip to content

Commit

Permalink
Everything except multi bookmark functionality works
Browse files Browse the repository at this point in the history
  • Loading branch information
konijn committed Jan 22, 2012
1 parent 7760695 commit 0e90f1d
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 87 deletions.
6 changes: 4 additions & 2 deletions bc.css
Expand Up @@ -22,6 +22,8 @@
.menu { color: rgb(0,0,0); background: rgb(0,128,128);}
.white { color: rgb(255,255,255); background: rgb(0,128,128);}
.selected { color: rgb(0,0,0); background: rgb(0,128,128);}
.paars { color: rgb(223, 0,255); }
.yellow { color: rgb(255,255, 0); }
.js { color: rgb(0,255,0); background: rgb(0,0,128); }
.fcode { color: rgb(192,192,192); background: rgb(0,0,0); }
.speed { color: rgb(255,255,0); }
Expand Down Expand Up @@ -49,12 +51,12 @@
background-color: inherit;
}


@-webkit-keyframes blink {
0% { opacity: 0 } 50% { opacity: 0 }
50.01% { opacity: 1 } 100% { opacity: 1 }
}

blink {
-webkit-animation: blink 0.7s infinite linear alternate;
-webkit-font-smoothing: antialiased;
Expand Down
53 changes: 4 additions & 49 deletions bc.js
Expand Up @@ -43,8 +43,8 @@

//html 5 should have stuff like this, really..
String.prototype.remove = function(needle)
{
return this.replaceAll(needle, "");
{
return this.replaceAll(needle, "");
}

//To go where jQuery dares not go
Expand Down Expand Up @@ -79,56 +79,10 @@
var day = this.getDate();
var month = this.getMonth()+1;
var year = this.getYear()+1900;

return ( month + "/" + day + "/" + year );
}

//"662"
//Yes, google provides a search function
//But I can debug this one
function findBookmarkId( stuff , id )
{
var node;

var seek = function( stuff, id )
{
if( stuff && stuff.id && stuff.id == id )
node = stuff;
else
for(var key in stuff)
if( typeof stuff[key] == "object" )
seek( stuff[key] , id );
}
seek( stuff , id );

return node;
}

function findBookmarkTitle( id )
{
//This is not entirely true, sue me
var parent = findBookmarkId( commander.bookmarks , id );
//Start from scratch
var title = "";
//Indicate whether we are dealing with a folder
if( parent.children )
title = title + "/";
//Do some recursive magic
while( parent.parentId )
{
title = "/" + parent.title + title;
parent = findBookmarkId( commander.bookmarks , parent.parentId );
}
//Prefix & postfix to make it look even better
title = " " + title + " ";
//Cut off at the right size
if( title.length > panelwidth )
title = "..." + title.right( panelwidth - 3 );
//Give it back
return title
return ( month + "/" + day + "/" + year );
}


//Linking to an external icon due to existing chrome bug
//http://code.google.com/p/chromium/issues/detail?id=84373

Expand All @@ -139,3 +93,4 @@
link.href = iconURL;
//this.docHead.appendChild(link);
this.document.head.appendChild(link);

2 changes: 1 addition & 1 deletion bookmarks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 72 additions & 33 deletions commander.js
Expand Up @@ -18,6 +18,36 @@
**
****/

/* INIT, RE-INIT */
commander.boot = function()
{
chrome.bookmarks.getTree( function(stuff)
{
commander.bookmarks = stuff ;
commander.draw();
});
}

/* HELPER, DRAW IT */
commander.draw = function()
{
if( commander.left.id == "search" )
{
chrome.bookmarks.search( commander.query , function(o){
commander.results = o;
commander.setPanel( commander.left );
commander.setPanel( commander.right );
});
return;
}

//First draw the active one
var panel = commander.left.active ? commander.left : commander.right;
commander.setPanel( panel );
commander.setPanel( panel.other );
}

/* Core wild magic */
commander.setPanel = function( panelConfig )
{
//Show we be here ?
Expand Down Expand Up @@ -60,7 +90,7 @@
}

//We merely do this to facilitate the following trick
var children = [].concat( o.children );
var children = [].concat( filterBookmarks( o.children , panelConfig.filter ) );

//Do we have a parent ?, if so top the entries with '..'
if( o.parentId )
Expand Down Expand Up @@ -124,7 +154,24 @@
element.setAttribute("class", style );

//Set the content
element.innerHTML = ( prefix + child.title ).extend( panelwidth );
var innerHTML = ( prefix + child.title ).extend( panelwidth );

//Highlight filter if any
if( panelConfig.filter )
{
innerHTML = innerHTML.replaceAll( panelConfig.filter , "\u2604" );
innerHTML = innerHTML.replaceAll( "\u2604" , "<span class='paars'>" + panelConfig.filter + "</span>" );
}

//Highlight filter if any
if( panelConfig.selector )
{
if( innerHTML.has( panelConfig.selector ) || panelConfig.selector == "*" )
innerHTML = "<span class='yellow'>" + innerHTML + "</span>";
}

//Set the final innerHTML only now to prevent potential flickering
element.innerHTML = innerHTML

//Set the new index
element.commander = { id : child.id };
Expand Down Expand Up @@ -594,7 +641,7 @@
if(commander.query)
searchtext = commander.query;
else
searchtext = prompt("Enter folder name","");
searchtext = prompt("Enter search string",""); //"" is the default
}
chrome.bookmarks.search( searchtext , function(o){
var panel = commander.left.active ? commander.left : commander.right;
Expand All @@ -605,38 +652,30 @@
});
}

/* HELPER, DRAW IT */
commander.draw = function()
/* FILTER */
commander.filter = function(panel)
{
if( commander.left.id == "search" )
{
chrome.bookmarks.search( commander.query , function(o){
commander.results = o;
commander.setPanel( commander.left );
commander.setPanel( commander.right );
});
return;
}
if(!panel)
panel = commander.left.active ? commander.left : commander.right;

//Less Ugly, but still ugly
if( commander.left.info )
{
commander.setPanel( commander.right );
commander.setPanel( commander.left );
}
else
{
commander.setPanel( commander.left );
commander.setPanel( commander.right );
}
panel.filter = prompt("Enter filter string", panel.filter ); //"" is the default

panel.filter.remove("*");

commander.draw();
}

/* INIT, RE-INIT */
commander.boot = function()
/* SELECT */
commander.selector = function(panel)
{
chrome.bookmarks.getTree( function(stuff)
{
commander.bookmarks = stuff ;
commander.draw();
});
}
if(!panel)
panel = commander.left.active ? commander.left : commander.right;

if(!panel.selector)
panel.selector = "*";

panel.selector = prompt("Select", panel.selector ); //"" is the default

commander.draw();
}

3 changes: 3 additions & 0 deletions keymaps.js
Expand Up @@ -47,6 +47,8 @@
key_mapping[38] = commander.up; //Arrow Up
key_mapping[36] = commander.home; //Home key
key_mapping[35] = commander.end; //End key
key_mapping[56] = commander.selector; //* key on main
key_mapping[106] = commander.selector; //* key on numeric
key_mapping[112] = commander.help; //F1
key_mapping[113] = commander.equalize; //F2
key_mapping[114] = commander.view; //F3
Expand All @@ -61,6 +63,7 @@
key_mapping[187] = commander.moveup; //+ on main
key_mapping[109] = commander.movedown; //- on numeric
key_mapping[189] = commander.movedown; //- on main
key_mapping[191] = commander.filter; // / on main and / on numeric
commander.key_mapping = key_mapping;

control_key_mapping = {};
Expand Down
47 changes: 45 additions & 2 deletions menu.js
Expand Up @@ -71,11 +71,11 @@ menu.init = function()

//Each menu is an object
//Bad violation of DRY, but its worth not rewriting this.
menu.left = { caption : "Left" , indent : 2 , items : menu.itemize( 2 , "&List,&Info,&Tree,_,Sort by &Date,&Sort by Length,Sort &Alphabetically,_,&Filter,_,&Rescan|C-r" ) };
menu.left = { caption : "Left" , indent : 2 , items : menu.itemize( 2 , "&List,&Info,&Tree,_,Sort by &Date,&Sort by Length,Sort &Alphabetically,_,&Filter|/,Select|*,_,&Rescan|C-r" ) };
menu.file = { caption : "File" , indent : 12 , items : menu.itemize( 12 , "&Help|F1,Mirror|F2,View|F3,Edit|F4,Copy|F5,Move|F6,Create Folder |F7,Delete|F8,Quit|F10,_,Move up|+,Move down|-,Select|*,Filter|/" ) };
menu.command = { caption : "Command" , indent : 21 , items : menu.itemize( 21 , "&Search,S&wap panels" ) };
menu.options = { caption : "Options" , indent : 33 , items : menu.itemize( 33 ,"&Learn Keys" ) };
menu.right = { caption : "Right" , indent : 45 , items : menu.itemize( 45 , "&List,&Info,&Tree,_,Sort by &Date,&Sort by Length,Sort &Alphabetically,_,&Filter,_,&Rescan|C-r" ) };
menu.right = { caption : "Right" , indent : 45 , items : menu.itemize( 45 , "&List,&Info,&Tree,_,Sort by &Date,&Sort by Length,Sort &Alphabetically,_,&Filter|/,Select|*,_,&Rescan|C-r" ) };

menu.left.left = menu.right;
menu.left.right = menu.file;
Expand Down Expand Up @@ -264,6 +264,49 @@ menu.dispatch = function( s )

}

if( command == "Search" )
{
commander.search();
}

if( command == "Swap panels" )
{
var temp = commander.left;
commander.left = commander.right;
commander.right = temp;

//This is unfortunate, a 'clever' hack bleeding thru
commander.left.prefix = "left";
commander.right.prefix = "rite";
}

if( command == "Filter" )
{
if (menu.current.caption == "File")
{
commander.filter();
}
else
{
var panel = (menu.current.caption == "Left") ? commander.left : commander.right;
commander.filter( panel );
}
}

if( command == "Select" )
{
if (menu.current.caption == "File")
{
commander.selector();
}
else
{
var panel = (menu.current.caption == "Left") ? commander.left : commander.right;
commander.selector( panel );
}
}


commander.boot();
}

0 comments on commit 0e90f1d

Please sign in to comment.