kopia lustrzana https://github.com/backface/turtlestitch
(morpic): Make urls clickable in read-only StringMorphs, thanks, @brollb !
rodzic
6c01f82354
commit
1a4bcb4959
|
@ -1322,6 +1322,14 @@ function isWordChar(aCharacter) {
|
||||||
return aCharacter.match(/[A-zÀ-ÿ0-9]/);
|
return aCharacter.match(/[A-zÀ-ÿ0-9]/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isURLChar(aCharacter) {
|
||||||
|
return aCharacter.match(/[A-z0-9./:?&_+%-]/);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isURL(text) {
|
||||||
|
return /^https?:\/\//.test(text);
|
||||||
|
}
|
||||||
|
|
||||||
function newCanvas(extentPoint, nonRetina) {
|
function newCanvas(extentPoint, nonRetina) {
|
||||||
// answer a new empty instance of Canvas, don't display anywhere
|
// answer a new empty instance of Canvas, don't display anywhere
|
||||||
// nonRetina - optional Boolean "false"
|
// nonRetina - optional Boolean "false"
|
||||||
|
@ -9165,9 +9173,33 @@ StringMorph.prototype.mouseClickLeft = function (pos) {
|
||||||
cursor.gotoPos(pos);
|
cursor.gotoPos(pos);
|
||||||
}
|
}
|
||||||
this.currentlySelecting = true;
|
this.currentlySelecting = true;
|
||||||
|
} else {
|
||||||
|
var slot = this.slotAt(pos),
|
||||||
|
clickedText,
|
||||||
|
startMark,
|
||||||
|
endMark;
|
||||||
|
|
||||||
|
if (slot === this.text.length) {
|
||||||
|
slot -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
startMark = slot;
|
||||||
|
while (startMark > 1 && isURLChar(this.text[startMark-1])) {
|
||||||
|
startMark -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
endMark = slot;
|
||||||
|
while (endMark < this.text.length - 1 && isURLChar(this.text[endMark + 1])) {
|
||||||
|
endMark += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
clickedText = this.text.substring(startMark, endMark + 1);
|
||||||
|
if (isURL(clickedText)) {
|
||||||
|
window.open(clickedText, '_blank');
|
||||||
} else {
|
} else {
|
||||||
this.escalateEvent('mouseClickLeft', pos);
|
this.escalateEvent('mouseClickLeft', pos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
StringMorph.prototype.mouseDoubleClick = function (pos) {
|
StringMorph.prototype.mouseDoubleClick = function (pos) {
|
||||||
|
|
Ładowanie…
Reference in New Issue