CKEDITOR - Set Caret to end - dom

I'm working a lot with positioning within CKEDITOR.
But i still can't figure out why the following code
sometimes doesn't work?
var range = new CKEDITOR.dom.range(editor.document);
range.moveToElementEditablePosition(element, setToEnd);
editor.getSelection().selectRanges([range]);
I think that it has something to do with the element input that i'm giving.
But i'm not sure.
Does anybody know what are the requirements for the moveToElementEditbalePosition to work?
The last time that i checked my input was a SPAN Element.
http://docs.ckeditor.com/#!/api/CKEDITOR.dom.range-method-moveToElementEditablePosition
Or is there a more secure(cross-browser) solution?
==== edit ====
I found an error, And it's coming from the new CKEDITOR.dom.range
TypeError: b is undefined
This means that editor.document is empty, but when i look in the editor.document it's filled?
When i'm trying to set the range a second time after the error also it shows the following error: uncaught exception: DOMException: INVALID_STATE_ERR

Try this HTML:
<p><span id="test">Text</span></p>
And this JS:
var e = CKEDITOR.instances.editor1;
var span = e.document.getById( 'test' );
var range = e.createRange();
range.moveToElementEditablePosition( span, 1 );
range.select();
e.insertText( 'FOO' );
range.moveToElementEditablePosition( span );
range.select();
e.insertText( 'BAR' );
The result seems to be correct:
<p><span>BARTextFOO</span></p>
Do you have any other cases?

Related

Protractor - unable to get h2 value

I'm unable to get value from h2 tag using protractor.
Html Code:
<h2 class="ng-binding">7</h2>
I need this 7 value. This is from website "http://juliemr.github.io/protractor-demo/". I am adding 5+2.
Appreciate your help.
Try xpath
Here I am getting the element with ID, moving one position back and then looking for the h2
var result = element(by.xpath('//*[#id=\'gobutton\']/../h2'))
result.getText().then(function(value){
expect(value).toBe('7');
})
Or look directly to the h2:
element(by.xpath('//h2[#class='ng-binding']'))
In case you plan to always have 7 as a result then you can also look for the cssContainingText
var result = element.all(by.cssContainingText('.ng-binding', '7')).first();
in this case I am using .all and .first because this will return 2 elements so I am telling protractor to use always the first one
So your code should be something like this:
it('Should access the page and perform sum', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
element(by.model('first')).sendKeys(5);
element(by.model('second')).sendKeys(2);
element(by.id('gobutton')).click();
var result = element(by.xpath('//*[#id=\'gobutton\']/../h2'))
result.getText().then(function(value){
console.log('result is '+value)
expect(value).toBe('7');
})
});
As per the url given, After clicking Go it loads for some time. So add some wait and then try to getText() with the below locator.
browser.sleep(5000);
element(by.css('form>h2.ng-binding')).getText().then((text: String) =>{
expect(text).toBe("7");
})
Hope it helps you...
First, you find the element, for example with a by.css call. Then you use getText method to retrieve the desired tag content. Finally, you assert it to be equal to the value you expect:
result = element(by.css('h2.ng-binding'))
expect(result.getText()).toEqual('7')

Protractor- ElementFinder returning unexpected values

I am writing a protractor test case to compare the name(s) of the displayed data is same as the searched name.
Even though my test case works fine, I am not able to understand what is happening. Because when i expect the name to compare, it compares as expected, but when i print the elementFinder's(rowData)(i have attached the output screen shot here) value in console.log, it show a huge list of some values which i am not able to understand?
PS: I am a newbie to protractor`
This is the testCase:
it('should show proper data for given last name', function () {
var searchValue='manning';
searchBox.sendKeys(searchValue);
search.click();
element.all(by.binding('row.loanNumber')).count().then(function(value) {
var loanCount = value;
for (var i = 0; i < loanCount; i++) {
var rowData = element.all(by.binding('row.borrowerName')).get(i).getText();
expect(rowData).toMatch(searchValue.toUpperCase());
console.log(rowData,'*****',searchValue.toUpperCase());
}
});
});`
And give me valuable suggestions about my style of code
rowData is a promise (not a value), so when you console.log it, you get the promise object
Protractor patches Jasmine to automatically resolve promises within the expect(), so that's how it knows to resolve the value and compare to the expected result.
If you want to console.log the value, you need to resolve the promise with .then() to get the value.
rowData.then(function(rowDataText) {
console.log(rowDataText);
)}
This is pretty much everyone's first question when they start using protractor. You will want to learn how promises work if you want a good understanding of how to manipulate them.

