The Drupal 7 AJAX library is great, very easy to use. However, I cannot find any resources that can explain to me how to add some effects when the ajax happens. for example, when i use ajax_command_replace to dynamically replace content with certain div, how can I make it fade in?
Thanks.
http://api.drupal.org/api/drupal/includes--ajax.inc/group/ajax/7
In the AJAX array, you can add an item "effect" and set it to slide, fade, or none (defaults to none). To make your item fade in, here's what you write:
'#ajax' => array(
'wrapper' => ...,
'callback' => ...,
'effect' => 'fade'
),
according to this link
ajax['effect']: The jQuery effect to use when placing the new HTML.
Defaults to no effect. Valid options are 'none', 'slide', or 'fade'.**
For future reference, the effect goes in as a new entry in the array returned by ajax_command_*.
For example:
$command = ajax_command_replace('#my-container', $html);
$command['effect'] = 'slide';
Related
Where can I find breaking changes when upgrading to kendo ui core?
For e.g. in previous version
Html.Kendo().Chart()
.Name("test")
.Legend(l => l
.Position(ChartLegendPosition.Top)
.Color("#111111") //This gives error .Color is not available
)
.ChartArea(chartarea => chartarea.Border(3, "#111111", ChartDashType.Dash)) //This gives error No overload method 'Border' takes 3 arguments
I am unable to find how to fix them and there are other controls with similar issues. So I would also like to know if there is any where I can look for all such breaking changes?
You can see breaking changes listed in the documentation here, sorted into years.
Edit:
Based on the API reference found here, it seems that your code should look something like this:
Html.Kendo().Chart()
.Name("test")
.Legend(legend => legend
.Position(ChartLegendPosition.Top)
.Labels(labels => labels.Color("#111111"))
)
.ChartArea(chartarea => chartarea
.Border(border => border
.Width(3)
.Color("#111111")
.DashType(ChartDashType.Dash))
Edit #2: Changed to set legend label color.
I want to retrieve hidden text when the visibiility attribute is hidden:
<div id = "tt52433002" class="yui-module yui-overlay yui-tt yui-overlay-hidden" style="z-index: 2; visibility: hidden;">
<div class="bd">Associated with the domain : testci20160503105556.com</div>
</div>
I tried:
browser.hidden(:class, 'bd').text
and
browser.hidden(:class, 'bd').value
But I get this error:
"unable to locate element, using {:class=>"bd", :tag_name=>"input", :type=>"hidden"}"
Watir is designed to act like a user. So if a user can not see the text in an element, then Watir will not return the text of the element.
Also, the element you are looking for is a div not a hidden.
If you need the text you can do:
browser.div(class: 'bd').inner_html
which makes a JavaScript call to provide the result.
This works:
browser.div.attribute_value('id') => tt52433002
as does this:
browser.div(class: 'bd').inner_html[/testci\d{14}/] => testci20160503105556
First things first. The error says that Watir cannot find an element using the criteria you specified. That means either that no such thing exists anywhere in the DOM, or that it might be inside a frame.
Since the element you want is a div, then you should be using the .div method to access it
browser.div(:class => 'bd') #finds first matching div
A potential second problem could occur if that classname is not very unique. Unless you specify an additional parameter, such as index, or perhaps a portion of the text contained by the div, you may not find the div you are looking for. A fast debugging trick (I like to do it from IRB) is to get a collection of matching divs and check the size
div_count = browser.divs(:class => 'bd').size
puts "there are #{divcount} divs of class bd in the dom"
If the count is anything more than 1, then you likely need to change how you are selecting it to ensure you get the right one. for example
browser.div(:class => 'bd', :text => /Associated with the domain/)
If the count is zero, then check for frames
frame_count = browser.frames.size
iframe_count = browser.iframes.size
If there are frames you will have to tell watir to look inside the frame for the div, if more than one frame then be sure you specify the right one
browser.frame.div(:class => 'bd') #looks for div inside first frame
Once you are sure you have the right div, then you ought to be able to use a method like .text or as in another answer .inner_html to get the contents of the div.
I have the following code snippet (just to illustrate the question, it is not full production code) for the CkEditor plugin:
onOk: function() {
var dialog = this,
element = dialog.element;
.........
element.setStyle('width', width+'%');
element.setStyle('text-align', align)
dialog.commitContent(element);
}
In this small code snippet a modification of one dialog element occurs using setStyle() method, after which commitContent is triggered.
So, the questions are:
Do I understand correctly, that each setStyle call here triggers
element rerender (repaint) since this element already exists in
DOM?
What is the purpose of commitContent() ckEditor method? Just an event for dialog elements to store some data?
setStyle
I belive that setStyle repaints the components already existing in the DOM, have a look at this example (that I have taken from the official documentation):
var element = CKEDITOR.document.getById( 'myElement' );
element.setStyle( 'background-color', '#ff0000' );
element.setStyle( 'margin-top', '10px' );
element.setStyle( 'float', 'right' );
It first gets the element from the doc and Then sets the style, so basically it is repaiting it triggering events.
commitContent
From the official documentation:
Calls the CKEDITOR.dialog.definition.uiElement.commit method of each
of the UI elements, with the arguments passed through it. It is
usually being called when the user confirms the dialog, to process the
values.
Hope this helped you!
I'd like to know how I can display images in select element in Drupal form API.
The following code shows simple select with two options which are in text format: "-34-", "-36-".
$sizes = array_combine(array(34, 36), array("-34-", "-36-"));
$form['editplayer']['clothes_size_female']['clothes'] = array(
'#type' => 'select',
'#default_value' => 34,
'#options' => $sizes,
);
I tried to place path to images but it considers it as a string. $sizes = array_combine(array(34, 36), array("http://localhost/drupal/renderImage.php?user_id=34", "http://localhost/drupal/renderImage.php?user_id=36"));
There is not a well-supported way to do this using stock HTML select box elements. There are solutions to do it with JavaScript though:
http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx
You'd have to write a custom Drupal form element though to have it work with the Form API.
I was wondering if anyone has found a solution or example to actually populating the input box of a slider and having it slide to the appropriate position onBlur() .. Currently, as we all know, it just updates this value with the position you are at. So in some regards, I am trying to reverse the functionality of this amazing slider.
One link I found: http://www.webdeveloper.com/forum/archive/index.php/t-177578.html is a bit outdated, but looks like they made an attempt. However, the links to the results do not exist. I am hoping that there may be a solution out there.
I know Filament has re-engineered the slider to handle select (drop down) values, and it works flawlessly.. So the goal would be to do the same, but with an input text box.
Will this do what you want?
$("#slider-text-box").blur(function() {
$("#slider").slider('option', 'value', parseInt($(this).val()));
});
Each option on the slider has a setter as well as a getter, so you can set the value with that, as in the example above. From the documentation:
//getter
var value = $('.selector').slider('option', 'value');
//setter
$('.selector').slider('option', 'value', 37);
UPDATE:
For dual sliders you'll need to use:
$("#amount").blur(function () {
$("#slider-range").slider("values", 0, parseInt($(this).val()));
});
$("#amount2").blur(function () {
$("#slider-range").slider("values", 1, parseInt($(this).val()));
});
You'll need to use Math.min/max to make sure that one value doesn't pass the other, as the setter doesn't seem to prevent this.
You were almost there when you were using the $("#slider-range").slider("values", 0) to get each value. A lot of jQuery has that kind of get/set convention in which the extra parameter is used to set the value.
I've done some work around the jQuery UI slider to make it accept values from a textbox, it may not be exactly what you were after but could help:
http://chowamigo.blogspot.com/2009/10/jquery-ui-slider-that-uses-text-box-for.html
$slider = $("#slider");
$("#amountMin").blur(function () {
$slider.slider("values", 0,Math.min($slider.slider("values", 1),parseInt($(this).val()) ) );
$(this).val(Math.min($slider.slider("values", 1),parseInt($(this).val())));
});
$("#amountMax").blur(function () {
$slider.slider("values",1,Math.max($slider.slider("values", 0),parseInt($(this).val()) ) );
$(this).val(Math.max($slider.slider("values", 0),parseInt($(this).val())));
});
I just used martin's code and updated the id to #slider also added the math.max as he suggested so the sliders won't overlap.