Maximum width of text in CKEditor - ckeditor

I need to check the width of text that a user enters and not allow any further entry if it exceeds a maximum value. I know how to measure the width of the text in a div, using the current font and font size. I test the width of the text with the following function:
editor.on("change", function (ev) {
var imprintText = editor.getData();
var textWidth = measureText(imprintText);
var hfMaxImprintWidth = document.getElementById("<%=hfMaxImprintWidth.ClientID%>");
var maxWidth = hfMaxImprintWidth.value;
if (textWidth >= maxWidth) {
};
});
But I don't know how to keep additional characters from being added to the textarea. I'd also like to limit the text to one line (no line breaks or new paragraphs). Can someone please help me with this? Thanks!

Too long to be a comment - how appropriate.
Sounds like something that I would solve by using a workaround. For example, if the text is too long, set CKEditor background color to red and prevent saving. Like some websites do for comments - for example stackoverflow shows "too long by 27 characters". Do a similar message on save: display an alert that whines to the user that they have too much content but just leave the character count out.
As for "no line breaks or new paragraphs" - this could be a little more complex. Advanced Content Filter can easily deal with the line breaks, but for the one paragraph only limit I think what you could do is again always check during save and alert the user.
As for automated trickery, how about something like capturing the key event and checking if (evt.data.keyCode === 13) {} and deleting the new element from the editable.
Better still, if the enter key event is cancelable, you could try evt.cancel() as well to ignore it completely. Sorry no example code.

Related

Get possible hyphenation for the selected word

I am new to scripting in Adobe Software.
I would like to write a script, which shows me, where I can hyphenate a word. I wonder, if there is any way to get this information from the build in spellchecker. It should also take the current language into consideration.
This is what I came up with so far:
// Get the current selection
var mySelection = app.selection;
// Check, if it is a word
if (mySelection instanceof Word) {
// Get the possible hypenation options
var hyphenated =
// Add all hyphenation options to the text string
mySelection[0].contents = hyphenated;
}
I know it is not much, but I can’t find any way to access the spellchecker manually.
No, you can't get hyphenation info via scripting.
I suppose the best you could do would be to create a text frame, insert the word, than make the frame increasingly narrow and see where InDesign hyphenates. But that is a pretty klydgy workaround!

apps-script TextArea: can't scroll text into view with setCursorPos

I have a long text in a gas TextArea and I want to scroll a line of text into view. I tried several solutions (setCursorPos, setSelectionRange), but the text is always displayed at the top; i.e. it never scrolls down to the position I want...
I did notice that the doc says: "This will only work when the TextArea is attached to the document and not hidden.". That shouldn't really apply in my case (I want the app to pop up at the specific position...), but I tried to set it before and after the app is displayed.
Here is the code.
....
var cursorPos=15;//just a test...
var fileString = "a very long text that I'm not putting in here....";
var mytextArea=myapp.createTextArea().setValue(fileString).setSize("100%","100%").setName("TextArea").setId("TextArea");
myapp.add(mytextArea.setCursorPos(cursorPos));
var doc=SpreadsheetApp.getActive();
doc.show(myapp);
myapp.getElementById("TextArea").setFocus().setCursorPos(cursorPos);
I must be doing something obviously wrong. Any suggestions?
Issue is here: http://code.google.com/p/google-apps-script-issues/issues/detail?id=1635
The issue response was: "Unfortunately this is a limitation of the underlying GWT technology" :( So no fix any time soon... : i.e setCursorPos(cursorPos) does nothing...
Have you tried wrapping the text area in a scroll panel and setting the position of the scroll panel?

Firefox XUL textbox: How to scroll to the bottom?

I'm working on a Firefox extension, and I have created a multiline text box. When the user presses a button, I add text to the textbox by using (Javascript) TextBoxElement.value += "More Text";
The problem with this code, is that whenever more text is added, the textbox scrolls all the way to the top. With much testing, I haven't figured out how to make it scroll all the way to the bottom again. For some reason the scrollTop property is always 0, and setting it doesn't effect the scroll bar.
Is there any ways I can set the scroll bar back to the bottom of the text box?
My extension's purpose is to embed a small chat box. I'm using a textbox to store the chat history. Maybe using a textbox isn't the most efficient way, so any other suggestions would be great as well.
Someone on Chatzilla helped me out on this one. Thank You!
Anyway, here is the solution:
var TextBoxElement = <TextBoxElement>;
var ti = document.getAnonymousNodes(TextBoxElement)[0].childNodes[0];
ti.scrollTop=ti.scrollHeight;
The another solution is to move caret to the end of textbox content. Caret is controlled with selectionStart and selectionEnd properties (which can be set or get).
Here is the sample code:
var TextBoxElement = document.getElementById("myTextboxId");
var pos = TextBoxElement.value.length;
TextBoxElement.selectionStart = pos;
TextBoxElement.selectionEnd = pos;

Symbian S60 - Scrolling text in a CEikLabel

I have a single line CEikLabel in my application that needs to scroll text.
The simple solution that comes to mind (but possibly naive) would be something like..
[begin pseduo code]
on timer.fire {
set slightly shifted text in label
redraw label
}
start timer
[end pseudo code]
Using a CPeriodic class as the timer and label.DrawDeferred() on each update.
Do you think this is the best way, it may be rather inefficient redrawing the label two or three times a second.. but is there any other way?
Thanks :)
I've seen the timer based solution used for scrolling item names in listboxes.
A couple of things to watch out for are that it could flicker a bit while scrolling and that you need to make sure the text you put on the label is not too long, otherwise it will automatically clip the string and add an elipsis (...)
Use TextUtils::ClipToFit to get a string that fits on the label and remove the elipsis it adds before putting the text on the label (search for KTextUtilClipEndChar in your clipped string). You will need to work out how many characters to skip at the beginning of the string before passing it to the clip function.
I don't know whether there is another way to do it and can't say whether the approach you have in your mind will be inefficient. However, you may want to take a look at this thread which discusses pretty much the same question as yours and also briefly mentions somewhat the same solution as the one you have conceived of.
I have done it like this
TTimeIntervalMicroSeconds32 scrolltime(70000);
iPeriodicScroll = CPeriodic::NewL(CActive::EPriorityIdle);
iPeriodicScroll->Start(scrolltime, scrolltime, TCallBack(CVisTagContainerView::ScrollTextL, this));
and then in the repeated function
CEikLabel *label = iContainer->Label();
const TDesC16 *temp = label->Text();
if (temp->Length() <= 0) {
if (iTextState != ETextIdle) { return; }
DownloadMoreTextL();
return;
}
TPtrC16 right = temp->Right(temp->Length()-1);
label->SetTextL(right);
label->DrawDeferred();
So text moves right to left, and when all gone, the label is repopulated by DownloadMoreTextL

