<commit_before>
var 	   _ = require("alloy/underscore")._,
	Backbone = require("alloy/backbone"),
	osname   = Ti.Platform.osname,
	SQLSync, 
	SQLSyncInit,
	FileSysSync;
	
module.exports._ = _;
module.exports.Backbone = Backbone;

Backbone.Collection.notify = _.extend({}, Backbone.Events);

Backbone.sync = function(method, model, opts) {
	// Ti.API.info("sync called with method="+method+", model="+JSON.stringify(model)+", opts="+JSON.stringify(opts));
	// Ti.API.info("config => "+JSON.stringify(model.config));
	
	var m = (model.config || {});
	var type = (m.adapter ? m.adapter.type : null) || 'sql';
	
	switch (type) {
		case 'sql': {
			SQLSync  = require("alloy/sync/sql");
			SQLSync.sync(model,method,opts);
			break;
		}
		case 'filesystem': {
			FileSysSync  = require("alloy/sync/filesys");
			FileSysSync.sync(model,method,opts);
			break;
		}
		default: {
			Ti.API.error("No sync adapter found for: "+type);
			return;
		}
	}

	Backbone.Collection.notify.trigger('sync', {method:method,model:model});
};

module.exports.M = function(name,config,modelFn,migrations) {
	
    var type = (config.adapter ? config.adapter.type : null) || 'sql';
    if (type === 'sql' && !SQLSyncInit) {
 		SQLSyncInit = true;
    	SQLSync.init(); 
    }
	
	var Model = Backbone.Model.extend( {
		
		defaults: config.defaults,
		
		validate: function(attrs) {
			if (typeof __validate !== 'undefined') {
				if (_.isFunction(__validate)) {
					for (var k in attrs) {
						var t = __validate(k, attrs[k]);
						if (!t) {
							return "validation failed for: "+k;
						}
					}
				}
			}
		}
	});
	
	if (migrations && migrations.length > 0) {
		if (type == 'sql') { 
			SQLSync.migrate(migrations);
		}
	}

	Model.prototype.config = config;

	modelFn(Model);
	
	return Model;
};

module.exports.A = function(t,type,parent) {
	_.extend(t,Backbone.Events);
	
	(function() {
		
		// we are going to wrap addEventListener and removeEventListener
		// with on, off so we can use the Backbone events
		var al = t.addEventListener,
			rl = t.removeEventListener,
			oo = t.on,
			of = t.off,
			tg = t.trigger,
		   cbs = [],
		   ctx = {};

		t.on = function(e,cb,context) {
			var wcb = function(evt) {
				try {
					_.bind(tg,ctx,e,evt)();
				}
				catch(E) {
					Ti.API.error("Error triggering '"+e+"' event: "+E);
				}
			};
			cbs[cb]=wcb;

			if (osname === 'android') {
				al.call(t, e, wcb);
			} else {
				al(e, wcb);
			}

			_.bind(oo,ctx,e,cb,context)();
		};

		t.off = function(e,cb,context) {
			var f = cbs[cb];
			if (f) {
				_.bind(of,ctx,e,cb,context)();

				if (osname === 'android') {
					rl.call(t, e, f);
				} else {
					rl(e, f);
				}
				
				delete cbs[cb];
				f = null;
			}
		};
		
	})();<commit_msg>Like andriod, mobile web needed to use the call method when hooking Backbones events. Hello world app now runs on Mobile Web.<commit_after>
var 	   _ = require("alloy/underscore")._,
	Backbone = require("alloy/backbone"),
	osname   = Ti.Platform.osname,
	SQLSync, 
	SQLSyncInit,
	FileSysSync;
	
module.exports._ = _;
module.exports.Backbone = Backbone;

Backbone.Collection.notify = _.extend({}, Backbone.Events);

Backbone.sync = function(method, model, opts) {
	// Ti.API.info("sync called with method="+method+", model="+JSON.stringify(model)+", opts="+JSON.stringify(opts));
	// Ti.API.info("config => "+JSON.stringify(model.config));
	
	var m = (model.config || {});
	var type = (m.adapter ? m.adapter.type : null) || 'sql';
	
	switch (type) {
		case 'sql': {
			SQLSync  = require("alloy/sync/sql");
			SQLSync.sync(model,method,opts);
			break;
		}
		case 'filesystem': {
			FileSysSync  = require("alloy/sync/filesys");
			FileSysSync.sync(model,method,opts);
			break;
		}
		default: {
			Ti.API.error("No sync adapter found for: "+type);
			return;
		}
	}

	Backbone.Collection.notify.trigger('sync', {method:method,model:model});
};

module.exports.M = function(name,config,modelFn,migrations) {
	
    var type = (config.adapter ? config.adapter.type : null) || 'sql';
    if (type === 'sql' && !SQLSyncInit) {
 		SQLSyncInit = true;
    	SQLSync.init(); 
    }
	
	var Model = Backbone.Model.extend( {
		
		defaults: config.defaults,
		
		validate: function(attrs) {
			if (typeof __validate !== 'undefined') {
				if (_.isFunction(__validate)) {
					for (var k in attrs) {
						var t = __validate(k, attrs[k]);
						if (!t) {
							return "validation failed for: "+k;
						}
					}
				}
			}
		}
	});
	
	if (migrations && migrations.length > 0) {
		if (type == 'sql') { 
			SQLSync.migrate(migrations);
		}
	}

	Model.prototype.config = config;

	modelFn(Model);
	
	return Model;
};

module.exports.A = function(t,type,parent) {
	_.extend(t,Backbone.Events);
	
	(function() {
		
		// we are going to wrap addEventListener and removeEventListener
		// with on, off so we can use the Backbone events
		var al = t.addEventListener,
			rl = t.removeEventListener,
			oo = t.on,
			of = t.off,
			tg = t.trigger,
		   cbs = [],
		   ctx = {};

		t.on = function(e,cb,context) {
			var wcb = function(evt) {
				try {
					_.bind(tg,ctx,e,evt)();
				}
				catch(E) {
					Ti.API.error("Error triggering '"+e+"' event: "+E);
				}
			};
			cbs[cb]=wcb;

			if (osname !== 'iphone') {
				al.call(t, e, wcb);
			} else {
				al(e, wcb);
			}

			_.bind(oo,ctx,e,cb,context)();
		};

		t.off = function(e,cb,context) {
			var f = cbs[cb];
			if (f) {
				_.bind(of,ctx,e,cb,context)();

				if (osname !== 'iphone') {
					rl.call(t, e, f);
				} else {
					rl(e, f);
				}
				
				delete cbs[cb];
				f = null;
			}
		};
		
	})();
{'fraction_non_alphanumeric': 0.1791606886657102, 'fraction_numerical': 0.0003586800573888092, 'mean_word_length': 2.851519337016575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372058', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2045, 'n_words': 417}