tinyMCE - point between block elements - tinymce

I am using tinyMCE in show block elements mode.
I have written custom plugin that inserts prepared html blocks (layout partials) in actual cursor position.
It's problematic to point a space between two divs.
If I have markup like that:
<div id="first"></div><div id="second"></div>
When I click beteween those divs I would land in first or second div, never between.
So I try to edit html source and result in markup whit br's:
<div id="first"></div><br/><div id="second"></div>
Now I can point between those divs, but it does not work with elements that I add dynamically via tinyMCE. If I add partial eg.
<div></div><br/>
clicking after that div is not posibble. But it's posibble when I edit source manually. Weird. Do you have any solution at this subject?

Tinymce takes care that the user is not able to click between div or p tags.
The reason for this is easy: If a user could click inbetween and he would type in a letter - then there would be another div or p created containing that letter. This is not the way rtes are designed to work. If you want to insert somthing between two divs you will need to use a special button or own plugin to take care of this, but placing the cursor where you won't it to be by hand won't work.

Related

Tiny MCE - Stopping wrapping of images

I am using the TinyMCE Editor, after some Googling it is apparent that the editor needs a root element, which by default is a paragraph.
So everything wrapped in a p tag <p></p>
However, I don't want my images to be wrapped in a paragraph as I want them to be a standalone item.
I know you can strip all p tags but can you be selective with the imagery?
There's currently no way to do this within TinyMCE. You could always strip the root <p> tag on content export.

How to completely change the css position of an element on the page to appear in another part of the document flow?

I have a long form with text inputs, and in the middle of it, I'd like to insert a jquery upload (blueimp) file plugin which uses a form element. I know that nested forms are not valid markup. How can I use CSS to visually position a form element inside another form element without doing some messy absolute positioning?
It seems like using an iframe to generate the content, and then inserting the iframe into the middle of the original form works quite well. I'm unfamiliar with the caveats of iframes but everything seems to work fine.

How to force a node inside tiny mce?

I'm using tiny mce for my project and want to validate the node inside the tiny mce. On click of a text element, let's say a paragraph with some id, I load editor for the element. But, sometimes if user replaces the whole content, the node and its HTML is lost. I want to retain this node and only the content is removed. The node can be a paragraph or heading or ul or ol.
EDIT :
I'm providing dummy text such as "Lorem epsum .....". User will be removing this dummy text and add his content.
EDIT2
I want to allow the user to change the content only and the surrounding HTML and styles should remain intact.
How can I accomplish this ?
This would check if node content is in editor, and if not will add it at the bottom.
var nodecontent;
if (!tinyMCE.activeEditor.getContent().match(/nodecontent/) {
tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent()+nodecontent);
}
You could make a new button in tinymce which gives you a pop-up asking for the ID or the title of a node. This button then puts a small piece of "code" in the tinymce textfield.
for example: ((id:10))
When loading a node, you can search if the current node has that "code" in it by a regular expression. If it has, load the content from the node with that ID from the database.
Hmmm, it will be very tricky to keep the surrounding html while the user is able to delete html elements in the editor. You would need to intercept each attempt where a user could delete your surrounding html (Copy/paste, delete, backspace, usage of the code-plugin, and so on...) and then handle it case for case.
Suggestion:
In case the surrounding html will never change you could give the user total control over the editor content through adding the surrounding html after the user submits/saves the editor content. To keep the style even without the surrounding html it might be sufficient to create a css class and apply it to the body element of the editors iframe. The body element is not deletable. I do not know if this is acceptable in your use-case (let us know).

Is there a Zend_Form_Element that renders a plain div with some content?

Working on a bunch of forms at the moment and I'm finding that I want to be able to split a form into sections with some text in between. Is there a Zend_Form_Element that simply allows me to place some text mixed in with my form (not as a label or description linked to an individual input)?
Thanks!
I think there's not.
Although, you can do one of the following things:
If the text inbetween is more like a title, you can group them in display groups.
If you want to put a lot of text then you'll have to write your own custom form element.
If you choose the second option beware of your form decorations. If you want the text to be from side to side of the page (ie. without the labels space to the left and not aligned to the rest of the input forms) you'll probably have to disable default decorators and set new ones.

How do I select only visible elements using XPath?

I have a GWT application for which I'm trying to write some tests using Selenium.
I'm using XPath to identify the elements on the page for the tests. Using id won't work as the id values are auto-generated by GWT and can change. Things started going well when I realised I could find buttons by their labels as follows:
//button[.='OK']
However, when I started running multiple tests I started having problems. I realised that the issue was all the different "pages" of the GWT app once generated by the Javascript remain in the HTML in hidden <div> elements. This meant my Selenium tests were sometimes clicking hidden buttons instead of the button visible in the current view.
Examining the HTML with Firebug, it seems that GWT hides the <div> elements by adding display: none to their style attribute. This means I can find all the hidden OK buttons as follows:
//div[contains(#style,'display: none')]//button[.='OK']
This will find all the hidden OK buttons, i.e the buttons which have an ancestor <div> which is hidden by having display: none in the style.
My question is: how do I use XPath to find only the visible OK buttons? How do I find the buttons which have no ancestor <div> elements with display: none in the style?
This should work:
.//button[.='OK' and not(ancestor::div[contains(#style,'display:none')])
and not(ancestor::div[contains(#style,'display: none')])]
EDIT:
The simpler and more efficient expression below:
//div[not(contains(#style,'display:none'))]//button[.='OK']
does not work properly because every button has at least one div that's visible in its ancestors.
Selenium 2 Webdriver gives us the option of the isDisplayed() method which deals with this problem. Nice work by the selenium contributors.
This works for me:
//div[not(#hidden)]
//div[(contains(#style,'display: block'))]//button[#id='buttonid']
This worked for me. Like 'display: none' representing hidden blocks, 'display: block' represents currently displayed block and we can specify any inner tags to be identified as above
For me this worked to eliminate hidden elements:
//div[#open]//*
I added this code to the namemapping editor and it did not find the Keep button once it came up. The system sees it in the editor but it doesn't want to click on the button whenever create a new test which will include this item.
Now one other thing this is a dynamic button click so what happens is I will select a button that opens up a to drop downs where I place these items inside those dropdowns. Now it works for the first item but fails to recognize the same mapped item for the next time it is used in another screen. The buttonKeep is the same in both areas.
//div[contains(#style,'display: block')]
This code will find visible element xpath