Permalink
Browse files

First commit

  • Loading branch information...
jcreamer898 committed Dec 24, 2011
0 parents commit 3061ae95fd95fdcdd60df4e96aae64748492c1fe
Showing with 14,812 additions and 0 deletions.
  1. +10 −0 index.htm
  2. +29 −0 js/app.build.js
  3. +7 −0 js/app.js
  4. +3 −0 js/build.bat
  5. +104 −0 js/libs/backbone-localstorage.js
  6. +1,219 −0 js/libs/backbone.js
  7. +1,116 −0 js/libs/modernizr-latest.js
  8. +30 −0 js/libs/underscore-min.js
  9. +977 −0 js/libs/underscore.js
  10. +15 −0 js/main.js
  11. +5 −0 js/models/model.js
  12. +8 −0 js/order.js
  13. +11,234 −0 js/require-jquery.js
  14. +21 −0 js/routers/home.js
  15. +1 −0 js/templates/main.html
  16. +11 −0 js/text.js
  17. +22 −0 js/views/view.js
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>RequireJS Backbone App</title>
+ <script data-main="js/main" src="js/require-jquery.js"></script>
+</head>
+<body>
+ <div id="main"></div>
+</body>
+</html>
@@ -0,0 +1,29 @@
+({
+ appDir: "../",
+ baseUrl: "js/",
+ dir: "../../requirejsbackbone-build/",
+ //Comment out the optimize line if you want
+ //the code minified by UglifyJS
+ //optimize: "none",
+
+ paths: {
+ "jquery": "require-jquery",
+ "underscore": "libs/underscore",
+ "backbone": "libs/backbone"
+ },
+
+ modules: [
+ //Optimize the require-jquery.js file by applying any minification
+ //that is desired via the optimize: setting above.
+ {
+ name: "require-jquery"
+ },
+
+ //Optimize the application files. Exclude jQuery since it is
+ //included already in require-jquery.js
+ {
+ name: "main",
+ exclude: ["jquery"]
+ }
+ ]
+})
@@ -0,0 +1,7 @@
+define(['routers/home'], function(router){
+ var init = function(){
+ this.router = new router();
+ };
+
+ return { init: init};
+});
@@ -0,0 +1,3 @@
+cd c:/inetpub/wwwroot/
+node r.js -o requirebackbone/js/app.build.js
+#java -cp c:/classpath/js.jar;c:/classpath/compiler.jar org.mozilla.javascript.tools.shell.Main r.js -o "c:/inetpub/wwwroot/savefavs/scripts/app.build.js"
@@ -0,0 +1,104 @@
+/**
+ * Backbone localStorage Adapter v1.0
+ * https://github.com/jeromegn/Backbone.localStorage
+ *
+ * Date: Sun Aug 14 2011 09:53:55 -0400
+ */
+define(['backbone','underscore'],function(Backbone,_){
+// A simple module to replace `Backbone.sync` with *localStorage*-based
+// persistence. Models are given GUIDS, and saved into a JSON object. Simple
+// as that.
+
+// Generate four random hex digits.
+function S4() {
+ return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
+};
+
+// Generate a pseudo-GUID by concatenating random hexadecimal.
+function guid() {
+ return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
+};
+
+// Our Store is represented by a single JS object in *localStorage*. Create it
+// with a meaningful name, like the name you'd give a table.
+var Store = function(name) {
+ this.name = name;
+ var store = localStorage.getItem(this.name);
+ this.records = (store && store.split(",")) || [];
+};
+
+_.extend(Store.prototype, {
+
+ // Save the current state of the **Store** to *localStorage*.
+ save: function() {
+ localStorage.setItem(this.name, this.records.join(","));
+ },
+
+ // Add a model, giving it a (hopefully)-unique GUID, if it doesn't already
+ // have an id of it's own.
+ create: function(model) {
+ if (!model.id) model.id = model.attributes.id = guid();
+ localStorage.setItem(this.name+"-"+model.id, JSON.stringify(model));
+ this.records.push(model.id.toString());
+ this.save();
+ return model;
+ },
+
+ // Update a model by replacing its copy in `this.data`.
+ update: function(model) {
+ localStorage.setItem(this.name+"-"+model.id, JSON.stringify(model));
+ if (!_.include(this.records, model.id.toString())) this.records.push(model.id.toString()); this.save();
+ return model;
+ },
+
+ // Retrieve a model from `this.data` by id.
+ find: function(model) {
+ return JSON.parse(localStorage.getItem(this.name+"-"+model.id));
+ },
+
+ // Return the array of all models currently in storage.
+ findAll: function() {
+ return _.map(this.records, function(id){return JSON.parse(localStorage.getItem(this.name+"-"+id));}, this);
+ },
+
+ // Delete a model from `this.data`, returning it.
+ destroy: function(model) {
+ localStorage.removeItem(this.name+"-"+model.id);
+ this.records = _.reject(this.records, function(record_id){return record_id == model.id.toString();});
+ this.save();
+ return model;
+ }
+
+});
+
+// Override `Backbone.sync` to use delegate to the model or collection's
+// *localStorage* property, which should be an instance of `Store`.
+Backbone.sync = function(method, model, options, error) {
+
+ // Backwards compatibility with Backbone <= 0.3.3
+ if (typeof options == 'function') {
+ options = {
+ success: options,
+ error: error
+ };
+ }
+
+ var resp;
+ var store = model.localStorage || model.collection.localStorage;
+
+ switch (method) {
+ case "read": resp = model.id ? store.find(model) : store.findAll(); break;
+ case "create": resp = store.create(model); break;
+ case "update": resp = store.update(model); break;
+ case "delete": resp = store.destroy(model); break;
+ }
+
+ if (resp) {
+ options.success(resp);
+ } else {
+ options.error("Record not found");
+ }
+};
+
+return Store;
+});
Oops, something went wrong.

0 comments on commit 3061ae9

Please sign in to comment.