remove ghfinder

This commit is contained in:
Sami Samhuri 2011-11-26 19:26:01 -08:00
parent 92bc92ac32
commit 1bd690c08a
4 changed files with 4 additions and 608 deletions

View file

@ -1,475 +0,0 @@
;(function() {
/* Panel */
window.Panel = function(finder, options) {
this.finder = finder
this.tree = options.tree || []
this.index = options.index || 0
this.name = options.name
this.item = options.item
this.render()
}
Panel.prototype.dispose = function() {
$('p' + this.index ).remove()
this.p = null
}
Panel.prototype.render = function() {
this.finder.psW.insert({ bottom: this.html() })
}
Panel.prototype.html = function() {
var it, css, recent, ix=this.index, t=this.tree,bH = this.finder.bW.offsetHeight,
h = '<ul class=files>'
for( var i = 0; i < t.length; i++ ) {
it = t[i]
h += '<li class=' + it.type + '>' +
'<span class="ico">' +
'<a href="#" data-sha="' + it.sha + '" data-name="' + it.name + '" onclick="return false">' +
it.name +
'</a>' +
'</span>'+
'</li>'
}
h += '</ul>'
return '<div id=p' + ix + ' data-index=' + ix +' class=panel style="height:' + bH +'px">' + h + '</div>'
}
/* parse URL Params as a hash with key are lowered case. (Doesn't handle duplicated key). */
var urlParams = function() {
var ps = [], pair, pairs,
url = window.location.href.split('?')
if( url.length == 1 ) return ps
url = url[1].split('#')[0]
pairs = url.split('&')
for( var i = 0; i < pairs.length; i++ ) {
pair = pairs[i].split('=')
ps[ pair[0].toLowerCase() ] = pair[1]
}
return ps
}
var _loading = 0
function loading() {
if (_loading === 0) { $('in').className = 'on' }
_loading += 1
}
function loaded() {
_loading -= 1
if (_loading === 0) { $('in').className = 'off' }
}
/* Finder */
window.FP = [] // this array contains the list of all registered plugins
window.Finder = function(options){
options = Object.extend( {
user_id: 'samsonjs'
,project: 'samhuri.net'
,branch: 'master'
}, options || {} )
this.ps = []
this.shas = {}
this.user_id = options.user_id
this.project = options.project
this.repo = this.user_id + '/' + this.project
this.branch = options.branch
this.id = options.id
this.render(this.id)
document.observe('click', function(e) {
e = e.findElement()
if( !e.readAttribute('data-sha') ) return
this.click( e.readAttribute('data-sha'), e )
e.blur()
}.bind(this))
/* init plugins */
if( FP )
for( var i = 0; i < FP.length; i++ )
new FP[i](this)
this.openRepo()
}
Finder.prototype.render = function(selector) {
$(selector || document.body).insert(this.html())
this.psW = $('ps_w')
this.bW = $('b_w')
}
Finder.prototype.html = function() {
return [
'<div id=content>',
'<div id=finder class=tbb>',
'<div id=r_w>',
'<div class=p>',
'<table width=100%>',
'<tr>',
'<td align=left id=r></td>', // repo
'<td align=center>Branch: <span id=brs_w></span></td>', // branches
'<td align=center id=in>Loading...</td>',
'<td align=right style=font-weight:bold><a href=https://github.com/sr3d/GithubFinder>Github Finder</a></td>',
'</tr>',
'</table>',
'</div>', // .p
'</div>', // #r_w
'<div id=b_w>', // browser wrapper
'<div id=ps_w style="width:200px"></div>',
'</div>',
// '<div class=clear></div>',
'</div>', // #finder
'<div id=f_c_w style="display:none">', // file content wrapper
'<div class=p>',
'<div id=f_h class=big></div>',
'</div>',
'<div id=f_c>', // file content
'<div class=p>', // padding
'<div id=f_w>', // file wrapper
'<div id=f></div>', // file
'</div>',
'</div>', // padding
'</div>',
'<div class=clear></div>',
'</div>', // #f_c_w
'<div id=footer><b><a href=http://github.com/sr3d/GithubFinder>GithubFinder</a></b></div>',
'</div>' // # content
].join(' ')
}
/* openRepo */
Finder.prototype.openRepo = function() {
this.reset()
$('r').innerHTML = this.repo
var self = this
/* Load the master branch */
loading()
GITR.commits( this.repo, this.branch, function(err, cs) {
loaded()
if (err) {
console.log('GITR.commits failed: ' + err)
return
}
var tree_sha = cs[0].tree
self.renderPanel(tree_sha)
})
/* Show branches info */
loading()
GITR.branches( this.repo, function(err, bes) {
loaded()
if (err) {
console.log('GITR.branches failed: ' + err)
return
}
self.bes = $H(bes) // FIXME
self.renderBranches()
})
}
Finder.prototype.reset = function() {
$('f_c_w').hide()
this.cI = -1
this.pI = 0
while (this.ps.length > 0)
(this.ps.pop()).dispose()
}
/* render branches */
Finder.prototype.renderBranches = function() {
var h = '<select id=brs>'
this.bes.each(function(b) {
h +=
'<option ' + (this.branch == b.key ? ' selected=""' : ' ' ) + '>' +
b.key +
'</option>'
}.bind(this))
$('brs_w').innerHTML = h + '</select>'
document.getElementById('brs').observe('change', function() {
this.openRepo()
return false
}.bind(this))
}
Finder.prototype.renderPanel = function( sh, ix, it ) {
ix = ix || 0
/* clear previously opened panels */
for( var i = this.ps.length - 1; i > ix; i-- ) {
(this.ps.pop()).dispose()
}
this.open( sh, it )
}
Finder.prototype._resizePanelsWrapper = function() {
var w = (this.ps.length * 241)
this.psW.style.width = w + 'px'
/* scroll to the last panel */
this.bW.scrollLeft = w
}
/* request the content of the tree and render the panel */
Finder.prototype.open = function( tree_sha, item ) {
var self = this
GITR.tree( this.repo, tree_sha, function(err, tree) {
var blobs = tree.blobs.sort(function(a, b) {
// blobs always lose to tree
if ( a.type == 'blob' && b.type == 'tree' )
return 1
if ( a.type == 'tree' && b.type == 'blob' )
return -1
return a.name > b.name ? 1 : ( a.name < b.name ? - 1 : 0 )
})
/* add the index to the item */
for ( var i = 0, len = blobs.length, b = blobs[i]; i < len; i++, b = blobs[i] ) {
b.index = i
b.repo = self.repo
b.tree = tree.sha
/* add item to cache */
self.shas[ b.sha ] = b
}
var name = item ? item.name : ''
// debugger
var p = new Panel( self, { tree: blobs, index: self.ps.length, name: name, tree_sha: tree_sha, item: item } )
self.ps.push( p )
self._resizePanelsWrapper()
})
}
/**
* @sha: the sha of the object
* @e: the source element
* @kb: is this trigged by the keyboard
*/
Finder.prototype.click = function(sha, e, kb) {
var it = this.shas[ sha ]
, ix = +(e.up('.panel')).readAttribute('data-index')
/* set selection cursor && focus the item */
e.up('ul').select('li.cur').invoke('removeClassName','cur')
var p = e.up('div.panel')
, li = e.up('li').addClassName('cur')
// FIXME broken, presumably by style changes
// posTop = li.positionedOffset().top + li.offsetHeight - p.offsetHeight
// if ( posTop > p.scrollTop) {
// p.scrollTop = posTop
// }
/* current index */
this.cI = it.index
this.pI = ix // current panel index
/* remember the current selected item */
this.ps[ ix ].cI = it.index
/* don't be trigger happy: ptm = preview timer */
if (this._p) clearTimeout( this._p )
/* set a small delay here incase user switches really fast (e.g. keyboard navigation ) */
var self = this
this._p = setTimeout( function() {
if ( it.type == 'tree' ) {
self.renderPanel( it.sha, ix, it )
// don't show file preview panel
$('f_c_w').hide()
} else {
$('f_c_w').show()
if ( /text/.test(it.mimeType) ) {
loading()
GITR.blob( it.repo, it.tree, it.name, function(err, blob) {
loaded()
if (err) {
console.log('GITR.raw failed, ' + err)
return
}
self.previewTextFile(blob.data('data'), it)
})
}
}
}.bind(this), (kb ? 350 : 10)) // time out
return false
}
Finder.prototype.previewTextFile = function( text, it ) {
text = text.replace(/\r\n/, "\n").split(/\n/)
var ln = [],
l = [],
sloc = 0
for( var i = 0, len = text.length; i < len; i++ ) {
ln.push( '<span>' + (i + 1) + "</span>\n")
l.push( text[i] ? text[i].replace(/&/g, '&amp;').replace(/</g, '&lt;') : "" )
// count actual loc
sloc += text[i] ? 1 : 0
}
if (typeof f.theme === 'undefined') f.theme = 'Light'
var html = [
'<div class=meta>',
'<span>' + it.mode + '</span>',
'<span>' + text.length + ' lines (' + sloc +' sloc)</span>',
'<span>' + it.size + ' bytes</span>',
'<span style="float:right">Theme: <select id="theme">',
'<option ' + (f.theme == 'Light' ? 'selected' : '' ) + '>Light</option>',
'<option ' + (f.theme == 'Dark' ? 'selected' : '' ) + '>Dark</option>',
'</select></span>',
'</div>',
'<div id=f_c_s>', // file content scroll
'<table cellspacing=0 cellpadding=0>',
'<tr>',
'<td valign=top>',
'<pre class=ln>',
ln.join(''),
'</pre>',
'</td>',
'<td width=100% valign=top>',
'<pre id=code>',
l.join("\n"),
'</pre>',
'</td>',
'</tr>',
'</div>'
]
$('f').update( html.join('') ).show()
/* HACK!! */
$('theme').observe('change', function() {
window.f.theme = $F('theme')
$('code').removeClassName('Light').removeClassName('Dark').addClassName(window.f.theme)
})
}
/* keyboard plugin */
var Keyboard = function(f) {
document.observe('keydown', function(e) {
if(e.findElement().tagName == 'INPUT') return // user has focus in something, bail out.
var k = e.which || e.keyCode; // keycode
var cI = f.cI,
pI = f.pI
var p = f.ps[pI] // panel
var t = p.tree // the panel's tree
var d = function() {
if( t[ ++cI ] ) {
var item = t[cI]
// debugger
f.click( item.sha, $$('#p' + pI + ' a')[cI], true )
} else {
cI--
}
}
var u = function() {
if( t[ --cI ] ) {
var item = t[cI]
f.click( item.sha, $$('#p' + pI + ' a')[cI], true )
} else {
cI++
}
}
var l = function() {
if( f.ps[--pI] ) {
// debugger
t = f.ps[pI].tree
// get index of the previously selected item
cI = f.ps[pI].cI
// var item = f.ps[pI];
f.click( t[cI].sha, $$('#p' + pI + ' a')[cI], true )
} else {
pI++ // undo
}
}
var r = function() {
if( !t[cI] || t[cI].type != 'tree' ) return
if( f.ps[++pI] ) {
t = f.ps[pI].tree
cI = -1
d() // down!
} else {
pI-- // undo
}
}
// k == 40 ? d() : ( k == 39 ? r() : ( k == 38 ? u() : ( k == 37 ? l() : ''
switch( k ) {
case 40: // key down
d()
break
case 38: // up
u()
break
case 37: //left
l()
break
case 39: // right
r()
break
default:
break
}
if ( k >= 37 && k <= 40)
e.stop()
})
}
/* add the plugin to the plugins list */
FP.push(Keyboard)
}());

