From 35fc30e330bbc8e12a65f89ca67f74e37666ff93 Mon Sep 17 00:00:00 2001 From: kayone Date: Sun, 10 Nov 2013 13:33:44 -0800 Subject: [PATCH] fixed rjs task. --- Gruntfile.js | 94 +++---------- src/UI/JsLibraries/backbone.deep.model.js | 139 ++++++++++++++++--- src/UI/Mixins/underscore.mixin.deepExtend.js | 122 ---------------- src/UI/app.js | 15 +- src/UI/jQuery/jquery.shim.js | 7 + 5 files changed, 159 insertions(+), 218 deletions(-) delete mode 100644 src/UI/Mixins/underscore.mixin.deepExtend.js create mode 100644 src/UI/jQuery/jquery.shim.js diff --git a/Gruntfile.js b/Gruntfile.js index 9780b6e71..20a533ca5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -105,52 +105,26 @@ module.exports = function (grunt) { }, copy: { - index : { + content: { cwd : srcRoot, expand: true, - src : '*ndex.html', + src : [ + 'index.html', + '**/*.css', + '**/*.png', + '**/*.jpg', + '**/*.ico', + '**/FontAwesome/*.*', + '**/fonts/*.*' + ], dest : outputDir }, scripts: { cwd : srcRoot, expand: true, - src : '**/*.js', - dest : outputDir - }, - styles : { - cwd : srcRoot, - expand: true, - src : '**/*.css', - dest : outputDir - }, - images : { - cwd : srcRoot, - expand: true, - src : '**/*.png', - dest : outputDir - }, - jpg : { - cwd : srcRoot, - expand: true, - src : '**/*.jpg', - dest : outputDir - }, - icon : { - cwd : srcRoot, - expand: true, - src : '**/*.ico', - dest : outputDir - }, - fontAwesome : { - cwd : srcRoot, - expand: true, - src : '**/FontAwesome/*.*', - dest : outputDir - }, - fonts : { - cwd : srcRoot, - expand: true, - src : '**/fonts/*.*', + src : [ + '**/*.js', + ], dest : outputDir } }, @@ -158,16 +132,17 @@ module.exports = function (grunt) { requirejs: { compile:{ options: { - mainConfigFile: "_output/UI/app.js", + mainConfigFile: "src/UI/app.js", fileExclusionRegExp: /^.*\.(?!js$)[^.]+$/, - preserveLicenseComments: true, - dir: "rjs/", + preserveLicenseComments: false, + dir: outputDir, optimize: 'none', removeCombined: true, inlineText: false, + keepBuildDir : true, modules: [{ name: 'app', - exclude: ['JsLibraries/jquery'] + exclude: ['JsLibraries/jquery', 'templates.js'] }], } @@ -190,37 +165,13 @@ module.exports = function (grunt) { files: '<%= handlebars.files.src %>', tasks: ['handlebars'] }, - copyIndex : { - files: '<%= copy.index.cwd %><%= copy.index.src %>', - tasks: ['copy:index'] + copyContent : { + files: '<%= copy.content.cwd %><%= copy.content.src %>', + tasks: ['copy:content'] }, copyScripts: { files: '<%= copy.scripts.cwd %><%= copy.scripts.src %>', tasks: ['copy:scripts'] - }, - copyStyles : { - files: '<%= copy.styles.cwd %><%= copy.styles.src %>', - tasks: ['copy:styles'] - }, - copyImages : { - files: '<%= copy.images.cwd %><%= copy.images.src %>', - tasks: ['copy:images'] - }, - copyJpg : { - files: '<%= copy.jpg.cwd %><%= copy.jpg.src %>', - tasks: ['copy:jpg'] - }, - copyIcon : { - files: '<%= copy.icon.cwd %><%= copy.icon.src %>', - tasks: ['copy:icon'] - }, - copyFontAwesome : { - files: '<%= copy.fontAwesome.cwd %><%= copy.fontAwesome.src %>', - tasks: ['copy:fontAwesome'] - }, - copyFonts : { - files: '<%= copy.fonts.cwd %><%= copy.fonts.src %>', - tasks: ['copy:fonts'] } } }); @@ -234,7 +185,8 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-curl'); grunt.loadNpmTasks('grunt-contrib-requirejs'); - grunt.registerTask('package', ['clean:output', 'copy', 'less', 'handlebars']); + grunt.registerTask('package', ['clean:output','handlebars', 'copy', 'less']); + grunt.registerTask('packagerjs', ['clean:output','handlebars', 'requirejs', 'copy:content', 'less']); grunt.registerTask('default', ['package', 'watch']); grunt.registerTask('update', ['curl']); diff --git a/src/UI/JsLibraries/backbone.deep.model.js b/src/UI/JsLibraries/backbone.deep.model.js index cbea78c52..7d65d8802 100644 --- a/src/UI/JsLibraries/backbone.deep.model.js +++ b/src/UI/JsLibraries/backbone.deep.model.js @@ -1,3 +1,124 @@ +/*jshint expr:true eqnull:true */ +/** + * + * Backbone.DeepModel v0.10.4 + * + * Copyright (c) 2013 Charles Davison, Pow Media Ltd + * + * https://github.com/powmedia/backbone-deep-model + * Licensed under the MIT License + */ + +/** + * Underscore mixins for deep objects + * + * Based on https://gist.github.com/echong/3861963 + */ +(function() { + var arrays, basicObjects, deepClone, deepExtend, deepExtendCouple, isBasicObject, + __slice = [].slice; + + deepClone = function(obj) { + var func, isArr; + if (!_.isObject(obj) || _.isFunction(obj)) { + return obj; + } + if (obj instanceof Backbone.Collection || obj instanceof Backbone.Model) { + return obj; + } + if (_.isDate(obj)) { + return new Date(obj.getTime()); + } + if (_.isRegExp(obj)) { + return new RegExp(obj.source, obj.toString().replace(/.*\//, "")); + } + isArr = _.isArray(obj || _.isArguments(obj)); + func = function(memo, value, key) { + if (isArr) { + memo.push(deepClone(value)); + } else { + memo[key] = deepClone(value); + } + return memo; + }; + return _.reduce(obj, func, isArr ? [] : {}); + }; + + isBasicObject = function(object) { + if (object == null) return false; + return (object.prototype === {}.prototype || object.prototype === Object.prototype) && _.isObject(object) && !_.isArray(object) && !_.isFunction(object) && !_.isDate(object) && !_.isRegExp(object) && !_.isArguments(object); + }; + + basicObjects = function(object) { + return _.filter(_.keys(object), function(key) { + return isBasicObject(object[key]); + }); + }; + + arrays = function(object) { + return _.filter(_.keys(object), function(key) { + return _.isArray(object[key]); + }); + }; + + deepExtendCouple = function(destination, source, maxDepth) { + var combine, recurse, sharedArrayKey, sharedArrayKeys, sharedObjectKey, sharedObjectKeys, _i, _j, _len, _len1; + if (maxDepth == null) { + maxDepth = 20; + } + if (maxDepth <= 0) { + console.warn('_.deepExtend(): Maximum depth of recursion hit.'); + return _.extend(destination, source); + } + sharedObjectKeys = _.intersection(basicObjects(destination), basicObjects(source)); + recurse = function(key) { + return source[key] = deepExtendCouple(destination[key], source[key], maxDepth - 1); + }; + for (_i = 0, _len = sharedObjectKeys.length; _i < _len; _i++) { + sharedObjectKey = sharedObjectKeys[_i]; + recurse(sharedObjectKey); + } + sharedArrayKeys = _.intersection(arrays(destination), arrays(source)); + combine = function(key) { + return source[key] = _.union(destination[key], source[key]); + }; + for (_j = 0, _len1 = sharedArrayKeys.length; _j < _len1; _j++) { + sharedArrayKey = sharedArrayKeys[_j]; + combine(sharedArrayKey); + } + return _.extend(destination, source); + }; + + deepExtend = function() { + var finalObj, maxDepth, objects, _i; + objects = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), maxDepth = arguments[_i++]; + if (!_.isNumber(maxDepth)) { + objects.push(maxDepth); + maxDepth = 20; + } + if (objects.length <= 1) { + return objects[0]; + } + if (maxDepth <= 0) { + return _.extend.apply(this, objects); + } + finalObj = objects.shift(); + while (objects.length > 0) { + finalObj = deepExtendCouple(finalObj, deepClone(objects.shift()), maxDepth); + } + return finalObj; + }; + + _.mixin({ + deepClone: deepClone, + isBasicObject: isBasicObject, + basicObjects: basicObjects, + arrays: arrays, + deepExtend: deepExtend + }); + +}).call(this); + /** * Main source */ @@ -208,15 +329,11 @@ // var separator = DeepModel.keyPathSeparator; - var alreadyTriggered = {}; // * @restorer for (var i = 0, l = changes.length; i < l; i++) { var key = changes[i]; - if (!alreadyTriggered.hasOwnProperty(key) || !alreadyTriggered[key]) { // * @restorer - alreadyTriggered[key] = true; // * @restorer - this.trigger('change:' + key, this, getNested(current, key), options); - } // * @restorer + this.trigger('change:' + key, this, getNested(current, key), options); var fields = key.split(separator); @@ -225,17 +342,7 @@ var parentKey = _.first(fields, n).join(separator), wildcardKey = parentKey + separator + '*'; - if (!alreadyTriggered.hasOwnProperty(wildcardKey) || !alreadyTriggered[wildcardKey]) { // * @restorer - alreadyTriggered[wildcardKey] = true; // * @restorer - this.trigger('change:' + wildcardKey, this, getNested(current, parentKey), options); - } // * @restorer - - // + @restorer - if (!alreadyTriggered.hasOwnProperty(parentKey) || !alreadyTriggered[parentKey]) { - alreadyTriggered[parentKey] = true; - this.trigger('change:' + parentKey, this, getNested(current, parentKey), options); - } - // - @restorer + this.trigger('change:' + wildcardKey, this, getNested(current, parentKey), options); } // } diff --git a/src/UI/Mixins/underscore.mixin.deepExtend.js b/src/UI/Mixins/underscore.mixin.deepExtend.js deleted file mode 100644 index 70596a584..000000000 --- a/src/UI/Mixins/underscore.mixin.deepExtend.js +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Underscore mixins for deep objects - * - * Based on https://gist.github.com/echong/3861963 - */ -define( - [ - 'underscore' - ], function (_) { - - var arrays, basicObjects, deepClone, deepExtend, deepExtendCouple, isBasicObject, __slice = - [ - ].slice; - - deepClone = function (obj) { - var func, isArr; - if (!_.isObject(obj) || _.isFunction(obj)) { - return obj; - } - if (obj instanceof Backbone.Collection || obj instanceof Backbone.Model) { - return obj; - } - if (_.isDate(obj)) { - return new Date(obj.getTime()); - } - if (_.isRegExp(obj)) { - return new RegExp(obj.source, obj.toString().replace(/.*\//, '')); - } - isArr = _.isArray(obj || _.isArguments(obj)); - func = function (memo, value, key) { - if (isArr) { - memo.push(deepClone(value)); - } - else { - memo[key] = deepClone(value); - } - return memo; - }; - return _.reduce(obj, func, isArr ? - [ - ] :{}); - }; - - isBasicObject = function (object) { - if (object == null) { - return false; - } - return (object.prototype === {}.prototype || object.prototype === Object.prototype) && _.isObject(object) && !_.isArray(object) && !_.isFunction(object) && !_.isDate(object) && !_.isRegExp(object) && !_.isArguments(object); - }; - - basicObjects = function (object) { - return _.filter(_.keys(object), function (key) { - return isBasicObject(object[key]); - }); - }; - - arrays = function (object) { - return _.filter(_.keys(object), function (key) { - return _.isArray(object[key]); - }); - }; - - deepExtendCouple = function (destination, source, maxDepth) { - var combine, recurse, sharedArrayKey, sharedArrayKeys, sharedObjectKey, sharedObjectKeys, _i, _j, _len, _len1; - if (maxDepth == null) { - maxDepth = 20; - } - if (maxDepth <= 0) { - console.warn('_.deepExtend(): Maximum depth of recursion hit.'); - return _.extend(destination, source); - } - sharedObjectKeys = _.intersection(basicObjects(destination), basicObjects(source)); - recurse = function (key) { - return source[key] = deepExtendCouple(destination[key], source[key], maxDepth - 1); - }; - for (_i = 0, _len = sharedObjectKeys.length; _i < _len; _i++) { - sharedObjectKey = sharedObjectKeys[_i]; - recurse(sharedObjectKey); - } - sharedArrayKeys = _.intersection(arrays(destination), arrays(source)); - combine = function (key) { - return source[key] = _.union(destination[key], source[key]); - }; - for (_j = 0, _len1 = sharedArrayKeys.length; _j < _len1; _j++) { - sharedArrayKey = sharedArrayKeys[_j]; - combine(sharedArrayKey); - } - return _.extend(destination, source); - }; - - deepExtend = function () { - var finalObj, maxDepth, objects, _i; - objects = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) :(_i = 0, - [ - ]), maxDepth = arguments[_i++]; - if (!_.isNumber(maxDepth)) { - objects.push(maxDepth); - maxDepth = 20; - } - if (objects.length <= 1) { - return objects[0]; - } - if (maxDepth <= 0) { - return _.extend.apply(this, objects); - } - finalObj = objects.shift(); - while (objects.length > 0) { - finalObj = deepExtendCouple(finalObj, deepClone(objects.shift()), maxDepth); - } - return finalObj; - }; - - - _.mixin({ - deepClone : deepClone, - isBasicObject: isBasicObject, - basicObjects : basicObjects, - arrays : arrays, - deepExtend : deepExtend - }); - }); - diff --git a/src/UI/app.js b/src/UI/app.js index 7d4aab71d..7bbcb7b96 100644 --- a/src/UI/app.js +++ b/src/UI/app.js @@ -21,7 +21,7 @@ require.config({ 'signalR' : 'JsLibraries/jquery.signalR', 'jquery.knob' : 'JsLibraries/jquery.knob', 'jquery.dotdotdot' : 'JsLibraries/jquery.dotdotdot', - 'jquery' : 'JsLibraries/jquery', + 'jquery' : 'jquery/jquery.shim', 'libs' : 'JsLibraries/', 'api': 'Require/require.api' @@ -29,6 +29,11 @@ require.config({ shim: { + + jquery :{ + exports: '$' + }, + signalR: { deps: [ @@ -76,14 +81,6 @@ require.config({ exports: 'Backbone' }, - - 'backbone.deepmodel': { - deps: - [ - 'Mixins/underscore.mixin.deepExtend' - ] - }, - 'backbone.validation': { deps : [ diff --git a/src/UI/jQuery/jquery.shim.js b/src/UI/jQuery/jquery.shim.js new file mode 100644 index 000000000..8afee0490 --- /dev/null +++ b/src/UI/jQuery/jquery.shim.js @@ -0,0 +1,7 @@ +'use strict'; +define( + [ + + ], function () { + return window.$; + });