PDA

View Full Version : Getting Started: Fade & Hide



kokoglen
21 Feb 2007, 3:15 PM
I've been scouring the forums, but I can't seem to find an answer.
Are there any "Getting Started" tutorials or demos of simple stuff?

Here is my simple "How do I...?" question:

I have several tags with a class of "readOnlyVersion" each with siblings that have a class of "editableVersion".

I have a button with a script to run when it's clicked. I want it to
1. Hide all the ReadOnly Versions and
2. Fade In the EditableVersions.

Ideally it would "toggle" them because I have a cancel button that reverses it.

Thanks for the help.

Glen

Herm
22 Feb 2007, 9:22 PM
Glen had to move from jQuery to Ext. In his blog, he also posted the same question as

In jQuery its:
$(".readOnly").hide();
$(".editable").fadeIn("slow");

WhatÂ’s the way to do that in YUI-ext?


Can anyone help him out?

Zixon
22 Feb 2007, 10:19 PM
Try something like this:



Ext.select('.readOnlyVersion').hide();
Ext.select('.editableVersion').fadeIn();


(it worked for me in ext-1.0-alpha1 rev9)

kokoglen
23 Feb 2007, 10:33 AM
I think I understand now what this post is saying:
http://www.yui-ext.com/forum/viewtopic.php?t=2315&highlight=flyweight

Ext.query returns an array. Ext.select returns a YUI-ext Element object. Is that correct?

I believe this isn't available until 1.0 is released. We are using 0.4 of domQuery and 0.33 of yui-ext and the compositeElement.js.

Is there something like a patch to enable this before 1.0 arrives?

Thank you very much for the help. When this is available to me its EXACTLY what I needed.

brian.moeskau
23 Feb 2007, 12:01 PM
Hi Glen,

Ext.select actually returns a CompositeElement so that you can easily act on all Element instances returned from the DomQuery call using the same convenient Element API. But yes, essentially, it returns Elements as opposed to the array returned by Ext.query.

You are also correct that this capability is specific to 1.0. I started trying to port an example that would work for .33, but frankly, it gets overly complicated for what you are trying to do (which is why it was greatly simplified in 1.0 :)). I think you're better off waiting for 1.0 if possible.

Here is a slightly-expanded version of the code with a couple of comments following:


var ExtSwap = function(){
return {
init : function(){
Ext.get('doSwap').on('click', this.swap);
},
swap : function(){
Ext.select('.readOnly').enableDisplayMode('block').hide();
Ext.select('.editable').fadeIn().frame();
}
};
}();

Ext.onReady(ExtSwap.init, ExtSwap, true);
Points of interest:
* Since you're associating the action to a button, this shows how to properly attach the click handler (assuming 'doSwap' is the buttin id), deferring until the document is ready to do that.
* The .hide() call, by default, uses visibility mode (as opposed to display mode). In other words, if you are operating on inline elements, the whitespace will be preserved when hidden. Assuming that you don't want this, I added the enableDisplayMode() call to make sure the element actually disappears completely.
* With 1.0, the CompositeElement calls can be chained together, so I'm showing an example of fading them in and then adding the frame effect to visually highlight the elements. You don't have to use that, just showing you that it's possible. You could also replace .frame() with .highlight() for another nice option.

Hopefully this helps, but please reply if you need more help getting it to work.

Brian

kokoglen
27 Feb 2007, 8:23 AM
Thanks for the help. :)

kokoglen
27 Feb 2007, 5:53 PM
I'm sorry, this unfortunately won't work. We aren't using 1.0 until it's released.
Is there a 0.33 way to do this?

Glen

brian.moeskau
27 Feb 2007, 11:27 PM
Hi Glen,

As promised, this code is a bit more complex in .33, but I guess this isn't too bad... :) I think this should be pretty close to what you're looking for .33 style:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Ext v.33 Hide/Show</title>


<script type="text/javascript" src="_src/0.33/scripts/utilities.js"></script>
<script type="text/javascript" src="_src/0.33/scripts/ext-all-debug.js"></script>
<style>
.editable {display:none;}
</style>

<script>
YAHOO.ext.EventManager.onDocumentReady(function(){
getEl('doSwap').on('click', function(){
var doc = getEl(document);
var roNodes = doc.getChildrenByClassName('readOnly');
var edNodes = doc.getChildrenByClassName('editable');

for (var i=0; i<roNodes.length; i++){
roNodes[i].setDisplayed('none');
}
for (var i=0; i<edNodes.length; i++){
edNodes[i].enableDisplayMode('block').show(true, .5);
}
});
});
</script>
</head>
<body>
<h1>Ext v.33 Hide/Show</h1>

Some text: <div class="readOnly">Read-only 1</div>
<div class="editable"><input type="text" value="Editable 1" /></div>
More text: <div class="readOnly">Read-only 2</div>
<div class="editable"><input type="text" value="Editable 2" /></div>



<input type="button" value="Swap" id="doSwap" /></p>
</body>
</html>

So obviously, there's no nice selector functionality going on here. The reason is that in .33, yui-ext simply did not have a true selector library (in fact, you could optionally import cssQuery for that reason). That's precisely what led to DomQuery, so that starting with 1.0, Ext would have a native selector lib out of the box. I tried adapting the DomQuery class to run under .33, but it has too many dependencies on 1.0. You could maybe get it to work if you ported some functions from 1.0 directly into the DQ class, but I don't think I would bother and it may not even work anyway.

Here are a few things to note about the code:
* If you have a logical container node that is more specific than 'document' you should use it instead
* The 1.0 visual effects like highlight() were not built into Element in .33. If you wanted to do anything fancy visually, you'd probably want to look into the Actor class (but Actor has been deprecated in 1.0, so I probably wouldn't bother).
* The show/hide methods in .33 do support an animation parameter and duration, which allow you to fade in/out as shown in the .show(true, .5) -- I think this is similar to what you're after.
* Ext defaults to visibility mode (visibility:hidden), so we have to use display mode calls to flow the document correctly. Since hiding requires no anim, just call setDisplayed('none'). Since we want to animate the show though, we call enableDisplayMode first so that show will then use it correctly.
* This is a one-way conversion from hidden to displayed -- to toggle the elements multiple times, you could add in a call to .replaceClass() at the end of each chain to swap the class names as appropriate.

Anyway, hope this helps. One more thing, in my previous post, the 1.0 code was a bit verbose. Here's what the same code could look like under 1.0 using anonymous functions like I did in this example:


Ext.onReady(function() {
Ext.get('doSwap').on('click', function(){
Ext.select('.readOnly').setDisplayed('none');
Ext.select('.editable').fadeIn();
});
});
Brian

kokoglen
14 Mar 2007, 2:41 PM
Thank you. This worked. Although I REALLY can't wait until 1.0 so I can go back to short, simple commands.

One item though. The text was blurry when I faded it in. (IE)

Turns out that you need to explicitly declare a background on the node you ade fading for the fonts to render right in IE.

Thanks again for your help.

Glen