Author
cron112
View
403
Download
6
Embed Size (px)
Welcome to the Yahoo! User Interface Library (YUI)A free, open-source JavaScript and CSS library. The same one we use at Yahoo! every day. In February, 2006, Yahoo! opened its frontend library under a BSD license, making it freely available to all developers. Now the library that powers the world!s most visited website can also power yours.YUI provides a suite of JavaScript utilities and UI controls that help developers create rich, dynamic interfaces within the browser. It also provides four core CSS utilities that help to normalize your baseline styles and to build robust, semantic, CSS-driven page layouts utilizing a compact and exible toolkit. YUI is an la carte library, one that allows you to pick and choose which features you want on any given page. The code is compact and efcient. If you enable server-side compression, no single YUI component (other than the Rich Text Editor) requires a download of more than 35KB and most are much smaller than that. Today!s YUI consists of a CSS foundation, a core of three essential utilities (YAHOO, Dom, and Event), numerous other utilities that empower rich interactions (like Connection Manager, Drag & Drop, and Animation), and more than a dozen rich UI controls ranging from DHTML windowing to AutoComplete to a full Rich Text Editor. YUI provides support for what we consider to be the A-Grade browsers: Firefox, Opera, Safari and Internet Explorer. You can count on all of our components working across the A-Grade; rare exceptions are documented as known issues and you can rely on Yahoo! to work with browser manufacturers to resolve known issues as promptly as possible.
YUI Destinations:YUI Website http://developer.yahoo.com/yui Download YUI Read ofcial documentation Explore searchable APIs Find user!s guides for every component YDN-JavaScript http://tech.groups.yahoo.com/group/ ydn-javascript/ Ask questions Discuss YUI development and usage Share your implementation with other developers SourceForge http://sourceforge.net/projects/yui/
Explore YUI: YUI ships with nearly 200 examples. Download the library and explore the YUI core YAHOO Global Object, the Dom Collection, and the Event Utility and their examples. Then start exploring some of the other utilities like Animation, Connection Manager (for Ajax), and Drag & Drop. Then take a look at the UI controls like AutoComplete and TabView and see how you can transform your web page with just a few lines of code and a few KB of library includes.
Make feature requests File bug reports YUIBlog http://yuiblog.com Read articles and watch videos about YUI, JavaScript, CSS and more See YUI implementations in the wild Let others know about your own YUI implementations Next: Were working hard to improve YUI and better serve the YUI community. Please join YDNJavaScript, follow the blog, and let the community know what youre doing with YUI.
YUI Library: AnimationSimple Use CasemyAnimObj = new YAHOO.util.Anim("myDiv", {width: {to: 100}, height: {to: 100}}); myAnimObj.animate(); Makes the HTML element whose id attribute is "myDiv" resize to a height and width of 100 pixels.
2009-2-6
v2.7
Interesting Moments in AnimationEvent onStart onTween onComplete
Fires... ...when anim begins ...on every frame ...when anim ends
Arguments
YAHOO.util.Anim: Propertiesattributes (obj) currentFrame (int) duration (num) totalFrames (int) useSeconds (b)
[0] {frames: total frames, fps: frames per second, duration: of animation in miliseconds}
Constructor (YAHOO.util.Anim, ColorAnim, etc.)YAHOO.util.Anim(str | element target, obj attributes[, num duration, obj easing]); Arguments: (1) Element id or reference: HTML ID or element reference for the element being animated. (2) Attributes object: Defines the qualities being animated; see below. (3) Duration: Approximate, in seconds. (4) Easing: Reference to an easing effect, member of YAHOO.util.Easing.
These are Custom Event members of YAHOO.util.Anim; use these by subscribing:
myAnimInstance.onComplete.subscribe(myOnCompleteHandler);
Using the Motion SubclassUse the Motion subclass to define animations to/from a specific point, using (optional) bezier control points. var attributes = { points: { to: [250, 450],control: [[100, 800], [-100, 200], [500, 500]]}};
YAHOO.util.Anim: Methodsanimate() getEl() getStartTime() isAnimated() stop(bFinish) if true, advancesto last frame of animation
var anim = new YAHOO.util.Motion(element, attributes, 1, YAHOO.util.Easing.easeIn);
Easing EffectsMembers of YAHOO.util.Easing
Attributes ObjectanimAttributes = { animatedProperty: { by: 100, //start at to: 100, //start at from: 100, //ignore unit: 'em' //can be } }
Using the ColorAnim SubclassUse the ColorAnim subclass to background, text or border colors. current, change by this much current, go to this current; start from this any legal numeric unit var myAnim = new YAHOO.util.ColorAnim(element, {back groundColor: { to: '#dcdcdc' } }); myAnim.animate();
Using the Scroll SubclassUse the Scroll subclass to animate horizontal or vertical scrolling of an overflowing page element. var attributes = { scroll: { to: [220, 0] } }; var anim = new YAHOO.util.Scroll(element, attributes, 1, YAHOO.util.Easing.easeOut);
Note: Do not include to and by for the same animation property.
Animation PropertiesUse Animation to apply gradual transitions to these properties*: borderWidth bottom fontSize left right top height margin opacity lineHeight padding width
backBoth backIn backOut bounceBoth bounceIn bounceOut easeBoth easeBothStrong easeIn easeInStrong easeNone default; no easing easeOut easeOutStrong elasticBoth elasticIn elasticOut
SolutionsSubscribe to an API method: myAnimObj = new YAHOO.util.Anim(element, {width: {to: 100}, height: {to: 100}}); myHandler = function(type, args) { someDiv.innerHTML = args[0].fps; //gets framesper-second from the onComplete event} myAnimObj.onComplete.subscribe(myHandler); myAnimObj.animate();
*or to any other member of an element's style object that takes a numeric value
DependenciesAnimation requires the YAHOO Global Object, Dom Collection, and Event Utility.
YUI Library: AutoCompleteSimple Use CaseMarkup: Script: var myAutoComp = new YAHOO.widget.AutoComplete ("myInput", "myContainer", myDataSource); Instantiates a new AutoComplete object, myAutoComp, which queries an existing DataSource myDataSource.
2009-2-6
v2.7
Interesting MomentsEventtextboxFocusEvent/ textboxBlurEvent/ textboxChangeEvent textboxKeyEvent dataRequestEvent dataReturnEvent dataErrorEvent containerExpandEvent/ containerCollapseEvent/ containerPopulateEvent itemArrowToEvent/ itemArrowFromEvent itemMouseOverEvent/ itemMouseOutEvent itemSelectEvent
Arguments (passed via args array)[0] AC instance [0] AC instance; [1] keycode int [0] AC instance; [1] query string; [2] request object [0] AC instance; [1] query string; [2] results array 0] AC instance; [1] query string [0] AC instance [0] AC instance; [1] element [0] AC instance; [1] element
YAHOO.widget. AutoComplete Key Properties:alwaysShow Container (b) animHoriz (b) animSpeed (int) animVert (b) applyLocalFilter (b) autoHighlight (b) delimChar (char || array) forceSelection (b) highlightClassName (string) maxResultsDisplayed (int) minQueryLength (int) prehighlightClass Name (string) queryDelay (int) queryMatchCase (b) queryMatchContains (b) queryMatchSubset (b) queryQuestionMark (b) resultsTypeList (b) suppressInputUpdate (b) typeAhead (b) typeAheadDelay (int) useIFrame (b) useShadow (b)
ConstructorYAHOO.widget.AutoComplete(str | el ref input field, str | el ref suggestion container, obj DataSource instance[, obj configuration object]); Arguments: (1) HTML element (string or object): Text input or textarea element. (2) HTML element (string or object): Suggestion container. (3) DataSource instance (obj): An instantiated DataSource object; see below for DataSource types and constructor syntax. (4) Configuration object (object): An optional object literal defines property values of an AutoComplete instance.
[0] AC instance; [1] element; [2] item data object or array selectionEnforceEvent [0] AC instance [0] AC instance; [1] query string; [2] prefill typeAheadEvent string unmatchedItemSelectEvent [0] AC instance; [1] user selected string Subscribe to AutoComplete Custom Events on your AutoComplete instance:myAC.containerExpandEvent.subscribe(myFn[, myObj, bScope]);
SolutionsCustom cell formatting: myAC.resultsTypeList = false; // pass data as an object myAC.formatResult = function(oData, sQuery, sMatch) { return (sMatch + "(" + oData.param + ")" ); } Custom local filtering: myAC.applyLocalFilter = true; // pass results thru filter myAC.filterResults = function(sQuery, oFullResponse, oParsedResponse, oCallback) { var matches = [], matchee; for(var i=0; i 0) { matches[matches.length] = oParsedResponse.results[i] } } oParsedResponse.results = matches; return oParsedResponse; }
Abstract MethodsMethoddoBeforeLoadData
DescriptionThis overridable abstract method gives implementers access to the DataSource response before it is consumed by the AutoComplete instance and rendered into the results container. This overridable abstract method gives implementers access to result data and DOM elements after the container has been rendered with results but before it is displayed to the user, for example to move the container to a different position on the screen.
doBeforeExpandContainer
DependenciesAutoComplete requires the YAHOO Global Object, Dom, and Event, and DataSource. Animation (for animated opening of the suggestion container) is optional.
YUI Library: Browser History ManagerGetting Started with Browser History Manager1. Required MarkupThe Browser History Manager requires the following in-page markup: 1. The asset loaded in the IFrame must be in the same domain as the page (use a relative path for the src attribute to make sure of that) 2. The asset loaded in the IFrame does not have to be an HTML document. It can be an image for example (if you use an image that you also happen to use in your page, you will avoid an unnecessary round-trip, which is always good for performance) 3. This markup should appear right after the opening