forked from yui/yui3-gallery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gallery-2010.04.02-17-26 caridy gallery-stalker
- Loading branch information
YUI Builder
committed
Apr 2, 2010
1 parent
d78bc68
commit 167ef46
Showing
3 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Stalker Plugin Build Properties | ||
|
||
# As long as the 'builder' project is cloned to the default folder | ||
# next to the 'yui3-gallery' project folder, the 'builddir' property does not | ||
# need to be changed | ||
# | ||
# If the 'builder' project is checked out to an alternate location, this | ||
# property should be updated to point to the checkout location. | ||
builddir=../../../builder/componentbuild | ||
|
||
# The name of the component. E.g. event, attribute, widget | ||
component=gallery-stalker | ||
|
||
# The list of files which should be concatenated to create the component. | ||
# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead. | ||
# component.jsfiles=stalker.js, stalkerHelperClass.js, stalkerSubComponentClass.js | ||
component.jsfiles=gallery-stalker.js | ||
|
||
# The list of modules this component requires. Used to set up the Y.add module call for YUI 3. | ||
component.requires=plugin,node-base,event-resize,event-base,dom-screen, classnamemanager | ||
|
||
# The list of modules this component supersedes. Used to set up the Y.add module call for YUI 3. | ||
component.supersedes= | ||
|
||
# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3. | ||
component.optional= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- YUI 3 Gallery Component Build File --> | ||
<project name="Stalker Plugin" default="local"> | ||
<description>Stalker Plugin Build File</description> | ||
<property file="build.properties" /> | ||
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" /> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/** | ||
* <p>Stalker plugin will allow you to keep elements at a fixed position "floating" but at | ||
* the same time, keeping those elements embeded to the layout of the page. The general idea | ||
* is that an element can control it's own position within the layout in order to keep its | ||
* area within the viewport boundaries. | ||
* | ||
* <p>To use the Stalker Plugin, simply pass a reference to the plugin to a | ||
* Node instance's <code>plug</code> method.</p> | ||
* | ||
* <p> | ||
* <code> | ||
* <script type="text/javascript"> <br> | ||
* <br> | ||
* // Call the "use" method, passing in "gallery-stalker". This will <br> | ||
* // load the script for the Stalker Plugin and all of <br> | ||
* // the required dependencies. <br> | ||
* <br> | ||
* YUI().use("gallery-stalker", function(Y) { <br> | ||
* <br> | ||
* Y.one('#mytarget').plug(Y.Plugin.Stalker); <br> | ||
* <br> | ||
* }); <br> | ||
* <br> | ||
* </script> <br> | ||
* </code> | ||
* </p> | ||
* @module gallery-stalker | ||
*/ | ||
|
||
|
||
// Util shortcuts | ||
var UA = Y.UA, | ||
getClassName = Y.ClassNameManager.getClassName, | ||
|
||
// Frequently used strings | ||
STALKER = "stalker", | ||
HOST = "host", | ||
PX = 'px', | ||
|
||
// CSS class names | ||
CLASS_STALKER = getClassName(STALKER), | ||
|
||
// Utility functions | ||
/** | ||
* The NodeStalker class is a plugin for a Node instance.The class is used via | ||
* the <a href="Node.html#method_plug"><code>plug</code></a> method of Node and | ||
* should not be instantiated directly. | ||
* @namespace Y.Plugin | ||
* @class NodeStalker | ||
*/ | ||
NodeStalker = function() { | ||
|
||
NodeStalker.superclass.constructor.apply(this, arguments); | ||
|
||
}; | ||
|
||
NodeStalker.NAME = "NodeStalker"; | ||
NodeStalker.NS = STALKER; | ||
|
||
NodeStalker.ATTRS = {}; | ||
|
||
Y.extend(NodeStalker, Y.Plugin.Base, { | ||
|
||
// Protected properties | ||
/** | ||
* @property _root | ||
* @description Node instance representing the target node to follow. | ||
* @default null | ||
* @protected | ||
* @type Node | ||
*/ | ||
_root: null, | ||
_eventHandlers: [], | ||
|
||
// Public methods | ||
initializer: function(config) { | ||
var fn = Y.bind(this.refresh, this); | ||
if ((this._root = this.get(HOST))) { | ||
|
||
this._root.addClass(CLASS_STALKER); | ||
|
||
// Wire up all event handlers | ||
this._eventHandlers.push(Y.on('scroll', fn)); | ||
this._eventHandlers.push(Y.on('windowresize', fn)); | ||
|
||
} | ||
}, | ||
|
||
destructor: function() { | ||
if (this._root) { | ||
this._root.removeClass(CLASS_STALKER); | ||
} | ||
Y.Array.each(this._eventHandlers, | ||
function(handle) { | ||
handle.detach(); | ||
}); | ||
}, | ||
|
||
/** | ||
* @method refresh | ||
* @description Refreshing the position of the element in every scroll/resize event | ||
* @public | ||
*/ | ||
refresh: function() { | ||
Y.log ('Refreshing the target', 'info', STALKER); | ||
|
||
var top = Y.DOM.docScrollY(), | ||
left = Y.DOM.docScrollX(), | ||
n = this._root, | ||
r = n.get('parentNode').getXY(), | ||
c = ["marginTop", "marginLeft", "borderLeftWidth", "borderTopWidth"]; | ||
|
||
// viewport computations | ||
r[1] = Math.max(0, r[1] - top); | ||
r[0] = r[0] - left; | ||
// node size computation | ||
Y.Array.each(c, | ||
function(v) { | ||
r[v] = parseInt(n.getStyle(v), 10) || 0; | ||
}); | ||
n.setStyles({ | ||
top: r[1] - r.borderTopWidth - r.marginTop, | ||
left: r[0] - r.borderLeftWidth - r.marginLeft, | ||
position: 'fixed' | ||
}); | ||
}, | ||
|
||
// Protected methods | ||
/** | ||
* @method _IE6Fix | ||
* @description Adding a CSS expression to workaround the lack of "position:fixed" in IE6 | ||
* @protected | ||
* @return {boolean} whether or not is this fix needed | ||
*/ | ||
_IE6Fix: function() { | ||
var targetID, | ||
parentID, | ||
css; | ||
if (UA.ie == 6) { | ||
Y.log('Appliying IE6 fix for static position.', 'info', STALKER); | ||
targetID = this._root.get('id'); | ||
parentID = this._root.get('parentNode').get('id'); | ||
css = "#" + targetID + " {top:expression((ignore = document.documentElement.scrollTop>document.getElementById('" + parentID + "').offsetTop) ? document.documentElement.scrollTop : document.getElementById('" + parentID + "').offsetTop + 'px' );}"; | ||
// adding CSS to the page | ||
Y.on('domready', | ||
function(e) { | ||
Y.log('Inserting IE6 fix in the page: ' + css, 'info', STALKER); | ||
// TODO | ||
}); | ||
return true; | ||
} | ||
} | ||
|
||
}); | ||
|
||
Y.namespace('Plugin'); | ||
|
||
Y.Plugin.NodeStalker = NodeStalker; |