Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
storminwalker committed Jun 23, 2011
0 parents commit f00518a
Show file tree
Hide file tree
Showing 4,415 changed files with 2,104,245 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
A little bit of a hack to get Sencha's ExtJS library running under NodeJS.

Essentially mocks out the little bit of DOM required so that it's just a DOM-less framework.

Only includes those objects and components necessary to use ExtJS as a core library with Node.

Also includes some custom extensions to ExtJS to further enhance the library. These are slightly opinionated
but work.

FUTURE: Adding all model, store related stuff and including custom proxies to CouchDB, Redis etc

Installation:
npm install node-extjs

Usage:

require("node-extjs");



(Big hat-tip to Christoph Hagenbrock (@agebrock) - basically stole his code but wanted my own repository rather
than a fork to have better control going forward)




23 changes: 23 additions & 0 deletions examples/test/ext.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Ext.ns("ext");

Ext.define("ext.test", {
extend: "Ext.util.Observable",

foo: "bar",

constructor: function(config) {
config = config || {};
Ext.apply(this, config);

this.addEvents("test");
this.listeners = config.listeners;

this.callParent(arguments);
},

getFoo: function() {
this.fireEvent("test", this);
return this.foo;
}
});
63 changes: 63 additions & 0 deletions examples/test/node-extjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
var fs = require("fs");

var window = {
status: __defineSetter__("status", function(debugStatusMsg){
console.log(debugStatusMsg);
})
}

var fileList = [
"/extjs/src/core/src/Ext.js",

"/extjs/src/core/src/version/Version.js",

"/extjs/src/core/src/lang/String.js",
"/extjs/src/core/src/lang/Array.js",
"/extjs/src/core/src/lang/Number.js",
"/extjs/src/core/src/lang/Date.js",
"/extjs/src/core/src/lang/Object.js",
"/extjs/src/core/src/lang/Function.js",

"/extjs/src/core/src/class/Base.js",
"/extjs/src/core/src/class/Class.js",
"/extjs/src/core/src/class/ClassManager.js",

"/extjs/src/core/src/util/TaskManager.js",
"/extjs/src/core/src/util/Format.js",

"/extjs/src/core/src/class/Loader.js",

"/extjs/src/core/src/util/DelayedTask.js",
"/extjs/src/core/src/util/Event.js",

"/extjs-overrides.js",

"/extjs/src/util/Observable.js",
"/extjs/src/util/Filter.js",
"/extjs/src/util/Sorter.js",
"/extjs/src/util/Sortable.js",
"/extjs/src/util/AbstractMixedCollection.js" ,
"/extjs/src/util/MixedCollection.js",
"/extjs/src/util/HashMap.js",
"/extjs/src/util/Inflector.js",

"/extensions/Math.js",
"/extensions/String.js",
"/extensions/Guid.js",
"/extensions/Hex.js"
];

var extBasePath = __dirname + '/../../lib';

var fileList = fileList.map(function(file) {
return extBasePath + file;
});

var injectExtJS = function(fileList){
fileList.forEach(function(file) {
//console.log(file);
eval(fs.readFileSync(file, encoding = "utf8"));
});
}

injectExtJS(fileList);
25 changes: 25 additions & 0 deletions examples/test/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require('./node-extjs');
require('./ext.test');

console.log(Ext.getVersion().version);

console.log(new ext.test());

console.log(new ext.test({
listeners: {
"test": function() {
console.log("yada");
}
}
}).getFoo());

var yada = Ext.create("ext.test");
console.log(yada);

yada.on({
test: function() {
console.log("yada again");
}
});

console.log(yada.getFoo());
65 changes: 65 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var fs = require("fs");

var window = {
status: __defineSetter__("status", function(debugStatusMsg){
console.log(debugStatusMsg);
})
}

var fileList = [
"/extjs/src/core/src/Ext.js",

"/extjs/src/core/src/version/Version.js",

"/extjs/src/core/src/lang/String.js",
"/extjs/src/core/src/lang/Array.js",
"/extjs/src/core/src/lang/Number.js",
"/extjs/src/core/src/lang/Date.js",
"/extjs/src/core/src/lang/Object.js",
"/extjs/src/core/src/lang/Function.js",

"/extjs/src/core/src/class/Base.js",
"/extjs/src/core/src/class/Class.js",
"/extjs/src/core/src/class/ClassManager.js",

"/extjs/src/core/src/util/TaskManager.js",
"/extjs/src/core/src/util/Format.js",

"/extjs/src/core/src/class/Loader.js",

"/extjs/src/core/src/util/DelayedTask.js",
"/extjs/src/core/src/util/Event.js",

"/extjs-overrides.js",

"/extjs/src/util/Observable.js",
"/extjs/src/util/Filter.js",
"/extjs/src/util/Sorter.js",
"/extjs/src/util/Sortable.js",
"/extjs/src/util/AbstractMixedCollection.js" ,
"/extjs/src/util/MixedCollection.js",
"/extjs/src/util/HashMap.js",
"/extjs/src/util/Inflector.js",

"/extensions/Math.js",
"/extensions/String.js",
"/extensions/Guid.js",
"/extensions/Hex.js"
];

var extBasePath = __dirname + '/lib';

