_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3 values | text stringlengths 52 373k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q35800 | train | function (elm, name, value) {
elm = this.$$(elm).css(name, value);
if (this.settings.update_styles) {
updateInternalStyleAttr(this, elm);
}
} | javascript | {
"resource": ""
} | |
q35801 | train | function (e) {
return this.run(e, function (e) {
var i, attrs = e.attributes;
for (i = attrs.length - 1; i >= 0; i--) {
e.removeAttributeNode(attrs.item(i));
}
});
} | javascript | {
"resource": ""
} | |
q35802 | train | function (elm, name, value) {
var self = this, originalValue, hook, settings = self.settings;
if (value === '') {
value = null;
}
elm = self.$$(elm);
originalValue = elm.attr(name);
if (!elm.length) {
return;
}
hook = self.attrHooks[name];
if (hook && hook.set) {
hook.set(elm, value, name);
} else {
elm.attr(name, value);
}
if (originalValue != value && settings.onSetAttrib) {
settings.onSetAttrib({
attrElm: elm,
attrName: name,
attrValue: value
});
}
} | javascript | {
"resource": ""
} | |
q35803 | train | function (elm, attrs) {
var self = this;
self.$$(elm).each(function (i, node) {
each(attrs, function (value, name) {
self.setAttrib(node, name, value);
});
});
} | javascript | {
"resource": ""
} | |
q35804 | train | function (elm, name, defaultVal) {
var self = this, hook, value;
elm = self.$$(elm);
if (elm.length) {
hook = self.attrHooks[name];
if (hook && hook.get) {
value = hook.get(elm, name);
} else {
value = elm.attr(name);
}
}
if (typeof value == 'undefined') {
value = defaultVal || '';
}
return value;
} | javascript | {
"resource": ""
} | |
q35805 | train | function (cssText) {
var self = this, doc = self.doc, head, styleElm;
// Prevent inline from loading the same styles twice
if (self !== DOMUtils.DOM && doc === document) {
var addedStyles = DOMUtils.DOM.addedStyles;
addedStyles = addedStyles || [];
if (addedStyles[cssText]) {
return;
}
addedStyles[cssText] = true;
DOMUtils.DOM.addedStyles = addedStyles;
}
// Create style element if needed
styleElm = doc.getElementById('mceDefaultStyles');
if (!styleElm) {
styleElm = doc.createElement('style');
styleElm.id = 'mceDefaultStyles';
styleElm.type = 'text/css';
head = doc.getElementsByTagName('head')[0];
if (head.firstChild) {
head.insertBefore(styleElm, head.firstChild);
} else {
head.appendChild(styleElm);
}
}
// Append style data to old or new style element
if (styleElm.styleSheet) {
styleElm.styleSheet.cssText += cssText;
} else {
styleElm.appendChild(doc.createTextNode(cssText));
}
} | javascript | {
"resource": ""
} | |
q35806 | train | function (elm, html) {
elm = this.$$(elm);
if (isIE) {
elm.each(function (i, target) {
if (target.canHaveHTML === false) {
return;
}
// Remove all child nodes, IE keeps empty text nodes in DOM
while (target.firstChild) {
target.removeChild(target.firstChild);
}
try {
// IE will remove comments from the beginning
// unless you padd the contents with something
target.innerHTML = '<br>' + html;
target.removeChild(target.firstChild);
} catch (ex) {
// IE sometimes produces an unknown runtime error on innerHTML if it's a div inside a p
$('<div></div>').html('<br>' + html).contents().slice(1).appendTo(target);
}
return html;
});
} else {
elm.html(html);
}
} | javascript | {
"resource": ""
} | |
q35807 | train | function (elm) {
elm = this.get(elm);
// Older FF doesn't have outerHTML 3.6 is still used by some orgaizations
return elm.nodeType == 1 && "outerHTML" in elm ? elm.outerHTML : $('<div></div>').append($(elm).clone()).html();
} | javascript | {
"resource": ""
} | |
q35808 | train | function (elm, html) {
var self = this;
self.$$(elm).each(function () {
try {
// Older FF doesn't have outerHTML 3.6 is still used by some organizations
if ("outerHTML" in this) {
this.outerHTML = html;
return;
}
} catch (ex) {
// Ignore
}
// OuterHTML for IE it sometimes produces an "unknown runtime error"
self.remove($(this).html(html), true);
});
} | javascript | {
"resource": ""
} | |
q35809 | train | function (node, referenceNode) {
referenceNode = this.get(referenceNode);
return this.run(node, function (node) {
var parent, nextSibling;
parent = referenceNode.parentNode;
nextSibling = referenceNode.nextSibling;
if (nextSibling) {
parent.insertBefore(node, nextSibling);
} else {
parent.appendChild(node);
}
return node;
});
} | javascript | {
"resource": ""
} | |
q35810 | train | function (elm, name) {
var self = this, newElm;
if (elm.nodeName != name.toUpperCase()) {
// Rename block element
newElm = self.create(name);
// Copy attribs to new block
each(self.getAttribs(elm), function (attrNode) {
self.setAttrib(newElm, attrNode.nodeName, self.getAttrib(elm, attrNode.nodeName));
});
// Replace block
self.replace(newElm, elm, 1);
}
return newElm || elm;
} | javascript | {
"resource": ""
} | |
q35811 | train | function (a, b) {
var ps = a, pe;
while (ps) {
pe = b;
while (pe && ps != pe) {
pe = pe.parentNode;
}
if (ps == pe) {
break;
}
ps = ps.parentNode;
}
if (!ps && a.ownerDocument) {
return a.ownerDocument.documentElement;
}
return ps;
} | javascript | {
"resource": ""
} | |
q35812 | train | function (elm) {
var attrs;
elm = this.get(elm);
if (!elm) {
return [];
}
if (isIE) {
attrs = [];
// Object will throw exception in IE
if (elm.nodeName == 'OBJECT') {
return elm.attributes;
}
// IE doesn't keep the selected attribute if you clone option elements
if (elm.nodeName === 'OPTION' && this.getAttrib(elm, 'selected')) {
attrs.push({ specified: 1, nodeName: 'selected' });
}
// It's crazy that this is faster in IE but it's because it returns all attributes all the time
var attrRegExp = /<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi;
elm.cloneNode(false).outerHTML.replace(attrRegExp, '').replace(/[\w:\-]+/gi, function (a) {
attrs.push({ specified: 1, nodeName: a });
});
return attrs;
}
return elm.attributes;
} | javascript | {
"resource": ""
} | |
q35813 | train | function (target, name, func, scope) {
var self = this;
if (Tools.isArray(target)) {
var i = target.length;
while (i--) {
target[i] = self.bind(target[i], name, func, scope);
}
return target;
}
// Collect all window/document events bound by editor instance
if (self.settings.collect && (target === self.doc || target === self.win)) {
self.boundEvents.push([target, name, func, scope]);
}
return self.events.bind(target, name, func, scope || self);
} | javascript | {
"resource": ""
} | |
q35814 | train | function (target, name, func) {
var self = this, i;
if (Tools.isArray(target)) {
i = target.length;
while (i--) {
target[i] = self.unbind(target[i], name, func);
}
return target;
}
// Remove any bound events matching the input
if (self.boundEvents && (target === self.doc || target === self.win)) {
i = self.boundEvents.length;
while (i--) {
var item = self.boundEvents[i];
if (target == item[0] && (!name || name == item[1]) && (!func || func == item[2])) {
this.events.unbind(item[0], item[1], item[2]);
}
}
}
return this.events.unbind(target, name, func);
} | javascript | {
"resource": ""
} | |
q35815 | train | function () {
var self = this;
// Unbind all events bound to window/document by editor instance
if (self.boundEvents) {
var i = self.boundEvents.length;
while (i--) {
var item = self.boundEvents[i];
this.events.unbind(item[0], item[1], item[2]);
}
self.boundEvents = null;
}
// Restore sizzle document to window.document
// Since the current document might be removed producing "Permission denied" on IE see #6325
if (Sizzle.setDocument) {
Sizzle.setDocument();
}
self.win = self.doc = self.root = self.events = self.frag = null;
} | javascript | {
"resource": ""
} | |
q35816 | loadScript | train | function loadScript(url, success, failure) {
var dom = DOM, elm, id;
// Execute callback when script is loaded
function done() {
dom.remove(id);
if (elm) {
elm.onreadystatechange = elm.onload = elm = null;
}
success();
}
function error() {
/*eslint no-console:0 */
// We can't mark it as done if there is a load error since
// A) We don't want to produce 404 errors on the server and
// B) the onerror event won't fire on all browsers.
// done();
if (isFunction(failure)) {
failure();
} else {
// Report the error so it's easier for people to spot loading errors
if (typeof console !== "undefined" && console.log) {
console.log("Failed to load script: " + url);
}
}
}
id = dom.uniqueId();
// Create new script element
elm = document.createElement('script');
elm.id = id;
elm.type = 'text/javascript';
elm.src = Tools._addCacheSuffix(url);
// Seems that onreadystatechange works better on IE 10 onload seems to fire incorrectly
if ("onreadystatechange" in elm) {
elm.onreadystatechange = function () {
if (/loaded|complete/.test(elm.readyState)) {
done();
}
};
} else {
elm.onload = done;
}
// Add onerror event will get fired on some browsers but not all of them
elm.onerror = error;
// Add script to document
(document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
} | javascript | {
"resource": ""
} |
q35817 | train | function (name, languages) {
var language = AddOnManager.language;
if (language && AddOnManager.languageLoad !== false) {
if (languages) {
languages = ',' + languages + ',';
// Load short form sv.js or long form sv_SE.js
if (languages.indexOf(',' + language.substr(0, 2) + ',') != -1) {
language = language.substr(0, 2);
} else if (languages.indexOf(',' + language + ',') == -1) {
return;
}
}
ScriptLoader.ScriptLoader.add(this.urls[name] + '/langs/' + language + '.js');
}
} | javascript | {
"resource": ""
} | |
q35818 | train | function (id, addOn, dependencies) {
this.items.push(addOn);
this.lookup[id] = { instance: addOn, dependencies: dependencies };
return addOn;
} | javascript | {
"resource": ""
} | |
q35819 | train | function (name, addOnUrl, success, scope, failure) {
var self = this, url = addOnUrl;
function loadDependencies() {
var dependencies = self.dependencies(name);
each(dependencies, function (dep) {
var newUrl = self.createUrl(addOnUrl, dep);
self.load(newUrl.resource, newUrl, undefined, undefined);
});
if (success) {
if (scope) {
success.call(scope);
} else {
success.call(ScriptLoader);
}
}
}
if (self.urls[name]) {
return;
}
if (typeof addOnUrl === "object") {
url = addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix;
}
if (url.indexOf('/') !== 0 && url.indexOf('://') == -1) {
url = AddOnManager.baseURL + '/' + url;
}
self.urls[name] = url.substring(0, url.lastIndexOf('/'));
if (self.lookup[name]) {
loadDependencies();
} else {
ScriptLoader.ScriptLoader.add(url, loadDependencies, scope, failure);
}
} | javascript | {
"resource": ""
} | |
q35820 | findClosestIeRange | train | function findClosestIeRange(clientX, clientY, doc) {
var element, rng, rects;
element = doc.elementFromPoint(clientX, clientY);
rng = doc.body.createTextRange();
if (!element || element.tagName == 'HTML') {
element = doc.body;
}
rng.moveToElementText(element);
rects = Tools.toArray(rng.getClientRects());
rects = rects.sort(function (a, b) {
a = Math.abs(Math.max(a.top - clientY, a.bottom - clientY));
b = Math.abs(Math.max(b.top - clientY, b.bottom - clientY));
return a - b;
});
if (rects.length > 0) {
clientY = (rects[0].bottom + rects[0].top) / 2;
try {
rng.moveToPoint(clientX, clientY);
rng.collapse(true);
return rng;
} catch (ex) {
// At least we tried
}
}
return null;
} | javascript | {
"resource": ""
} |
q35821 | Node | train | function Node(name, type) {
this.name = name;
this.type = type;
if (type === 1) {
this.attributes = [];
this.attributes.map = {};
}
} | javascript | {
"resource": ""
} |
q35822 | train | function (node, refNode, before) {
var parent;
if (node.parent) {
node.remove();
}
parent = refNode.parent || this;
if (before) {
if (refNode === parent.firstChild) {
parent.firstChild = node;
} else {
refNode.prev.next = node;
}
node.prev = refNode.prev;
node.next = refNode;
refNode.prev = node;
} else {
if (refNode === parent.lastChild) {
parent.lastChild = node;
} else {
refNode.next.prev = node;
}
node.next = refNode.next;
node.prev = refNode;
refNode.next = node;
}
node.parent = parent;
return node;
} | javascript | {
"resource": ""
} | |
q35823 | addCustomElements | train | function addCustomElements(customElements) {
var customElementRegExp = /^(~)?(.+)$/;
if (customElements) {
// Flush cached items since we are altering the default maps
mapCache.text_block_elements = mapCache.block_elements = null;
each(split(customElements, ','), function (rule) {
var matches = customElementRegExp.exec(rule),
inline = matches[1] === '~',
cloneName = inline ? 'span' : 'div',
name = matches[2];
children[name] = children[cloneName];
customElementsMap[name] = cloneName;
// If it's not marked as inline then add it to valid block elements
if (!inline) {
blockElementsMap[name.toUpperCase()] = {};
blockElementsMap[name] = {};
}
// Add elements clone if needed
if (!elements[name]) {
var customRule = elements[cloneName];
customRule = extend({}, customRule);
delete customRule.removeEmptyAttrs;
delete customRule.removeEmpty;
elements[name] = customRule;
}
// Add custom elements at span/div positions
each(children, function (element, elmName) {
if (element[cloneName]) {
children[elmName] = element = extend({}, children[elmName]);
element[name] = element[cloneName];
}
});
});
}
} | javascript | {
"resource": ""
} |
q35824 | findEndTag | train | function findEndTag(schema, html, startIndex) {
var count = 1, index, matches, tokenRegExp, shortEndedElements;
shortEndedElements = schema.getShortEndedElements();
tokenRegExp = /<([!?\/])?([A-Za-z0-9\-_\:\.]+)((?:\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\/|\s+)>/g;
tokenRegExp.lastIndex = index = startIndex;
while ((matches = tokenRegExp.exec(html))) {
index = tokenRegExp.lastIndex;
if (matches[1] === '/') { // End element
count--;
} else if (!matches[1]) { // Start element
if (matches[2] in shortEndedElements) {
continue;
}
count++;
}
if (count === 0) {
break;
}
}
return index;
} | javascript | {
"resource": ""
} |
q35825 | getBrClientRect | train | function getBrClientRect(brNode) {
var doc = brNode.ownerDocument,
rng = createRange(doc),
nbsp = doc.createTextNode('\u00a0'),
parentNode = brNode.parentNode,
clientRect;
parentNode.insertBefore(nbsp, brNode);
rng.setStart(nbsp, 0);
rng.setEnd(nbsp, 1);
clientRect = ClientRect.clone(rng.getBoundingClientRect());
parentNode.removeChild(nbsp);
return clientRect;
} | javascript | {
"resource": ""
} |
q35826 | CaretPosition | train | function CaretPosition(container, offset, clientRects) {
function isAtStart() {
if (isText(container)) {
return offset === 0;
}
return offset === 0;
}
function isAtEnd() {
if (isText(container)) {
return offset >= container.data.length;
}
return offset >= container.childNodes.length;
}
function toRange() {
var range;
range = createRange(container.ownerDocument);
range.setStart(container, offset);
range.setEnd(container, offset);
return range;
}
function getClientRects() {
if (!clientRects) {
clientRects = getCaretPositionClientRects(new CaretPosition(container, offset));
}
return clientRects;
}
function isVisible() {
return getClientRects().length > 0;
}
function isEqual(caretPosition) {
return caretPosition && container === caretPosition.container() && offset === caretPosition.offset();
}
function getNode(before) {
return resolveIndex(container, before ? offset - 1 : offset);
}
return {
/**
* Returns the container node.
*
* @method container
* @return {Node} Container node.
*/
container: Fun.constant(container),
/**
* Returns the offset within the container node.
*
* @method offset
* @return {Number} Offset within the container node.
*/
offset: Fun.constant(offset),
/**
* Returns a range out of a the caret position.
*
* @method toRange
* @return {DOMRange} range for the caret position.
*/
toRange: toRange,
/**
* Returns the client rects for the caret position. Might be multiple rects between
* block elements.
*
* @method getClientRects
* @return {Array} Array of client rects.
*/
getClientRects: getClientRects,
/**
* Returns true if the caret location is visible/displayed on screen.
*
* @method isVisible
* @return {Boolean} true/false if the position is visible or not.
*/
isVisible: isVisible,
/**
* Returns true if the caret location is at the beginning of text node or container.
*
* @method isVisible
* @return {Boolean} true/false if the position is at the beginning.
*/
isAtStart: isAtStart,
/**
* Returns true if the caret location is at the end of text node or container.
*
* @method isVisible
* @return {Boolean} true/false if the position is at the end.
*/
isAtEnd: isAtEnd,
/**
* Compares the caret position to another caret position. This will only compare the
* container and offset not it's visual position.
*
* @method isEqual
* @param {tinymce.caret.CaretPosition} caretPosition Caret position to compare with.
* @return {Boolean} true if the caret positions are equal.
*/
isEqual: isEqual,
/**
* Returns the closest resolved node from a node index. That means if you have an offset after the
* last node in a container it will return that last node.
*
* @method getNode
* @return {Node} Node that is closest to the index.
*/
getNode: getNode
};
} | javascript | {
"resource": ""
} |
q35827 | Selection | train | function Selection(dom, win, serializer, editor) {
var self = this;
self.dom = dom;
self.win = win;
self.serializer = serializer;
self.editor = editor;
self.bookmarkManager = new BookmarkManager(self);
self.controlSelection = new ControlSelection(self, editor);
// No W3C Range support
if (!self.win.getSelection) {
self.tridentSel = new TridentSelection(self);
}
} | javascript | {
"resource": ""
} |
q35828 | train | function (node, offset) {
var self = this, rng = self.dom.createRng();
if (!node) {
self._moveEndPoint(rng, self.editor.getBody(), true);
self.setRng(rng);
} else {
rng.setStart(node, offset);
rng.setEnd(node, offset);
self.setRng(rng);
self.collapse(false);
}
} | javascript | {
"resource": ""
} | |
q35829 | train | function (node, content) {
var self = this, dom = self.dom, rng = dom.createRng(), idx;
// Clear stored range set by FocusManager
self.lastFocusBookmark = null;
if (node) {
if (!content && self.controlSelection.controlSelect(node)) {
return;
}
idx = dom.nodeIndex(node);
rng.setStart(node.parentNode, idx);
rng.setEnd(node.parentNode, idx + 1);
// Find first/last text node or BR element
if (content) {
self._moveEndPoint(rng, node, true);
self._moveEndPoint(rng, node);
}
self.setRng(rng);
}
return node;
} | javascript | {
"resource": ""
} | |
q35830 | train | function (toStart) {
var self = this, rng = self.getRng(), node;
// Control range on IE
if (rng.item) {
node = rng.item(0);
rng = self.win.document.body.createTextRange();
rng.moveToElementText(node);
}
rng.collapse(!!toStart);
self.setRng(rng);
} | javascript | {
"resource": ""
} | |
q35831 | train | function (w3c) {
var self = this, selection, rng, elm, doc, ieRng, evt;
function tryCompareBoundaryPoints(how, sourceRange, destinationRange) {
try {
return sourceRange.compareBoundaryPoints(how, destinationRange);
} catch (ex) {
// Gecko throws wrong document exception if the range points
// to nodes that where removed from the dom #6690
// Browsers should mutate existing DOMRange instances so that they always point
// to something in the document this is not the case in Gecko works fine in IE/WebKit/Blink
// For performance reasons just return -1
return -1;
}
}
if (!self.win) {
return null;
}
doc = self.win.document;
if (typeof doc === 'undefined' || doc === null) {
return null;
}
// Use last rng passed from FocusManager if it's available this enables
// calls to editor.selection.getStart() to work when caret focus is lost on IE
if (!w3c && self.lastFocusBookmark) {
var bookmark = self.lastFocusBookmark;
// Convert bookmark to range IE 11 fix
if (bookmark.startContainer) {
rng = doc.createRange();
rng.setStart(bookmark.startContainer, bookmark.startOffset);
rng.setEnd(bookmark.endContainer, bookmark.endOffset);
} else {
rng = bookmark;
}
return rng;
}
// Found tridentSel object then we need to use that one
if (w3c && self.tridentSel) {
return self.tridentSel.getRangeAt(0);
}
try {
if ((selection = self.getSel())) {
if (selection.rangeCount > 0) {
rng = selection.getRangeAt(0);
} else {
rng = selection.createRange ? selection.createRange() : doc.createRange();
}
}
} catch (ex) {
// IE throws unspecified error here if TinyMCE is placed in a frame/iframe
}
evt = self.editor.fire('GetSelectionRange', { range: rng });
if (evt.range !== rng) {
return evt.range;
}
// We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
// IE 11 doesn't support the selection object so we check for that as well
if (isIE && rng && rng.setStart && doc.selection) {
try {
// IE will sometimes throw an exception here
ieRng = doc.selection.createRange();
} catch (ex) {
// Ignore
}
if (ieRng && ieRng.item) {
elm = ieRng.item(0);
rng = doc.createRange();
rng.setStartBefore(elm);
rng.setEndAfter(elm);
}
}
// No range found then create an empty one
// This can occur when the editor is placed in a hidden container element on Gecko
// Or on IE when there was an exception
if (!rng) {
rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
}
// If range is at start of document then move it to start of body
if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
elm = self.dom.getRoot();
rng.setStart(elm, 0);
rng.setEnd(elm, 0);
}
if (self.selectedRange && self.explicitRange) {
if (tryCompareBoundaryPoints(rng.START_TO_START, rng, self.selectedRange) === 0 &&
tryCompareBoundaryPoints(rng.END_TO_END, rng, self.selectedRange) === 0) {
// Safari, Opera and Chrome only ever select text which causes the range to change.
// This lets us use the originally set range if the selection hasn't been changed by the user.
rng = self.explicitRange;
} else {
self.selectedRange = null;
self.explicitRange = null;
}
}
return rng;
} | javascript | {
"resource": ""
} | |
q35832 | train | function () {
var self = this, rng = self.getRng(), elm;
var startContainer, endContainer, startOffset, endOffset, root = self.dom.getRoot();
function skipEmptyTextNodes(node, forwards) {
var orig = node;
while (node && node.nodeType === 3 && node.length === 0) {
node = forwards ? node.nextSibling : node.previousSibling;
}
return node || orig;
}
// Range maybe lost after the editor is made visible again
if (!rng) {
return root;
}
startContainer = rng.startContainer;
endContainer = rng.endContainer;
startOffset = rng.startOffset;
endOffset = rng.endOffset;
if (rng.setStart) {
elm = rng.commonAncestorContainer;
// Handle selection a image or other control like element such as anchors
if (!rng.collapsed) {
if (startContainer == endContainer) {
if (endOffset - startOffset < 2) {
if (startContainer.hasChildNodes()) {
elm = startContainer.childNodes[startOffset];
}
}
}
// If the anchor node is a element instead of a text node then return this element
//if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
// return sel.anchorNode.childNodes[sel.anchorOffset];
// Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
// This happens when you double click an underlined word in FireFox.
if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
if (startContainer.length === startOffset) {
startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);
} else {
startContainer = startContainer.parentNode;
}
if (endOffset === 0) {
endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);
} else {
endContainer = endContainer.parentNode;
}
if (startContainer && startContainer === endContainer) {
return startContainer;
}
}
}
if (elm && elm.nodeType == 3) {
return elm.parentNode;
}
return elm;
}
elm = rng.item ? rng.item(0) : rng.parentElement();
// IE 7 might return elements outside the iframe
if (elm.ownerDocument !== self.win.document) {
elm = root;
}
return elm;
} | javascript | {
"resource": ""
} | |
q35833 | getAttribs | train | function getAttribs(node) {
var attribs = {};
each(dom.getAttribs(node), function (attr) {
var name = attr.nodeName.toLowerCase();
// Don't compare internal attributes or style
if (name.indexOf('_') !== 0 && name !== 'style' && name.indexOf('data-') !== 0) {
attribs[name] = dom.getAttrib(node, name);
}
});
return attribs;
} | javascript | {
"resource": ""
} |
q35834 | compareObjects | train | function compareObjects(obj1, obj2) {
var value, name;
for (name in obj1) {
// Obj1 has item obj2 doesn't have
if (obj1.hasOwnProperty(name)) {
value = obj2[name];
// Obj2 doesn't have obj1 item
if (typeof value == "undefined") {
return false;
}
// Obj2 item has a different value
if (obj1[name] != value) {
return false;
}
// Delete similar value
delete obj2[name];
}
}
// Check if obj 2 has something obj 1 doesn't have
for (name in obj2) {
// Obj2 has item obj1 doesn't have
if (obj2.hasOwnProperty(name)) {
return false;
}
}
return true;
} | javascript | {
"resource": ""
} |
q35835 | process | train | function process(node) {
var children, i, l, lastContentEditable, hasContentEditableState;
// Node has a contentEditable value
if (node.nodeType === 1 && getContentEditable(node)) {
lastContentEditable = contentEditable;
contentEditable = getContentEditable(node) === "true";
hasContentEditableState = true; // We don't want to wrap the container only it's children
}
// Grab the children first since the nodelist might be changed
children = grep(node.childNodes);
// Process current node
if (contentEditable && !hasContentEditableState) {
for (i = 0, l = formatList.length; i < l; i++) {
if (removeFormat(formatList[i], vars, node, node)) {
break;
}
}
}
// Process the children
if (format.deep) {
if (children.length) {
for (i = 0, l = children.length; i < l; i++) {
process(children[i]);
}
if (hasContentEditableState) {
contentEditable = lastContentEditable; // Restore last contentEditable state from stack
}
}
}
} | javascript | {
"resource": ""
} |
q35836 | match | train | function match(name, vars, node) {
var startNode;
function matchParents(node) {
var root = dom.getRoot();
if (node === root) {
return false;
}
// Find first node with similar format settings
node = dom.getParent(node, function (node) {
if (matchesUnInheritedFormatSelector(node, name)) {
return true;
}
return node.parentNode === root || !!matchNode(node, name, vars, true);
});
// Do an exact check on the similar format element
return matchNode(node, name, vars);
}
// Check specified node
if (node) {
return matchParents(node);
}
// Check selected node
node = selection.getNode();
if (matchParents(node)) {
return TRUE;
}
// Check start node if it's different
startNode = selection.getStart();
if (startNode != node) {
if (matchParents(startNode)) {
return TRUE;
}
}
return FALSE;
} | javascript | {
"resource": ""
} |
q35837 | formatChanged | train | function formatChanged(formats, callback, similar) {
var currentFormats;
// Setup format node change logic
if (!formatChangeData) {
formatChangeData = {};
currentFormats = {};
ed.on('NodeChange', function (e) {
var parents = getParents(e.element), matchedFormats = {};
// Ignore bogus nodes like the <a> tag created by moveStart()
parents = Tools.grep(parents, function (node) {
return node.nodeType == 1 && !node.getAttribute('data-mce-bogus');
});
// Check for new formats
each(formatChangeData, function (callbacks, format) {
each(parents, function (node) {
if (matchNode(node, format, {}, callbacks.similar)) {
if (!currentFormats[format]) {
// Execute callbacks
each(callbacks, function (callback) {
callback(true, { node: node, format: format, parents: parents });
});
currentFormats[format] = callbacks;
}
matchedFormats[format] = callbacks;
return false;
}
if (matchesUnInheritedFormatSelector(node, format)) {
return false;
}
});
});
// Check if current formats still match
each(currentFormats, function (callbacks, format) {
if (!matchedFormats[format]) {
delete currentFormats[format];
each(callbacks, function (callback) {
callback(false, { node: e.element, format: format, parents: parents });
});
}
});
});
}
// Add format listeners
each(formats.split(','), function (format) {
if (!formatChangeData[format]) {
formatChangeData[format] = [];
formatChangeData[format].similar = similar;
}
formatChangeData[format].push(callback);
});
return this;
} | javascript | {
"resource": ""
} |
q35838 | replaceVars | train | function replaceVars(value, vars) {
if (typeof value != "string") {
value = value(vars);
} else if (vars) {
value = value.replace(/%(\w+)/g, function (str, name) {
return vars[name] || str;
});
}
return value;
} | javascript | {
"resource": ""
} |
q35839 | removeFormat | train | function removeFormat(format, vars, node, compareNode) {
var i, attrs, stylesModified;
// Check if node matches format
if (!matchName(node, format) && !isColorFormatAndAnchor(node, format)) {
return FALSE;
}
// Should we compare with format attribs and styles
if (format.remove != 'all') {
// Remove styles
each(format.styles, function (value, name) {
value = normalizeStyleValue(replaceVars(value, vars), name);
// Indexed array
if (typeof name === 'number') {
name = value;
compareNode = 0;
}
if (format.remove_similar || (!compareNode || isEq(getStyle(compareNode, name), value))) {
dom.setStyle(node, name, '');
}
stylesModified = 1;
});
// Remove style attribute if it's empty
if (stylesModified && dom.getAttrib(node, 'style') === '') {
node.removeAttribute('style');
node.removeAttribute('data-mce-style');
}
// Remove attributes
each(format.attributes, function (value, name) {
var valueOut;
value = replaceVars(value, vars);
// Indexed array
if (typeof name === 'number') {
name = value;
compareNode = 0;
}
if (!compareNode || isEq(dom.getAttrib(compareNode, name), value)) {
// Keep internal classes
if (name == 'class') {
value = dom.getAttrib(node, name);
if (value) {
// Build new class value where everything is removed except the internal prefixed classes
valueOut = '';
each(value.split(/\s+/), function (cls) {
if (/mce\-\w+/.test(cls)) {
valueOut += (valueOut ? ' ' : '') + cls;
}
});
// We got some internal classes left
if (valueOut) {
dom.setAttrib(node, name, valueOut);
return;
}
}
}
// IE6 has a bug where the attribute doesn't get removed correctly
if (name == "class") {
node.removeAttribute('className');
}
// Remove mce prefixed attributes
if (MCE_ATTR_RE.test(name)) {
node.removeAttribute('data-mce-' + name);
}
node.removeAttribute(name);
}
});
// Remove classes
each(format.classes, function (value) {
value = replaceVars(value, vars);
if (!compareNode || dom.hasClass(compareNode, value)) {
dom.removeClass(node, value);
}
});
// Check for non internal attributes
attrs = dom.getAttribs(node);
for (i = 0; i < attrs.length; i++) {
var attrName = attrs[i].nodeName;
if (attrName.indexOf('_') !== 0 && attrName.indexOf('data-') !== 0) {
return FALSE;
}
}
}
// Remove the inline child if it's empty for example <b> or <span>
if (format.remove != 'none') {
removeNode(node, format);
return TRUE;
}
} | javascript | {
"resource": ""
} |
q35840 | createCaretContainer | train | function createCaretContainer(fill) {
var caretContainer = dom.create('span', { id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : '' });
if (fill) {
caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR));
}
return caretContainer;
} | javascript | {
"resource": ""
} |
q35841 | getParentCaretContainer | train | function getParentCaretContainer(node) {
while (node) {
if (node.id === caretContainerId) {
return node;
}
node = node.parentNode;
}
} | javascript | {
"resource": ""
} |
q35842 | findFirstTextNode | train | function findFirstTextNode(node) {
var walker;
if (node) {
walker = new TreeWalker(node, node);
for (node = walker.current(); node; node = walker.next()) {
if (node.nodeType === 3) {
return node;
}
}
}
} | javascript | {
"resource": ""
} |
q35843 | applyCaretFormat | train | function applyCaretFormat() {
var rng, caretContainer, textNode, offset, bookmark, container, text;
rng = selection.getRng(true);
offset = rng.startOffset;
container = rng.startContainer;
text = container.nodeValue;
caretContainer = getParentCaretContainer(selection.getStart());
if (caretContainer) {
textNode = findFirstTextNode(caretContainer);
}
// Expand to word if caret is in the middle of a text node and the char before/after is a alpha numeric character
var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/;
if (text && offset > 0 && offset < text.length &&
wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) {
// Get bookmark of caret position
bookmark = selection.getBookmark();
// Collapse bookmark range (WebKit)
rng.collapse(true);
// Expand the range to the closest word and split it at those points
rng = expandRng(rng, get(name));
rng = rangeUtils.split(rng);
// Apply the format to the range
apply(name, vars, rng);
// Move selection back to caret position
selection.moveToBookmark(bookmark);
} else {
if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
caretContainer = createCaretContainer(true);
textNode = caretContainer.firstChild;
rng.insertNode(caretContainer);
offset = 1;
apply(name, vars, caretContainer);
} else {
apply(name, vars, caretContainer);
}
// Move selection to text node
selection.setCursorLocation(textNode, offset);
}
} | javascript | {
"resource": ""
} |
q35844 | moveStart | train | function moveStart(rng) {
var container = rng.startContainer,
offset = rng.startOffset, isAtEndOfText,
walker, node, nodes, tmpNode;
if (rng.startContainer == rng.endContainer) {
if (isInlineBlock(rng.startContainer.childNodes[rng.startOffset])) {
return;
}
}
// Convert text node into index if possible
if (container.nodeType == 3 && offset >= container.nodeValue.length) {
// Get the parent container location and walk from there
offset = nodeIndex(container);
container = container.parentNode;
isAtEndOfText = true;
}
// Move startContainer/startOffset in to a suitable node
if (container.nodeType == 1) {
nodes = container.childNodes;
container = nodes[Math.min(offset, nodes.length - 1)];
walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
// If offset is at end of the parent node walk to the next one
if (offset > nodes.length - 1 || isAtEndOfText) {
walker.next();
}
for (node = walker.current(); node; node = walker.next()) {
if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
// IE has a "neat" feature where it moves the start node into the closest element
// we can avoid this by inserting an element before it and then remove it after we set the selection
tmpNode = dom.create('a', { 'data-mce-bogus': 'all' }, INVISIBLE_CHAR);
node.parentNode.insertBefore(tmpNode, node);
// Set selection and remove tmpNode
rng.setStart(node, 0);
selection.setRng(rng);
dom.remove(tmpNode);
return;
}
}
}
} | javascript | {
"resource": ""
} |
q35845 | train | function () {
var level;
if (index < data.length - 1) {
level = data[++index];
Levels.applyToEditor(editor, level, false);
setDirty(true);
editor.fire('redo', { level: level });
}
return level;
} | javascript | {
"resource": ""
} | |
q35846 | train | function () {
data = [];
index = 0;
self.typing = false;
self.data = data;
editor.fire('ClearUndos');
} | javascript | {
"resource": ""
} | |
q35847 | train | function (callback1, callback2) {
var lastLevel, bookmark;
if (self.transact(callback1)) {
bookmark = data[index].bookmark;
lastLevel = data[index - 1];
Levels.applyToEditor(editor, lastLevel, true);
if (self.transact(callback2)) {
data[index - 1].beforeBookmark = bookmark;
}
}
} | javascript | {
"resource": ""
} | |
q35848 | execCommand | train | function execCommand(command, ui, value, args) {
var func, customCommand, state = 0;
if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(command) && (!args || !args.skip_focus)) {
editor.focus();
}
args = editor.fire('BeforeExecCommand', { command: command, ui: ui, value: value });
if (args.isDefaultPrevented()) {
return false;
}
customCommand = command.toLowerCase();
if ((func = commands.exec[customCommand])) {
func(customCommand, ui, value);
editor.fire('ExecCommand', { command: command, ui: ui, value: value });
return true;
}
// Plugin commands
each(editor.plugins, function (p) {
if (p.execCommand && p.execCommand(command, ui, value)) {
editor.fire('ExecCommand', { command: command, ui: ui, value: value });
state = true;
return false;
}
});
if (state) {
return state;
}
// Theme commands
if (editor.theme && editor.theme.execCommand && editor.theme.execCommand(command, ui, value)) {
editor.fire('ExecCommand', { command: command, ui: ui, value: value });
return true;
}
// Browser commands
try {
state = editor.getDoc().execCommand(command, ui, value);
} catch (ex) {
// Ignore old IE errors
}
if (state) {
editor.fire('ExecCommand', { command: command, ui: ui, value: value });
return true;
}
return false;
} | javascript | {
"resource": ""
} |
q35849 | queryCommandState | train | function queryCommandState(command) {
var func;
// Is hidden then return undefined
if (editor.quirks.isHidden()) {
return;
}
command = command.toLowerCase();
if ((func = commands.state[command])) {
return func(command);
}
// Browser commands
try {
return editor.getDoc().queryCommandState(command);
} catch (ex) {
// Fails sometimes see bug: 1896577
}
return false;
} | javascript | {
"resource": ""
} |
q35850 | train | function () {
if (selection.isCollapsed()) {
var elm = editor.dom.getParent(editor.selection.getStart(), 'a');
if (elm) {
editor.dom.remove(elm, true);
}
return;
}
formatter.remove("link");
} | javascript | {
"resource": ""
} | |
q35851 | train | function (command) {
var align = command.substring(7);
if (align == 'full') {
align = 'justify';
}
// Remove all other alignments first
each('left,center,right,justify'.split(','), function (name) {
if (align != name) {
formatter.remove('align' + name);
}
});
if (align != 'none') {
toggleFormat('align' + align);
}
} | javascript | {
"resource": ""
} | |
q35852 | hasRightSideContent | train | function hasRightSideContent() {
var walker = new TreeWalker(container, parentBlock), node;
var nonEmptyElementsMap = editor.schema.getNonEmptyElements();
while ((node = walker.next())) {
if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
return true;
}
}
} | javascript | {
"resource": ""
} |
q35853 | URI | train | function URI(url, settings) {
var self = this, baseUri, baseUrl;
url = trim(url);
settings = self.settings = settings || {};
baseUri = settings.base_uri;
// Strange app protocol that isn't http/https or local anchor
// For example: mailto,skype,tel etc.
if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
self.source = url;
return;
}
var isProtocolRelative = url.indexOf('//') === 0;
// Absolute path with no host, fake host and protocol
if (url.indexOf('/') === 0 && !isProtocolRelative) {
url = (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url;
}
// Relative path http:// or protocol relative //path
if (!/^[\w\-]*:?\/\//.test(url)) {
baseUrl = settings.base_uri ? settings.base_uri.path : new URI(location.href).directory;
if (settings.base_uri.protocol === "") {
url = '//mce_host' + self.toAbsPath(baseUrl, url);
} else {
url = /([^#?]*)([#?]?.*)/.exec(url);
url = ((baseUri && baseUri.protocol) || 'http') + '://mce_host' + self.toAbsPath(baseUrl, url[1]) + url[2];
}
}
// Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
url = url.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
/*jshint maxlen: 255 */
/*eslint max-len: 0 */
url = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
each(queryParts, function (v, i) {
var part = url[i];
// Zope 3 workaround, they use @@something
if (part) {
part = part.replace(/\(mce_at\)/g, '@@');
}
self[v] = part;
});
if (baseUri) {
if (!self.protocol) {
self.protocol = baseUri.protocol;
}
if (!self.userInfo) {
self.userInfo = baseUri.userInfo;
}
if (!self.port && self.host === 'mce_host') {
self.port = baseUri.port;
}
if (!self.host || self.host === 'mce_host') {
self.host = baseUri.host;
}
self.source = '';
}
if (isProtocolRelative) {
self.protocol = '';
}
//t.path = t.path || '/';
} | javascript | {
"resource": ""
} |
q35854 | train | function (path) {
var self = this;
path = /^(.*?)\/?(\w+)?$/.exec(path);
// Update path parts
self.path = path[0];
self.directory = path[1];
self.file = path[2];
// Rebuild source
self.source = '';
self.getURI();
} | javascript | {
"resource": ""
} | |
q35855 | train | function (uri) {
var self = this, output;
if (uri === "./") {
return uri;
}
uri = new URI(uri, { base_uri: self });
// Not on same domain/port or protocol
if ((uri.host != 'mce_host' && self.host != uri.host && uri.host) || self.port != uri.port ||
(self.protocol != uri.protocol && uri.protocol !== "")) {
return uri.getURI();
}
var tu = self.getURI(), uu = uri.getURI();
// Allow usage of the base_uri when relative_urls = true
if (tu == uu || (tu.charAt(tu.length - 1) == "/" && tu.substr(0, tu.length - 1) == uu)) {
return tu;
}
output = self.toRelPath(self.path, uri.path);
// Add query
if (uri.query) {
output += '?' + uri.query;
}
// Add anchor
if (uri.anchor) {
output += '#' + uri.anchor;
}
return output;
} | javascript | {
"resource": ""
} | |
q35856 | train | function (uri, noHost) {
uri = new URI(uri, { base_uri: this });
return uri.getURI(noHost && this.isSameOrigin(uri));
} | javascript | {
"resource": ""
} | |
q35857 | train | function (noProtoHost) {
var s, self = this;
// Rebuild source
if (!self.source || noProtoHost) {
s = '';
if (!noProtoHost) {
if (self.protocol) {
s += self.protocol + '://';
} else {
s += '//';
}
if (self.userInfo) {
s += self.userInfo + '@';
}
if (self.host) {
s += self.host;
}
if (self.port) {
s += ':' + self.port;
}
}
if (self.path) {
s += self.path;
}
if (self.query) {
s += '?' + self.query;
}
if (self.anchor) {
s += '#' + self.anchor;
}
self.source = s;
}
return self.source;
} | javascript | {
"resource": ""
} | |
q35858 | fire | train | function fire(name, args) {
var handlers, i, l, callback;
name = name.toLowerCase();
args = args || {};
args.type = name;
// Setup target is there isn't one
if (!args.target) {
args.target = scope;
}
// Add event delegation methods if they are missing
if (!args.preventDefault) {
// Add preventDefault method
args.preventDefault = function () {
args.isDefaultPrevented = returnTrue;
};
// Add stopPropagation
args.stopPropagation = function () {
args.isPropagationStopped = returnTrue;
};
// Add stopImmediatePropagation
args.stopImmediatePropagation = function () {
args.isImmediatePropagationStopped = returnTrue;
};
// Add event delegation states
args.isDefaultPrevented = returnFalse;
args.isPropagationStopped = returnFalse;
args.isImmediatePropagationStopped = returnFalse;
}
if (settings.beforeFire) {
settings.beforeFire(args);
}
handlers = bindings[name];
if (handlers) {
for (i = 0, l = handlers.length; i < l; i++) {
callback = handlers[i];
// Unbind handlers marked with "once"
if (callback.once) {
off(name, callback.func);
}
// Stop immediate propagation if needed
if (args.isImmediatePropagationStopped()) {
args.stopPropagation();
return args;
}
// If callback returns false then prevent default and stop all propagation
if (callback.func.call(scope, args) === false) {
args.preventDefault();
return args;
}
}
}
return args;
} | javascript | {
"resource": ""
} |
q35859 | on | train | function on(name, callback, prepend, extra) {
var handlers, names, i;
if (callback === false) {
callback = returnFalse;
}
if (callback) {
callback = {
func: callback
};
if (extra) {
Tools.extend(callback, extra);
}
names = name.toLowerCase().split(' ');
i = names.length;
while (i--) {
name = names[i];
handlers = bindings[name];
if (!handlers) {
handlers = bindings[name] = [];
toggleEvent(name, true);
}
if (prepend) {
handlers.unshift(callback);
} else {
handlers.push(callback);
}
}
}
return self;
} | javascript | {
"resource": ""
} |
q35860 | off | train | function off(name, callback) {
var i, handlers, bindingName, names, hi;
if (name) {
names = name.toLowerCase().split(' ');
i = names.length;
while (i--) {
name = names[i];
handlers = bindings[name];
// Unbind all handlers
if (!name) {
for (bindingName in bindings) {
toggleEvent(bindingName, false);
delete bindings[bindingName];
}
return self;
}
if (handlers) {
// Unbind all by name
if (!callback) {
handlers.length = 0;
} else {
// Unbind specific ones
hi = handlers.length;
while (hi--) {
if (handlers[hi].func === callback) {
handlers = handlers.slice(0, hi).concat(handlers.slice(hi + 1));
bindings[name] = handlers;
}
}
}
if (!handlers.length) {
toggleEvent(name, false);
delete bindings[name];
}
}
}
} else {
for (name in bindings) {
toggleEvent(name, false);
}
bindings = {};
}
return self;
} | javascript | {
"resource": ""
} |
q35861 | once | train | function once(name, callback, prepend) {
return on(name, callback, prepend, { once: true });
} | javascript | {
"resource": ""
} |
q35862 | train | function (data) {
var name, value;
data = data || {};
for (name in data) {
value = data[name];
if (value instanceof Binding) {
data[name] = value.create(this, name);
}
}
this.data = data;
} | javascript | {
"resource": ""
} | |
q35863 | train | function (name, value) {
var key, args, oldValue = this.data[name];
if (value instanceof Binding) {
value = value.create(this, name);
}
if (typeof name === "object") {
for (key in name) {
this.set(key, name[key]);
}
return this;
}
if (!isEqual(oldValue, value)) {
this.data[name] = value;
args = {
target: this,
name: name,
value: value,
oldValue: oldValue
};
this.fire('change:' + name, args);
this.fire('change', args);
}
return this;
} | javascript | {
"resource": ""
} | |
q35864 | unique | train | function unique(array) {
var uniqueItems = [], i = array.length, item;
while (i--) {
item = array[i];
if (!item.__checked) {
uniqueItems.push(item);
item.__checked = 1;
}
}
i = uniqueItems.length;
while (i--) {
delete uniqueItems[i].__checked;
}
return uniqueItems;
} | javascript | {
"resource": ""
} |
q35865 | parseChunks | train | function parseChunks(selector, selectors) {
var parts = [], extra, matches, i;
do {
chunker.exec("");
matches = chunker.exec(selector);
if (matches) {
selector = matches[3];
parts.push(matches[1]);
if (matches[2]) {
extra = matches[3];
break;
}
}
} while (matches);
if (extra) {
parseChunks(extra, selectors);
}
selector = [];
for (i = 0; i < parts.length; i++) {
if (parts[i] != '>') {
selector.push(compile(parts[i], [], parts[i - 1] === '>'));
}
}
selectors.push(selector);
return selectors;
} | javascript | {
"resource": ""
} |
q35866 | train | function (container) {
var matches = [], i, l, selectors = this._selectors;
function collect(items, selector, index) {
var i, l, fi, fl, item, filters = selector[index];
for (i = 0, l = items.length; i < l; i++) {
item = items[i];
// Run each filter against the item
for (fi = 0, fl = filters.length; fi < fl; fi++) {
if (!filters[fi](item, i, l)) {
fi = fl + 1;
break;
}
}
// All filters matched the item
if (fi === fl) {
// Matched item is on the last expression like: panel toolbar [button]
if (index == selector.length - 1) {
matches.push(item);
} else {
// Collect next expression type
if (item.items) {
collect(item.items(), selector, index + 1);
}
}
} else if (filters.direct) {
return;
}
// Collect child items
if (item.items) {
collect(item.items(), selector, index);
}
}
}
if (container.items) {
for (i = 0, l = selectors.length; i < l; i++) {
collect(container.items(), selectors[i], 0);
}
// Unique the matches if needed
if (l > 1) {
matches = unique(matches);
}
}
// Fix for circular reference
if (!Collection) {
// TODO: Fix me!
Collection = Selector.Collection;
}
return new Collection(matches);
} | javascript | {
"resource": ""
} | |
q35867 | train | function (items) {
var self = this;
// Force single item into array
if (!Tools.isArray(items)) {
if (items instanceof Collection) {
self.add(items.toArray());
} else {
push.call(self, items);
}
} else {
push.apply(self, items);
}
return self;
} | javascript | {
"resource": ""
} | |
q35868 | train | function (items) {
var self = this, len = self.length, i;
self.length = 0;
self.add(items);
// Remove old entries
for (i = self.length; i < len; i++) {
delete self[i];
}
return self;
} | javascript | {
"resource": ""
} | |
q35869 | train | function (selector) {
var self = this, i, l, matches = [], item, match;
// Compile string into selector expression
if (typeof selector === "string") {
selector = new Selector(selector);
match = function (item) {
return selector.match(item);
};
} else {
// Use selector as matching function
match = selector;
}
for (i = 0, l = self.length; i < l; i++) {
item = self[i];
if (match(item)) {
matches.push(item);
}
}
return new Collection(matches);
} | javascript | {
"resource": ""
} | |
q35870 | train | function (ctrl) {
var self = this, i = self.length;
while (i--) {
if (self[i] === ctrl) {
break;
}
}
return i;
} | javascript | {
"resource": ""
} | |
q35871 | train | function (name) {
var self = this, args = Tools.toArray(arguments).slice(1);
self.each(function (item) {
if (item[name]) {
item[name].apply(item, args);
}
});
return self;
} | javascript | {
"resource": ""
} | |
q35872 | train | function (value) {
var len, radix = 10;
if (!value) {
return;
}
if (typeof value === "number") {
value = value || 0;
return {
top: value,
left: value,
bottom: value,
right: value
};
}
value = value.split(' ');
len = value.length;
if (len === 1) {
value[1] = value[2] = value[3] = value[0];
} else if (len === 2) {
value[2] = value[0];
value[3] = value[1];
} else if (len === 3) {
value[3] = value[1];
}
return {
top: parseInt(value[0], radix) || 0,
right: parseInt(value[1], radix) || 0,
bottom: parseInt(value[2], radix) || 0,
left: parseInt(value[3], radix) || 0
};
} | javascript | {
"resource": ""
} | |
q35873 | train | function (cls) {
if (cls && !this.contains(cls)) {
this.cls._map[cls] = true;
this.cls.push(cls);
this._change();
}
return this;
} | javascript | {
"resource": ""
} | |
q35874 | train | function (cls) {
if (this.contains(cls)) {
for (var i = 0; i < this.cls.length; i++) {
if (this.cls[i] === cls) {
break;
}
}
this.cls.splice(i, 1);
delete this.cls._map[cls];
this._change();
}
return this;
} | javascript | {
"resource": ""
} | |
q35875 | train | function (cls, state) {
var curState = this.contains(cls);
if (curState !== state) {
if (curState) {
this.remove(cls);
} else {
this.add(cls);
}
this._change();
}
return this;
} | javascript | {
"resource": ""
} | |
q35876 | train | function (elm) {
var ctrl, lookup = this.getRoot().controlIdLookup;
while (elm && lookup) {
ctrl = lookup[elm.id];
if (ctrl) {
break;
}
elm = elm.parentNode;
}
return ctrl;
} | javascript | {
"resource": ""
} | |
q35877 | train | function () {
var self = this;
self.parent()._lastRect = null;
DomUtils.css(self.getEl(), { width: '', height: '' });
self._layoutRect = self._lastRepaintRect = self._lastLayoutRect = null;
self.initLayoutRect();
} | javascript | {
"resource": ""
} | |
q35878 | train | function (name, callback) {
var self = this;
function resolveCallbackName(name) {
var callback, scope;
if (typeof name != 'string') {
return name;
}
return function (e) {
if (!callback) {
self.parentsAndSelf().each(function (ctrl) {
var callbacks = ctrl.settings.callbacks;
if (callbacks && (callback = callbacks[name])) {
scope = ctrl;
return false;
}
});
}
if (!callback) {
e.action = name;
this.fire('execute', e);
return;
}
return callback.call(scope, e);
};
}
getEventDispatcher(self).on(name, resolveCallbackName(callback));
return self;
} | javascript | {
"resource": ""
} | |
q35879 | train | function (selector) {
var self = this, ctrl, parents = new Collection();
// Add each parent to collection
for (ctrl = self.parent(); ctrl; ctrl = ctrl.parent()) {
parents.add(ctrl);
}
// Filter away everything that doesn't match the selector
if (selector) {
parents = parents.filter(selector);
}
return parents;
} | javascript | {
"resource": ""
} | |
q35880 | train | function (suffix) {
var id = suffix ? this._id + '-' + suffix : this._id;
if (!this._elmCache[id]) {
this._elmCache[id] = $('#' + id)[0];
}
return this._elmCache[id];
} | javascript | {
"resource": ""
} | |
q35881 | train | function (name, value) {
var self = this, elm = self.getEl(self.ariaTarget);
if (typeof value === "undefined") {
return self._aria[name];
}
self._aria[name] = value;
if (self.state.get('rendered')) {
elm.setAttribute(name == 'role' ? name : 'aria-' + name, value);
}
return self;
} | javascript | {
"resource": ""
} | |
q35882 | train | function (text, translate) {
if (translate !== false) {
text = this.translate(text);
}
return (text || '').replace(/[&<>"]/g, function (match) {
return '&#' + match.charCodeAt(0) + ';';
});
} | javascript | {
"resource": ""
} | |
q35883 | train | function (items) {
var self = this, parent = self.parent();
if (parent) {
parent.insert(items, parent.items().indexOf(self), true);
}
return self;
} | javascript | {
"resource": ""
} | |
q35884 | train | function (align) {
function getOffset(elm, rootElm) {
var x, y, parent = elm;
x = y = 0;
while (parent && parent != rootElm && parent.nodeType) {
x += parent.offsetLeft || 0;
y += parent.offsetTop || 0;
parent = parent.offsetParent;
}
return { x: x, y: y };
}
var elm = this.getEl(), parentElm = elm.parentNode;
var x, y, width, height, parentWidth, parentHeight;
var pos = getOffset(elm, parentElm);
x = pos.x;
y = pos.y;
width = elm.offsetWidth;
height = elm.offsetHeight;
parentWidth = parentElm.clientWidth;
parentHeight = parentElm.clientHeight;
if (align == "end") {
x -= parentWidth - width;
y -= parentHeight - height;
} else if (align == "center") {
x -= (parentWidth / 2) - (width / 2);
y -= (parentHeight / 2) - (height / 2);
}
parentElm.scrollLeft = x;
parentElm.scrollTop = y;
return this;
} | javascript | {
"resource": ""
} | |
q35885 | train | function () {
ReflowQueue.remove(this);
var parent = this.parent();
if (parent._layout && !parent._layout.isNative()) {
parent.reflow();
}
return this;
} | javascript | {
"resource": ""
} | |
q35886 | train | function (type, settings) {
var ControlType;
// If string is specified then use it as the type
if (typeof type == 'string') {
settings = settings || {};
settings.type = type;
} else {
settings = type;
type = settings.type;
}
// Find control type
type = type.toLowerCase();
ControlType = types[type];
// #if debug
if (!ControlType) {
throw new Error("Could not find control by type: " + type);
}
// #endif
ControlType = new ControlType(settings);
ControlType.type = type; // Set the type on the instance, this will be used by the Selector engine
return ControlType;
} | javascript | {
"resource": ""
} | |
q35887 | getRole | train | function getRole(elm) {
elm = elm || focusedElement;
if (isElement(elm)) {
return elm.getAttribute('role');
}
return null;
} | javascript | {
"resource": ""
} |
q35888 | getParentRole | train | function getParentRole(elm) {
var role, parent = elm || focusedElement;
while ((parent = parent.parentNode)) {
if ((role = getRole(parent))) {
return role;
}
}
} | javascript | {
"resource": ""
} |
q35889 | getFocusElements | train | function getFocusElements(elm) {
var elements = [];
function collect(elm) {
if (elm.nodeType != 1 || elm.style.display == 'none' || elm.disabled) {
return;
}
if (canFocus(elm)) {
elements.push(elm);
}
for (var i = 0; i < elm.childNodes.length; i++) {
collect(elm.childNodes[i]);
}
}
collect(elm || root.getEl());
return elements;
} | javascript | {
"resource": ""
} |
q35890 | getNavigationRoot | train | function getNavigationRoot(targetControl) {
var navigationRoot, controls;
targetControl = targetControl || focusedControl;
controls = targetControl.parents().toArray();
controls.unshift(targetControl);
for (var i = 0; i < controls.length; i++) {
navigationRoot = controls[i];
if (navigationRoot.settings.ariaRoot) {
break;
}
}
return navigationRoot;
} | javascript | {
"resource": ""
} |
q35891 | focusFirst | train | function focusFirst(targetControl) {
var navigationRoot = getNavigationRoot(targetControl);
var focusElements = getFocusElements(navigationRoot.getEl());
if (navigationRoot.settings.ariaRemember && "lastAriaIndex" in navigationRoot) {
moveFocusToIndex(navigationRoot.lastAriaIndex, focusElements);
} else {
moveFocusToIndex(0, focusElements);
}
} | javascript | {
"resource": ""
} |
q35892 | moveFocusToIndex | train | function moveFocusToIndex(idx, elements) {
if (idx < 0) {
idx = elements.length - 1;
} else if (idx >= elements.length) {
idx = 0;
}
if (elements[idx]) {
elements[idx].focus();
}
return idx;
} | javascript | {
"resource": ""
} |
q35893 | moveFocus | train | function moveFocus(dir, elements) {
var idx = -1, navigationRoot = getNavigationRoot();
elements = elements || getFocusElements(navigationRoot.getEl());
for (var i = 0; i < elements.length; i++) {
if (elements[i] === focusedElement) {
idx = i;
}
}
idx += dir;
navigationRoot.lastAriaIndex = moveFocusToIndex(idx, elements);
} | javascript | {
"resource": ""
} |
q35894 | left | train | function left() {
var parentRole = getParentRole();
if (parentRole == "tablist") {
moveFocus(-1, getFocusElements(focusedElement.parentNode));
} else if (focusedControl.parent().submenu) {
cancel();
} else {
moveFocus(-1);
}
} | javascript | {
"resource": ""
} |
q35895 | right | train | function right() {
var role = getRole(), parentRole = getParentRole();
if (parentRole == "tablist") {
moveFocus(1, getFocusElements(focusedElement.parentNode));
} else if (role == "menuitem" && parentRole == "menu" && getAriaProp('haspopup')) {
enter();
} else {
moveFocus(1);
}
} | javascript | {
"resource": ""
} |
q35896 | down | train | function down() {
var role = getRole(), parentRole = getParentRole();
if (role == "menuitem" && parentRole == "menubar") {
enter();
} else if (role == "button" && getAriaProp('haspopup')) {
enter({ key: 'down' });
} else {
moveFocus(1);
}
} | javascript | {
"resource": ""
} |
q35897 | tab | train | function tab(e) {
var parentRole = getParentRole();
if (parentRole == "tablist") {
var elm = getFocusElements(focusedControl.getEl('body'))[0];
if (elm) {
elm.focus();
}
} else {
moveFocus(e.shiftKey ? -1 : 1);
}
} | javascript | {
"resource": ""
} |
q35898 | train | function (selector) {
selector = selectorCache[selector] = selectorCache[selector] || new Selector(selector);
return selector.find(this);
} | javascript | {
"resource": ""
} | |
q35899 | train | function (items) {
var self = this;
self.items().add(self.create(items)).parent(self);
return self;
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.