1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Fix for the link macro to work around iPhone annoyance

This prevents Mobile Safari from sliding the address bar into view
whenever a tiddler link is clicked
This commit is contained in:
Jeremy Ruston 2013-04-29 16:03:35 +01:00
parent 0d1598eaa1
commit 594871e2d1

View File

@ -78,10 +78,10 @@ LinkWidget.prototype.generate = function() {
this.attributes.href = this.to;
} else {
var wikiLinkTemplateMacro = this.renderer.findMacroDefinition("tw-wikilink-template"),
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.text.trim() : "$uri_encoded$",
wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to));
wikiLinkText = wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
this.attributes.href = wikiLinkText;
wikiLinkTemplate = wikiLinkTemplateMacro ? wikiLinkTemplateMacro.text.trim() : "$uri_encoded$";
this.wikiLinkText = wikiLinkTemplate.replace("$uri_encoded$",encodeURIComponent(this.to));
this.wikiLinkText = this.wikiLinkText.replace("$uri_doubleencoded$",encodeURIComponent(encodeURIComponent(this.to)));
this.attributes.href = this.wikiLinkText;
}
this.events = events;
} else {
@ -101,6 +101,7 @@ LinkWidget.prototype.handleClickEvent = function(event) {
navigateFromClientRect: this.renderer.domNode.getBoundingClientRect()
});
event.preventDefault();
event.stopPropagation();
return false;
}
};
@ -153,6 +154,10 @@ LinkWidget.prototype.postRenderInDom = function() {
if(this.renderer.domNode.tagName === "A") {
this.renderer.domNode.setAttribute("draggable",true);
}
// Hack the href of internal links to include a #, again omitted from the static representation. This helps the browser see it as an internal link (eg it prevents Mobile Safari on iPhone from sliding the address bar into view)
if(!this.isExternal) {
this.renderer.domNode.setAttribute("href","#" + this.wikiLinkText);
}
};
LinkWidget.prototype.refreshInDom = function(changedAttributes,changedTiddlers) {