mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 00:21:40 +00:00
refactoring url handling + cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1785447fd4
commit
1da5cb65df
19
index2.html
19
index2.html
@ -71,31 +71,30 @@ $(function(){requirejs(['pwiki'], function(pwiki){
|
||||
client.page = page
|
||||
client.dom = $('.wiki')
|
||||
|
||||
// get the base url...
|
||||
var url = window.location.hash.slice(1)
|
||||
url = url != '' ? url
|
||||
// XXX get and load page location...
|
||||
client.location('WikiHome')
|
||||
// XXX
|
||||
: 'WikiHome'
|
||||
|
||||
// go to base location...
|
||||
client.location(url)
|
||||
|
||||
// handle hash change...
|
||||
// XXX move to client setup...
|
||||
// XXX need to resolve relative hashes...
|
||||
$(window).on('hashchange', function(evt){
|
||||
evt.preventDefault()
|
||||
|
||||
var path = location.hash.slice(1)
|
||||
var hash = path.split('#')
|
||||
path = hash.shift()
|
||||
hash = hash.pop() || ''
|
||||
|
||||
// expand the path...
|
||||
if(page.get(path).path() != path){
|
||||
location.hash = page.get(path).path()
|
||||
location.hash = client.get(path).path()
|
||||
|
||||
// open page...
|
||||
} else {
|
||||
client.location(path)
|
||||
|
||||
if(hash.length > 0){
|
||||
// XXX focus anchor...
|
||||
}
|
||||
}
|
||||
})
|
||||
})})
|
||||
|
||||
35
pwiki.js
35
pwiki.js
@ -1398,6 +1398,8 @@ var pWikiUIActions = actions.Actions({
|
||||
},
|
||||
},
|
||||
|
||||
// XXX add support for anchors -- #Wiki/Path#anchor...
|
||||
// ...not working yet...
|
||||
location: ['',
|
||||
function(path){
|
||||
var page = this.page
|
||||
@ -1407,17 +1409,40 @@ var pWikiUIActions = actions.Actions({
|
||||
return page.path()
|
||||
}
|
||||
|
||||
path = path.trim()
|
||||
path = path.trim().split('#')
|
||||
var hash = path[1]
|
||||
path = path[0]
|
||||
|
||||
// special paths...
|
||||
if(path in this.config['special-paths']){
|
||||
this[this.config['special-paths'][path]]()
|
||||
}
|
||||
|
||||
var orig = this.location()
|
||||
|
||||
page.location(path)
|
||||
|
||||
|
||||
this.reload()
|
||||
|
||||
// reset scroll location...
|
||||
orig != this.location()
|
||||
&& this.dom
|
||||
.scrollParent()
|
||||
.scrollLeft(0)
|
||||
.scrollTop(0)
|
||||
|
||||
// focus hash..
|
||||
// XXX not working yet...
|
||||
hash != null && hash != ''
|
||||
&& this.dom
|
||||
.scrollParent()
|
||||
.scrollLeft(0)
|
||||
.scrollTop(
|
||||
(this.dom
|
||||
.find('#'+hash+', a[name="'+hash+'"]').first()
|
||||
.offset() || {}).top || 0)
|
||||
&& console.log('HASH:', hash)
|
||||
|
||||
}],
|
||||
reload: ['',
|
||||
function(){
|
||||
@ -1459,6 +1484,10 @@ var pWikiUIActions = actions.Actions({
|
||||
filters[pattern].call(that, dom.find(pattern)) })
|
||||
}],
|
||||
|
||||
// shorthand...
|
||||
get: ['',
|
||||
function(){ return this.page.get.apply(this.page, arguments) }]
|
||||
|
||||
/*
|
||||
// XXX url?
|
||||
// - couch url
|
||||
@ -1493,7 +1522,7 @@ var pWikiClient =
|
||||
module.pWikiClient = object.makeConstructor('pWikiClient',
|
||||
actions.mix(
|
||||
// XXX not sure if we need this here...
|
||||
//actions.MetaActions,
|
||||
actions.MetaActions,
|
||||
pWikiUIActions))
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user