var fileList = fileList.map(function(file) {
return extBasePath + file;
});

var injectExtJS = function(fileList){
fileList.forEach(function(file) {
//console.log(file);
eval(fs.readFileSync(file, encoding = "utf8"));
});
}

injectExtJS(fileList);

console.log("ExtJS 4.0 loaded");
Binary file added lib/.DS_Store
Binary file not shown.
64 changes: 64 additions & 0 deletions lib/extensions/Guid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

Guid = function(config) {
this.id = this.createGUID();
}

Guid.prototype.valueOf = function(){ return this.id; };
Guid.prototype.toString = function(){ return this.id; };

Guid.prototype.createGUID = function() {
// Loose interpretation of the specification DCE 1.1: Remote Procedure Call
// described at http://www.opengroup.org/onlinepubs/009629399/apdxa.htm#tagtcjh_37
// since JavaScript doesn't allow access to internal systems, the last 48 bits
// of the node section is made up using a series of random numbers (6 octets long).

var dg = new Date(1582, 10, 15, 0, 0, 0, 0).getTime();
var dc = new Date().getTime();
var t = (dg < 0) ? Math.abs(dg) + dc : dc - dg;
var h = '-';
var tl = XERO.utils.Guid.getIntegerBits(t, 0, 31);
var tm = XERO.utils.Guid.getIntegerBits(t, 32, 47);
var thv = XERO.utils.Guid.getIntegerBits(t, 48, 59) + '1'; // version 1, security version is 2
var csar = XERO.utils.Guid.getIntegerBits(Math.randRange(0, 4095), 0, 7);
var csl = XERO.utils.Guid.getIntegerBits(Math.randRange(0, 4095), 0, 7);

// since detection of anything about the machine/browser is far too buggy,
// include some more random numbers here
// if nic or at least an IP can be obtained reliably, that should be put in
// here instead.
var n = XERO.utils.Guid.getIntegerBits(Math.randRange(0, 8191), 0, 7) +
XERO.utils.Guid.getIntegerBits(Math.randRange(0, 8191), 8, 15) +
XERO.utils.Guid.getIntegerBits(Math.randRange(0, 8191), 0, 7) +
XERO.utils.Guid.getIntegerBits(Math.randRange(0, 8191), 8, 15) +
XERO.utils.Guid.getIntegerBits(Math.randRange(0, 8191), 0, 15); // this last number is two octets long
return tl + h + tm + h + thv + h + csar + csl + h + n;
}

Guid.newGuid = function() {
return new Guid();
}

//
// GENERAL METHODS (Not instance specific)
//

// Pull out only certain bits from a very large integer, used to get the time
// code information for the first part of a GUID. Will return zero's if there
// aren't enough bits to shift where it needs to.
Guid.getIntegerBits = function(val, start, end) {
var base16 = XERO.utils.Guid.returnBase(val, 16);
var quadArray = base16.split('');
var quadString = '';
var i = 0;
for(i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
if(!quadArray[i] || quadArray[i] == '') quadString += '0';
else quadString += quadArray[i];
}
return quadString;
}

// In base 16: 0=0, 5=5, 10=A, 15=F
Guid.returnBase = function(number, base) {
return number.toString(base).toUpperCase();
}

64 changes: 64 additions & 0 deletions lib/extensions/Hex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

Ext.applyIf(Ext.util.Format, {

hexEncode: function(data) {
var digits = "0123456789ABCDEF";
var map = [];
var i = 0;
for(i; i < 256; i++) {
map[i] = digits.charAt(i >> 4) + digits.charAt(i & 15);
}

var result = [];
for (var i=0; i<data.length; i++) {
result[i] = map[data.charCodeAt(i)];
}

return result.join('');
},

hexDecode: function(data) {
var digits = "0123456789ABCDEF";
var map = [];
var i = 0;
for(i; i < 256; i++) {
map[digits.charAt(i >> 4) + digits.charAt(i & 15)] = String.fromCharCode(i);
}
if (!data.match(/^[a-f0-9]*$/i)) {
return false;
}

if (data.length % 2) {
data = '0' + data;
}

var result = [];
var j = 0;
i = 0;
var len = data.length;
for (i; i < len; i += 2) {
result[j++] = map[data.substr(i, 2)];
}

return result.join('');
}
});

Ext.apply(Ext, {

objectToHex: function(obj) {
return Ext.hexEncode(Ext.encode(obj));
},

objectFromHex: function(s) {
return Ext.decode(Ext.hexDecode(s));
},

hexEncode: function(value) {
return Ext.util.Format.hexEncode(value);
},

hexDecode: function(value) {
return Ext.util.Format.hexDecode(value);
}
});
21 changes: 21 additions & 0 deletions lib/extensions/Math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Ext.applyIf(Math, {
/**
* extend Math class with a randRange method
* @return {Number} A random number greater than or equal to min and less than or equal to max.
*/
randRange : function(min, max) {
return Math.max(Math.min(Math.round(Math.random() * max), max), min);
},

/**
* extend Math class with a sign method
* @return {Number} The correctly signed number
*/
sign: function(x) {
if(x == 0) {
return 0;
}
return x / Math.abs(x);
}
});
Loading

0 comments on commit f00518a

Please sign in to comment.