Can not read property 'position' undefined, get Coordinates - CustomTile - Openseadragon

I am trying to get the coordinates with below code : If i am clicking on the canvas to grab the X and Y position : showing me console error : Uncaught TypeError: Cannot read property 'position' of undefined
screenshot : http://screencast.com/t/0LHAae5AicRz
viewer.addHandler('canvas-click', function (target, info) {
var viewportPoint = viewer.viewport.pointFromPixel(info.position);
var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint.x, viewportPoint.y);
console.log(imagePoint.x, imagePoint.y);
});
The info parameter is probably not what you think it is.
Do console.log(info) to see what the variable is in the console.
Perhaps the variable you are looking for is another parameter.
Also log all the arguments that get passed to the function. Write this inside the function:
console.log(arguments)
This way you will be able to inspect the variables and find the data you need.
This way, I can remove the canvas-click related - position of undefined error : Take a look at here for the answer : https://github.com/openseadragon/openseadragon/issues/318
For the //! OpenSeadragon 1.1.1, please updated the code as per below.
viewer.addHandler('canvas-click', function (event)
{
console.log(event);
var viewportPoint = viewer.viewport.pointFromPixel(event.position);
var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint.x, viewportPoint.y);
console.log(imagePoint.x, imagePoint.y);
});

Joomla 3.3: Get data from column 'attribs' in the table 'content'

I'm using the Aixeena Easy CCK-plugin in my Joomla 3.3-website. It's a plugin that allows me to add custom fields in my Article Edit-page. The content I fill out there (should) show up on my website. The plugin stores his information in the #_content table in the attribs column.
On their website, Aixeena says that I have to use the following code to make the filled out text visible on my website:
$attrb = json_decode($this->item->attribs);
echo $attrb->fieldname;
This code drops the following error:
Notice: Undefined property: JDocumentHTML::$item in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Fatal error: Call to a member function get() on a non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 124
I think it is written for an older version of Joomla. Then I searched around and found this code:
$params = $this->item->params;
echo $params->get('fieldname');
When I use this code on my site, it gives me the following error's:
Notice: Undefined property: JDocumentHTML::$item in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 124
That's without a fatal error. I'm not sure why it is without.
Could anybody help me out getting the right code to get my variable out of the table? Thanks in advance!
EDIT 1: Link to the plugin: http://www.aixeena.org/aixeena-lab/aixeena-easy-cck
EDIT 2: Edited my question in reply on the comment of Elin.
So like the notices say, the problem is that $this->item does not exist. You need to figure out what the actual name of the object is and use that rather than $this->item. You will probably do that by looking in the layout of whereever it is that you are trying to display. Can you please check your template to see if it has a layout override for the article view (assuming that is the view you are trying to access the form from)?
I used this code to do a query on the database:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('attribs');
$query->from($db->quoteName('#__content'));
$query->where($db->quoteName('id')." = ".JRequest::getInt('id'));
$db->setQuery($query);
$attribs = $db->loadResult();
$attribs = json_decode($attribs, 'true');
$firstattr = $attribs['firstattr'];
$secondattr = $attribs['secondattr'];
$thirdattr = $attribs['thirdattr'];
$fourthattr = $attribs['fourthattr'];
But I'm sure this can be done simpler.
$attribs = new JRegistry($article->attribs);
echo $fieldname = $attribs['fieldname'];
For example, I use this code in on ContentPrepare like this
function onContentPrepare($context, &$article, &$params, $page) {
$attribs = new JRegistry($article->attribs);
//url is my custom field for the content
$url = $attribs['url'];
......

AMFPHP overiding default function arguments?

I've got this odd problem.
If I make a call on that function through amfphp service browser and give it a valid ID and leave the $num_images field blank amfphp will actually pass a blank string as the argument.
// if i call this function width just an ID
function getWorkers($id, $num_images = 100) {
...
// num_images will be set as ''
}
I can easily override using a check:
function getWorkers($id, $num_images = 100) {
if($num_images=='') $num_images = 100;
...
// num_images will now be really set as 100
}
Anyone experiencing the same with amfphp?
That's odd, I never got that from AMFPHP. If you don't have the latest version try updating your installation of AMFPHP. Also make sure Flash doesn't somehow pass an empty variable as the second variable.
(Copied from the comment.)