View file

@ -39,116 +39,3 @@ h4 { margin: 0.5em 0 0.7em }
#info > br.clear { clear: both }
#contributors-box a { line-height: 1.8em }
#browse { text-align: center
; font-size: 1.4em
; margin: 1.6em
}
/*
* Github Finder
*
*/
#gh-finder { font-size: 12px; font-family: Helvetica, Verdana, sans-serif; margin: 3em auto 1em; padding: 0; width: 92% }
#gh-finder .clear { clear:both }
#gh-finder a { color: #0E539C; text-decoration: none; border-bottom: none }
#gh-finder a:active { outline: none }
#gh-finder :focus { -moz-outline-style: none; outline: none;}
#gh-finder .p { padding: 10px; }
#gh-finder img { border: 0px}
#finder { width: 100%; overflow: hidden; height: 363px }
#r_w { width: 100%; background-color: #EEE; border-bottom: 1px solid #CCC }
.tbb { border-bottom: 3px solid #CCC;} /* thick bottom border */
/* logo */
.big { font-size: 14px; font-weight: bold;}
#r_w { -moz-border-radius-topright: 7px; -webkit-border-top-right-radius: 7px; border-top-right-radius: 7px;
-moz-border-radius-topleft: 7px; -webkit-border-top-left-radius: 7px; border-top-left-radius: 7px
}
#in { color: transparent; padding: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px }
#in.on { background-color: #4F4A45; color: white }
#b_w { overflow: hidden; overflow-x: auto; height: 320px }
.panel { float: left; width: 240px; border-right: 1px solid #CCC; overflow: scroll; height: 320px }
.files { padding: 0; margin: 0; font-size: 1.3em }
.files li { list-style:none outside none; border-bottom: 1px solid #CCC; background-color: #F8F8F8; }
.t { padding: 10px; border-bottom: 1px solid #CCC; font-size: 14px; font-weight: bold} /* title */
.tree { background: #F8F8F8 url('./img/la.gif') no-repeat 95% 50%; font-weight: bold; }
.ico { background:url('./img/txt.gif') no-repeat 3px 50%; display: block;}
.tree .ico { background-image: url('./img/dir.gif'); }
.cur { background: #3D8CFF url('./img/la_h.gif') no-repeat 95% 50% !important;}
#gh-finder .cur a { color: white;}
.blob { background-image: none !important; }
.files a { padding: 8px 8px 8px 23px; display:block; }
#f_c_w .p {padding: 10px}
#f_c { overflow: hidden; }
#f_c_s { overflow-y: auto; }
#f { border: 1px solid #CCC; }
#commits .big { padding: 10px; border-bottom: 1px solid #CCC;}
/* commit entry */
.ce { padding: 10px 0; border-bottom: 1px solid #CCC; }
pre, #code, .meta, .diff { font:12px Monaco,monospace; margin: 0; }
.meta, .diff thead th { background-color: #EEE; color:#333; overflow:hidden; padding:10px; border-bottom: 1px solid #CCC}
.meta span { margin-left: 5px; padding-left: 9px;}
.meta span:first-child { display: none }
.ln, .diff th { background-color:#ECECEC; border-right:1px solid #DDD; color:#AAA; text-align: right; padding: 5px 5px }
#code { padding: 5px;}
/*.hover { background-color: #FFFFC7; }*/
.insert { background-color:#9E9 }
#footer { padding: 10px }
/* extension stuff */
.resize { cursor: col-resize; float: left; background-color: #DCDCDC;border-right: 1px solid #CCC;}
.hrz { cursor: row-resize !important; background-color: #DCDCDC; ;border-bottom: 1px solid #CCC;height: 3px; line-height: 3px; width: 99.9%}
#bml_w { float: right; font-size: 11px; width: 300px;}
.bml { border: 1px solid #CCC; padding: 1px; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; font-weight: bold;}
.bml:hover { background-color: white;}
/**** code highlighting ****/
#code.Dark { background-color: #191919; color: white; }
#code.Dark .comment { color: #5E5A5F; }
#code.Dark .string { color: #93996D; }
#code.Dark .keywords { color: #CAA76F;}
#code.Dark .brackets { color: #F5F8F8; }
#code.Dark .symbol { color: #C06F52; }
/* CSS */
#code.Dark .properties { color: #C4AD7A}
#code.Dark .selectors { color: #977042 }
#code.Light { background-color: white; color: black; }
#code.Light .comment { color: green; }
#code.Light .string { color: teal; }
#code.Light .keywords { color: navy; font-weight: bold; }
#code.Light .brackets { color: navy; }
#code.Light .symbol { font-weight: bold; }
/* CSS */
#code.Light .properties { color: #C4AD7A}
#code.Light .selectors { color: #977042 }
/* CPP */
#code.Light .datatype { color: #006699; }
#code.Dark .datatype { font-weight: bold;}

View file

@ -8,12 +8,12 @@ echo "request,showdown,strftime,tmpl,jquery-serializeObject,blog -> assets/blog-
cat assets/{request,showdown,strftime,tmpl,jquery-serializeObject,blog}.min.js >|assets/blog-all.min.js
# project index
echo "gitter.store -> assets/proj-index-all.min.js"
echo "gitter,store -> assets/proj-index-all.min.js"
cat assets/{gitter,store}.min.js >|assets/proj-index-all.min.js
# projects
echo "gitter.store,proj,code_highlighter -> assets/proj-all.min.js"
cat assets/{gitter,store,proj,code_highlighter}.min.js >|assets/proj-all.min.js
echo "gitter,store,proj -> assets/proj-all.min.js"
cat assets/{gitter,store,proj}.min.js >|assets/proj-all.min.js
### css ###

View file

@ -59,21 +59,5 @@ _gaq.push( ['_setAccount', 'UA-214054-5']
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
<script src="../../assets/proj-all.min.js"></script>
<script>
(function() {
SJS.proj('{{name}}')
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', ready, false)
} else if (window.attachEvent) {
window.attachEvent('onload', ready)
}
function ready() {
var bl = document.getElementById('browse-link')
bl.onclick = function() {
document.getElementById('browse').style.display = 'none'
window.f = new Finder({ user_id: 'samsonjs', project: '{{name}}', id: 'gh-finder' })
return false
}
}
}())
SJS.proj('{{name}}')
</script>