Win32 List-View Control SubItem padding for custom-drawn SubItems?

When using custom-draw (NM_CUSTOMDRAW) to draw the entire contents of a ListView SubItem (in Report/Details view), it would be nice to be able to apply the same left and right
padding in my custom paint method that is applied by the control itself for non-custom-drawn items.
Is there a way to programmatically retrieve this padding value? Is it
related to the width of a particular character (" " or "w" or something?) or
is it a fixed value (6px on left and 3px on right or something) or...?
EDIT: To clarify, I want to add the same padding to my NM_CUSTOMDRAWn SubItems that the control adds to items that it draws, and the metric that I'm looking for, for example, is the white space between the beginning of the 2nd column and the word "Siamese" in the following screenshot (Note: screenshot from MSDN added to help explain my question):
(source: microsoft.com)
Note that the word "Siamese" is aligned with the header item ("Breed"). I would like to be able to guarantee the same alignment for custom-drawn items.
use ListView Header message HDM_GETBITMAPMARGIN
see link text
ListView_GetSubItemRect (LVM_GETSUBITEMTECT)
http://msdn.microsoft.com/en-us/library/ms930172.aspx
Despite what the documentation says I suspect LVIR_LABEL returns just the returns the bounding rectangle of the item text, as per ListView_GetItemRect.
(This just kept niggling me as I though I had actually seen an answer somewhere when playing with NM_CUSTOMDRAW).
Edit After Comment 2:
I imagine you have seen NMLVCUSTOMDRAW which if you are willing to use Version 6.0. has rcText. I wouldn't since I use Win2K.
Given what you have found I would go back to the suggestion of using
ListView_GetItemRect to get LVIR_LABEL and compare that with LVIR_BOUNDS and use the difference.
the way for doing this is retrieving the format of the corresponding column with
ListView_GetColumn()
then check the retrieved myLVCOLUMN.mask
LVCOLUMN myLVCOLUMN;
myLVCOLUMN.mask=LVCF_FMT;
ListView_GetColumn(hwnd,nCol,&myLVCOLUMN);
then when we draw the corresponding label belonging to that column
if(myLVCOLUMN.fmt & LVCFMT_CENTER)
DrawText(x,x,x,x, DT_CENTER | DT_WORD_ELLIPSIS );
else if (myLVCOLUMN.fmt & LVCFMT_RIGHT)
DrawText(x,x,x,x, DT_RIGHT | DT_WORD_ELLIPSIS );
else
DrawText(x,x,x,x, DT_LEFT | DT_WORD_ELLIPSIS );
I would assume that GetSystemMetrics() is that you need to look at. I think that SM_CXEDGE and SM_CYEDGE are probably the values you want, but don't quote me on that. ;-)
Can only guess without seeing your output.
A few suggestions: If you are using the DrawTextEx function, have you have experimented with DT_INTERNAL et al?
Are you accidentally putting in a blank image/icon.
Does it look ok in classic screen mode? If so I would look at XP Theme functions to see if some thing is going on.
Late edit after first comment:
I wonder if the size of rectangle matches the space required for the LVN_ENDLABELEDIT edit box around the text so the text doesn't move (or for a focus rectangle)?
I guess you could compare the result of LVM_GETITEMRECT with LVIR_LABEL on the first column and use the difference as your left border.

Resources