Permalink
Browse files

bug fixes

  • Loading branch information...
1 parent 4ddeb0f commit 3bbb3677f11cd994f1720b89485cccace981b23a @drewlesueur committed Feb 28, 2011
Showing with 52 additions and 27 deletions.
  1. +1 −0 .gitignore
  2. +24 −12 index.coffee
  3. +27 −15 index.js
View
@@ -0,0 +1 @@
+nohup.out
View
@@ -148,18 +148,19 @@ k.mixin
k.addPolymorphicMethods funcs
k.addPolymorphicProps props
obj
- new: (type, o, extra) ->
- extra = extra || {}
+ new: (type, rest...) ->
+ extra = {}
if type then extra.type = type
- o = o or {}
+ o = {}
metaO = k.meta(o)
_.extend metaO, extra
- if metaO.type and metaO.type.initialize then metaO.type.initialize o
+ if metaO.type and metaO.type.initialize then metaO.type.initialize o, rest...
o
+
reverseMeta: (cid) -> k.metaInfo[cid].record #meybe do this a different way
meta: (o) ->
- metaO = k.metaInfo[o.__cid]
- if metaO then return metaO
+ if o.__cid? and k.metaInfo[o.__cid]
+ return k.metaInfo[o.__cid]
cid = _.uniqueId()
o.__cid = cid
return k.metaInfo[cid] = record: o
@@ -180,9 +181,12 @@ window.m = m = k.meta
k.mixin
bind: (o, event, callback) ->
mo = m(o)
+ console.log "cid is #{o.__cid}"
+ mo._callbacks = mo._callbacks || {}
calls = mo._callbacks or (mo._callbacks = {})
list = mo._callbacks[event] or (mo._callbacks[event] = [])
list.push callback
+ return o
unbind: (o, event, callback) ->
mo = m(o)
@@ -202,7 +206,11 @@ k.mixin
trigger: (o, event, restOfArgs...) ->
mo = m(o)
+ console.log "triggering event" + event
+ console.log "cid is #{o.__cid}"
calls = mo._callbacks
+ console.log "calls are "
+ console.log calls
if not calls then return o
list = calls[event]
if list
@@ -218,18 +226,23 @@ k.mixin
k.mixin
+ change: (o, options) ->
+ k(o).trigger "change", o, options
+ m(o)._previousAttibutes = _.clone o
+ m(o).changed = false
+
set: (o, attrs, options) ->
options = options || {}
if (not options.silent) and p(o).validate and (not p(o)._performValidation(attrs, options)) then return false
- for attr of attrs
- val = attrs[val]
+ for attr, val of attrs
+ console.log o[attr], val
if not _.isEqual(o[attr], val)
o[attr] = val
if not options.silent
m(o)._changed = true
- p(o).trigger "change:" + attr, o, val, options
+ k(o).trigger "change:" + attr, o, val, options
- if not options.silent and m(o)._changed then p(o).change options
+ if not options.silent and m(o)._changed then k(o).change options
return o
k.mixin
@@ -255,14 +268,13 @@ k.mixin
#TODO: Polish and add in a bunch more backbone.js methods
#jQuery or zepto extensions.
-if not (jQuery || Zepto)
+if not (root['jQuery'] || root['Zepto'])
return
library = jQuery || Zepto
do (library) ->
$ = library
$.fn.dragsimple = (options) ->
el = this
- console.log el
$(el).bind "mousedown", (e) ->
obj = this
e.preventDefault()
View
@@ -167,28 +167,28 @@
k.addPolymorphicProps(props);
return obj;
},
- "new": function(type, o, extra) {
- var metaO;
- extra = extra || {};
+ "new": function() {
+ var extra, metaO, o, rest, type, _ref;
+ type = arguments[0], rest = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+ extra = {};
if (type) {
extra.type = type;
}
- o = o || {};
+ o = {};
metaO = k.meta(o);
_.extend(metaO, extra);
if (metaO.type && metaO.type.initialize) {
- metaO.type.initialize(o);
+ (_ref = metaO.type).initialize.apply(_ref, [o].concat(__slice.call(rest)));
}
return o;
},
reverseMeta: function(cid) {
return k.metaInfo[cid].record;
},
meta: function(o) {
- var cid, metaO;
- metaO = k.metaInfo[o.__cid];
- if (metaO) {
- return metaO;
+ var cid;
+ if ((o.__cid != null) && k.metaInfo[o.__cid]) {
+ return k.metaInfo[o.__cid];
}
cid = _.uniqueId();
o.__cid = cid;
@@ -229,9 +229,12 @@
bind: function(o, event, callback) {
var calls, list, mo;
mo = m(o);
+ console.log("cid is " + o.__cid);
+ mo._callbacks = mo._callbacks || {};
calls = mo._callbacks || (mo._callbacks = {});
list = mo._callbacks[event] || (mo._callbacks[event] = []);
- return list.push(callback);
+ list.push(callback);
+ return o;
},
unbind: function(o, event, callback) {
var calls, func, index, list, mo, _len;
@@ -261,7 +264,11 @@
var allList, calls, event, func, index, list, mo, o, restOfArgs, _len, _len2, _results;
o = arguments[0], event = arguments[1], restOfArgs = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
mo = m(o);
+ console.log("triggering event" + event);
+ console.log("cid is " + o.__cid);
calls = mo._callbacks;
+ console.log("calls are ");
+ console.log(calls);
if (!calls) {
return o;
}
@@ -284,24 +291,30 @@
}
});
k.mixin({
+ change: function(o, options) {
+ k(o).trigger("change", o, options);
+ m(o)._previousAttibutes = _.clone(o);
+ return m(o).changed = false;
+ },
set: function(o, attrs, options) {
var attr, val;
options = options || {};
if ((!options.silent) && p(o).validate && (!p(o)._performValidation(attrs, options))) {
return false;
}
for (attr in attrs) {
- val = attrs[val];
+ val = attrs[attr];
+ console.log(o[attr], val);
if (!_.isEqual(o[attr], val)) {
o[attr] = val;
if (!options.silent) {
m(o)._changed = true;
- p(o).trigger("change:" + attr, o, val, options);
+ k(o).trigger("change:" + attr, o, val, options);
}
}
}
if (!options.silent && m(o)._changed) {
- p(o).change(options);
+ k(o).change(options);
}
return o;
}
@@ -338,7 +351,7 @@
return _results;
}
});
- if (!(jQuery || Zepto)) {
+ if (!(root['jQuery'] || root['Zepto'])) {
return;
}
library = jQuery || Zepto;
@@ -348,7 +361,6 @@
return $.fn.dragsimple = function(options) {
var el;
el = this;
- console.log(el);
$(el).bind("mousedown", function(e) {
var mousemove, mouseup, obj, parent_offset_left, parent_offset_top, start_offset_left, start_offset_top;
obj = this;

0 comments on commit 3bbb367

Please sign in to comment.