* Implemented a link_title() convenience function to get the link title from a link, either from
it's query string "title=" arg or from the actual contained title. * Made use of this new function in various places where title-grabbing was being done manually. * Made Editor.mouse_clicked() highlight and bail if there's already an open editor with a matching title. (Previously, it only did this matching by id.) * Wiki.load_editor() now looks to an open Link_pulldown's title field for the note's title, if available. * Link_pulldown formats "title=" query string args with MochiKit's queryString() to escape spaces and such. * Updated NOTE_LINK_PATTERN in wiki download view (untested currently).
This commit is contained in:
parent
429dc44370
commit
52fd0d154a
|
@ -251,15 +251,15 @@ Editor.prototype.resolve_link = function ( link ) {
|
|||
this.scrape_title();
|
||||
|
||||
var id;
|
||||
var link_title = scrapeText( link );
|
||||
var editor = note_titles[ link_title ];
|
||||
var title = link_title( link );
|
||||
var editor = note_titles[ title ];
|
||||
// if the link's title corresponds to an open note id, set that as the link's destination
|
||||
if ( editor ) {
|
||||
id = editor.id;
|
||||
link.href = "/notebooks/" + this.notebook_id + "?note_id=" + id;
|
||||
// otherwise, resolve the link by looking up the link's title on the server
|
||||
} else {
|
||||
signal( this, "resolve_link", link_title, link );
|
||||
signal( this, "resolve_link", title, link );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -304,18 +304,23 @@ Editor.prototype.mouse_clicked = function ( event ) {
|
|||
|
||||
event.stop();
|
||||
|
||||
// if the note corresponding to the linked id is already open, highlight it
|
||||
// if the note corresponding to the link's id or title is already open, highlight it
|
||||
var query = parse_query( link );
|
||||
var link_title = query.title || scrapeText( link );
|
||||
var title = link_title( link, query );
|
||||
var id = query.note_id;
|
||||
var iframe = getElement( "note_" + id );
|
||||
if ( iframe ) {
|
||||
iframe.editor.highlight();
|
||||
return;
|
||||
}
|
||||
var editor = note_titles[ title ];
|
||||
if ( editor ) {
|
||||
editor.highlight();
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise, load the note for that id
|
||||
signal( this, "load_editor", link_title, this.iframe.id, id, null, link );
|
||||
signal( this, "load_editor", title, this.iframe.id, id, null, link );
|
||||
}
|
||||
|
||||
Editor.prototype.scrape_title = function () {
|
||||
|
@ -400,7 +405,7 @@ Editor.prototype.start_link = function () {
|
|||
} else {
|
||||
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
||||
var link = this.find_link_at_cursor();
|
||||
signal( this, "resolve_link", scrapeText( link ), link );
|
||||
signal( this, "resolve_link", strip( scrapeText( link ) ), link );
|
||||
}
|
||||
} else if ( this.document.selection ) { // browsers such as IE
|
||||
var range = this.document.selection.createRange();
|
||||
|
@ -415,7 +420,7 @@ Editor.prototype.start_link = function () {
|
|||
} else {
|
||||
this.exec_command( "createLink", "/notebooks/" + this.notebook_id + "?note_id=new" );
|
||||
var link = this.find_link_at_cursor();
|
||||
signal( this, "resolve_link", scrapeText( link ), link );
|
||||
signal( this, "resolve_link", strip( scrapeText( link ) ), link );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -444,7 +449,7 @@ Editor.prototype.end_link = function () {
|
|||
}
|
||||
|
||||
var query = parse_query( link );
|
||||
var link_title = query.title || scrapeText( link );
|
||||
var link_title = query.title || strip( scrapeText( link ) );
|
||||
signal( this, "resolve_link", link_title, link );
|
||||
}
|
||||
|
||||
|
@ -566,3 +571,17 @@ function parse_query( link ) {
|
|||
return parseQueryString( link.href.split( "?" ).pop() );
|
||||
}
|
||||
|
||||
// convenience function for getting a link's title (stripped of whitespace), either from a query
|
||||
// argument in the href or from the actual link title
|
||||
function link_title( link, query ) {
|
||||
if ( !query )
|
||||
query = parse_query( link );
|
||||
|
||||
var link_title = strip( query.title || scrapeText( link ) );
|
||||
|
||||
// work around an IE quirk in which link titles are sometimes 0xa0
|
||||
if ( link_title.charCodeAt( 0 ) == 160 )
|
||||
return "";
|
||||
|
||||
return link_title;
|
||||
}
|
||||
|
|
|
@ -177,6 +177,17 @@ Wiki.prototype.create_blank_editor = function ( event ) {
|
|||
Wiki.prototype.load_editor = function ( note_title, from_iframe_id, note_id, revision, link ) {
|
||||
var self = this;
|
||||
|
||||
// if a link is given with an open link pulldown, then ignore the note title given and use the
|
||||
// one from the pulldown instead
|
||||
var pulldown = this.link_pulldowns[ link ];
|
||||
if ( pulldown ) {
|
||||
pulldown_title = strip( pulldown.title_field.value );
|
||||
if ( pulldown_title )
|
||||
note_title = pulldown_title;
|
||||
else
|
||||
pulldown.title_field.value = note_title;
|
||||
}
|
||||
|
||||
// if there's not a valid destination note id, then load by title instead of by id
|
||||
if ( note_id == "new" || note_id == "null" ) {
|
||||
this.invoker.invoke(
|
||||
|
@ -246,7 +257,7 @@ Wiki.prototype.parse_loaded_editor = function ( result, from_iframe_id, note_tit
|
|||
|
||||
// if a link that launched this editor was provided, update it with the created note's id
|
||||
if ( link && id )
|
||||
link.href = "/notebooks/" + self.notebook_id + "?note_id=" + id;
|
||||
link.href = "/notebooks/" + this.notebook_id + "?note_id=" + id;
|
||||
}
|
||||
|
||||
Wiki.prototype.create_editor = function ( id, note_text, deleted_from, revisions_list, from_iframe_id, note_title, read_write, highlight, focus ) {
|
||||
|
@ -269,7 +280,7 @@ Wiki.prototype.create_editor = function ( id, note_text, deleted_from, revisions
|
|||
var links = getElementsByTagAndClassName( "a", null, getElement( from_iframe_id ).editor.document );
|
||||
for ( var i in links ) {
|
||||
// a link matches if its contained text is the same as this note's title
|
||||
if ( scrapeText( links[ i ] ) == note_title )
|
||||
if ( link_title( links[ i ] ) == note_title )
|
||||
links[ i ].href = "/notebooks/" + this.notebook_id + "?note_id=" + id;
|
||||
}
|
||||
}
|
||||
|
@ -880,10 +891,10 @@ function Link_pulldown( wiki, notebook_id, invoker, editor, link ) {
|
|||
appendChildNodes( this.div, this.note_preview );
|
||||
|
||||
var query = parse_query( link );
|
||||
var link_title = query.title || scrapeText( link );
|
||||
var title = link_title( link, query );
|
||||
var id = query.note_id;
|
||||
if ( id == "new" || id == "null" ) {
|
||||
this.title_field.value = link_title;
|
||||
this.title_field.value = title;
|
||||
replaceChildNodes( self.note_preview, "empty note" );
|
||||
return;
|
||||
}
|
||||
|
@ -909,7 +920,7 @@ function Link_pulldown( wiki, notebook_id, invoker, editor, link ) {
|
|||
self.title_field.value = result.note.title;
|
||||
self.display_preview( result.note.title, result.note.contents );
|
||||
} else {
|
||||
self.title_field.value = link_title;
|
||||
self.title_field.value = title;
|
||||
replaceChildNodes( self.note_preview, "empty note" );
|
||||
}
|
||||
}
|
||||
|
@ -954,19 +965,23 @@ Link_pulldown.prototype.title_field_changed = function ( event ) {
|
|||
|
||||
var self = this;
|
||||
replaceChildNodes( this.note_preview, "" );
|
||||
this.previous_title = this.title_field.value;
|
||||
var title = strip( this.title_field.value );
|
||||
this.previous_title = title;
|
||||
|
||||
this.invoker.invoke(
|
||||
"/notebooks/load_note_by_title", "GET", {
|
||||
"notebook_id": this.notebook_id,
|
||||
"note_title": this.title_field.value
|
||||
"note_title": title
|
||||
},
|
||||
function ( result ) {
|
||||
if ( result.note ) {
|
||||
self.link.href = "/notebooks/" + self.notebook_id + "?note_id=" + result.note.object_id;
|
||||
self.display_preview( result.note.title, result.note.contents );
|
||||
} else {
|
||||
self.link.href = "/notebooks/" + self.notebook_id + "?title=" + self.title_field.value + "¬e_id=null";
|
||||
self.link.href = "/notebooks/" + self.notebook_id + "?" + queryString(
|
||||
[ "title", "note_id" ],
|
||||
[ title, "null" ]
|
||||
);
|
||||
replaceChildNodes( self.note_preview, "empty note" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ from Tags import Html, Head, Title, Style, Meta, Body, H1, Div, Span, Hr, A
|
|||
|
||||
|
||||
class Html_file( Html ):
|
||||
NOTE_LINK_PATTERN = re.compile( u'<a\s+href="\/notebooks\/[a-z0-9]*\?note_id=([a-z0-9]*)"[^>]*>', re.IGNORECASE )
|
||||
NOTE_LINK_PATTERN = re.compile( u'<a\s+href="\/notebooks\/.+[?&]note_id=([a-z0-9]*)"[^>]*>', re.IGNORECASE )
|
||||
|
||||
def __init__( self, notebook_name, notes ):
|
||||
relinked_notes = {} # map from note id to relinked note contents
|
||||
|
|
Reference in New Issue