iOS: Is it possible to change the text selection mode in UIWebView? - javascript

I am developing an epub renderer app for iOS with highlights included as one of its features. I have the algorithm for highlight creation (based on text selections made by user), removal and tap-on-highlight detection that works very well. But to get even better behaviour I would like to restrict text selection on plain text selecting.
In other words, on iOS7 & iOS8 devices I can create selection blocks around html nodes, like this:
As you can see on the pic above, the text selection box goes until header's margins and it is not bound to the text only. I would like that UIWebView automatically transforms that kind of selections to "around-text-only" selection, like this:
The reason I need this restriction is because in the first case some adjacent html nodes can get included under selection (like empty paragraphs, etc), while in the second case I have plain text selection that I can easily handle with my algorithm.
Once again, I don't want to disable text selection, I just want to bind blue selection box to the plain text only.
So can I do something to get that transformation in UIWebView? Use some javascript method perhaps?

Related

Can i get an event for the currently visible text in quill?

i'm interested in providing secondary information elsewhere in the document - e.g. as you scroll through a document in Quill, another text area shows the number of capitalized words in the visible part of the document. I'm not concerned here with visible in the sense of a partly obscured window, nor even in the case that the Quill text input area is partly obscured, e.g. by scrolling the document, but only in what text of the document is shown in the Quill editing area - it might e.g. be just part of one very long line.
Sorry if I understand you wrong, so you wanna be able to search through the Text that someone writes in the Quill Editor and get Feedback based on that for example how many Capitalized Letters it contains?
They have a Method to get the Content as a String:
getText
Retrieves the string contents of the editor.
More about that function
Note that the Editor shows you only text but in the background works with HTML Tags for example if you type in a Word and Select H1 then it generates you <h1>Word</h1> so keep that in mind when you try to analyse the string for certain things.

Change the value of a <textarea> and allow the user to undo

In the past, when you set the value of a textarea using javascript, Firefox allowed the user to undo this change (by pressing ctrl+Z, for example). However, this no longer works, and there doesn't appear to be any decent alternatives.
I've tried using document.execCommand to modify the textarea, but this requires you to select the text that you want to modify, and it doesn't appear to be possible to automatically select text in a textarea.
I've also heard about document.createEvent("TextEvent") but I can't find much information about this. It appears that you can only insert text at the cursor, and I need to delete text as well.
Creating my own undo/redo system and capturing ctrl+Z/Y presses is not an acceptable solution.
Similar questions have already been asked here, but they involve only inserting text at the cursor, not changing the value of the textarea entirely.
You can use the setSelectionRange API to manually manipulate the textarea's selection. Get the original values from textarea.selectionStart and textarea.selectionEnd.

SlickGrid, copy text from Tooltip using AutoTooltips plugin

I use objects as the data for my grid. These objects contain a text value as well as an arbitrary amount of issues.
The text is displayed in the cell and the issue-messages are displayed as a tooltip via the AutoTooltips plugin for each cell. This works fine so far.
My problem: I want to copy text from the tooltip. However: the tooltip disappears as soon as the mouse leaves the cell and I can't figure out how to keep the tooltip 'active' long enough (e.g. as long as the mouse moves towards it) to enter the tooltip and copy text from it. Is there a way to achieve this using the AutoTooltips plugin?
The AutoTooltips plugin only adds the property title. You have to either change the code behind or add another library/scripts that generate tooltip and allows to copy text.
Check http://jquerytools.github.io/demos/tooltip/index.html.
To implement it, just add the code $(grid_container).tooltip() after the grid/rows are rendered.

How to get (not set) the background color of selected text in Chrome via an extension?

I've seen lots of questions about setting the background color of selected text in Chrome and other browsers using the ::selection selector, but I haven't been able to find anything that discusses getting the color currently being used by the browser on the user's OS.
For a Chrome extension I've created a fake input element, and would like to style the "selected" text in that element with the same foreground and background colors as used in real input elements. So I'm wondering if there's an extension API in Chrome that lets JavaScript look up the colors currently being used by the browser for selected text. Given different combinations of platform, OS version and desktop theme, those colors may change from user to user, so simply hard-coding a couple of values isn't sufficient (though that's what I'm doing currently).
One approach might be to render an input with selected text into a canvas and sample the colors, though I haven't investigated whether taking what's essentially a screenshot is possible via an extension without user interaction (the desktopCapture API seems to show a dialog to the user). So I'm hoping there's an API for looking up the colors used by various UI elements. Simply getting access to the browser's default user agent style sheet would suffice.
Rob W points out that the chrome.tabs.captureVisibleTab call can capture the visible area of the current tab into a dataUrl, which could then be rendered into a canvas. By inserting an <input> element at a known location, putting some text into it, focusing the element, selecting the text and then doing the screen capture, you could scan the canvas for the element's pixels and pick out the selection's foreground and background colors. Bit kludgy, but it should work.
The drawback is that this feature requires the <all_urls> permission, even if your extension only needs to work on one domain. It would also mean that a focused input field would briefly flash when the extension loads, which could be distracting.
You could use this:
function elemPropVal(elem, prop){
var r = getComputedStyle(elem) || elem.currentStyle;
return r[prop];
}
console.log(elemPropVal(document.getElementById('someId'), 'backgroundColor'));

Manipulating text in a TextBox in Adobe InDesign CS5

How can I do some manipulations with the text in a TextBox on resize in Adobe InDesign CS5?
The main goal is too split the last word on every row to achieve something like a custom hyphenation.
Is it possible using JavaScript (or ExtendScript?) ?
Thanks.
UPDATE
I've tried to describe my problem in comments
I need an example on ExtendScript, which would find textbox dimensions and hyphenate the text according to dimension and after I'd like to create an event on textbox resize, which would do the same thing after every resize.
You'll probably be able to write a script to do what you want, but the functionality is already built into InDesign.
If I understand your problem correctly it's InDesign does not hyphenate Armenian properly? You can insert manual hyphenationsin the text using the text tool and pressing 'Ctrl'+'-' where you want the hyphen in the text. Unfortunately you'll have to do that everytime you resize the box, because the words will move around - which is probably the problem you're having.
You can set the language in InDesign in the Character tab (shortcut is 'Ctrl'+'t') and upload custom dictionaries/word lists with rules specific to your language including rules for spelling and hyphenation. Unfortunately I couldn't find Armenian in my short search, but perhaps you're more lucky.
Check out the link for more details:
http://help.adobe.com/en_US/indesign/cs/using/WSa285fff53dea4f8617383751001ea8cb3f-6f4da.html

Categories

Resources