_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3 values | text stringlengths 52 373k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q30400 | train | function (name,sheet) {
return !!(name && sheet instanceof StyleSheet &&
!sheets[name] && (sheets[name] = sheet));
} | javascript | {
"resource": ""
} | |
q30401 | train | function(el, node) {
this.logger.log("animating expand");
if (this._expandAnim && this._animCount < this.maxAnim) {
// this.locked = true;
var tree = this;
var a = Widget.TVAnim.getAnim(this._expandAnim, el,
function() { tree.expandComplete(node); });
if (a) {
++this._animCount;
this.fireEvent("animStart", {
"node": node,
"type": "expand"
});
a.animate();
}
return true;
}
return false;
} | javascript | {
"resource": ""
} | |
q30402 | train | function(el, node) {
this.logger.log("animating collapse");
if (this._collapseAnim && this._animCount < this.maxAnim) {
// this.locked = true;
var tree = this;
var a = Widget.TVAnim.getAnim(this._collapseAnim, el,
function() { tree.collapseComplete(node); });
if (a) {
++this._animCount;
this.fireEvent("animStart", {
"node": node,
"type": "collapse"
});
a.animate();
}
return true;
}
return false;
} | javascript | {
"resource": ""
} | |
q30403 | train | function(node) {
if (node.expanded) {
// wait until the animation is complete before deleting to
// avoid javascript errors
if (this._collapseAnim) {
this.subscribe("animComplete",
this._removeChildren_animComplete, this, true);
Widget.Node.prototype.collapse.call(node);
return;
}
node.collapse();
}
this.logger.log("Removing children for " + node);
while (node.children.length) {
this._deleteNode(node.children[0]);
}
if (node.isRoot()) {
Widget.Node.prototype.expand.call(node);
}
node.childrenRendered = false;
node.dynamicLoadComplete = false;
node.updateIcon();
} | javascript | {
"resource": ""
} | |
q30404 | train | function(node) {
this.logger.log("insertAfter: " + node);
var p = node.parent;
if (p) {
if (this.tree) {
this.tree.popNode(this);
}
var refIndex = node.isChildOf(p);
this.logger.log(refIndex);
if (!node.nextSibling) {
this.nextSibling = null;
return this.appendTo(p);
}
p.children.splice(refIndex + 1, 0, this);
node.nextSibling.previousSibling = this;
this.previousSibling = node;
this.nextSibling = node.nextSibling;
node.nextSibling = this;
this.applyParent(p);
}
return this;
} | javascript | {
"resource": ""
} | |
q30405 | train | function() {
// this.logger.log("No children, " + " isDyanmic: " + this.isDynamic() + " expanded: " + this.expanded);
if (this.isLoading) {
this.logger.log("returning the loading icon");
return "ygtvloading";
} else {
// location top or bottom, middle nodes also get the top style
var loc = (this.nextSibling) ? "t" : "l";
// type p=plus(expand), m=minus(collapase), n=none(no children)
var type = "n";
if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {
// if (this.hasChildren(true)) {
type = (this.expanded) ? "m" : "p";
}
// this.logger.log("ygtv" + loc + type);
return "ygtv" + loc + type;
}
} | javascript | {
"resource": ""
} | |
q30406 | train | function() {
this.logger.log("rendering children for " + this.index);
var node = this;
if (this.isDynamic() && !this.dynamicLoadComplete) {
this.isLoading = true;
this.tree.locked = true;
if (this.dataLoader) {
this.logger.log("Using dynamic loader defined for this node");
setTimeout(
function() {
node.dataLoader(node,
function() {
node.loadComplete();
});
}, 10);
} else if (this.tree.root.dataLoader) {
this.logger.log("Using the tree-level dynamic loader");
setTimeout(
function() {
node.tree.root.dataLoader(node,
function() {
node.loadComplete();
});
}, 10);
} else {
this.logger.log("no loader found");
return "Error: data loader not found or not specified.";
}
return "";
} else {
return this.completeRender();
}
} | javascript | {
"resource": ""
} | |
q30407 | train | function() {
this.logger.log(this.index + " loadComplete, children: " + this.children.length);
this.getChildrenEl().innerHTML = this.completeRender();
if (this.propagateHighlightDown) {
if (this.highlightState === 1 && !this.tree.singleNodeHighlight) {
for (var i = 0; i < this.children.length; i++) {
this.children[i].highlight(true);
}
} else if (this.highlightState === 0 || this.tree.singleNodeHighlight) {
for (i = 0; i < this.children.length; i++) {
this.children[i].unhighlight(true);
}
} // if (highlighState == 2) leave child nodes with whichever highlight state they are set
}
this.dynamicLoadComplete = true;
this.isLoading = false;
this.expand(true);
this.tree.locked = false;
} | javascript | {
"resource": ""
} | |
q30408 | train | function() {
this.logger.log("Generating html");
var sb = [];
sb[sb.length] = '<table id="ygtvtableel' + this.index + '" border="0" cellpadding="0" cellspacing="0" class="ygtvtable ygtvdepth' + this.depth;
if (this.enableHighlight) {
sb[sb.length] = ' ygtv-highlight' + this.highlightState;
}
if (this.className) {
sb[sb.length] = ' ' + this.className;
}
sb[sb.length] = '"><tr class="ygtvrow">';
for (var i=0;i<this.depth;++i) {
sb[sb.length] = '<td class="ygtvcell ' + this.getDepthStyle(i) + '"><div class="ygtvspacer"></div></td>';
}
if (this.hasIcon) {
sb[sb.length] = '<td id="' + this.getToggleElId();
sb[sb.length] = '" class="ygtvcell ';
sb[sb.length] = this.getStyle() ;
sb[sb.length] = '"><a href="#" class="ygtvspacer"> </a></td>';
}
sb[sb.length] = '<td id="' + this.contentElId;
sb[sb.length] = '" class="ygtvcell ';
sb[sb.length] = this.contentStyle + ' ygtvcontent" ';
sb[sb.length] = (this.nowrap) ? ' nowrap="nowrap" ' : '';
sb[sb.length] = ' >';
sb[sb.length] = this.getContentHtml();
sb[sb.length] = '</td></tr></table>';
return sb.join("");
} | javascript | {
"resource": ""
} | |
q30409 | train | function(r, g, b) {
if (isArray(r)) {
return this.rgb2hex.apply(this, r);
}
var f=this.dec2hex;
return f(r) + f(g) + f(b);
} | javascript | {
"resource": ""
} | |
q30410 | train | function(n) {
n = parseInt(n,10)|0;
n = (n > 255 || n < 0) ? 0 : n;
return (ZERO+n.toString(16)).slice(-2).toUpperCase();
} | javascript | {
"resource": ""
} | |
q30411 | train | function(s) {
var f = this.hex2dec;
return [f(s.slice(0, 2)), f(s.slice(2, 4)), f(s.slice(4, 6))];
} | javascript | {
"resource": ""
} | |
q30412 | train | function(r, g, b) {
if (isArray(r)) {
return this.websafe.apply(this, r);
}
// returns the closest match [0, 51, 102, 153, 204, 255]
var f = function(v) {
if (isNumber(v)) {
v = Math.min(Math.max(0, v), 255);
var i, next;
for (i=0; i<256; i=i+51) {
next = i+51;
if (v >= i && v <= next) {
return (v-i > 25) ? next : i;
}
}
}
return v;
};
return [f(r), f(g), f(b)];
} | javascript | {
"resource": ""
} | |
q30413 | ColorPicker | train | function ColorPicker(el, attr) {
_pickercount = _pickercount + 1;
attr = attr || {};
if (arguments.length === 1 && !YAHOO.lang.isString(el) && !el.nodeName) {
attr = el; // treat first arg as attr object
el = attr.element || null;
}
if (!el && !attr.element) { // create if we dont have one
el = this._createHostElement(attr);
}
ColorPicker.superclass.constructor.call(this, el, attr);
this.initPicker();
} | javascript | {
"resource": ""
} |
q30414 | train | function () {
var el = document.createElement('div');
if (this.CSS.BASE) {
el.className = this.CSS.BASE;
}
return el;
} | javascript | {
"resource": ""
} | |
q30415 | train | function(rgb, silent) {
silent = (silent) || false;
this.set(this.OPT.RGB, rgb, silent);
this._updateSliders();
} | javascript | {
"resource": ""
} | |
q30416 | train | function() {
var rgb = this.get(this.OPT.RGB),
websafe = this.get(this.OPT.WEBSAFE),
el = this.getElement(this.ID.SWATCH),
color = rgb.join(","),
txt = this.get(this.OPT.TXT);
Dom.setStyle(el, "background-color", "rgb(" + color + ")");
el.title = sub(txt.CURRENT_COLOR, {
"rgb": "#" + this.get(this.OPT.HEX)
});
el = this.getElement(this.ID.WEBSAFE_SWATCH);
color = websafe.join(",");
Dom.setStyle(el, "background-color", "rgb(" + color + ")");
el.title = sub(txt.CLOSEST_WEBSAFE, {
"rgb": "#" + Color.rgb2hex(websafe)
});
} | javascript | {
"resource": ""
} | |
q30417 | train | function(e) {
var c = Event.getCharCode(e);
//alert(Event.getCharCode(e) + ", " + e.keyCode + ", " + e.charCode);
// special keys
if (c === 38) { // up arrow
return 3;
} else if (c === 13) { // return
return 6;
} else if (c === 40) { // down array
return 4;
} else if (c >= 48 && c<=57) { // 0-9
return 1;
} else if (c >= 97 && c<=102) { // a-f
return 2;
} else if (c >= 65 && c<=70) { // A-F
return 2;
//} else if ("8, 9, 13, 27, 37, 39".indexOf(c) > -1 ||
// (c >= 112 && c <=123)) { // including F-keys
// tab, delete, return, escape, left, right or ctrl/meta sequences
} else if ("8, 9, 13, 27, 37, 39".indexOf(c) > -1 ||
e.ctrlKey || e.metaKey) { // special chars
return 5;
} else { // something we probably don't want
return 0;
}
} | javascript | {
"resource": ""
} | |
q30418 | train | function(e, el, prop) {
var val = el.value;
if (prop !== this.OPT.HEX) {
val = parseInt(val, 10);
}
if (val !== this.get(prop)) {
this.set(prop, val);
}
} | javascript | {
"resource": ""
} | |
q30419 | train | function(e, el, prop) {
var command = this._getCommand(e),
inc = (e.shiftKey) ? 10 : 1;
switch (command) {
case 6: // return, update the value
this._useFieldValue.apply(this, arguments);
break;
case 3: // up arrow, increment
this.set(prop, Math.min(this.get(prop)+inc, 255));
this._updateFormFields();
//Event.stopEvent(e);
break;
case 4: // down arrow, decrement
this.set(prop, Math.max(this.get(prop)-inc, 0));
this._updateFormFields();
//Event.stopEvent(e);
break;
default:
}
} | javascript | {
"resource": ""
} | |
q30420 | train | function(e, el, prop) {
var command = this._getCommand(e);
if (command === 6) { // return, update the value
this._useFieldValue.apply(this, arguments);
}
} | javascript | {
"resource": ""
} | |
q30421 | train | function(e, numbersOnly) {
var command = this._getCommand(e);
switch (command) {
case 6: // return
case 5: // special char
case 1: // number
break;
case 2: // hex char (a-f)
if (numbersOnly !== true) {
break;
}
// fallthrough is intentional
default: // prevent alpha and punctuation
Event.stopEvent(e);
return false;
}
} | javascript | {
"resource": ""
} | |
q30422 | train | function () {
var ID = this.ID,
O = this.OPT;
this.hueSlider.subscribe("change",
this._onHueSliderChange, this, true);
this.pickerSlider.subscribe("change",
this._onPickerSliderChange, this, true);
Event.on(this.getElement(ID.WEBSAFE_SWATCH), "click", function(e) {
this.setValue(this.get(O.WEBSAFE));
}, this, true);
Event.on(this.getElement(ID.CONTROLS_LABEL), "click", function(e) {
this.set(O.SHOW_CONTROLS, !this.get(O.SHOW_CONTROLS));
Event.preventDefault(e);
}, this, true);
this._attachRGBHSV(ID.R, O.RED);
this._attachRGBHSV(ID.G, O.GREEN);
this._attachRGBHSV(ID.B, O.BLUE);
this._attachRGBHSV(ID.H, O.HUE);
this._attachRGBHSV(ID.S, O.SATURATION);
this._attachRGBHSV(ID.V, O.VALUE);
Event.on(this.getElement(ID.HEX), "keydown", function(e, me) {
me._hexFieldKeypress(e, this, O.HEX);
}, this);
Event.on(this.getElement(this.ID.HEX), "keypress",
this._hexOnly, this,true);
Event.on(this.getElement(this.ID.HEX), "blur", function(e, me) {
me._useFieldValue(e, this, O.HEX);
}, this);
} | javascript | {
"resource": ""
} | |
q30423 | train | function(id, on) {
var el = (lang.isString(id) ? this.getElement(id) : id);
Dom.setStyle(el, "display", (on) ? "" : "none");
} | javascript | {
"resource": ""
} | |
q30424 | train | function (options) {
var x;
options = options || {};
// Store folders
this.folders = options.folders || {};
this.safenames = options.safenames || false;
// check for existing folders
for (x in this.folders) {
if (!fs.existsSync( this.folders[x] )){
// create folder if not exists
mkdirp( this.folders[x] );
}
}
} | javascript | {
"resource": ""
} | |
q30425 | train | function (callback) {
var fn, scope;
fn = callback.fn;
scope = callback.scope;
if (this.formAvailable) {
fn.call(scope);
} else {
this.formAvailableEvt.subscribe(fn, scope, true);
}
} | javascript | {
"resource": ""
} | |
q30426 | train | function (key, value, silent) {
var property;
key = key.toLowerCase();
YAHOO.log("setProperty: " + key + "=" + value, "info", "Config");
if (this.queueInProgress && ! silent) {
// Currently running through a queue...
this.queueProperty(key,value);
return true;
} else {
property = this.config[key];
if (property && property.event) {
if (property.validator && !property.validator(value)) {
return false;
} else {
property.value = value;
if (! silent) {
this.fireEvent(key, value);
this.configChangedEvent.fire([key, value]);
}
return true;
}
} else {
return false;
}
}
} | javascript | {
"resource": ""
} | |
q30427 | train | function (key, value) {
key = key.toLowerCase();
YAHOO.log("queueProperty: " + key + "=" + value, "info", "Config");
var property = this.config[key],
foundDuplicate = false,
iLen,
queueItem,
queueItemKey,
queueItemValue,
sLen,
supercedesCheck,
qLen,
queueItemCheck,
queueItemCheckKey,
queueItemCheckValue,
i,
s,
q;
if (property && property.event) {
if (!Lang.isUndefined(value) && property.validator &&
!property.validator(value)) { // validator
return false;
} else {
if (!Lang.isUndefined(value)) {
property.value = value;
} else {
value = property.value;
}
foundDuplicate = false;
iLen = this.eventQueue.length;
for (i = 0; i < iLen; i++) {
queueItem = this.eventQueue[i];
if (queueItem) {
queueItemKey = queueItem[0];
queueItemValue = queueItem[1];
if (queueItemKey == key) {
/*
found a dupe... push to end of queue, null
current item, and break
*/
this.eventQueue[i] = null;
this.eventQueue.push(
[key, (!Lang.isUndefined(value) ?
value : queueItemValue)]);
foundDuplicate = true;
break;
}
}
}
// this is a refire, or a new property in the queue
if (! foundDuplicate && !Lang.isUndefined(value)) {
this.eventQueue.push([key, value]);
}
}
if (property.supercedes) {
sLen = property.supercedes.length;
for (s = 0; s < sLen; s++) {
supercedesCheck = property.supercedes[s];
qLen = this.eventQueue.length;
for (q = 0; q < qLen; q++) {
queueItemCheck = this.eventQueue[q];
if (queueItemCheck) {
queueItemCheckKey = queueItemCheck[0];
queueItemCheckValue = queueItemCheck[1];
if (queueItemCheckKey ==
supercedesCheck.toLowerCase() ) {
this.eventQueue.push([queueItemCheckKey,
queueItemCheckValue]);
this.eventQueue[q] = null;
break;
}
}
}
}
}
YAHOO.log("Config event queue: " + this.outputEventQueue(), "info", "Config");
return true;
} else {
return false;
}
} | javascript | {
"resource": ""
} | |
q30428 | train | function (type, args, obj) {
var pos = args[0],
x = pos[0],
y = pos[1];
this.cfg.setProperty("x", x);
this.cfg.setProperty("y", y);
this.beforeMoveEvent.fire([x, y]);
x = this.cfg.getProperty("x");
y = this.cfg.getProperty("y");
YAHOO.log(("xy: " + [x, y]), "iframe");
this.cfg.refireEvent("iframe");
this.moveEvent.fire([x, y]);
} | javascript | {
"resource": ""
} | |
q30429 | train | function () {
var me = this;
me.logger.log("Setting hide tooltip timeout", "time");
return setTimeout(function () {
me.logger.log("Hide tooltip", "time");
me.hide();
}, this.cfg.getProperty("autodismissdelay"));
} | javascript | {
"resource": ""
} | |
q30430 | train | function (pageX, pageY) {
var height = this.element.offsetHeight,
mousePoint = new YAHOO.util.Point(pageX, pageY),
elementRegion = Dom.getRegion(this.element);
elementRegion.top -= 5;
elementRegion.left -= 5;
elementRegion.right += 5;
elementRegion.bottom += 5;
this.logger.log("context " + elementRegion, "ttip");
this.logger.log("mouse " + mousePoint, "ttip");
if (elementRegion.contains(mousePoint)) {
this.logger.log("OVERLAP", "warn");
this.cfg.setProperty("y", (pageY - height - 5));
}
} | javascript | {
"resource": ""
} | |
q30431 | train | function(name, method){
//create instrumented version of function
var newMethod = function () {
var start = new Date(),
retval = method.apply(this, arguments),
stop = new Date();
saveDataPoint(name, stop-start);
return retval;
};
//copy the function properties over
lang.augmentObject(newMethod, method);
//assign prototype and flag as being profiled
newMethod.__yuiProfiled = true;
newMethod.prototype = method.prototype;
//store original method
container[name] = method;
container[name].__yuiFuncName = name;
//create the report
createReport(name);
//return the new method
return newMethod;
} | javascript | {
"resource": ""
} | |
q30432 | train | function () {
var start = new Date(),
retval = method.apply(this, arguments),
stop = new Date();
saveDataPoint(name, stop-start);
return retval;
} | javascript | {
"resource": ""
} | |
q30433 | train | function(name){
if(container[name]){
throw new Error("Cannot use '" + name + "' for profiling through start(), name is already in use.");
} else {
//create report if necessary
if (!report[name]){
createReport(name);
}
//create stopwatch object if necessary
if (!stopwatches[name]){
stopwatches[name] = {
state: WATCH_STOPPED,
start: 0,
total: 0
};
}
if (stopwatches[name].state == WATCH_STOPPED){
stopwatches[name].state = WATCH_STARTED;
stopwatches[name].start = new Date();
}
}
} | javascript | {
"resource": ""
} | |
q30434 | train | function(name){
var now = new Date(),
stopwatch = stopwatches[name];
if (stopwatch){
if (stopwatch.state == WATCH_STARTED){
saveDataPoint(name, stopwatch.total + (now - stopwatch.start));
} else if (stopwatch.state == WATCH_PAUSED){
saveDataPoint(name, stopwatch.total);
}
//reset stopwatch information
stopwatch.start = 0;
stopwatch.total = 0;
stopwatch.state = WATCH_STOPPED;
}
} | javascript | {
"resource": ""
} | |
q30435 | train | function(name /*:String*/, owner /*:Object*/, registerPrototype /*:Boolean*/) /*:Void*/{
//figure out the function name without namespacing
var funcName = (name.indexOf(".") > -1 ?
name.substring(name.lastIndexOf(".")+1) : name),
method,
prototype;
//if owner isn't an object, try to find it from the name
if (!lang.isObject(owner)){
owner = eval(name.substring(0, name.lastIndexOf(".")));
}
//get the method and prototype
method = owner[funcName];
prototype = method.prototype;
//see if the method has already been registered
if (lang.isFunction(method) && !method.__yuiProfiled){
//replace the function with the profiling one
owner[funcName] = this.instrument(name, method);
/*
* Store original function information. We store the actual
* function as well as the owner and the name used to identify
* the function so it can be restored later.
*/
container[name].__yuiOwner = owner;
container[name].__yuiFuncName = funcName; //overwrite with less-specific name
//register prototype if necessary
if (registerPrototype) {
this.registerObject(name + ".prototype", prototype);
}
}
} | javascript | {
"resource": ""
} | |
q30436 | get_user_collection | train | function get_user_collection(req, res, next) {
app.db.collection('users', function(error, user_collection) {
if(error) { throw error; }
else {
req.user_collection = user_collection;
next();
}
});
} | javascript | {
"resource": ""
} |
q30437 | train | function() {
this.subfieldWrapper = inputEx.cn('div', {className: "inputEx-SerializedField-SubFieldWrapper"});
this.fieldContainer.appendChild( this.subfieldWrapper );
var config = {parentEl: this.subfieldWrapper};
lang.augmentObject(config, this.options.subfield);
this.subField = inputEx( config, this);
} | javascript | {
"resource": ""
} | |
q30438 | train | function() {
inputEx.SerializeField.superclass.initEvents.call(this);
this.subField.updatedEvt.subscribe(this.fireUpdatedEvt, this, true);
} | javascript | {
"resource": ""
} | |
q30439 | train | function(o) {
if(!XML || !YAHOO.lang.isFunction(XML.ObjTree) ) {
alert("ObjTree.js not loaded.");
return null;
}
var xotree = new XML.ObjTree();
return xotree.writeXML(o);
} | javascript | {
"resource": ""
} | |
q30440 | train | function(sValue) {
if(!XML || !YAHOO.lang.isFunction(XML.ObjTree) ) {
alert("ObjTree.js not loaded.");
return null;
}
var xotree = new XML.ObjTree();
var tree = xotree.parseXML( sValue );
return tree;
} | javascript | {
"resource": ""
} | |
q30441 | train | function(req, res){
return function(){
var buf = [],
messages = req.flash(),
types = Object.keys(messages),
len = types.length;
if (!len) {
return '';
}
buf.push('<div id="messages">');
for (var i = 0 ; i < len; ++i) {
var type = types[i],
msgs = messages[type], j;
buf.push(' <ul class="' + type + '">');
for (j = 0, len = msgs.length; j < len; ++j) {
var msg = msgs[j];
buf.push(' <li>' + msg + '</li>');
}
buf.push(' </ul>');
}
buf.push('</div>');
return buf.join('\n');
};
} | javascript | {
"resource": ""
} | |
q30442 | Slider | train | function Slider(sElementId, sGroup, oThumb, sType) {
Slider.ANIM_AVAIL = (!YAHOO.lang.isUndefined(YAHOO.util.Anim));
if (sElementId) {
this.init(sElementId, sGroup, true);
this.initSlider(sType);
this.initThumb(oThumb);
}
} | javascript | {
"resource": ""
} |
q30443 | train | function (sBGElId, sHandleElId, iUp, iDown, iTickSize) {
return new Slider(sBGElId, sBGElId,
new YAHOO.widget.SliderThumb(sHandleElId, sBGElId, 0, 0,
iUp, iDown, iTickSize), "vert");
} | javascript | {
"resource": ""
} | |
q30444 | train | function(t) {
var self = this;
/**
* A YAHOO.widget.SliderThumb instance that we will use to
* reposition the thumb when the background is clicked
* @property thumb
* @type YAHOO.widget.SliderThumb
*/
this.thumb = t;
t.cacheBetweenDrags = true;
if (t._isHoriz && t.xTicks && t.xTicks.length) {
this.tickPause = Math.round(360 / t.xTicks.length);
} else if (t.yTicks && t.yTicks.length) {
this.tickPause = Math.round(360 / t.yTicks.length);
}
// delegate thumb methods
t.onAvailable = function() {
return self.setStartSliderState();
};
t.onMouseDown = function () {
self._mouseDown = true;
return self.focus();
};
t.startDrag = function() {
self._slideStart();
};
t.onDrag = function() {
self.fireEvents(true);
};
t.onMouseUp = function() {
self.thumbMouseUp();
};
} | javascript | {
"resource": ""
} | |
q30445 | train | function () {
Event.on(this.id, "keydown", this.handleKeyDown, this, true);
Event.on(this.id, "keypress", this.handleKeyPress, this, true);
} | javascript | {
"resource": ""
} | |
q30446 | train | function(e) {
if (this.enableKeys) {
var kc = Event.getCharCode(e);
switch (kc) {
case 0x25: // left
case 0x26: // up
case 0x27: // right
case 0x28: // down
case 0x24: // home
case 0x23: // end
Event.preventDefault(e);
break;
default:
}
}
} | javascript | {
"resource": ""
} | |
q30447 | train | function(e) {
if (this.enableKeys) {
var kc = Event.getCharCode(e),
t = this.thumb,
h = this.getXValue(),
v = this.getYValue(),
changeValue = true;
switch (kc) {
// left
case 0x25: h -= this.keyIncrement; break;
// up
case 0x26: v -= this.keyIncrement; break;
// right
case 0x27: h += this.keyIncrement; break;
// down
case 0x28: v += this.keyIncrement; break;
// home
case 0x24: h = t.leftConstraint;
v = t.topConstraint;
break;
// end
case 0x23: h = t.rightConstraint;
v = t.bottomConstraint;
break;
default: changeValue = false;
}
if (changeValue) {
if (t._isRegion) {
this._setRegionValue(Slider.SOURCE_KEY_EVENT, h, v, true);
} else {
this._setValue(Slider.SOURCE_KEY_EVENT,
(t._isHoriz ? h : v), true);
}
Event.stopEvent(e);
}
}
} | javascript | {
"resource": ""
} | |
q30448 | train | function() {
var el = this.thumb.getEl();
if (el) {
/**
* The center of the slider element is stored so we can
* place it in the correct position when the background is clicked.
* @property thumbCenterPoint
* @type {"x": int, "y": int}
*/
this.thumbCenterPoint = {
x: parseInt(el.offsetWidth/2, 10),
y: parseInt(el.offsetHeight/2, 10)
};
}
} | javascript | {
"resource": ""
} | |
q30449 | train | function() {
var args = _AS.call(arguments);
args.unshift(Slider.SOURCE_SET_VALUE);
return this._setValue.apply(this,args);
} | javascript | {
"resource": ""
} | |
q30450 | train | function(finalCoord) {
var t = this.thumb,
self = this,
nextCoord = null,
tmpX, tmpY;
if (t._isRegion) {
nextCoord = this._getNextX(this.curCoord, finalCoord);
tmpX = (nextCoord !== null) ? nextCoord[0] : this.curCoord[0];
nextCoord = this._getNextY(this.curCoord, finalCoord);
tmpY = (nextCoord !== null) ? nextCoord[1] : this.curCoord[1];
nextCoord = tmpX !== this.curCoord[0] || tmpY !== this.curCoord[1] ?
[ tmpX, tmpY ] : null;
} else if (t._isHoriz) {
nextCoord = this._getNextX(this.curCoord, finalCoord);
} else {
nextCoord = this._getNextY(this.curCoord, finalCoord);
}
if (nextCoord) {
// cache the position
this.curCoord = nextCoord;
// move to the next coord
this.thumb.alignElWithMouse(t.getEl(), nextCoord[0] + this.thumbCenterPoint.x, nextCoord[1] + this.thumbCenterPoint.y);
// check if we are in the final position, if not make a recursive call
if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) {
setTimeout(function() { self.moveOneTick(finalCoord); },
this.tickPause);
} else {
this.unlock();
if (!this._mouseDown) {
this.endMove();
}
}
} else {
this.unlock();
if (!this._mouseDown) {
this.endMove();
}
}
} | javascript | {
"resource": ""
} | |
q30451 | train | function(e) {
if (!this.backgroundEnabled || this.isLocked()) {
return false;
}
this._mouseDown = true;
var x = Event.getPageX(e),
y = Event.getPageY(e);
this.focus();
this._slideStart();
this.moveThumb(x, y);
} | javascript | {
"resource": ""
} | |
q30452 | train | function () {
var t = this.thumb;
t.setXConstraint(t.leftConstraint, t.rightConstraint, t.xTickSize);
t.setYConstraint(t.topConstraint, t.bottomConstraint, t.xTickSize);
} | javascript | {
"resource": ""
} | |
q30453 | train | function(parentPos) {
var myPos = YAHOO.util.Dom.getXY(this.getEl()),
ppos = parentPos || YAHOO.util.Dom.getXY(this.parentElId);
return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];
} | javascript | {
"resource": ""
} | |
q30454 | train | function (iLeft, iRight, iUp, iDown, iTickSize) {
this.initLeft = iLeft;
this.initRight = iRight;
this.initUp = iUp;
this.initDown = iDown;
this.setXConstraint(iLeft, iRight, iTickSize);
this.setYConstraint(iUp, iDown, iTickSize);
if (iTickSize && iTickSize > 1) {
this._graduated = true;
}
this._isHoriz = (iLeft || iRight);
this._isVert = (iUp || iDown);
this._isRegion = (this._isHoriz && this._isVert);
} | javascript | {
"resource": ""
} | |
q30455 | train | function () {
if (!this.available) {
return 0;
}
var newOffset = this.getOffsetFromParent();
if (YAHOO.lang.isNumber(newOffset[0])) {
this.lastOffset = newOffset;
return (newOffset[0] - this.startOffset[0]);
} else {
return (this.lastOffset[0] - this.startOffset[0]);
}
} | javascript | {
"resource": ""
} | |
q30456 | train | function (slider) {
Event.on(slider.id,'keydown', this._handleKeyDown, this,true);
Event.on(slider.id,'keypress',this._handleKeyPress,this,true);
} | javascript | {
"resource": ""
} | |
q30457 | train | function (min, max, skipAnim, force, silent) {
var mins = this.minSlider,
maxs = this.maxSlider,
mint = mins.thumb,
maxt = maxs.thumb,
self = this,
done = { min : false, max : false };
// Clear constraints to prevent animated thumbs from prematurely
// stopping when hitting a constraint that's moving with the other
// thumb.
if (mint._isHoriz) {
mint.setXConstraint(mint.leftConstraint,maxt.rightConstraint,mint.tickSize);
maxt.setXConstraint(mint.leftConstraint,maxt.rightConstraint,maxt.tickSize);
} else {
mint.setYConstraint(mint.topConstraint,maxt.bottomConstraint,mint.tickSize);
maxt.setYConstraint(mint.topConstraint,maxt.bottomConstraint,maxt.tickSize);
}
// Set up one-time slideEnd callbacks to call updateValue when both
// thumbs have been set
this._oneTimeCallback(mins,'slideEnd',function () {
done.min = true;
if (done.max) {
self.updateValue(silent);
// Clean the slider's slideEnd events on a timeout since this
// will be executed from inside the event's fire
setTimeout(function () {
self._cleanEvent(mins,'slideEnd');
self._cleanEvent(maxs,'slideEnd');
},0);
}
});
this._oneTimeCallback(maxs,'slideEnd',function () {
done.max = true;
if (done.min) {
self.updateValue(silent);
// Clean both sliders' slideEnd events on a timeout since this
// will be executed from inside one of the event's fire
setTimeout(function () {
self._cleanEvent(mins,'slideEnd');
self._cleanEvent(maxs,'slideEnd');
},0);
}
});
// Must emit Slider slideEnd event to propagate to updateValue
mins.setValue(min,skipAnim,force,false);
maxs.setValue(max,skipAnim,force,false);
} | javascript | {
"resource": ""
} | |
q30458 | train | function (min, skipAnim, force, silent) {
var mins = this.minSlider,
self = this;
this.activeSlider = mins;
// Use a one-time event callback to delay the updateValue call
// until after the slide operation is done
self = this;
this._oneTimeCallback(mins,'slideEnd',function () {
self.updateValue(silent);
// Clean the slideEnd event on a timeout since this
// will be executed from inside the event's fire
setTimeout(function () { self._cleanEvent(mins,'slideEnd'); }, 0);
});
mins.setValue(min, skipAnim, force);
} | javascript | {
"resource": ""
} | |
q30459 | train | function (max, skipAnim, force, silent) {
var maxs = this.maxSlider,
self = this;
this.activeSlider = maxs;
// Use a one-time event callback to delay the updateValue call
// until after the slide operation is done
this._oneTimeCallback(maxs,'slideEnd',function () {
self.updateValue(silent);
// Clean the slideEnd event on a timeout since this
// will be executed from inside the event's fire
setTimeout(function () { self._cleanEvent(maxs,'slideEnd'); }, 0);
});
maxs.setValue(max, skipAnim, force);
} | javascript | {
"resource": ""
} | |
q30460 | train | function(silent) {
var min = this.minSlider.getValue(),
max = this.maxSlider.getValue(),
changed = false,
mint,maxt,dim,minConstraint,maxConstraint,thumbInnerWidth;
if (min != this.minVal || max != this.maxVal) {
changed = true;
mint = this.minSlider.thumb;
maxt = this.maxSlider.thumb;
dim = this.isHoriz ? 'x' : 'y';
thumbInnerWidth = this.minSlider.thumbCenterPoint[dim] +
this.maxSlider.thumbCenterPoint[dim];
// Establish barriers within the respective other thumb's edge, less
// the minRange. Limit to the Slider's range in the case of
// negative minRanges.
minConstraint = Math.max(max-thumbInnerWidth-this.minRange,0);
maxConstraint = Math.min(-min-thumbInnerWidth-this.minRange,0);
if (this.isHoriz) {
minConstraint = Math.min(minConstraint,maxt.rightConstraint);
mint.setXConstraint(mint.leftConstraint,minConstraint, mint.tickSize);
maxt.setXConstraint(maxConstraint,maxt.rightConstraint, maxt.tickSize);
} else {
minConstraint = Math.min(minConstraint,maxt.bottomConstraint);
mint.setYConstraint(mint.leftConstraint,minConstraint, mint.tickSize);
maxt.setYConstraint(maxConstraint,maxt.bottomConstraint, maxt.tickSize);
}
}
this.minVal = min;
this.maxVal = max;
if (changed && !silent) {
this.fireEvent("change", this);
}
} | javascript | {
"resource": ""
} | |
q30461 | train | function(e) {
var min = this.minSlider,
max = this.maxSlider,
minLocked = min.isLocked() || !min.backgroundEnabled,
maxLocked = max.isLocked() || !min.backgroundEnabled,
Ev = YAHOO.util.Event,
d;
if (minLocked || maxLocked) {
this.activeSlider = minLocked ? max : min;
} else {
if (this.isHoriz) {
d = Ev.getPageX(e)-min.thumb.initPageX-min.thumbCenterPoint.x;
} else {
d = Ev.getPageY(e)-min.thumb.initPageY-min.thumbCenterPoint.y;
}
this.activeSlider = d*2 > max.getValue()+min.getValue() ? max : min;
}
} | javascript | {
"resource": ""
} | |
q30462 | train | function(e) {
if (!e._handled && !this.minSlider._sliding && !this.maxSlider._sliding) {
e._handled = true;
this.selectActiveSlider(e);
return YW.Slider.prototype.onMouseDown.call(this.activeSlider, e);
} else {
return false;
}
} | javascript | {
"resource": ""
} | |
q30463 | train | function (o,evt,fn) {
var sub = function () {
// Unsubscribe myself
o.unsubscribe(evt, sub);
// Pass the event handler arguments to the one time callback
fn.apply({},arguments);
};
o.subscribe(evt,sub);
} | javascript | {
"resource": ""
} | |
q30464 | train | function (o,evt) {
var ce,i,len,j,subs,newSubs;
if (o.__yui_events && o.events[evt]) {
for (i = o.__yui_events.length; i >= 0; --i) {
if (o.__yui_events[i].type === evt) {
ce = o.__yui_events[i];
break;
}
}
if (ce) {
subs = ce.subscribers;
newSubs = [];
j = 0;
for (i = 0, len = subs.length; i < len; ++i) {
if (subs[i]) {
newSubs[j++] = subs[i];
}
}
ce.subscribers = newSubs;
}
}
} | javascript | {
"resource": ""
} | |
q30465 | createElement | train | function createElement(el, attrs) {
var newEl = document.createElement(el);
attrs = attrs || {};
if (attrs.className) {
Dom.addClass(newEl, attrs.className);
}
if (attrs.styles) {
setStyles(newEl, attrs.styles);
}
if (attrs.parent) {
attrs.parent.appendChild(newEl);
}
if (attrs.id) {
newEl.setAttribute("id", attrs.id);
}
if (attrs.content) {
if (attrs.content.nodeName) {
newEl.appendChild(attrs.content);
} else {
newEl.innerHTML = attrs.content;
}
}
return newEl;
} | javascript | {
"resource": ""
} |
q30466 | getStyle | train | function getStyle(el, style, type) {
var value;
if (!el) {
return 0;
}
function getStyleIntVal(el, style) {
var val;
/*
* XXX: Safari calculates incorrect marginRight for an element
* which has its parent element style set to overflow: hidden
* https://bugs.webkit.org/show_bug.cgi?id=13343
* Let us assume marginLeft == marginRight
*/
if (style == "marginRight" && YAHOO.env.ua.webkit) {
val = parseInt(Dom.getStyle(el, "marginLeft"), 10);
} else {
val = parseInt(Dom.getStyle(el, style), 10);
}
return JS.isNumber(val) ? val : 0;
}
function getStyleFloatVal(el, style) {
var val;
/*
* XXX: Safari calculates incorrect marginRight for an element
* which has its parent element style set to overflow: hidden
* https://bugs.webkit.org/show_bug.cgi?id=13343
* Let us assume marginLeft == marginRight
*/
if (style == "marginRight" && YAHOO.env.ua.webkit) {
val = parseFloat(Dom.getStyle(el, "marginLeft"));
} else {
val = parseFloat(Dom.getStyle(el, style));
}
return JS.isNumber(val) ? val : 0;
}
if (typeof type == "undefined") {
type = "int";
}
switch (style) {
case "height":
value = el.offsetHeight;
if (value > 0) {
value += getStyleIntVal(el, "marginTop") +
getStyleIntVal(el, "marginBottom");
} else {
value = getStyleFloatVal(el, "height") +
getStyleIntVal(el, "marginTop") +
getStyleIntVal(el, "marginBottom") +
getStyleIntVal(el, "borderTopWidth") +
getStyleIntVal(el, "borderBottomWidth") +
getStyleIntVal(el, "paddingTop") +
getStyleIntVal(el, "paddingBottom");
}
break;
case "width":
value = el.offsetWidth;
if (value > 0) {
value += getStyleIntVal(el, "marginLeft") +
getStyleIntVal(el, "marginRight");
} else {
value = getStyleFloatVal(el, "width") +
getStyleIntVal(el, "marginLeft") +
getStyleIntVal(el, "marginRight") +
getStyleIntVal(el, "borderLeftWidth") +
getStyleIntVal(el, "borderRightWidth") +
getStyleIntVal(el, "paddingLeft") +
getStyleIntVal(el, "paddingRight");
}
break;
default:
if (type == "int") {
value = getStyleIntVal(el, style);
} else if (type == "float") {
value = getStyleFloatVal(el, style);
} else {
value = Dom.getStyle(el, style);
}
break;
}
return value;
} | javascript | {
"resource": ""
} |
q30467 | getCarouselItemSize | train | function getCarouselItemSize(which) {
var carousel = this,
child,
item,
size = 0,
first = carousel.get("firstVisible"),
vertical = false;
if (carousel._itemsTable.numItems === 0) {
return 0;
}
item = carousel._itemsTable.items[first] ||
carousel._itemsTable.loading[first];
if (JS.isUndefined(item)) {
return 0;
}
child = Dom.get(item.id);
if (typeof which == "undefined") {
vertical = carousel.get("isVertical");
} else {
vertical = which == "height";
}
if (this._itemAttrCache[which]) {
return this._itemAttrCache[which];
}
if (vertical) {
size = getStyle(child, "height");
} else {
size = getStyle(child, "width");
}
this._itemAttrCache[which] = size;
return size;
} | javascript | {
"resource": ""
} |
q30468 | getCarouselItemPosition | train | function getCarouselItemPosition(pos) {
var carousel = this,
itemsPerRow = carousel._cols,
itemsPerCol = carousel._rows,
page,
sz,
isVertical,
itemsCol,
itemsRow,
sentinel,
delta = 0,
top,
left,
rsz,
styles = {},
index = 0,
itemsTable = carousel._itemsTable,
items = itemsTable.items,
loading = itemsTable.loading;
isVertical = carousel.get("isVertical");
sz = getCarouselItemSize.call(carousel,
isVertical ? "height" : "width");
rsz = getRevealSize.call(carousel);
// adjust for items not yet loaded
while (index < pos) {
if (!items[index] && !loading[index]) {
delta++;
}
index++;
}
pos -= delta;
if (itemsPerCol) {
page = this.getPageForItem(pos);
if (isVertical) {
itemsRow = Math.floor(pos/itemsPerRow);
delta = itemsRow;
top = delta * sz;
styles.top = (top + rsz) + "px";
sz = getCarouselItemSize.call(carousel, "width");
itemsCol = pos % itemsPerRow;
delta = itemsCol;
left = delta * sz;
styles.left = left + "px";
} else {
itemsCol = pos % itemsPerRow;
sentinel = (page - 1) * itemsPerRow;
delta = itemsCol + sentinel;
left = delta * sz;
styles.left = (left + rsz) + "px";
sz = getCarouselItemSize.call(carousel, "height");
itemsRow = Math.floor(pos/itemsPerRow);
sentinel = (page - 1) * itemsPerCol;
delta = itemsRow - sentinel;
top = delta * sz;
styles.top = top + "px";
}
} else {
if (isVertical) {
styles.left = 0;
styles.top = ((pos * sz) + rsz) + "px";
} else {
styles.top = 0;
styles.left = ((pos * sz) + rsz) + "px";
}
}
return styles;
} | javascript | {
"resource": ""
} |
q30469 | getScrollOffset | train | function getScrollOffset(delta) {
var itemSize = 0,
size = 0;
itemSize = getCarouselItemSize.call(this);
size = itemSize * delta;
return size;
} | javascript | {
"resource": ""
} |
q30470 | setItemSelection | train | function setItemSelection(newpos, oldpos) {
var carousel = this,
cssClass = carousel.CLASSES,
el,
firstItem = carousel._firstItem,
isCircular = carousel.get("isCircular"),
numItems = carousel.get("numItems"),
numVisible = carousel.get("numVisible"),
position = oldpos,
sentinel = firstItem + numVisible - 1;
if (position >= 0 && position < numItems) {
if (!JS.isUndefined(carousel._itemsTable.items[position])) {
el = Dom.get(carousel._itemsTable.items[position].id);
if (el) {
Dom.removeClass(el, cssClass.SELECTED_ITEM);
}
}
}
if (JS.isNumber(newpos)) {
newpos = parseInt(newpos, 10);
newpos = JS.isNumber(newpos) ? newpos : 0;
} else {
newpos = firstItem;
}
if (JS.isUndefined(carousel._itemsTable.items[newpos])) {
newpos = getFirstVisibleForPosition.call(carousel, newpos);
carousel.scrollTo(newpos); // still loading the item
}
if (!JS.isUndefined(carousel._itemsTable.items[newpos])) {
el = Dom.get(carousel._itemsTable.items[newpos].id);
if (el) {
Dom.addClass(el, cssClass.SELECTED_ITEM);
}
}
if (newpos < firstItem || newpos > sentinel) { // out of focus
newpos = getFirstVisibleForPosition.call(carousel, newpos);
carousel.scrollTo(newpos);
}
} | javascript | {
"resource": ""
} |
q30471 | syncPagerUi | train | function syncPagerUi(page) {
var carousel = this, numPages, numVisible;
// Don't do anything if the Carousel is not rendered
if (!carousel._hasRendered) {
return;
}
numVisible = carousel.get("numVisible");
if (!JS.isNumber(page)) {
page = Math.floor(carousel.get("selectedItem") / numVisible);
}
numPages = Math.ceil(carousel.get("numItems") / numVisible);
carousel._pages.num = numPages;
carousel._pages.cur = page;
if (numPages > carousel.CONFIG.MAX_PAGER_BUTTONS) {
carousel._updatePagerMenu();
} else {
carousel._updatePagerButtons();
}
} | javascript | {
"resource": ""
} |
q30472 | getDimensions | train | function getDimensions(el, which) {
switch (which) {
case 'height':
return getStyle(el, "marginTop") +
getStyle(el, "marginBottom") +
getStyle(el, "paddingTop") +
getStyle(el, "paddingBottom") +
getStyle(el, "borderTopWidth") +
getStyle(el, "borderBottomWidth");
case 'width':
return getStyle(el, "marginLeft") +
getStyle(el, "marginRight") +
getStyle(el, "paddingLeft") +
getStyle(el, "paddingRight") +
getStyle(el, "borderLeftWidth") +
getStyle(el, "borderRightWidth");
default:
break;
}
return getStyle(el, which);
} | javascript | {
"resource": ""
} |
q30473 | syncUi | train | function syncUi(o) {
var carousel = this;
if (!JS.isObject(o)) {
return;
}
switch (o.ev) {
case itemAddedEvent:
carousel._syncUiForItemAdd(o);
break;
case itemRemovedEvent:
carousel._syncUiForItemRemove(o);
break;
case itemReplacedEvent:
carousel._syncUiForItemReplace(o);
break;
case loadItemsEvent:
carousel._syncUiForLazyLoading(o);
break;
}
carousel.fireEvent(uiUpdateEvent);
} | javascript | {
"resource": ""
} |
q30474 | updateStateAfterScroll | train | function updateStateAfterScroll(item, sentinel) {
var carousel = this,
page = carousel.get("currentPage"),
newPage,
numPerPage = carousel.get("numVisible");
newPage = parseInt(carousel._firstItem / numPerPage, 10);
if (newPage != page) {
carousel.setAttributeConfig("currentPage", { value: newPage });
carousel.fireEvent(pageChangeEvent, newPage);
}
if (carousel.get("selectOnScroll")) {
if (carousel.get("selectedItem") != carousel._selectedItem) {
carousel.set("selectedItem", carousel._selectedItem);
}
}
clearTimeout(carousel._autoPlayTimer);
delete carousel._autoPlayTimer;
if (carousel.isAutoPlayOn()) {
carousel.startAutoPlay();
}
carousel.fireEvent(afterScrollEvent,
{ first: carousel._firstItem,
last: sentinel },
carousel);
} | javascript | {
"resource": ""
} |
q30475 | train | function () {
var carousel = this, n = carousel.get("numItems");
while (n > 0) {
if (!carousel.removeItem(0)) {
YAHOO.log("Item could not be removed - missing?",
"warn", WidgetName);
}
/*
For dynamic loading, the numItems may be much larger than
the actual number of items in the table. So, set the
numItems to zero, and break out of the loop if the table
is already empty.
*/
if (carousel._itemsTable.numItems === 0) {
carousel.set("numItems", 0);
break;
}
n--;
}
carousel.fireEvent(allItemsRemovedEvent);
} | javascript | {
"resource": ""
} | |
q30476 | train | function () {
var carousel = this,
first,
focusEl,
isSelectionInvisible,
itemsTable,
last,
numVisible,
selectOnScroll,
selected,
selItem;
// Don't do anything if the Carousel is not rendered
if (!carousel._hasRendered) {
return;
}
if (carousel.isAnimating()) {
// this messes up real bad!
return;
}
selItem = carousel.get("selectedItem");
numVisible = carousel.get("numVisible");
selectOnScroll = carousel.get("selectOnScroll");
selected = (selItem >= 0) ?
carousel.getItem(selItem) : null;
first = carousel.get("firstVisible");
last = first + numVisible - 1;
isSelectionInvisible = (selItem < first || selItem > last);
focusEl = (selected && selected.id) ?
Dom.get(selected.id) : null;
itemsTable = carousel._itemsTable;
if (!selectOnScroll && isSelectionInvisible) {
focusEl = (itemsTable && itemsTable.items &&
itemsTable.items[first]) ?
Dom.get(itemsTable.items[first].id) : null;
}
if (focusEl) {
try {
focusEl.focus();
} catch (ex) {
// ignore focus errors
}
}
carousel.fireEvent(focusEvent);
} | javascript | {
"resource": ""
} | |
q30477 | train | function () {
var carousel = this;
if (carousel.fireEvent(beforeHideEvent) !== false) {
carousel.removeClass(carousel.CLASSES.VISIBLE);
carousel.fireEvent(hideEvent);
}
} | javascript | {
"resource": ""
} | |
q30478 | train | function (el, attrs) {
var carousel = this,
elId = el, // save for a rainy day
parse = false,
selected;
if (!el) {
YAHOO.log(el + " is neither an HTML element, nor a string",
"error", WidgetName);
return;
}
carousel._hasRendered = false;
carousel._navBtns = { prev: [], next: [] };
carousel._pages = { el: null, num: 0, cur: 0 };
carousel._pagination = {};
carousel._itemAttrCache = {};
carousel._itemsTable = { loading: {}, numItems: 0,
items: [], size: 0 };
YAHOO.log("Component initialization", WidgetName);
if (JS.isString(el)) {
el = Dom.get(el);
} else if (!el.nodeName) {
YAHOO.log(el + " is neither an HTML element, nor a string",
"error", WidgetName);
return;
}
Carousel.superclass.init.call(carousel, el, attrs);
// check if we're starting somewhere in the middle
selected = carousel.get("selectedItem");
if(selected > 0){
carousel.set("firstVisible",getFirstVisibleForPosition.call(carousel,selected));
}
if (el) {
if (!el.id) { // in case the HTML element is passed
el.setAttribute("id", Dom.generateId());
}
parse = carousel._parseCarousel(el);
if (!parse) {
carousel._createCarousel(elId);
}
} else {
el = carousel._createCarousel(elId);
}
elId = el.id;
carousel.initEvents();
if (parse) {
carousel._parseCarouselItems();
}
// add the selected class
if(selected > 0){
setItemSelection.call(carousel,selected,0);
}
if (!attrs || typeof attrs.isVertical == "undefined") {
carousel.set("isVertical", false);
}
carousel._parseCarouselNavigation(el);
carousel._navEl = carousel._setupCarouselNavigation();
instances[elId] = { object: carousel };
carousel._loadItems(Math.min(carousel.get("firstVisible")+carousel.get("numVisible"),carousel.get("numItems"))-1);
} | javascript | {
"resource": ""
} | |
q30479 | train | function (attrs) {
var carousel = this;
attrs = attrs || {};
Carousel.superclass.initAttributes.call(carousel, attrs);
/**
* @attribute carouselEl
* @description The type of the Carousel element.
* @default OL
* @type Boolean
*/
carousel.setAttributeConfig("carouselEl", {
validator : JS.isString,
value : attrs.carouselEl || "OL"
});
/**
* @attribute carouselItemEl
* @description The type of the list of items within the Carousel.
* @default LI
* @type Boolean
*/
carousel.setAttributeConfig("carouselItemEl", {
validator : JS.isString,
value : attrs.carouselItemEl || "LI"
});
/**
* @attribute currentPage
* @description The current page number (read-only.)
* @type Number
*/
carousel.setAttributeConfig("currentPage", {
readOnly : true,
value : 0
});
/**
* @attribute firstVisible
* @description The index to start the Carousel from (indexes begin
* from zero)
* @default 0
* @type Number
*/
carousel.setAttributeConfig("firstVisible", {
method : carousel._setFirstVisible,
validator : carousel._validateFirstVisible,
value :
attrs.firstVisible || carousel.CONFIG.FIRST_VISIBLE
});
/**
* @attribute selectOnScroll
* @description Set this to true to automatically set focus to
* follow scrolling in the Carousel.
* @default true
* @type Boolean
*/
carousel.setAttributeConfig("selectOnScroll", {
validator : JS.isBoolean,
value : attrs.selectOnScroll || true
});
/**
* @attribute numVisible
* @description The number of visible items in the Carousel's
* viewport.
* @default 3
* @type Number
*/
carousel.setAttributeConfig("numVisible", {
setter : carousel._numVisibleSetter,
method : carousel._setNumVisible,
validator : carousel._validateNumVisible,
value : attrs.numVisible || carousel.CONFIG.NUM_VISIBLE
});
/**
* @attribute numItems
* @description The number of items in the Carousel.
* @type Number
*/
carousel.setAttributeConfig("numItems", {
method : carousel._setNumItems,
validator : carousel._validateNumItems,
value : carousel._itemsTable.numItems
});
/**
* @attribute scrollIncrement
* @description The number of items to scroll by for arrow keys.
* @default 1
* @type Number
*/
carousel.setAttributeConfig("scrollIncrement", {
validator : carousel._validateScrollIncrement,
value : attrs.scrollIncrement || 1
});
/**
* @attribute selectedItem
* @description The index of the selected item.
* @type Number
*/
carousel.setAttributeConfig("selectedItem", {
setter : carousel._selectedItemSetter,
method : carousel._setSelectedItem,
validator : JS.isNumber,
value : -1
});
/**
* @attribute revealAmount
* @description The percentage of the item to be revealed on each
* side of the Carousel (before and after the first and last item
* in the Carousel's viewport.)
* @default 0
* @type Number
*/
carousel.setAttributeConfig("revealAmount", {
method : carousel._setRevealAmount,
validator : carousel._validateRevealAmount,
value : attrs.revealAmount || 0
});
/**
* @attribute isCircular
* @description Set this to true to wrap scrolling of the contents
* in the Carousel.
* @default false
* @type Boolean
*/
carousel.setAttributeConfig("isCircular", {
validator : JS.isBoolean,
value : attrs.isCircular || false
});
/**
* @attribute isVertical
* @description True if the orientation of the Carousel is vertical
* @default false
* @type Boolean
*/
carousel.setAttributeConfig("isVertical", {
method : carousel._setOrientation,
validator : JS.isBoolean,
value : attrs.isVertical || false
});
/**
* @attribute navigation
* @description The set of navigation controls for Carousel
* @default <br>
* { prev: null, // the previous navigation element<br>
* next: null } // the next navigation element
* @type Object
*/
carousel.setAttributeConfig("navigation", {
method : carousel._setNavigation,
validator : carousel._validateNavigation,
value :
attrs.navigation || {prev: null,next: null,page: null}
});
/**
* @attribute animation
* @description The optional animation attributes for the Carousel.
* @default <br>
* { speed: 0, // the animation speed (in seconds)<br>
* effect: null } // the animation effect (like
* YAHOO.util.Easing.easeOut)
* @type Object
*/
carousel.setAttributeConfig("animation", {
validator : carousel._validateAnimation,
value : attrs.animation || { speed: 0, effect: null }
});
/**
* @attribute autoPlay
* @description Set this to time in milli-seconds to have the
* Carousel automatically scroll the contents.
* @type Number
* @deprecated Use autoPlayInterval instead.
*/
carousel.setAttributeConfig("autoPlay", {
validator : JS.isNumber,
value : attrs.autoPlay || 0
});
/**
* @attribute autoPlayInterval
* @description The delay in milli-seconds for scrolling the
* Carousel during auto-play.
* Note: The startAutoPlay() method needs to be invoked to trigger
* automatic scrolling of Carousel.
* @type Number
*/
carousel.setAttributeConfig("autoPlayInterval", {
validator : JS.isNumber,
value : attrs.autoPlayInterval || 0
});
/**
* @attribute numPages
* @description The number of pages in the carousel.
* @type Number
*/
carousel.setAttributeConfig("numPages", {
readOnly : true,
getter : carousel._getNumPages
});
/**
* @attribute lastVisible
* @description The last item visible in the carousel.
* @type Number
*/
carousel.setAttributeConfig("lastVisible", {
readOnly : true,
getter : carousel._getLastVisible
});
} | javascript | {
"resource": ""
} | |
q30480 | train | function (index) {
var carousel = this;
if (index < 0 || index >= carousel.get("numItems")) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return null;
}
if (carousel._itemsTable.items[index]) {
return Dom.get(carousel._itemsTable.items[index].id);
}
return null;
} | javascript | {
"resource": ""
} | |
q30481 | train | function () {
var carousel = this, els = [], i;
for (i = 0; i < carousel._itemsTable.numItems; i++) {
els.push(carousel.getElementForItem(i));
}
return els;
} | javascript | {
"resource": ""
} | |
q30482 | train | function (index) {
var carousel = this;
if (index < 0 || index >= carousel.get("numItems")) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return null;
}
if (carousel._itemsTable.numItems > index) {
if (!JS.isUndefined(carousel._itemsTable.items[index])) {
return carousel._itemsTable.items[index];
}
}
return null;
} | javascript | {
"resource": ""
} | |
q30483 | train | function (id) {
var carousel = this,
n = carousel.get("numItems"),
i = 0,
items = carousel._itemsTable.items,
item;
while (i < n) {
item = items[i] || {};
if(item.id == id) {
return i;
}
i++;
}
return -1;
} | javascript | {
"resource": ""
} | |
q30484 | train | function () {
var carousel = this,
i = carousel.get("firstVisible"),
n = i + carousel.get("numVisible"),
r = [];
while (i < n) {
r.push(carousel.getElementForItem(i));
i++;
}
return r;
} | javascript | {
"resource": ""
} | |
q30485 | train | function (index) {
var carousel = this,
item,
num = carousel.get("numItems");
if (index < 0 || index >= num) {
YAHOO.log("Index out of bounds", "error", WidgetName);
return false;
}
item = carousel._itemsTable.items.splice(index, 1);
if (item && item.length == 1) {
carousel._itemsTable.numItems--;
carousel.set("numItems", num - 1);
carousel.fireEvent(itemRemovedEvent,
{ item: item[0], pos: index, ev: itemRemovedEvent });
return true;
}
return false;
} | javascript | {
"resource": ""
} | |
q30486 | train | function (item, index) {
var carousel = this,
className,
content,
elId,
numItems = carousel.get("numItems"),
oel,
el = item;
if (!item) {
return false;
}
if (JS.isString(item) || item.nodeName) {
content = item.nodeName ? item.innerHTML : item;
} else if (JS.isObject(item)) {
content = item.content;
} else {
YAHOO.log("Invalid argument to replaceItem", "error", WidgetName);
return false;
}
if (JS.isUndefined(index)) {
YAHOO.log("Index must be defined for replaceItem", "error", WidgetName);
return false;
} else {
if (index < 0 || index >= numItems) {
YAHOO.log("Index out of bounds in replaceItem", "error", WidgetName);
return false;
}
oel = carousel._itemsTable.items[index];
if(!oel){
oel = carousel._itemsTable.loading[index];
carousel._itemsTable.items[index] = undefined;
}
carousel._itemsTable.items.splice(index, 1, {
item : content,
className : item.className || "",
id : Dom.generateId()
});
el = carousel._itemsTable.items[index];
}
carousel.fireEvent(itemReplacedEvent,
{ newItem: el, oldItem: oel, pos: index, ev: itemReplacedEvent });
return true;
} | javascript | {
"resource": ""
} | |
q30487 | train | function (appendTo) {
var carousel = this,
cssClass = carousel.CLASSES,
rows = carousel._rows;
carousel.addClass(cssClass.CAROUSEL);
if (!carousel._clipEl) {
carousel._clipEl = carousel._createCarouselClip();
carousel._clipEl.appendChild(carousel._carouselEl);
}
if (appendTo) {
carousel.appendChild(carousel._clipEl);
carousel.appendTo(appendTo);
} else {
if (!Dom.inDocument(carousel.get("element"))) {
YAHOO.log("Nothing to render. The container should be " +
"within the document if appendTo is not " +
"specified", "error", WidgetName);
return false;
}
carousel.appendChild(carousel._clipEl);
}
if (rows) {
Dom.addClass(carousel._clipEl, cssClass.MULTI_ROW);
}
if (carousel.get("isVertical")) {
carousel.addClass(cssClass.VERTICAL);
} else {
carousel.addClass(cssClass.HORIZONTAL);
}
if (carousel.get("numItems") < 1) {
YAHOO.log("No items in the Carousel to render", "warn",
WidgetName);
return false;
}
carousel._refreshUi();
return true;
} | javascript | {
"resource": ""
} | |
q30488 | train | function () {
var carousel = this,
isVertical = carousel.get("isVertical"),
cols = carousel._cols,
item = carousel._firstItem - carousel.get("numVisible");
if (item < 0) { // only account for multi-row when scrolling backwards from item 0
if (cols) {
item = carousel._firstItem - cols;
}
}
if (carousel.get("selectOnScroll")) {
carousel._selectedItem = carousel._getSelectedItem(item);
}
carousel.scrollTo(item);
} | javascript | {
"resource": ""
} | |
q30489 | train | function () {
var carousel = this,
item = carousel._firstItem + carousel.get("numVisible");
if (item > carousel.get("numItems")) {
item = 0;
}
if (carousel.get("selectOnScroll")) {
carousel._selectedItem = carousel._getSelectedItem(item);
}
carousel.scrollTo(item);
} | javascript | {
"resource": ""
} | |
q30490 | train | function () {
var carousel = this,
newpos = 0,
selected = carousel.get("selectedItem");
if (selected == this._firstItem) {
newpos = selected - carousel.get("numVisible");
carousel._selectedItem = carousel._getSelectedItem(selected-1);
carousel.scrollTo(newpos);
} else {
newpos = carousel.get("selectedItem") -
carousel.get("scrollIncrement");
carousel.set("selectedItem",carousel._getSelectedItem(newpos));
}
} | javascript | {
"resource": ""
} | |
q30491 | train | function () {
var carousel = this, newpos = 0;
newpos = carousel.get("selectedItem") +
carousel.get("scrollIncrement");
carousel.set("selectedItem", carousel._getSelectedItem(newpos));
} | javascript | {
"resource": ""
} | |
q30492 | train | function () {
var carousel = this,
cssClass = carousel.CLASSES;
if (carousel.fireEvent(beforeShowEvent) !== false) {
carousel.addClass(cssClass.VISIBLE);
carousel.fireEvent(showEvent);
}
} | javascript | {
"resource": ""
} | |
q30493 | train | function () {
var carousel = this, timer;
if (JS.isUndefined(carousel._autoPlayTimer)) {
timer = carousel.get("autoPlayInterval");
if (timer <= 0) {
return;
}
carousel._isAutoPlayInProgress = true;
carousel.fireEvent(startAutoPlayEvent);
carousel._autoPlayTimer = setTimeout(function () {
carousel._autoScroll();
}, timer);
}
} | javascript | {
"resource": ""
} | |
q30494 | train | function () {
var carousel = this;
if (!JS.isUndefined(carousel._autoPlayTimer)) {
clearTimeout(carousel._autoPlayTimer);
delete carousel._autoPlayTimer;
carousel._isAutoPlayInProgress = false;
carousel.fireEvent(stopAutoPlayEvent);
}
} | javascript | {
"resource": ""
} | |
q30495 | train | function () {
var carousel = this,
pagination = carousel._pagination;
if(!pagination.el){ return false; }
var numItems = carousel.get('numItems'),
numVisible = carousel.get('numVisible'),
firstVisible = carousel.get('firstVisible')+1,
currentPage = carousel.get('currentPage')+1,
numPages = carousel.get('numPages'),
replacements = {
'numVisible' : numVisible,
'numPages' : numPages,
'numItems' : numItems,
'selectedItem' : carousel.get('selectedItem')+1,
'currentPage' : currentPage,
'firstVisible' : firstVisible,
'lastVisible' : carousel.get("lastVisible")+1
},
cb = pagination.callback || {},
scope = cb.scope && cb.obj ? cb.obj : carousel;
pagination.el.innerHTML = JS.isFunction(cb.fn) ? cb.fn.apply(scope, [pagination.template, replacements]) : YAHOO.lang.substitute(pagination.template, replacements);
} | javascript | {
"resource": ""
} | |
q30496 | train | function (tpl, pos, cb) {
var carousel = this;
carousel._pagination.template = tpl;
carousel._pagination.callback = cb || {};
if(!carousel._pagination.el){
carousel._pagination.el = createElement('DIV', {className:carousel.CLASSES.PAGINATION});
if(pos == "before"){
carousel._navEl.insertBefore(carousel._pagination.el, carousel._navEl.firstChild);
} else {
carousel._navEl.appendChild(carousel._pagination.el);
}
carousel.on('itemSelected', carousel.updatePagination);
carousel.on('pageChange', carousel.updatePagination);
}
carousel.updatePagination();
} | javascript | {
"resource": ""
} | |
q30497 | train | function (ev, p, o) {
o.scope._isAnimationInProgress = false;
updateStateAfterScroll.call(o.scope, o.item, o.last);
} | javascript | {
"resource": ""
} | |
q30498 | train | function() {
var carousel = this,
currIndex = carousel._firstItem,
index;
if (currIndex >= carousel.get("numItems") - 1) {
if (carousel.get("isCircular")) {
index = 0;
} else {
carousel.stopAutoPlay();
}
} else {
index = currIndex + carousel.get("numVisible");
}
carousel._selectedItem = carousel._getSelectedItem(index);
carousel.scrollTo.call(carousel, index);
} | javascript | {
"resource": ""
} | |
q30499 | train | function (elId) {
var carousel = this,
cssClass = carousel.CLASSES,
el = Dom.get(elId);
if (!el) {
el = createElement("DIV", {
className : cssClass.CAROUSEL,
id : elId
});
}
if (!carousel._carouselEl) {
carousel._carouselEl=createElement(carousel.get("carouselEl"),
{ className: cssClass.CAROUSEL_EL });
}
return el;
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.