Skip to content

Instantly share code, notes, and snippets.

function getNearestTextNode(node, forward) {
var body = node.ownerDocument.body,
sibling = forward ? 'nextSibling' : 'previousSibling',
child = forward ? 'firstChild' : 'lastChild',
current = node;
do {
node = current[sibling], current = node || current.parentNode;
if (current == body) return;
}
while (!node);
/*
* QWE - Browser
*
* Copyright (c) 2009 [Daniel Steigerwald](http://daniel.steigerwald.cz)
*/
QWE()(function(Q) {
Browser = {
platform: (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase(),
features: {
Type.extend({
/*
* BOM/DOM iterable objects are: array, arguments, nodeList
* - from bigger picture, iterable javascript objects has to support length and [] -> index access
* - but index access can't be tested.. :-(
* - also, for safari typeof nodeList == function..
* - and length property has also string or function, which are uniterable
* - so duck typing ftw!
*/
Class = new Type('Class', function(object) {
object.Extends = object.Extends || Class;
var newClass = function() {
return this.initialize ? this.initialize.apply(this, arguments) : this;
} .extend(this);
for (var key in Class.Mutators) {
if (object[key]) Class.Mutators[key].call(newClass, object[key]);
QWE()(function() {
Array.supplement({
forEach: function(fn, context) {
for (var i = 0, l = this.length >>> 0; i < l; i++) {
if (i in this) fn.call(context, this[i], i, this);
}
}
});
/*
Resource Manager
- change app language just in time -> AUI.ResourceManager.setLocales(swahilstina)
- give localized text to element - el.set('locale', 'fileOpen')
- locale value could be: 'fileOpen' or ['fileOpen', 'title(anyProperty)'] or custom localize function
- if custom localization function returns value, that value will be used for localization
- .. but first of all you have to create locale storage (exported .net or own localization to JSON { dictionaryKey: term})
unselectable: {
set: function(value) {
Browser.Engine.gecko && (this.style.MozUserSelect = value ? 'none' : 'text') ||
Browser.Engine.webkit && (this.style.KhtmlUserSelect = value ? 'none' : 'text') ||
(Browser.Engine.trident || Browser.Engine.opera) && (this.unselectable = value ? 'on' : 'off');
this.getChildren('*').set('unselectable', value);
return this;
}
},
/*
* ImageCanvas - image drawn by canvas with methods for scaling and rotation
*
* License: MIT-style license.
* Copyright: Copyright (c) 2009 [Daniel Steigerwald](http://daniel.steigerwald.cz/).
*
*/
var ImageCanvas = new Class({
Extends: Canvas,
/*
*
* Class - JavaScript prototype inheritance sugar
*
* - reference to parent class is stored in static property superclass
* - in every method, you can call parent method .parent(..)
* - todo: methods with underscore prefix are protected
*
*/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/qwe/compressed.js"></script>
<script type="text/javascript">
QWE({
version: '0.2',
debug: true,