D
dennis.sprengers
Ik ben bezig met een eigen UBB editor. Als iemand aan het typen is,
zorgt CTRL-B voor een \-tag en nogmaals CTRL-B voor een \ tag.
Als je eerst een selectie maakt en dan CTRL-B drukt, wordt de selectie
ingesloten door \ en \, net als hier op GoT.
Wat ik nu probeer is, om de B-knop uit de toolbar te laten oplichten
als de cursor op een woord staat dat omgeven is door B-tags:
I'm trying to write my own UBB editor. If a user types CTRL-B, a
tag is inserted into the textarea. CTRL-B again inserts . If CTRL-
B is pressed while text is selected, the selection is captured between
and tags.
What I'm trying now, is to enlighten the "B" button in the toolbar,
whenever the cursor is captured between tags. If the cursor is
captured between and tags, both these buttons should lighten
up. In the example the cursor is stading over the word "bold":
+---+ +---+ +---+
| B*| | U | | I |
+---+ +---+ +---+
+-----------------------------------------------+
| This is bo|ld and this is |
| bold and underlined |
| |
| |
+-----------------------------------------------+
In short, it's the same toolbar behaviour as we all know it from, i.e.
Microsoft Word.
If the editor were an iframe, I could do something like (taken from
widgEditor source)
But alas, it's a textarea we're dealing with and the tags are not HTML
but UBB, and can therefore not be found in the DOM. I have once
created a function which would remove the html bold tags from a
selection, if the selection was already bold and another "bold"
command would be given:
function selection_replace(type, text) {
switch (type) {
case 'bold':
var re = new RegExp('^<b[^>]*>(.*?)</b>$');
text = (!re.test(text)) ? '<b>'+ text +'</b>' : text.replace(re,
'$1');
break;
}
}
Perhaps part of the solution is here, although I don't think so
because I foresee problems when multiple tags are surrounding a
selection or cursor. Who could help me write a funcion that detects
which UBB tags the cursor in a textarea is captured between?
Your help would be greatly appreciated!
zorgt CTRL-B voor een \-tag en nogmaals CTRL-B voor een \ tag.
Als je eerst een selectie maakt en dan CTRL-B drukt, wordt de selectie
ingesloten door \ en \, net als hier op GoT.
Wat ik nu probeer is, om de B-knop uit de toolbar te laten oplichten
als de cursor op een woord staat dat omgeven is door B-tags:
I'm trying to write my own UBB editor. If a user types CTRL-B, a
tag is inserted into the textarea. CTRL-B again inserts . If CTRL-
B is pressed while text is selected, the selection is captured between
and tags.
What I'm trying now, is to enlighten the "B" button in the toolbar,
whenever the cursor is captured between tags. If the cursor is
captured between and tags, both these buttons should lighten
up. In the example the cursor is stading over the word "bold":
+---+ +---+ +---+
| B*| | U | | I |
+---+ +---+ +---+
+-----------------------------------------------+
| This is bo|ld and this is |
| bold and underlined |
| |
| |
+-----------------------------------------------+
In short, it's the same toolbar behaviour as we all know it from, i.e.
Microsoft Word.
If the editor were an iframe, I could do something like (taken from
widgEditor source)
Code:
theSelection =
theWidgEditor.theIframe.contentWindow.document.selection;
theRange = theSelection.createRange();
theParentNode = theRange.parentElement();
switch (theParentNode.nodeName.toLowerCase()) {
case "a":
theWidgEditor.theToolbar.setState("Link", "on");
break;
}
but UBB, and can therefore not be found in the DOM. I have once
created a function which would remove the html bold tags from a
selection, if the selection was already bold and another "bold"
command would be given:
function selection_replace(type, text) {
switch (type) {
case 'bold':
var re = new RegExp('^<b[^>]*>(.*?)</b>$');
text = (!re.test(text)) ? '<b>'+ text +'</b>' : text.replace(re,
'$1');
break;
}
}
Perhaps part of the solution is here, although I don't think so
because I foresee problems when multiple tags are surrounding a
selection or cursor. Who could help me write a funcion that detects
which UBB tags the cursor in a textarea is captured between?
Your help would be greatly appreciated!