2 importz = imports['seed/importz.js'].importz;
3 Element = importz('Element');
7 var has = "hasOwnProperty";
9 function rSet (items) {
14 for (var i = 0, ii = items.length; i < ii; i++) {
15 //if (items[i] && (items[i].constructor == Element.prototype.constructor || items[i].constructor == Set)) {
16 this[this.items.length] = this.items[this.items.length] = items[i];
29 for (var i = 0, ii = arguments.length; i < ii; i++) {
32 //print(item.constructor);
34 //if (item && (item.constructor == Element.prototype.constructor || item.constructor == Set)) {
35 len = this.items.length;
36 this[len] = this.items[len] = item;
44 this.length && delete this[this.length--];
45 return this.items.pop();
48 forEach : function (callback, thisArg) {
49 for (var i = 0, ii = this.items.length; i < ii; i++) {
50 if (callback.call(thisArg, this.items[i], i) === false) {
57 attr : function (name, value) {
58 if (name && R.is(name, array) && R.is(name[0], "object")) {
59 for (var j = 0, jj = name.length; j < jj; j++) {
60 this.items[j].attr(name[j]);
63 for (var i = 0, ii = this.items.length; i < ii; i++) {
64 this.items[i].attr(name, value);
76 splice : function (index, count, insertion) {
77 index = index < 0 ? mmax(this.length + index, 0) : index;
78 count = mmax(0, mmin(this.length - index, count));
83 for (i = 2; i < arguments.length; i++) {
84 args.push(arguments[i]);
86 for (i = 0; i < count; i++) {
87 todel.push(this[index + i]);
89 for (; i < this.length - index; i++) {
90 tail.push(this[index + i]);
92 var arglen = args.length;
93 for (i = 0; i < arglen + tail.length; i++) {
94 this.items[index + i] = this[index + i] = i < arglen ? args[i] : tail[i - arglen];
96 i = this.items.length = this.length -= count - arglen;
100 return new rSet(todel);
103 exclude : function (el) {
104 for (var i = 0, ii = this.length; i < ii; i++) if (this[i] == el) {
110 animate : function (params, ms, easing, callback) {
111 (R.is(easing, "function") || !easing) && (callback = easing || null);
112 var len = this.items.length,
120 callback && (collector = function () {
121 !--len && callback.call(set);
123 easing = R.is(easing, string) ? easing : collector;
124 var anim = R.animation(params, ms, easing, collector);
125 item = this.items[--i].animate(anim);
127 this.items[i] && !this.items[i].removed && this.items[i].animateWith(item, anim);
131 insertAfter : function (el) {
132 var i = this.items.length;
134 this.items[i].insertAfter(el);
138 getBBox : function () {
139 //Roo.log("SET : getBBox");
144 for (var i = this.items.length; i--;) if (!this.items[i].removed) {
145 var box = this.items[i].getBBox();
146 //Roo.log(['box of set item: ' ,JSON.stringify(box)]);
149 w.push(box.x + box.width);
150 h.push(box.y + box.height);
152 x = Math.min.apply(0, x);
153 y = Math.min.apply(0, y);
154 //Roo.log(['set bbox return :', x,y,Math.max.apply(0, w) - x,Math.max.apply(0, h) - y]);
159 width: Math.max.apply(0, w) - x,
160 height: Math.max.apply(0, h) - y
163 clone : function (s) {
165 for (var i = 0, ii = this.items.length; i < ii; i++) {
166 s.push(this.items[i].clone());
170 toString : function () {
171 return "Rapha\xebl\u2018s set";
175 // seems an odd way to copy prototypes...
176 for (var method in Element.prototype) {
177 if (!Element.prototype[has](method)) {
180 if (rSet.prototype[has](method)) {
183 rSet.prototype[method] = (function (methodname) {
186 return this.forEach(function (el) {
187 el[methodname].apply(el, arg);