language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
emberjs
ember.js
b947b89ab37c3baabf8182f3592570a9da11f6d9.json
Fix documentation on what Ember.tryInvoke returns
packages/ember-metal/lib/utils.js
@@ -388,8 +388,7 @@ Ember.canInvoke = canInvoke; @param {String} methodName The method name to check for @param {Array} args The arguments to pass to the method - @returns {Boolean} true if the method does not return false - @returns {Boolean} false otherwise + @returns {*} whatever the invoked function returns if it can be invoked */ Ember.tryInvoke = function(obj, methodName, args) { if (canInvoke(obj, methodName)) {
false
Other
emberjs
ember.js
baede126baf9e001b67bdd45412be89e86a987bf.json
Provide default args to tryInvoke - fixes #1327
packages/ember-metal/lib/utils.js
@@ -393,6 +393,6 @@ Ember.canInvoke = canInvoke; */ Ember.tryInvoke = function(obj, methodName, args) { if (canInvoke(obj, methodName)) { - return obj[methodName].apply(obj, args); + return obj[methodName].apply(obj, args || []); } };
false
Other
emberjs
ember.js
279de45122a7441e3c125cdeb3ee6e209c9203cb.json
Fix a bug in multi-selects with primitive options The single select code path handled this case but the multi-select did not.
packages/ember-handlebars/lib/controls/select.js
@@ -313,7 +313,7 @@ Ember.SelectOption = Ember.View.extend({ var content = get(this, 'content'), selection = get(this, 'parentView.selection'); if (get(this, 'parentView.multiple')) { - return selection && indexOf(selection, content) > -1; + return selection && indexOf(selection, content.valueOf()) > -1; } else { // Primitives get passed through bindings as objects... since // `new Number(4) !== 4`, we use `==` below @@ -341,4 +341,3 @@ Ember.SelectOption = Ember.View.extend({ }).property(valuePath).cacheable()); }, 'parentView.optionValuePath') }); -
true
Other
emberjs
ember.js
279de45122a7441e3c125cdeb3ee6e209c9203cb.json
Fix a bug in multi-selects with primitive options The single select code path handled this case but the multi-select did not.
packages/ember-handlebars/tests/controls/select_test.js
@@ -220,6 +220,21 @@ test("Ember.SelectedOption knows when it is selected when multiple=true", functi deepEqual(selectedOptions(), [false, true, true, false], "After changing it, selection should be correct"); }); +test("Ember.SelectedOption knows when it is selected when multiple=true and options are primatives", function() { + select.set('content', Ember.A([1, 2, 3, 4])); + select.set('multiple', true); + + select.set('selection', [1, 3]); + + append(); + + deepEqual(selectedOptions(), [true, false, true, false], "Initial selection should be correct"); + + select.set('selection', [2, 3]); + + deepEqual(selectedOptions(), [false, true, true, false], "After changing it, selection should be correct"); +}); + test("a prompt can be specified", function() { var yehuda = { id: 1, firstName: 'Yehuda' }, tom = { id: 2, firstName: 'Tom' };
true
Other
emberjs
ember.js
e53be50824d38b3e2b4ea17639571a74d049bdb0.json
Fix formatURL to use rootURL and remove formatPath
packages/ember-routing/lib/location/history_location.js
@@ -47,7 +47,7 @@ Ember.HistoryLocation = Ember.Object.extend( var state = window.history.state, initialURL = get(this, '_initialURL'); - path = this.formatPath(path); + path = this.formatURL(path); if ((initialURL !== path && !state) || (state && state.path !== path)) { window.history.pushState({ path: path }, null, path); @@ -71,26 +71,16 @@ Ember.HistoryLocation = Ember.Object.extend( /** @private - returns the given path appended to rootURL - */ - formatPath: function(path) { + Used when using {{action}} helper. The url is always appended to the rootURL. + */ + formatURL: function(url) { var rootURL = get(this, 'rootURL'); - if (path !== '') { + if (url !== '') { rootURL = rootURL.replace(/\/$/, ''); } - return rootURL + path; - }, - - /** - @private - - Used when using {{action}} helper. Since no formatting - is required we just return the url given. - */ - formatURL: function(url) { - return url; + return rootURL + url; }, /** @private */
true
Other
emberjs
ember.js
e53be50824d38b3e2b4ea17639571a74d049bdb0.json
Fix formatURL to use rootURL and remove formatPath
packages/ember-routing/tests/location_test.js
@@ -169,7 +169,7 @@ test("it calls pushState if at initialURL and history.state does not exist", fun }); test("it handles an empty path as root", function() { - equal(locationObject.formatPath(''), '/', "The formatted url is '/'"); + equal(locationObject.formatURL(''), '/', "The formatted url is '/'"); }); test("it prepends rootURL to path", function() {
true
Other
emberjs
ember.js
3f7a1181510c21c3afd87731970e3b79eb2e37b1.json
move guid key init before initMixins cache more functions locally
packages/ember-runtime/lib/system/core_object.js
@@ -10,17 +10,23 @@ // Ember.Object. We only define this separately so that Ember.Set can depend on it - -var classToString = Ember.Mixin.prototype.toString; -var set = Ember.set, get = Ember.get; -var o_create = Ember.create, +var set = Ember.set, get = Ember.get, + o_create = Ember.create, o_defineProperty = Ember.platform.defineProperty, a_slice = Array.prototype.slice, + GUID_KEY = Ember.GUID_KEY, + guidFor = Ember.guidFor, + generateGuid = Ember.generateGuid, meta = Ember.meta, rewatch = Ember.rewatch, finishChains = Ember.finishChains, - finishPartial = Ember.Mixin.finishPartial, - reopen = Ember.Mixin.prototype.reopen; + destroy = Ember.destroy, + schedule = Ember.run.schedule, + Mixin = Ember.Mixin, + applyMixin = Mixin._apply, + finishPartial = Mixin.finishPartial, + reopen = Mixin.prototype.reopen, + classToString = Mixin.prototype.toString; var undefinedDescriptor = { configurable: true, @@ -42,14 +48,14 @@ function makeCtor() { if (!wasApplied) { Class.proto(); // prepare prototype... } - var m = Ember.meta(this); + o_defineProperty(this, GUID_KEY, undefinedDescriptor); + o_defineProperty(this, '_super', undefinedDescriptor); + var m = meta(this); m.proto = this; if (initMixins) { this.reopen.apply(this, initMixins); initMixins = null; } - o_defineProperty(this, Ember.GUID_KEY, undefinedDescriptor); - o_defineProperty(this, '_super', undefinedDescriptor); finishPartial(this, m); delete m.proto; finishChains(this); @@ -59,7 +65,7 @@ function makeCtor() { Class.toString = classToString; Class.willReopen = function() { if (wasApplied) { - Class.PrototypeMixin = Ember.Mixin.create(Class.PrototypeMixin); + Class.PrototypeMixin = Mixin.create(Class.PrototypeMixin); } wasApplied = false; @@ -85,11 +91,11 @@ function makeCtor() { var CoreObject = makeCtor(); -CoreObject.PrototypeMixin = Ember.Mixin.create( +CoreObject.PrototypeMixin = Mixin.create( /** @scope Ember.CoreObject.prototype */ { reopen: function() { - Ember.Mixin._apply(this, arguments, true); + applyMixin(this, arguments, true); return this; }, @@ -124,7 +130,7 @@ CoreObject.PrototypeMixin = Ember.Mixin.create( if (this.willDestroy) { this.willDestroy(); } set(this, 'isDestroyed', true); - Ember.run.schedule('destroy', this, this._scheduledDestroy); + schedule('destroy', this, this._scheduledDestroy); return this; }, @@ -135,7 +141,7 @@ CoreObject.PrototypeMixin = Ember.Mixin.create( @private */ _scheduledDestroy: function() { - Ember.destroy(this); + destroy(this); if (this.didDestroy) { this.didDestroy(); } }, @@ -146,7 +152,7 @@ CoreObject.PrototypeMixin = Ember.Mixin.create( }, toString: function() { - return '<'+this.constructor.toString()+':'+Ember.guidFor(this)+'>'; + return '<'+this.constructor.toString()+':'+guidFor(this)+'>'; } }); @@ -156,7 +162,7 @@ if (Ember.config.overridePrototypeMixin) { CoreObject.__super__ = null; -var ClassMixin = Ember.Mixin.create( +var ClassMixin = Mixin.create( /** @scope Ember.ClassMixin.prototype */ { ClassMixin: Ember.required(), @@ -169,8 +175,8 @@ var ClassMixin = Ember.Mixin.create( extend: function() { var Class = makeCtor(), proto; - Class.ClassMixin = Ember.Mixin.create(this.ClassMixin); - Class.PrototypeMixin = Ember.Mixin.create(this.PrototypeMixin); + Class.ClassMixin = Mixin.create(this.ClassMixin); + Class.PrototypeMixin = Mixin.create(this.PrototypeMixin); Class.ClassMixin.ownerConstructor = Class; Class.PrototypeMixin.ownerConstructor = Class; @@ -182,7 +188,7 @@ var ClassMixin = Ember.Mixin.create( proto = Class.prototype = o_create(this.prototype); proto.constructor = Class; - Ember.generateGuid(proto, 'ember'); + generateGuid(proto, 'ember'); meta(proto).proto = proto; // this will disable observers on prototype Class.ClassMixin.apply(Class); @@ -203,7 +209,7 @@ var ClassMixin = Ember.Mixin.create( reopenClass: function() { reopen.apply(this.ClassMixin, arguments); - Ember.Mixin._apply(this, arguments, false); + applyMixin(this, arguments, false); return this; },
false
Other
emberjs
ember.js
933b2b4a6eb4f82884c4ec5c567890ffb458beab.json
Add disconnectOutlet method to controller
packages/ember-views/lib/system/controller.js
@@ -132,8 +132,10 @@ Ember.ControllerMixin.reopen(/** @scope Ember.ControllerMixin.prototype */ { Ember.assert("The name you supplied " + name + " did not resolve to a controller " + name + 'Controller', (!!controller && !!context) || !context); } - if (controller && context) { controller.set('content', context); } - view = viewClass.create(); + if (controller && context) { set(controller, 'content', context); } + + view = this.createOutletView(outletName, viewClass); + if (controller) { set(view, 'controller', controller); } set(this, outletName, view); @@ -160,6 +162,25 @@ Ember.ControllerMixin.reopen(/** @scope Ember.ControllerMixin.prototype */ { controllerName = controllerNames[i] + 'Controller'; set(this, controllerName, get(controllers, controllerName)); } + }, + + /** + `disconnectOutlet` removes previously attached view from given outlet. + + @param {String} outletName the outlet name. (optional) + */ + disconnectOutlet: function(outletName) { + outletName = outletName || 'view'; + + set(this, outletName, null); + }, + + /** + `createOutletView` is a hook you may want to override if you need to do + something special with the view created for the outlet. For example + you may want to implement views sharing across outlets. + */ + createOutletView: function(outletName, viewClass) { + return viewClass.create(); } }); -
true
Other
emberjs
ember.js
933b2b4a6eb4f82884c4ec5c567890ffb458beab.json
Add disconnectOutlet method to controller
packages/ember-views/tests/system/controller_test.js
@@ -183,3 +183,26 @@ test("connectControllers injects other controllers", function() { equal(controller.get('postController'), postController, "should connect postController"); equal(controller.get('commentController'), commentController, "should connect commentController"); }); + +test("can disconnect outlet from controller", function() { + var appController = TestApp.ApplicationController.create({ + controllers: {}, + namespace: TestApp + }); + + var view = appController.connectOutlet('post'); + + equal(appController.get('view'), view, "the app controller's view is set"); + + appController.disconnectOutlet(); + + equal(appController.get('view'), null, "the app controller's view is null"); + + view = appController.connectOutlet({outletName: 'master', name: 'post'}); + + equal(appController.get('master'), view, "the app controller's master view is set"); + + appController.disconnectOutlet('master'); + + equal(appController.get('master'), null, "the app controller's master view is null"); +});
true
Other
emberjs
ember.js
a1fa3dbabe633dc8ee46a832c89ee781089c6c28.json
Add API doc for Ember.alias
packages/ember-metal/lib/mixin.js
@@ -572,6 +572,24 @@ Alias = function(methodName) { }; Alias.prototype = new Ember.Descriptor(); +/** + Makes a property or method available via an additional name. + + App.PaintSample = Ember.Object.extend({ + color: 'red', + colour: Ember.alias('color'), + name: function(){ + return "Zed"; + }, + moniker: Ember.alias("name") + }); + var paintSample = App.PaintSample.create() + paintSample.get('colour'); //=> 'red' + paintSample.moniker(); //=> 'Zed' + + @param {String} methodName name of the method or property to alias + @returns {Ember.Descriptor} +*/ Ember.alias = function(methodName) { return new Alias(methodName); };
false
Other
emberjs
ember.js
35fb8026e6f5abbeb936cd98f17e749f257beef1.json
Support jQuery 1.8 - fixes #1267
Rakefile
@@ -137,7 +137,8 @@ task :test, [:suite] => :dist do |t, args| :default => packages.map{|p| "package=#{p}" }, :runtime => [ "package=ember-metal,ember-runtime" ], :all => packages.map{|p| "package=#{p}" } + - ["package=all&jquery=git&nojshint=true", + ["package=all&jquery=1.7.2&nojshint=true", + "package=all&jquery=git&nojshint=true", "package=all&extendprototypes=true&nojshint=true", "package=all&extendprototypes=true&jquery=git&nojshint=true", "package=all&nocpdefaultcacheable=true&nojshint=true",
true
Other
emberjs
ember.js
35fb8026e6f5abbeb936cd98f17e749f257beef1.json
Support jQuery 1.8 - fixes #1267
packages/ember-views/lib/core.js
@@ -5,5 +5,5 @@ // License: Licensed under MIT license (see license.js) // ========================================================================== -Ember.assert("Ember Views require jQuery 1.7", window.jQuery && (window.jQuery().jquery.match(/^1\.7(\.\d+)?(pre|rc\d?)?/) || Ember.ENV.FORCE_JQUERY)); +Ember.assert("Ember Views require jQuery 1.7 or 1.8", window.jQuery && (window.jQuery().jquery.match(/^1\.[78](\.\d+)?(pre|rc\d?)?/) || Ember.ENV.FORCE_JQUERY)); Ember.$ = window.jQuery;
true
Other
emberjs
ember.js
35fb8026e6f5abbeb936cd98f17e749f257beef1.json
Support jQuery 1.8 - fixes #1267
tests/index.html
@@ -104,7 +104,7 @@ <h2 id="qunit-userAgent"></h2> <script> // Load custom version of jQuery if possible - var jQueryVersion = QUnit.urlParams.jquery || "1.7.2"; + var jQueryVersion = QUnit.urlParams.jquery || "1.8.0"; if (jQueryVersion !== 'none') { document.write('<script src="http://code.jquery.com/jquery-'+jQueryVersion+'.js"><\/script>'); }
true
Other
emberjs
ember.js
0be5c862660e284a86ec35306da85325571987f3.json
add scheduleOnce and remove flag
packages/ember-metal/lib/run_loop.js
@@ -474,6 +474,35 @@ function invokeOnceTimer(guid, onceTimers) { delete timers[guid]; } +function scheduleOnce(queue, target, method, args) { + var tguid = Ember.guidFor(target), + mguid = Ember.guidFor(method), + onceTimers = run.autorun().onceTimers, + guid = onceTimers[tguid] && onceTimers[tguid][mguid], + timer; + + if (guid && timers[guid]) { + timers[guid].args = args; // replace args + } else { + timer = { + target: target, + method: method, + args: args, + tguid: tguid, + mguid: mguid + }; + + guid = Ember.guidFor(timer); + timers[guid] = timer; + if (!onceTimers[tguid]) { onceTimers[tguid] = {}; } + onceTimers[tguid][mguid] = guid; // so it isn't scheduled more than once + + run.schedule(queue, timer, invokeOnceTimer, guid, onceTimers); + } + + return guid; +} + /** Schedules an item to run one time during the current RunLoop. Calling this method with the same target/method combination will have no effect. @@ -503,32 +532,11 @@ function invokeOnceTimer(guid, onceTimers) { @returns {Object} timer */ Ember.run.once = function(target, method) { - var tguid = Ember.guidFor(target), - mguid = Ember.guidFor(method), - onceTimers = run.autorun().onceTimers, - guid = onceTimers[tguid] && onceTimers[tguid][mguid], - timer; - - if (guid && timers[guid]) { - timers[guid].args = slice.call(arguments); // replace args - } else { - timer = { - target: target, - method: method, - args: slice.call(arguments), - tguid: tguid, - mguid: mguid - }; - - guid = Ember.guidFor(timer); - timers[guid] = timer; - if (!onceTimers[tguid]) { onceTimers[tguid] = {}; } - onceTimers[tguid][mguid] = guid; // so it isn't scheduled more than once - - run.schedule('actions', timer, invokeOnceTimer, guid, onceTimers); - } + return scheduleOnce('actions', target, method, slice.call(arguments)); +}; - return guid; +Ember.run.scheduleOnce = function(queue, target, method) { + return scheduleOnce(queue, target, method, slice.call(arguments)); }; var scheduledNext;
true
Other
emberjs
ember.js
0be5c862660e284a86ec35306da85325571987f3.json
add scheduleOnce and remove flag
packages/ember-views/lib/views/container_view.js
@@ -350,7 +350,11 @@ Ember.ContainerView = Ember.View.extend({ if (currentView) { childViews.pushObject(currentView); } - }, 'currentView') + }, 'currentView'), + + _ensureChildrenAreInDOM: function () { + this.invokeForState('ensureChildrenAreInDOM', this); + } }); // Ember.ContainerView extends the default view states to provide different @@ -396,14 +400,10 @@ Ember.ContainerView.states = { }, childViewsDidChange: function(view, views, start, added) { - if (!view._ensureChildrenAreInDOMScheduled) { - view._ensureChildrenAreInDOMScheduled = true; - Ember.run.schedule('render', this, this.invokeForState, 'ensureChildrenAreInDOM', view); - } + Ember.run.scheduleOnce('render', this, '_ensureChildrenAreInDOM'); }, ensureChildrenAreInDOM: function(view) { - view._ensureChildrenAreInDOMScheduled = false; var childViews = view.get('childViews'), i, len, childView, previous, buffer; for (i = 0, len = childViews.length; i < len; i++) { childView = childViews[i];
true
Other
emberjs
ember.js
1f1909bfef698d7fa1e8cdd569961e18f4c35a80.json
Remove remaining references to viewstates
ember.json
@@ -27,7 +27,6 @@ "ember-views", "ember-states", "ember-routing", - "ember-viewstates", "ember-handlebars" ] }
true
Other
emberjs
ember.js
1f1909bfef698d7fa1e8cdd569961e18f4c35a80.json
Remove remaining references to viewstates
tests/index.html
@@ -189,7 +189,6 @@ <h2 id="qunit-userAgent"></h2> 'ember-states', 'ember-views', 'ember-routing', - 'ember-viewstates', 'ember-application' ]; }
true
Other
emberjs
ember.js
817e2671b600dcc063b8b5f5643ffc81d6452af5.json
Remove stray require Test files apparently do not (and should not) have `require` calls.
packages/ember-routing/tests/routable_test.js
@@ -1,5 +1,3 @@ -require('ember-routing/location'); - module("Ember.Routable"); test("it should have its updateRoute method called when it is entered", function() {
false
Other
emberjs
ember.js
032e874ba0dec3cec3eb1a9efcd5e5c9b77852ab.json
Add documentation for ControllerMixin
packages/ember-runtime/lib/controllers/controller.js
@@ -1,6 +1,33 @@ require('ember-runtime/system/object'); require('ember-runtime/system/string'); +/** + @class + + Ember.ControllerMixin provides a standard interface for all classes + that compose Ember's controller layer: Ember.Controller, Ember.ArrayController, + and Ember.ObjectController. + + Within an Ember.Router-managed application single shared instaces of every + Controller object in your application's namespace will be added to the + application's Ember.Router instance. See `Ember.Application#initialize` + for additional information. + + ## Views + By default a controller instance will be the rendering context + for its associated Ember.View. This connection is made during calls to + `Ember.ControllerMixin#connectOutlet`. + + Within the view's template, the Ember.View instance can be accessed + through the controller with `{{view}}`. + + ## Target Forwarding + By default a controller will target your application's Ember.Router instance. + Calls to `{{action}}` within the template of a controller's view are forwarded + to the router. See `Ember.Handlebars.helpers.action` for additional information. + + @extends Ember.Mixin +*/ Ember.ControllerMixin = Ember.Mixin.create({ /** The object to which events from the view should be sent.
true
Other
emberjs
ember.js
032e874ba0dec3cec3eb1a9efcd5e5c9b77852ab.json
Add documentation for ControllerMixin
packages/ember-views/lib/system/controller.js
@@ -1,6 +1,7 @@ var get = Ember.get, set = Ember.set; -Ember.ControllerMixin.reopen({ +// @class declaration and documentation in runtime/lib/controllers/controller.js +Ember.ControllerMixin.reopen(/** @scope Ember.ControllerMixin.prototype */ { target: null, controllers: null,
true
Other
emberjs
ember.js
1f56feb5fe5be11c0968a61c2affd16038cb6f5b.json
Add documentation for ObjectController
packages/ember-runtime/lib/controllers/object_controller.js
@@ -1,4 +1,18 @@ require('ember-runtime/system/object_proxy'); require('ember-runtime/controllers/controller'); +/** + @class + + Ember.ObjectController is part of Ember's Controller layer. A single + shared instance of each Ember.ObjectController subclass in your application's + namespace will be created at application initialization and be stored on your + application's Ember.Router instance. + + Ember.ObjectController derives its functionality from its superclass + Ember.ObjectProxy and the Ember.ControllerMixin mixin. + + @extends Ember.ObjectProxy + @extends Ember.ControllerMixin +**/ Ember.ObjectController = Ember.ObjectProxy.extend(Ember.ControllerMixin);
false
Other
emberjs
ember.js
c7203f636e97d7fb7ba90c370ff2549effcf276c.json
* packages/ember-routing/lib/router.js: Fix bits of documentation.
packages/ember-routing/lib/router.js
@@ -108,11 +108,11 @@ var merge = function(original, hash) { route: '/theBaseRouteForThisSet', indexSubRoute: Ember.Route.extend({ - route: '/', + route: '/' }), subRouteOne: Ember.Route.extend({ - route: '/subroute1 + route: '/subroute1' }), subRouteTwo: Ember.Route.extend({
false
Other
emberjs
ember.js
d8f76a7fdde741ae3d1e07b12df9cb6718170e48.json
Use git version of github_downloads
Gemfile
@@ -8,7 +8,7 @@ gem "uglifier", :git => "https://github.com/lautis/uglifier.git" group :development do gem "rack" - gem "github_downloads" + gem "github_downloads", :git => "https://github.com/pangratz/github_downloads.git" gem "ember-docs", :git => "https://github.com/emberjs/docs-generator.git" gem "kicker" end
true
Other
emberjs
ember.js
d8f76a7fdde741ae3d1e07b12df9cb6718170e48.json
Use git version of github_downloads
Gemfile.lock
@@ -22,6 +22,14 @@ GIT rake (~> 0.9.0) thor +GIT + remote: https://github.com/pangratz/github_downloads.git + revision: 021d83165bcf37f6c2752736a9c05c13d6976f38 + specs: + github_downloads (0.1.2) + github_api (~> 0.6) + rest-client (~> 1.6) + GIT remote: https://github.com/wycats/rake-pipeline-web-filters.git revision: 81a22fb0808dfdeab8ed92d5d8c898ad198b9938 @@ -38,20 +46,16 @@ GEM multi_json (~> 1.0) faraday (0.8.1) multipart-post (~> 1.1) - github_api (0.6.1) + github_api (0.6.4) faraday (~> 0.8.1) hashie (~> 1.2.0) multi_json (~> 1.3) nokogiri (~> 1.5.2) oauth2 - github_downloads (0.1.1) - github_api (~> 0.6.0) - rest-client (~> 1.6.7) hashie (1.2.0) httpauth (0.1) - json (1.7.3) - jwt (0.1.4) - json (>= 1.2.4) + jwt (0.1.5) + multi_json (>= 1.0) kicker (2.5.0) rb-fsevent mime-types (1.19) @@ -77,7 +81,7 @@ PLATFORMS DEPENDENCIES colored ember-docs! - github_downloads + github_downloads! kicker rack rake-pipeline!
true
Other
emberjs
ember.js
a6b437824d618b549e5ae1d3d98eba8cca7dd1be.json
Fix routing with initialState
packages/ember-routing/lib/routable.js
@@ -364,8 +364,10 @@ Ember.Routable = Ember.Mixin.create({ state of the state it will eventually move into. */ unroutePath: function(router, path) { + var parentState = get(this, 'parentState'); + // If we're at the root state, we're done - if (get(this, 'parentState') === router) { + if (parentState === router) { return; } @@ -388,8 +390,12 @@ Ember.Routable = Ember.Mixin.create({ } // Transition to the parent and call unroute again. - var parentPath = get(get(this, 'parentState'), 'path'); - router.transitionTo(parentPath); + router.enterState({ + exitStates: [this], + enterStates: [], + finalState: parentState + }); + router.send('unroutePath', path); },
true
Other
emberjs
ember.js
a6b437824d618b549e5ae1d3d98eba8cca7dd1be.json
Fix routing with initialState
packages/ember-routing/tests/router_test.js
@@ -355,6 +355,30 @@ test("should be able to unroute out of a state with context", function() { equal(get(router, 'currentState.path'), 'root.components.show.index', "should go to the correct state"); }); +test("should be able to route with initialState", function() { + var router = Ember.Router.create({ + location: location, + namespace: namespace, + root: Ember.Route.create({ + initialState: 'stateOne', + + stateOne: Ember.Route.create({ + route: '/state_one' + }), + + stateTwo: Ember.Route.create({ + route: '/state_two' + }) + }) + }); + + equal(get(router, 'currentState.path'), 'root.stateOne', "should be in stateOne"); + + router.route('/state_two'); + + equal(get(router, 'currentState.path'), 'root.stateTwo', "should be in stateTwo"); +}); + test("should update route for redirections", function() { var router = Ember.Router.create({ location: location,
true
Other
emberjs
ember.js
079adc65f3ad2e53a48c3339a06e0e62ae4500da.json
Implement immediateObserver placeholder At present, observers are fired synchronously when a property changes, unless they have been manually suspended (via begin/endPropertyChanges) or automatically, as part of the binding synchronization process. However, we have plans to make observers asynchronous in the future, and encourage developers to never assume that observers fire synchronously. When using computed properties to implement two-way binding behavior, it can be important that side-effects occur synchronously. However, these side-effects should not happen inside of the computed property itself, as this can trigger an infinite loop. This mechanism may become obsolete if all observers (including Array observers) become asynchronous, AND can be immediately delivered upon an attempt to access their object.
packages/ember-metal/lib/mixin.js
@@ -586,6 +586,17 @@ Ember.observer = function(func) { return func; }; +// If observers ever become asynchronous, Ember.immediateObserver +// must remain synchronous. +Ember.immediateObserver = function() { + for (var i=0, l=arguments.length; i<l; i++) { + var arg = arguments[i]; + Ember.assert("Immediate observers must observe internal properties only, not properties on other objects.", typeof arg !== "string" || arg.indexOf('.') === -1); + } + + return Ember.observer.apply(this, arguments); +}; + Ember.beforeObserver = function(func) { var paths = a_slice.call(arguments, 1); func.__ember_observesBefore__ = paths;
true
Other
emberjs
ember.js
079adc65f3ad2e53a48c3339a06e0e62ae4500da.json
Implement immediateObserver placeholder At present, observers are fired synchronously when a property changes, unless they have been manually suspended (via begin/endPropertyChanges) or automatically, as part of the binding synchronization process. However, we have plans to make observers asynchronous in the future, and encourage developers to never assume that observers fire synchronously. When using computed properties to implement two-way binding behavior, it can be important that side-effects occur synchronously. However, these side-effects should not happen inside of the computed property itself, as this can trigger an infinite loop. This mechanism may become obsolete if all observers (including Array observers) become asynchronous, AND can be immediately delivered upon an attempt to access their object.
packages/ember-metal/tests/observer_test.js
@@ -629,3 +629,45 @@ testBoth('setting a cached computed property whose value has changed should trig equal(count, 3); equal(get(obj, 'foo'), 'bar'); }); + +module("Ember.immediateObserver"); + +testBoth("immediate observers should fire synchronously", function(get, set) { + var obj = {}, + observerCalled = 0, + mixin; + + // explicitly create a run loop so we do not inadvertently + // trigger deferred behavior + Ember.run(function() { + mixin = Ember.Mixin.create({ + fooDidChange: Ember.immediateObserver(function() { + observerCalled++; + equal(get(this, 'foo'), "barbaz", "newly set value is immediately available"); + }, 'foo') + }); + + mixin.apply(obj); + + Ember.defineProperty(obj, 'foo', Ember.computed(function(key, value) { + if (arguments.length > 1) { + return value; + } + return "yes hello this is foo"; + }).cacheable()); + + equal(get(obj, 'foo'), "yes hello this is foo", "precond - computed property returns a value"); + equal(observerCalled, 0, "observer has not yet been called"); + + set(obj, 'foo', 'barbaz'); + + equal(observerCalled, 1, "observer was called once"); + }); +}); + +testBoth("immediate observers are for internal properties only", function(get, set) { + raises(function() { + Ember.immediateObserver(Ember.K, 'foo.bar'); + }); +}); +
true
Other
emberjs
ember.js
6a863c6cbef95f232d2933486c69830e381bcc1c.json
Call pushState when state null and at initial url
packages/ember-application/lib/system/history_location.js
@@ -42,8 +42,7 @@ Ember.HistoryLocation = Ember.Object.extend({ path = this.formatPath(path); - if ((initialURL && initialURL !== path) || (state && state.path !== path)) { - set(this, '_initialURL', null); + if ((initialURL !== path && !state) || (state && state.path !== path)) { window.history.pushState({ path: path }, null, path); } },
false
Other
emberjs
ember.js
464d9502d6221946864028a716d1c4f8b5fe35f9.json
add failing test
packages/ember-metal/tests/watching/watch_test.js
@@ -60,6 +60,26 @@ testBoth('watching a regular defined property', function(get, set) { set(obj, 'foo', 'bar'); equal(willCount, 1, 'should have invoked willCount'); equal(didCount, 1, 'should have invoked didCount'); + + equal(get(obj, 'foo'), 'bar', 'should get new value'); + equal(obj.foo, 'bar', 'property should be accessible on obj'); +}); + +testBoth('watching a regular undefined property', function(get, set) { + + var obj = { }; + + Ember.watch(obj, 'foo'); + + equal('foo' in obj, false, 'precond undefined'); + + set(obj, 'foo', 'bar'); + + equal(willCount, 1, 'should have invoked willCount'); + equal(didCount, 1, 'should have invoked didCount'); + + equal(get(obj, 'foo'), 'bar', 'should get new value'); + equal(obj.foo, 'bar', 'property should be accessible on obj'); }); testBoth('watches should inherit', function(get, set) {
false
Other
emberjs
ember.js
632307eba5d030e2f5085987e293e6ee4c314b86.json
destroy previous currentView
packages/ember-views/lib/views/container_view.js
@@ -356,6 +356,7 @@ Ember.ContainerView = Ember.View.extend({ if (currentView) { childViews.removeObject(currentView); + currentView.destroy(); } }, 'currentView'),
false
Other
emberjs
ember.js
26519bc932b1e96fef2530449c22cb0dc3f0dad4.json
add failing test
packages/ember-views/tests/views/container_view_test.js
@@ -246,7 +246,7 @@ test("if a ContainerView starts with a currentView and then is set to null, the equal(get(container, 'childViews.length'), 0, "should not have any child views"); }); -test("if a ContainerView starts with a currentView and then is set to null, the ContainerView is updated", function() { +test("if a ContainerView starts with a currentView and then is set to null, the ContainerView is updated and the previous currentView is destroyed", function() { var container = Ember.ContainerView.create(); var mainView = Ember.View.create({ template: function() { @@ -267,11 +267,13 @@ test("if a ContainerView starts with a currentView and then is set to null, the set(container, 'currentView', null); }); + equal(mainView.isDestroyed, true, 'should destroy the previous currentView.'); + equal(container.$().text(), '', "has a empty contents"); equal(get(container, 'childViews.length'), 0, "should not have any child views"); }); -test("if a ContainerView starts with a currentView and then a different currentView is set, the old view is removed and the new one is added", function() { +test("if a ContainerView starts with a currentView and then a different currentView is set, the old view is destroyed and the new one is added", function() { var container = Ember.ContainerView.create(); var mainView = Ember.View.create({ template: function() { @@ -299,6 +301,8 @@ test("if a ContainerView starts with a currentView and then a different currentV set(container, 'currentView', secondaryView); }); + equal(mainView.isDestroyed, true, 'should destroy the previous currentView.'); + equal(container.$().text(), "This is the secondary view.", "should render its child"); equal(get(container, 'childViews.length'), 1, "should have one child view"); equal(get(container, 'childViews').objectAt(0), secondaryView, "should have the currentView as the only child view");
false
Other
emberjs
ember.js
396c08b1322f4b642a65005cc89cdd7bb8acce06.json
Add connectControllers convenience
packages/ember-views/lib/system/controller.js
@@ -137,6 +137,28 @@ Ember.ControllerMixin.reopen({ set(this, outletName, view); return view; + }, + + /** + Convenience method to connect controllers. This method makes other controllers + available on the controller the method was invoked on. + + For example, to make the `personController` and the `postController` available + on the `overviewController`, you would call: + + overviewController.connectControllers('person', 'post'); + + @param {String...} controllerNames the controllers to make available + */ + connectControllers: function() { + var controllers = get(this, 'controllers'), + controllerNames = Array.prototype.slice.apply(arguments), + controllerName; + + for (var i=0, l=controllerNames.length; i<l; i++) { + controllerName = controllerNames[i] + 'Controller'; + set(this, controllerName, get(controllers, controllerName)); + } } });
true
Other
emberjs
ember.js
396c08b1322f4b642a65005cc89cdd7bb8acce06.json
Add connectControllers convenience
packages/ember-views/tests/system/controller_test.js
@@ -167,3 +167,19 @@ test("if the controller is not given while connecting an outlet, the instantiate equal(view.get('controller'), postController, "the controller was inherited from the parent"); }); + +test("connectControllers injects other controllers", function() { + var postController = {}, commentController = {}; + + var controller = Ember.Controller.create({ + controllers: { + postController: postController, + commentController: commentController + } + }); + + controller.connectControllers('post', 'comment'); + + equal(controller.get('postController'), postController, "should connect postController"); + equal(controller.get('commentController'), commentController, "should connect commentController"); +});
true
Other
emberjs
ember.js
852f41faa7862cd3908ebee08041fef160c29f03.json
Delay routing while contexts are loading
packages/ember-routing/lib/resolved_state.js
@@ -0,0 +1,45 @@ +var get = Ember.get; + +Ember._ResolvedState = Ember.Object.extend({ + manager: null, + state: null, + match: null, + + object: Ember.computed(function(key, value) { + if (arguments.length === 2) { + this._object = value; + return value; + } else { + if (this._object) { + return this._object; + } else { + var state = get(this, 'state'), + match = get(this, 'match'), + manager = get(this, 'manager'); + return state.deserialize(manager, match.hash); + } + } + }).property(), + + hasPromise: Ember.computed(function() { + return Ember.canInvoke(get(this, 'object'), 'then'); + }).property('object'), + + promise: Ember.computed(function() { + var object = get(this, 'object'); + if (Ember.canInvoke(object, 'then')) { + return object; + } else { + return { + then: function(success) { success(object); } + }; + } + }).property('object'), + + transition: function() { + var manager = get(this, 'manager'), + path = get(this, 'state.path'), + object = get(this, 'object'); + manager.transitionTo(path, object); + } +});
true
Other
emberjs
ember.js
852f41faa7862cd3908ebee08041fef160c29f03.json
Delay routing while contexts are loading
packages/ember-routing/lib/routable.js
@@ -1,3 +1,5 @@ +require('ember-routing/resolved_state'); + var get = Ember.get; // The Ember Routable mixin assumes the existance of a simple @@ -275,16 +277,9 @@ Ember.Routable = Ember.Mixin.create({ /** @private - - Once `unroute` has finished unwinding, `routePath` will be called - with the remainder of the route. - - For example, if you were in the /posts/1/comments state, and you - moved into the /posts/2/comments state, `routePath` will be called - on the state whose path is `/posts` with the path `/2/comments`. */ - routePath: function(manager, path) { - if (get(this, 'isLeafRoute')) { return; } + resolvePath: function(manager, path) { + if (get(this, 'isLeafRoute')) { return Ember.A(); } var childStates = get(this, 'childStates'), match; @@ -316,9 +311,47 @@ Ember.Routable = Ember.Mixin.create({ Ember.assert("Could not find state for path " + path, !!state); - var object = state.deserialize(manager, match.hash); - manager.transitionTo(get(state, 'path'), object); - manager.send('routePath', match.remaining); + var resolvedState = Ember._ResolvedState.create({ + manager: manager, + state: state, + match: match + }); + + var states = state.resolvePath(manager, match.remaining); + + return Ember.A([resolvedState]).pushObjects(states); + }, + + /** + @private + + Once `unroute` has finished unwinding, `routePath` will be called + with the remainder of the route. + + For example, if you were in the /posts/1/comments state, and you + moved into the /posts/2/comments state, `routePath` will be called + on the state whose path is `/posts` with the path `/2/comments`. + */ + routePath: function(manager, path) { + if (get(this, 'isLeafRoute')) { return; } + + var resolvedStates = this.resolvePath(manager, path), + hasPromises = resolvedStates.some(function(s) { return get(s, 'hasPromise'); }); + + function runTransition() { + resolvedStates.forEach(function(rs) { rs.transition(); }); + } + + if (hasPromises) { + manager.transitionTo('loading'); + + Ember.assert('Loading state should be the child of a route', Ember.Routable.detect(get(manager, 'currentState.parentState'))); + Ember.assert('Loading state should not be a route', !Ember.Routable.detect(get(manager, 'currentState'))); + + manager.handleStatePromises(resolvedStates, runTransition); + } else { + runTransition(); + } }, /**
true
Other
emberjs
ember.js
852f41faa7862cd3908ebee08041fef160c29f03.json
Delay routing while contexts are loading
packages/ember-routing/lib/router.js
@@ -396,7 +396,14 @@ Ember.Router = Ember.StateManager.extend( */ transitionEvent: 'connectOutlets', + transitionTo: function() { + this.abortRoutingPromises(); + this._super.apply(this, arguments); + }, + route: function(path) { + this.abortRoutingPromises(); + set(this, 'isRouting', true); var routableState; @@ -468,6 +475,45 @@ Ember.Router = Ember.StateManager.extend( } }, + abortRoutingPromises: function() { + if (this._routingPromises) { + this._routingPromises.abort(); + this._routingPromises = null; + } + }, + + /** + @private + */ + handleStatePromises: function(states, complete) { + this.abortRoutingPromises(); + + this.set('isLocked', true); + + var manager = this; + + this._routingPromises = Ember._PromiseChain.create({ + promises: states.slice(), + + successCallback: function() { + manager.set('isLocked', false); + complete(); + }, + + failureCallback: function() { + throw "Unable to load object"; + }, + + promiseSuccessCallback: function(item, args) { + set(item, 'object', args[0]); + }, + + abortCallback: function() { + manager.set('isLocked', false); + } + }).start(); + }, + /** @private */ init: function() { this._super();
true
Other
emberjs
ember.js
852f41faa7862cd3908ebee08041fef160c29f03.json
Delay routing while contexts are loading
packages/ember-routing/tests/routable_test.js
@@ -345,21 +345,225 @@ test("should use a specified class `modelType` in the default `deserialize`", fu router.route("/users/1"); }); -module("default serialize and deserialize without modelType", { +var postSuccessCallback, postFailureCallback, + userSuccessCallback, userFailureCallback, + connectedUser, connectedPost, connectedChild, connectedOther, + isLoading, userLoaded; + +module("modelType with promise", { setup: function() { window.TestApp = Ember.Namespace.create(); - window.TestApp.Post = Ember.Object.extend(); + + window.TestApp.User = Ember.Object.extend({ + then: function(success, failure) { + userLoaded = true; + userSuccessCallback = success; + userFailureCallback = failure; + } + }); + window.TestApp.User.find = function(id) { + if (id === "1") { + return firstUser; + } + }; + + window.TestApp.Post = Ember.Object.extend({ + then: function(success, failure) { + postSuccessCallback = success; + postFailureCallback = failure; + } + }); window.TestApp.Post.find = function(id) { + // Simulate dependency on user + if (!userLoaded) { return; } if (id === "1") { return firstPost; } }; - window.TestApp.User = Ember.Object.extend(); - window.TestApp.User.find = function(id) { - if (id === "1") { return firstUser; } + firstUser = window.TestApp.User.create({ id: 1 }); + firstPost = window.TestApp.Post.create({ id: 1 }); + + router = Ember.Router.create({ + location: { + setURL: function(passedURL) { + url = passedURL; + } + }, + + root: Ember.Route.extend({ + users: Ember.Route.extend({ + route: '/users', + + user: Ember.Route.extend({ + route: '/:user_id', + modelType: 'TestApp.User', + + connectOutlets: function(router, obj) { + connectedUser = obj; + }, + + posts: Ember.Route.extend({ + route: '/posts', + + post: Ember.Route.extend({ + route: '/:post_id', + modelType: 'TestApp.Post', + + connectOutlets: function(router, obj) { + connectedPost = obj; + }, + + show: Ember.Route.extend({ + route: '/', + + connectOutlets: function(router) { + connectedChild = true; + } + }) + }) + }) + }) + }), + + other: Ember.Route.extend({ + route: '/other', + + connectOutlets: function() { + connectedOther = true; + } + }), + + loading: Ember.State.extend({ + connectOutlets: function() { + isLoading = true; + }, + + exit: function() { + isLoading = false; + } + }) + }) + }); + }, + + teardown: function() { + window.TestApp = undefined; + postSuccessCallback = postFailureCallback = undefined; + userSuccessCallback = userFailureCallback = undefined; + connectedUser = connectedPost = connectedChild = connectedOther = undefined; + isLoading = userLoaded = undefined; + } +}); + +test("should handle promise success", function() { + ok(!isLoading, 'precond - should not start loading'); + + Ember.run(function() { + router.route('/users/1/posts/1'); + }); + + ok(!connectedUser, 'precond - should not connect user immediately'); + ok(!connectedPost, 'precond - should not connect post immediately'); + ok(!connectedChild, 'precond - should not connect child immediately'); + ok(isLoading, 'should be loading'); + + Ember.run(function() { + userSuccessCallback('loadedUser'); + }); + + ok(!connectedUser, 'should not connect user until all promises are loaded'); + ok(!connectedPost, 'should not connect post until all promises are loaded'); + ok(!connectedChild, 'should not connect child until all promises are loaded'); + ok(isLoading, 'should still be loading'); + + Ember.run(function() { + postSuccessCallback('loadedPost'); + }); + + equal(connectedUser, 'loadedUser', 'should connect user after success callback'); + equal(connectedPost, 'loadedPost', 'should connect post after success callback'); + ok(connectedChild, "should connect child's outlets after success callback"); + ok(!isLoading, 'should not be loading'); +}); + +test("should handle early promise failure", function() { + router.route('/users/1/posts/1'); + + ok(userFailureCallback, 'precond - has failureCallback'); + + raises(function() { + userFailureCallback('failedUser'); + }, "Unable to load record.", "should throw exception on failure"); + + ok(!connectedUser, 'should not connect user after early failure'); + ok(!connectedPost, 'should not connect post after early failure'); + ok(!connectedChild, 'should not connect child after early failure'); +}); + +test("should handle late promise failure", function() { + router.route('/users/1/posts/1'); + + userSuccessCallback('loadedUser'); + + ok(postFailureCallback, 'precond - has failureCallback'); + + raises(function() { + postFailureCallback('failedPost'); + }, "Unable to load record.", "should throw exception on failure"); + + ok(!connectedUser, 'should not connect user after late failure'); + ok(!connectedPost, 'should not connect post after late failure'); + ok(!connectedChild, 'should not connect child after late failure'); +}); + +test("should stop promises if new route is targeted", function() { + router.route('/users/1/posts/1'); + + userSuccessCallback('loadedUser'); + + ok(!connectedOther, 'precond - has not yet connected other'); + + Ember.run(function() { + router.route('/other'); + }); + + ok(connectedOther, 'should connect other'); + + postSuccessCallback('loadedPost'); + + ok(!connectedUser, 'should not connect user after reroute'); + ok(!connectedPost, 'should not connect post after reroute'); + ok(!connectedChild, 'should not connect child after reroute'); +}); + +test("should stop promises if transitionTo is called", function() { + router.route('/users/1/posts/1'); + + userSuccessCallback('loadedUser'); + + ok(!connectedOther, 'precond - has not yet connected other'); + + Ember.run(function() { + router.transitionTo('other'); + }); + + ok(connectedOther, 'should connect other'); + + postSuccessCallback('loadedPost'); + + ok(!connectedUser, 'should not connect user after reroute'); + ok(!connectedPost, 'should not connect post after reroute'); + ok(!connectedChild, 'should not connect child after reroute'); +}); + +module("default serialize and deserialize without modelType", { + setup: function() { + window.TestApp = Ember.Namespace.create(); + window.TestApp.Post = Ember.Object.extend(); + window.TestApp.Post.find = function(id) { + if (id === "1") { return firstPost; } }; firstPost = window.TestApp.Post.create({ id: 1 }); - firstUser = window.TestApp.User.create({ id: 1 }); router = Ember.Router.create({ namespace: window.TestApp,
true
Other
emberjs
ember.js
9250abaf5e12084cd12ee62a7d1e335a5ee7c5f1.json
Remove odd construct in normalizeTuples
packages/ember-metal/lib/accessors.js
@@ -217,8 +217,6 @@ Ember.normalizeTuple = function(target, path) { return normalizeTuple(target, path); }; -Ember.normalizeTuple.primitive = normalizeTuple; - Ember.getWithDefault = function(root, key, defaultValue) { var value = get(root, key); @@ -318,4 +316,4 @@ if (Ember.config.overrideAccessors) { Ember.config.overrideAccessors(); get = Ember.get; set = Ember.set; -} \ No newline at end of file +}
true
Other
emberjs
ember.js
9250abaf5e12084cd12ee62a7d1e335a5ee7c5f1.json
Remove odd construct in normalizeTuples
packages/ember-metal/lib/watching.js
@@ -16,7 +16,7 @@ var guidFor = Ember.guidFor, // utils.js metaFor = Ember.meta, // utils.js get = Ember.get, // accessors.js set = Ember.set, // accessors.js - normalizeTuple = Ember.normalizeTuple.primitive, // accessors.js + normalizeTuple = Ember.normalizeTuple, // accessors.js GUID_KEY = Ember.GUID_KEY, // utils.js META_KEY = Ember.META_KEY, // utils.js // circular reference observer depends on Ember.watch
true
Other
emberjs
ember.js
3d0fbece8afe03610db33ed07a864e18772933d3.json
Remove LEGACY_HANDLEBARS_TAG flag
packages/ember-handlebars/lib/loader.js
@@ -18,10 +18,6 @@ require("ember-handlebars/ext"); Ember.Handlebars.bootstrap = function(ctx) { var selectors = 'script[type="text/x-handlebars"], script[type="text/x-raw-handlebars"]'; - if (Ember.ENV.LEGACY_HANDLEBARS_TAGS) { selectors += ', script[type="text/html"]'; } - - Ember.warn("Ember no longer parses text/html script tags by default. Set ENV.LEGACY_HANDLEBARS_TAGS = true to restore this functionality.", Ember.ENV.LEGACY_HANDLEBARS_TAGS || Ember.$('script[type="text/html"]').length === 0); - Ember.$(selectors, ctx) .each(function() { // Get a reference to the script tag
true
Other
emberjs
ember.js
3d0fbece8afe03610db33ed07a864e18772933d3.json
Remove LEGACY_HANDLEBARS_TAG flag
packages/ember-handlebars/tests/loader_test.js
@@ -72,22 +72,6 @@ test('template without data-element-id should still get an attribute', function( ok(id && /^ember\d+$/.test(id), "has standard Ember id"); }); -test('template with type text/html should work if LEGACY_HANDLEBARS_TAGS is true', function() { - Ember.ENV.LEGACY_HANDLEBARS_TAGS = true; - - try { - Ember.$('#qunit-fixture').html('<script type="text/html" data-template-name="funkyTemplate">Tobias Fünke</script>'); - - Ember.run(function() { - Ember.Handlebars.bootstrap(Ember.$('#qunit-fixture')); - }); - - ok(Ember.TEMPLATES['funkyTemplate'], 'template with name funkyTemplate available'); - } finally { - Ember.ENV.LEGACY_HANDLEBARS_TAGS = false; - } -}); - test('template with type text/x-raw-handlebars should be parsed', function() { Ember.$('#qunit-fixture').html('<script type="text/x-raw-handlebars" data-template-name="funkyTemplate">{{name}}</script>');
true
Other
emberjs
ember.js
96840c6b861603a312e28fa1ab5944328fcb6372.json
Add more documentation
packages/ember-views/lib/views/view.js
@@ -162,6 +162,14 @@ var invokeForState = { isEnabled: true }); + Will result in view instances with an HTML representation of: + + <div id="ember1" class="ember-view enabled"></div> + + When isEnabled is `false`, the resulting HTML reprensentation looks like this: + + <div id="ember1" class="ember-view disabled"></div> + Updates to the the value of a class name binding will result in automatic update of the HTML `class` attribute in the view's rendered HTML representation.
false
Other
emberjs
ember.js
b0d48458e28d484ac58b8ea85698aaa589e578a5.json
Add some documentation to Ember.View helpers
packages/ember-views/lib/views/view.js
@@ -1991,6 +1991,23 @@ Ember.View.reopen({ }); Ember.View.reopenClass({ + + /** + @private + + Parse a path and return an object which holds the parsed properties. + + For example a path like "content.isEnabled:enabled:disabled" wil return the + following object: + + { + path: "content.isEnabled", + className: "enabled", + falsyClassName: "disabled", + classNames: ":enabled:disabled" + } + + */ _parsePropertyPath: function(path) { var split = path.split(/:/), propertyPath = split[0], @@ -2019,6 +2036,19 @@ Ember.View.reopenClass({ }; }, + /** + @private + + Get the class name for a given value, based on the path, optional className + and optional falsyClassName. + + - if the value is truthy and a className is defined, the className is returned + - if the value is true, the dasherized last part of the supplied path is returned + - if the value is false and a falsyClassName is supplied, the falsyClassName is returned + - if the value is truthy, the value is returned + - if none of the above rules apply, null is returned + + */ _classStringForValue: function(path, val, className, falsyClassName) { // If the value is truthy and we're using the colon syntax, // we should return the className directly
false
Other
emberjs
ember.js
6309f24ccd4e2dccf7e68a876d853d12dbd45544.json
Change ternary syntax to double colon sytax The syntax to define class names for truthy and falsy values changed from isEnabled?enabled:disabled to isEnabled:enabled:disabled
packages/ember-handlebars/tests/handlebars_test.js
@@ -1155,7 +1155,7 @@ test("{{view}} should evaluate class bindings set to global paths", function() { }); view = Ember.View.create({ - template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled?enabled:disabled"}}') + template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled:enabled:disabled"}}') }); appendView(); @@ -1187,7 +1187,7 @@ test("{{view}} should evaluate class bindings set in the current context", funct isEditable: true, directClass: "view-direct", isEnabled: true, - template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="isEditable:editable directClass isView isEnabled?enabled:disabled"}}') + template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="isEditable:editable directClass isView isEnabled:enabled:disabled"}}') }); appendView(); @@ -1218,7 +1218,7 @@ test("{{view}} should evaluate class bindings set with either classBinding or cl }); view = Ember.View.create({ - template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.isEnabled?enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled?really-enabled:really-disabled"}}') + template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.isEnabled:enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled:really-enabled:really-disabled"}}') }); appendView(); @@ -1572,7 +1572,7 @@ test("should not allow XSS injection via {{bindAttr}} with class", function() { }); test("should be able to bind class attribute using ternary operator in {{bindAttr}}", function() { - var template = Ember.Handlebars.compile('<img {{bindAttr class="content.isDisabled?disabled:enabled"}} />'); + var template = Ember.Handlebars.compile('<img {{bindAttr class="content.isDisabled:disabled:enabled"}} />'); var content = Ember.Object.create({ isDisabled: true }); @@ -1596,7 +1596,7 @@ test("should be able to bind class attribute using ternary operator in {{bindAtt }); test("should be able to add multiple classes using {{bindAttr class}}", function() { - var template = Ember.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing :is-super-duper content.isEnabled?enabled:disabled"}}></div>'); + var template = Ember.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing :is-super-duper content.isEnabled:enabled:disabled"}}></div>'); var content = Ember.Object.create({ isAwesomeSauce: true, isAlsoCool: true,
true
Other
emberjs
ember.js
6309f24ccd4e2dccf7e68a876d853d12dbd45544.json
Change ternary syntax to double colon sytax The syntax to define class names for truthy and falsy values changed from isEnabled?enabled:disabled to isEnabled:enabled:disabled
packages/ember-views/lib/views/view.js
@@ -1972,23 +1972,22 @@ Ember.View.reopen({ Ember.View.reopenClass({ _parsePropertyPath: function(path) { - var split = path.split(/\?|:/), + var split = path.split(/:/), propertyPath = split[0], className, falsyClassName; - // check if the property is defined as prop?trueClass:falseClass + // check if the property is defined as prop:class or prop:trueClass:falseClass if (split.length > 1) { className = split[1]; if (split.length === 3) { falsyClassName = split[2]; } } var classNames = ""; if (className) { + classNames += ':' + className; if (falsyClassName) { - classNames = '?' + className + ':' + falsyClassName; - } else { - classNames = ':' + className; + classNames += ':' + falsyClassName; } }
true
Other
emberjs
ember.js
6309f24ccd4e2dccf7e68a876d853d12dbd45544.json
Change ternary syntax to double colon sytax The syntax to define class names for truthy and falsy values changed from isEnabled?enabled:disabled to isEnabled:enabled:disabled
packages/ember-views/tests/views/view/class_name_bindings_test.js
@@ -12,7 +12,7 @@ test("should apply bound class names to the element", function() { var view = Ember.View.create({ classNameBindings: ['priority', 'isUrgent', 'isClassified:classified', 'canIgnore', 'messages.count', 'messages.resent:is-resent', 'isNumber:is-number', - 'isEnabled?enabled:disabled'], + 'isEnabled:enabled:disabled'], priority: 'high', isUrgent: true, @@ -46,7 +46,7 @@ test("should add, remove, or change class names if changed after element is crea var view = Ember.View.create({ classNameBindings: ['priority', 'isUrgent', 'isClassified:classified', 'canIgnore', 'messages.count', 'messages.resent:is-resent', - 'isEnabled?enabled:disabled'], + 'isEnabled:enabled:disabled'], priority: 'high', isUrgent: true,
true
Other
emberjs
ember.js
6309f24ccd4e2dccf7e68a876d853d12dbd45544.json
Change ternary syntax to double colon sytax The syntax to define class names for truthy and falsy values changed from isEnabled?enabled:disabled to isEnabled:enabled:disabled
packages/ember-views/tests/views/view/parse_property_path_test.js
@@ -28,10 +28,10 @@ test("className is extracted", function() { }); test("falsyClassName is extracted", function() { - var parsed = Ember.View._parsePropertyPath("content.simpleProperty?class:falsyClass"); + var parsed = Ember.View._parsePropertyPath("content.simpleProperty:class:falsyClass"); equal(parsed.path, "content.simpleProperty", "path is parsed correctly"); equal(parsed.className, "class", "className is extracted"); equal(parsed.falsyClassName, "falsyClass", "falsyClassName is extracted"); - equal(parsed.classNames, "?class:falsyClass", "there is a classNames"); + equal(parsed.classNames, ":class:falsyClass", "there is a classNames"); }); \ No newline at end of file
true
Other
emberjs
ember.js
e596ab0cb9b3a176e1598b0a1d59629c2043669b.json
Add tests for Ember.View helpers
packages/ember-views/tests/views/view/class_string_for_value_test.js
@@ -0,0 +1,36 @@ +module("Ember.View - _classStringForValue"); + +var cSFV = Ember.View._classStringForValue; + +test("returns dasherized version of last path part if value is true", function() { + equal(cSFV("propertyName", true), "property-name", "class is dasherized"); + equal(cSFV("content.propertyName", true), "property-name", "class is dasherized"); +}); + +test("returns className if value is true and className is specified", function() { + equal(cSFV("propertyName", true, "truthyClass"), "truthyClass", "returns className if given"); + equal(cSFV("content.propertyName", true, "truthyClass"), "truthyClass", "returns className if given"); +}); + +test("returns falsyClassName if value is false and falsyClassName is specified", function() { + equal(cSFV("propertyName", false, "truthyClass", "falsyClass"), "falsyClass", "returns falsyClassName if given"); + equal(cSFV("content.propertyName", false, "truthyClass", "falsyClass"), "falsyClass", "returns falsyClassName if given"); +}); + +test("returns null if value is false and falsyClassName is not specified", function() { + equal(cSFV("propertyName", false, "truthyClass"), null, "returns null if falsyClassName is not specified"); + equal(cSFV("content.propertyName", false, "truthyClass"), null, "returns null if falsyClassName is not specified"); +}); + +test("returns null if value is false", function() { + equal(cSFV("propertyName", false), null, "returns null if value is false"); + equal(cSFV("content.propertyName", false), null, "returns null if value is false"); +}); + +test("returns the value if the value is truthy", function() { + equal(cSFV("propertyName", "myString"), "myString", "returns value if the value is truthy"); + equal(cSFV("content.propertyName", "myString"), "myString", "returns value if the value is truthy"); + + equal(cSFV("propertyName", "123"), 123, "returns value if the value is truthy"); + equal(cSFV("content.propertyName", 123), 123, "returns value if the value is truthy"); +}); \ No newline at end of file
true
Other
emberjs
ember.js
e596ab0cb9b3a176e1598b0a1d59629c2043669b.json
Add tests for Ember.View helpers
packages/ember-views/tests/views/view/parse_property_path_test.js
@@ -0,0 +1,37 @@ +module("Ember.View - _parsePropertyPath"); + +test("it works with a simple property path", function() { + var parsed = Ember.View._parsePropertyPath("simpleProperty"); + + equal(parsed.path, "simpleProperty", "path is parsed correctly"); + equal(parsed.className, undefined, "there is no className"); + equal(parsed.falsyClassName, undefined, "there is no falsyClassName"); + equal(parsed.classNames, "", "there is no classNames"); +}); + +test("it works with a more complex property path", function() { + var parsed = Ember.View._parsePropertyPath("content.simpleProperty"); + + equal(parsed.path, "content.simpleProperty", "path is parsed correctly"); + equal(parsed.className, undefined, "there is no className"); + equal(parsed.falsyClassName, undefined, "there is no falsyClassName"); + equal(parsed.classNames, "", "there is no classNames"); +}); + +test("className is extracted", function() { + var parsed = Ember.View._parsePropertyPath("content.simpleProperty:class"); + + equal(parsed.path, "content.simpleProperty", "path is parsed correctly"); + equal(parsed.className, "class", "className is extracted"); + equal(parsed.falsyClassName, undefined, "there is no falsyClassName"); + equal(parsed.classNames, ":class", "there is a classNames"); +}); + +test("falsyClassName is extracted", function() { + var parsed = Ember.View._parsePropertyPath("content.simpleProperty?class:falsyClass"); + + equal(parsed.path, "content.simpleProperty", "path is parsed correctly"); + equal(parsed.className, "class", "className is extracted"); + equal(parsed.falsyClassName, "falsyClass", "falsyClassName is extracted"); + equal(parsed.classNames, "?class:falsyClass", "there is a classNames"); +}); \ No newline at end of file
true
Other
emberjs
ember.js
411321a81346b2d15ecfb110510a0bd9dd68108b.json
Implement helper methods in Ember.View The helper methods are - _parsePropertyPath - _classStringForValue - _classStringForPath
packages/ember-views/lib/views/view.js
@@ -926,7 +926,7 @@ Ember.View = Ember.Object.extend(Ember.Evented, // Variable in which the old class value is saved. The observer function // closes over this variable, so it knows which string to remove when // the property changes. - var oldClass, property; + var oldClass; // Set up an observer on the context. If the property changes, toggle the // class name. @@ -968,8 +968,8 @@ Ember.View = Ember.Object.extend(Ember.Evented, } // Extract just the property name from bindings like 'foo:bar' - property = binding.split(':')[0]; - addObserver(this, property, observer); + var parsedPath = Ember.View._parsePropertyPath(binding); + addObserver(this, parsedPath.path, observer); }, this); }, @@ -1018,41 +1018,8 @@ Ember.View = Ember.Object.extend(Ember.Evented, passing `isUrgent` to this method will return `"is-urgent"`. */ _classStringForProperty: function(property) { - var split = property.split(':'), - className = split[1]; - - property = split[0]; - - // TODO: Remove this `false` when the `getPath` globals support is removed - var val = Ember.getPath(this, property, false); - if (val === undefined && Ember.isGlobalPath(property)) { - val = Ember.getPath(window, property); - } - - // If the value is truthy and we're using the colon syntax, - // we should return the className directly - if (!!val && className) { - return className; - - // If value is a Boolean and true, return the dasherized property - // name. - } else if (val === true) { - // Normalize property path to be suitable for use - // as a class name. For exaple, content.foo.barBaz - // becomes bar-baz. - var parts = property.split('.'); - return Ember.String.dasherize(parts[parts.length-1]); - - // If the value is not false, undefined, or null, return the current - // value of the property. - } else if (val !== false && val !== undefined && val !== null) { - return val; - - // Nothing to display. Return null so that the old class is removed - // but no new class is added. - } else { - return null; - } + var parsedPath = Ember.View._parsePropertyPath(property); + return Ember.View._classStringForPath(this, parsedPath.path, parsedPath.className, parsedPath.falsyClassName); }, // .......................................................... @@ -2003,6 +1970,78 @@ Ember.View.reopen({ domManager: DOMManager }); +Ember.View.reopenClass({ + _parsePropertyPath: function(path) { + var split = path.split(/\?|:/), + propertyPath = split[0], + className, + falsyClassName; + + // check if the property is defined as prop?trueClass:falseClass + if (split.length > 1) { + className = split[1]; + if (split.length === 3) { falsyClassName = split[2]; } + } + + var classNames = ""; + if (className) { + if (falsyClassName) { + classNames = '?' + className + ':' + falsyClassName; + } else { + classNames = ':' + className; + } + } + + return { + path: propertyPath, + classNames: classNames, + className: className, + falsyClassName: falsyClassName + }; + }, + + _classStringForValue: function(path, val, className, falsyClassName) { + // If the value is truthy and we're using the colon syntax, + // we should return the className directly + if (!!val && className) { + return className; + + // If value is a Boolean and true, return the dasherized property + // name. + } else if (val === true) { + // Normalize property path to be suitable for use + // as a class name. For exaple, content.foo.barBaz + // becomes bar-baz. + var parts = path.split('.'); + return Ember.String.dasherize(parts[parts.length-1]); + + // If the value is false and a falsyClassName is specified, return it + } else if (val === false && falsyClassName) { + return falsyClassName; + + // If the value is not false, undefined, or null, return the current + // value of the property. + } else if (val !== false && val !== undefined && val !== null) { + return val; + + // Nothing to display. Return null so that the old class is removed + // but no new class is added. + } else { + return null; + } + }, + + _classStringForPath: function(root, path, className, falsyClassName, options) { + // TODO: Remove this `false` when the `getPath` globals support is removed + var val = getPath(root, path, options); + if (val === undefined && Ember.isGlobalPath(path)) { + val = getPath(window, path); + } + + return Ember.View._classStringForValue(path, val, className, falsyClassName); + } +}); + // Create a global view hash. Ember.View.views = {};
false
Other
emberjs
ember.js
a75451c878d3cda382da583118e8c021366ee82f.json
Add tests for ternary operator in class bindings
packages/ember-handlebars/tests/handlebars_test.js
@@ -1149,12 +1149,13 @@ test("{{view}} should evaluate class bindings set to global paths", function() { window.App = Ember.Application.create({ isApp: true, isGreat: true, - directClass: "app-direct" + directClass: "app-direct", + isEnabled: true }); }); view = Ember.View.create({ - template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp"}}') + template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.directClass App.isApp App.isEnabled?enabled:disabled"}}') }); appendView(); @@ -1163,12 +1164,17 @@ test("{{view}} should evaluate class bindings set to global paths", function() { ok(view.$('input').hasClass('great'), "evaluates classes bound to global paths"); ok(view.$('input').hasClass('app-direct'), "evaluates classes bound directly to global paths"); ok(view.$('input').hasClass('is-app'), "evaluates classes bound directly to booleans in global paths - dasherizes and sets class when true"); + ok(view.$('input').hasClass('enabled'), "evaluates ternary operator in classBindings"); + ok(!view.$('input').hasClass('disabled'), "evaluates ternary operator in classBindings"); Ember.run(function() { App.set('isApp', false); + App.set('isEnabled', false); }); ok(!view.$('input').hasClass('is-app'), "evaluates classes bound directly to booleans in global paths - removes class when false"); + ok(!view.$('input').hasClass('enabled'), "evaluates ternary operator in classBindings"); + ok(view.$('input').hasClass('disabled'), "evaluates ternary operator in classBindings"); Ember.run(function() { window.App.destroy(); @@ -1180,7 +1186,8 @@ test("{{view}} should evaluate class bindings set in the current context", funct isView: true, isEditable: true, directClass: "view-direct", - template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="isEditable:editable directClass isView"}}') + isEnabled: true, + template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="isEditable:editable directClass isView isEnabled?enabled:disabled"}}') }); appendView(); @@ -1189,30 +1196,49 @@ test("{{view}} should evaluate class bindings set in the current context", funct ok(view.$('input').hasClass('editable'), "evaluates classes bound in the current context"); ok(view.$('input').hasClass('view-direct'), "evaluates classes bound directly in the current context"); ok(view.$('input').hasClass('is-view'), "evaluates classes bound directly to booleans in the current context - dasherizes and sets class when true"); + ok(view.$('input').hasClass('enabled'), "evaluates ternary operator in classBindings"); + ok(!view.$('input').hasClass('disabled'), "evaluates ternary operator in classBindings"); Ember.run(function() { view.set('isView', false); + view.set('isEnabled', false); }); ok(!view.$('input').hasClass('is-view'), "evaluates classes bound directly to booleans in the current context - removes class when false"); + ok(!view.$('input').hasClass('enabled'), "evaluates ternary operator in classBindings"); + ok(view.$('input').hasClass('disabled'), "evaluates ternary operator in classBindings"); }); test("{{view}} should evaluate class bindings set with either classBinding or classNameBindings", function() { Ember.run(function() { window.App = Ember.Application.create({ - isGreat: true + isGreat: true, + isEnabled: true }); }); view = Ember.View.create({ - template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great" classNameBindings="App.isGreat:really-great"}}') + template: Ember.Handlebars.compile('{{view Ember.TextField class="unbound" classBinding="App.isGreat:great App.isEnabled?enabled:disabled" classNameBindings="App.isGreat:really-great App.isEnabled?really-enabled:really-disabled"}}') }); appendView(); - ok(view.$('input').hasClass('unbound'), "sets unbound classes directly"); - ok(view.$('input').hasClass('great'), "evaluates classBinding"); - ok(view.$('input').hasClass('really-great'), "evaluates classNameBinding"); + ok(view.$('input').hasClass('unbound'), "sets unbound classes directly"); + ok(view.$('input').hasClass('great'), "evaluates classBinding"); + ok(view.$('input').hasClass('really-great'), "evaluates classNameBinding"); + ok(view.$('input').hasClass('enabled'), "evaluates ternary operator in classBindings"); + ok(view.$('input').hasClass('really-enabled'), "evaluates ternary operator in classBindings"); + ok(!view.$('input').hasClass('disabled'), "evaluates ternary operator in classBindings"); + ok(!view.$('input').hasClass('really-disabled'), "evaluates ternary operator in classBindings"); + + Ember.run(function() { + App.set('isEnabled', false); + }); + + ok(!view.$('input').hasClass('enabled'), "evaluates ternary operator in classBindings"); + ok(!view.$('input').hasClass('really-enabled'), "evaluates ternary operator in classBindings"); + ok(view.$('input').hasClass('disabled'), "evaluates ternary operator in classBindings"); + ok(view.$('input').hasClass('really-disabled'), "evaluates ternary operator in classBindings"); Ember.run(function() { window.App.destroy(); @@ -1545,11 +1571,10 @@ test("should not allow XSS injection via {{bindAttr}} with class", function() { equal(view.$('img').attr('class'), '" onmouseover="alert(\'I am in your classes hacking your app\');'); }); -test("should be able to bind boolean element attributes using {{bindAttr}}", function() { - var template = Ember.Handlebars.compile('<input type="checkbox" {{bindAttr disabled="content.isDisabled" checked="content.isChecked"}} />'); +test("should be able to bind class attribute using ternary operator in {{bindAttr}}", function() { + var template = Ember.Handlebars.compile('<img {{bindAttr class="content.isDisabled?disabled:enabled"}} />'); var content = Ember.Object.create({ - isDisabled: false, - isChecked: true + isDisabled: true }); view = Ember.View.create({ @@ -1559,24 +1584,24 @@ test("should be able to bind boolean element attributes using {{bindAttr}}", fun appendView(); - ok(!view.$('input').attr('disabled'), 'attribute does not exist upon initial render'); - ok(view.$('input').attr('checked'), 'attribute is present upon initial render'); + ok(view.$('img').hasClass('disabled'), 'disabled class is rendered'); + ok(!view.$('img').hasClass('enabled'), 'enabled class is not rendered'); Ember.run(function() { - set(content, 'isDisabled', true); - set(content, 'isChecked', false); + set(content, 'isDisabled', false); }); - ok(view.$('input').attr('disabled'), 'attribute exists after update'); - ok(!view.$('input').attr('checked'), 'attribute is not present after update'); + ok(!view.$('img').hasClass('disabled'), 'disabled class is not rendered'); + ok(view.$('img').hasClass('enabled'), 'enabled class is rendered'); }); test("should be able to add multiple classes using {{bindAttr class}}", function() { - var template = Ember.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing :is-super-duper"}}></div>'); + var template = Ember.Handlebars.compile('<div {{bindAttr class="content.isAwesomeSauce content.isAlsoCool content.isAmazing:amazing :is-super-duper content.isEnabled?enabled:disabled"}}></div>'); var content = Ember.Object.create({ isAwesomeSauce: true, isAlsoCool: true, - isAmazing: true + isAmazing: true, + isEnabled: true }); view = Ember.View.create({ @@ -1590,15 +1615,20 @@ test("should be able to add multiple classes using {{bindAttr class}}", function ok(view.$('div').hasClass('is-also-cool'), "dasherizes second property and sets classname"); ok(view.$('div').hasClass('amazing'), "uses alias for third property and sets classname"); ok(view.$('div').hasClass('is-super-duper'), "static class is present"); + ok(view.$('div').hasClass('enabled'), "truthy class in ternary classname definition is rendered"); + ok(!view.$('div').hasClass('disabled'), "falsy class in ternary classname definition is not rendered"); Ember.run(function() { set(content, 'isAwesomeSauce', false); set(content, 'isAmazing', false); + set(content, 'isEnabled', false); }); ok(!view.$('div').hasClass('is-awesome-sauce'), "removes dasherized class when property is set to false"); ok(!view.$('div').hasClass('amazing'), "removes aliased class when property is set to false"); ok(view.$('div').hasClass('is-super-duper'), "static class is still present"); + ok(!view.$('div').hasClass('enabled'), "truthy class in ternary classname definition is not rendered"); + ok(view.$('div').hasClass('disabled'), "falsy class in ternary classname definition is rendered"); }); test("should be able to bind classes to globals with {{bindAttr class}}", function() {
true
Other
emberjs
ember.js
a75451c878d3cda382da583118e8c021366ee82f.json
Add tests for ternary operator in class bindings
packages/ember-views/tests/views/view/class_name_bindings_test.js
@@ -11,13 +11,15 @@ module("Ember.View - Class Name Bindings"); test("should apply bound class names to the element", function() { var view = Ember.View.create({ classNameBindings: ['priority', 'isUrgent', 'isClassified:classified', - 'canIgnore', 'messages.count', 'messages.resent:is-resent', 'isNumber:is-number'], + 'canIgnore', 'messages.count', 'messages.resent:is-resent', 'isNumber:is-number', + 'isEnabled?enabled:disabled'], priority: 'high', isUrgent: true, isClassified: true, canIgnore: false, - isNumber: 5, + isNumber: 5, + isEnabled: true, messages: { count: 'five-messages', @@ -36,17 +38,21 @@ test("should apply bound class names to the element", function() { ok(view.$().hasClass('is-resent'), "supports customing class name for paths"); ok(view.$().hasClass('is-number'), "supports colon syntax with truthy properties"); ok(!view.$().hasClass('can-ignore'), "does not add false Boolean values as class"); + ok(view.$().hasClass('enabled'), "supports customizing class name for Boolean values with negation"); + ok(!view.$().hasClass('disabled'), "does not add class name for negated binding"); }); test("should add, remove, or change class names if changed after element is created", function() { var view = Ember.View.create({ classNameBindings: ['priority', 'isUrgent', 'isClassified:classified', - 'canIgnore', 'messages.count', 'messages.resent:is-resent'], + 'canIgnore', 'messages.count', 'messages.resent:is-resent', + 'isEnabled?enabled:disabled'], priority: 'high', isUrgent: true, isClassified: true, canIgnore: false, + isEnabled: true, messages: Ember.Object.create({ count: 'five-messages', @@ -59,6 +65,7 @@ test("should add, remove, or change class names if changed after element is crea set(view, 'priority', 'orange'); set(view, 'isUrgent', false); set(view, 'canIgnore', true); + set(view, 'isEnabled', false); setPath(view, 'messages.count', 'six-messages'); setPath(view, 'messages.resent', true ); }); @@ -73,6 +80,9 @@ test("should add, remove, or change class names if changed after element is crea ok(!view.$().hasClass('five-messages'), "removes old value when path changes"); ok(view.$().hasClass('is-resent'), "adds customized class name when path changes"); + + ok(!view.$().hasClass('enabled'), "updates class name for negated binding"); + ok(view.$().hasClass('disabled'), "adds negated class name for negated binding"); }); test("classNames should not be duplicated on rerender", function(){
true
Other
emberjs
ember.js
60a906c49ee023653a7329e1f74989bbfe8b3adc.json
Fix example js syntax in comment
packages/ember-handlebars/lib/controls/select.js
@@ -119,7 +119,7 @@ Ember.Select = Ember.View.extend( content: Ember.A([ { id: 1, firstName: 'Yehuda' }, { id: 2, firstName: 'Tom' } - ])), + ]), optionLabelPath: 'content.firstName', optionValuePath: 'content.id'
false
Other
emberjs
ember.js
7b7656f4d938b8979bdc760396b78d20403607eb.json
remove duplicate test
packages/ember-metal/tests/accessors/get_test.js
@@ -24,21 +24,6 @@ test('should get arbitrary properties on an object', function() { }); -test('should call unknownProperty if defined and value is undefined', function() { - - var obj = { - count: 0, - unknownProperty: function(key) { - equal(key, 'foo', 'should pass key'); - this.count++; - return 'FOO'; - } - }; - - equal(Ember.get(obj, 'foo'), 'FOO', 'should return value from unknown'); - equal(obj.count, 1, 'should have invoked'); -}); - testBoth("should call unknownProperty on watched values if the value is undefined", function(get, set) { var obj = { count: 0,
false
Other
emberjs
ember.js
e668276a3aab382e145c3bc7afd059a9a6438534.json
Allow alternate clicks for href handling - Fixes #1096
packages/ember-application/tests/system/action_url_test.js
@@ -108,3 +108,56 @@ test("it sets an URL with a context", function() { ok(view.$().html().match(/href=['"].*\/dashboard\/1['"]/), "The html (" + view.$().html() + ") has the href /dashboard/1 in it"); }); + +test("it does not trigger action with special clicks", function() { + var dispatcher = Ember.EventDispatcher.create(); + dispatcher.setup(); + + var showCalled = false; + + var view = Ember.View.create({ + template: compile("<a {{action show href=true}}>Hi</a>") + }); + + var controller = Ember.Object.create(Ember.ControllerMixin, { + target: { + urlForEvent: function(event, context) { + return "/foo/bar"; + }, + + show: function() { + showCalled = true; + } + } + }); + + Ember.run(function() { + view.set('controller', controller); + view.appendTo('#qunit-fixture'); + }); + + function checkClick(prop, value, expected) { + var event = Ember.$.Event("click"); + event[prop] = value; + view.$('a').trigger(event); + if (expected) { + ok(showCalled, "should call action with "+prop+":"+value); + ok(event.isDefaultPrevented(), "should prevent default"); + } else { + ok(!showCalled, "should not call action with "+prop+":"+value); + ok(!event.isDefaultPrevented(), "should not prevent default"); + } + } + + checkClick('ctrlKey', true, false); + checkClick('altKey', true, false); + checkClick('metaKey', true, false); + checkClick('shiftKey', true, false); + checkClick('button', 1, false); + + checkClick('button', 0, true); + + Ember.run(function() { + dispatcher.destroy(); + }); +});
true
Other
emberjs
ember.js
e668276a3aab382e145c3bc7afd059a9a6438534.json
Allow alternate clicks for href handling - Fixes #1096
packages/ember-handlebars/lib/helpers/action.js
@@ -6,12 +6,19 @@ var ActionHelper = EmberHandlebars.ActionHelper = { registeredActions: {} }; -ActionHelper.registerAction = function(actionName, eventName, target, view, context) { +ActionHelper.registerAction = function(actionName, eventName, target, view, context, link) { var actionId = (++Ember.$.uuid).toString(); ActionHelper.registeredActions[actionId] = { eventName: eventName, handler: function(event) { + if (link && (event.button !== 0 || event.shiftKey || event.metaKey || event.altKey || event.ctrlKey)) { + // Allow the browser to handle special link clicks normally + return; + } + + event.preventDefault(); + event.view = view; event.context = context; @@ -176,7 +183,7 @@ EmberHandlebars.registerHelper('action', function(actionName, options) { var hash = options.hash, eventName = hash.on || "click", view = options.data.view, - target, context, controller; + target, context, controller, link; view = get(view, 'concreteView'); @@ -195,9 +202,10 @@ EmberHandlebars.registerHelper('action', function(actionName, options) { if (hash.href && target.urlForEvent) { url = target.urlForEvent(actionName, context); output.push('href="' + url + '"'); + link = true; } - var actionId = ActionHelper.registerAction(actionName, eventName, target, view, context); + var actionId = ActionHelper.registerAction(actionName, eventName, target, view, context, link); output.push('data-ember-action="' + actionId + '"'); return new EmberHandlebars.SafeString(output.join(" "));
true
Other
emberjs
ember.js
e668276a3aab382e145c3bc7afd059a9a6438534.json
Allow alternate clicks for href handling - Fixes #1096
packages/ember-views/lib/system/event_dispatcher.js
@@ -139,7 +139,6 @@ Ember.EventDispatcher = Ember.Object.extend( handler = action.handler; if (action.eventName === eventName) { - evt.preventDefault(); return handler(evt); } });
true
Other
emberjs
ember.js
2a31b5fac2ba230565d6b64224d5598ef0bfa3cf.json
Fix failing location test
packages/ember-application/tests/system/location_test.js
@@ -151,14 +151,7 @@ test("doesn't push a state if path has not changed", function() { }); test("it handles an empty path as root", function() { - var setPath; - - window.history.pushState = function(data, title, path) { - setPath = path; - }; - - locationObject.setURL(''); - equal(setPath, '/', "The updated url is '/'"); + equal(locationObject.formatPath(''), '/', "The formatted url is '/'"); }); test("it prepends rootURL to path", function() {
false
Other
emberjs
ember.js
8348aba5031aa8cce8b3bb9a14be94b52af527ec.json
fix meta jquery.extend issue
packages/ember-metal/lib/utils.js
@@ -152,6 +152,21 @@ if (Object.freeze) Object.freeze(EMPTY_META); var isDefinePropertySimulated = Ember.platform.defineProperty.isSimulated; +function Meta(obj) { + this.descs = {}; + this.watching = {}; + this.cache = {}; + this.source = obj; +} + +if (isDefinePropertySimulated) { + // on platforms that don't support enumerable false + // make meta fail jQuery.isPlainObject() to hide from + // jQuery.extend() by having a property that fails + // hasOwnProperty check. + Meta.prototype.__preventPlainObject__ = true; +} + /** @private @function @@ -179,22 +194,9 @@ Ember.meta = function meta(obj, writable) { if (writable===false) return ret || EMPTY_META; if (!ret) { - o_defineProperty(obj, META_KEY, META_DESC); - - if (isDefinePropertySimulated) { - // on platforms that don't support enumerable false - // make meta fail jQuery.isPlainObject() to hide from - // jQuery.extend() by having a property that fails - // hasOwnProperty check. - ret = o_create({__preventPlainObject__: true}); - } + if (!isDefinePropertySimulated) o_defineProperty(obj, META_KEY, META_DESC); - ret = { - descs: {}, - watching: {}, - cache: {}, - source: obj - }; + ret = new Meta(obj); if (MANDATORY_SETTER) { ret.values = {}; }
false
Other
emberjs
ember.js
b019bed4daea16db7867ba806b6b00a0872a08e0.json
dataTransfer property for drag and drop events
packages/ember-views/lib/system.js
@@ -5,6 +5,7 @@ // License: Licensed under MIT license (see license.js) // ========================================================================== +require("ember-views/system/jquery_ext"); require("ember-views/system/render_buffer"); require("ember-views/system/event_dispatcher"); require("ember-views/system/ext");
true
Other
emberjs
ember.js
b019bed4daea16db7867ba806b6b00a0872a08e0.json
dataTransfer property for drag and drop events
packages/ember-views/lib/system/jquery_ext.js
@@ -0,0 +1,15 @@ +// ========================================================================== +// Project: Ember - JavaScript Application Framework +// Copyright: ©2006-2011 Strobe Inc. and contributors. +// Portions ©2008-2011 Apple Inc. All rights reserved. +// License: Licensed under MIT license (see license.js) +// ========================================================================== + +// http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dndevents +var dragEvents = Ember.String.w('dragstart drag dragenter dragleave dragover drop dragend'); + +// Copies the `dataTransfer` property from a browser event object onto the +// jQuery event object for the specified events +Ember.EnumerableUtils.forEach(dragEvents, function(eventName) { + Ember.$.event.fixHooks[eventName] = { props: ['dataTransfer'] }; +});
true
Other
emberjs
ember.js
b019bed4daea16db7867ba806b6b00a0872a08e0.json
dataTransfer property for drag and drop events
packages/ember-views/tests/system/jquery_ext_test.js
@@ -0,0 +1,83 @@ +// ========================================================================== +// Project: Ember - JavaScript Application Framework +// Copyright: ©2006-2011 Strobe Inc. and contributors. +// Portions ©2008-2011 Apple Inc. All rights reserved. +// License: Licensed under MIT license (see license.js) +// ========================================================================== + +var view, dispatcher; + +// Adapted from https://github.com/jquery/jquery/blob/f30f7732e7775b6e417c4c22ced7adb2bf76bf89/test/data/testinit.js +var fireNativeWithDataTransfer; +if (document.createEvent) { + fireNativeWithDataTransfer = function(node, type, dataTransfer) { + var event = document.createEvent('HTMLEvents'); + event.initEvent(type, true, true); + event.dataTransfer = dataTransfer; + node.dispatchEvent(event); + }; +} else { + fireNativeWithDataTransfer = function(node, type, dataTransfer) { + var event = document.createEventObject(); + event.dataTransfer = dataTransfer; + node.fireEvent('on' + type, event); + }; +} + +module("Ember.EventDispatcher", { + setup: function() { + Ember.run(function() { + dispatcher = Ember.EventDispatcher.create(); + dispatcher.setup(); + }); + }, + + teardown: function() { + Ember.run(function() { + if (view) { view.destroy(); } + dispatcher.destroy(); + }); + } +}); + +test("jQuery.event.fix copies over the dataTransfer property", function() { + var originalEvent; + var receivedEvent; + + originalEvent = { + type: 'drop', + dataTransfer: 'success', + target: document.body + }; + + receivedEvent = Ember.$.event.fix(originalEvent); + + ok(receivedEvent !== originalEvent, "attributes are copied to a new event object"); + equal(receivedEvent.dataTransfer, originalEvent.dataTransfer, "copies dataTransfer property to jQuery event"); +}); + +test("drop handler should receive event with dataTransfer property", function() { + var receivedEvent; + var dropCalled = 0; + + view = Ember.View.create({ + render: function(buffer) { + buffer.push('please drop stuff on me'); + this._super(buffer); + }, + + drop: function(evt) { + receivedEvent = evt; + dropCalled++; + } + }); + + Ember.run(function() { + view.append(); + }); + + fireNativeWithDataTransfer(view.$().get(0), 'drop', 'success'); + + equal(dropCalled, 1, "called drop handler once"); + equal(receivedEvent.dataTransfer, 'success', "copies dataTransfer property to jQuery event"); +});
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-debug/lib/main.js
@@ -8,6 +8,13 @@ if ('undefined' === typeof Ember) { } } +Ember.ENV = 'undefined' === typeof ENV ? {} : ENV; + +if (!('MANDATORY_SETTER' in Ember.ENV)) { + //Ember.ENV.MANDATORY_SETTER = 'defineProperty' in Object; + Ember.ENV.MANDATORY_SETTER = false; +} + /** Define an assertion that will throw an exception if the condition is not met. Ember build tools will remove any calls to Ember.assert() when
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-metal/lib/accessors.js
@@ -10,6 +10,8 @@ require('ember-metal/utils'); var META_KEY = Ember.META_KEY, get, set; +var MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER; + // .......................................................... // GET AND SET // @@ -30,6 +32,7 @@ get = function get(obj, keyName) { return obj.unknownProperty(keyName); } + if (MANDATORY_SETTER && meta && meta.watching[keyName] > 0) { return meta.values[keyName]; } return obj[keyName]; } }; @@ -38,6 +41,8 @@ get = function get(obj, keyName) { set = function set(obj, keyName, value) { Ember.assert("You need to provide an object and key to `set`.", !!obj && keyName !== undefined); + if (obj.isDestroyed) return; + var meta = obj[META_KEY], desc = meta && meta.descs[keyName]; if (desc) { desc.set(obj, keyName, value); @@ -50,11 +55,15 @@ set = function set(obj, keyName, value) { // `setUnknownProperty` method exists on the object if (isUnknown && 'function' === typeof obj.setUnknownProperty) { obj.setUnknownProperty(keyName, value); - } else if (meta && meta.watching[keyName]) { + } else if (meta && meta.watching[keyName] > 0) { // only trigger a change if the value has changed if (value !== obj[keyName]) { Ember.propertyWillChange(obj, keyName); - obj[keyName] = value; + if (MANDATORY_SETTER) { + meta.values[keyName] = value; + } else { + obj[keyName] = value; + } Ember.propertyDidChange(obj, keyName); } } else {
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-metal/lib/computed.js
@@ -266,7 +266,7 @@ ComputedPropertyPrototype.didChange = function(obj, keyName) { var meta = metaFor(obj); if (keyName in meta.cache) { delete meta.cache[keyName]; - if (!meta.watching[keyName]) { + if (!(meta.watching[keyName] > 0)) { removeDependentKeys(this, obj, keyName, meta); } } @@ -281,7 +281,7 @@ ComputedPropertyPrototype.get = function(obj, keyName) { cache = meta.cache; if (keyName in cache) { return cache[keyName]; } ret = cache[keyName] = this.func.call(obj, keyName); - if (!meta.watching[keyName]) { + if (!(meta.watching[keyName] > 0)) { addDependentKeys(this, obj, keyName, meta); } } else {
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-metal/lib/mixin.js
@@ -22,6 +22,7 @@ var Mixin, REQUIRED, Alias, EMPTY_META = {}, // dummy for non-writable meta META_SKIP = { __emberproto__: true, __ember_count__: true }, o_create = Ember.create, + defineProperty = Ember.defineProperty, guidFor = Ember.guidFor; /** @private */ @@ -190,8 +191,7 @@ function finishPartial(obj, m) { /** @private */ function applyMixin(obj, mixins, partial) { var descs = {}, values = {}, m = Ember.meta(obj), req = m.required, - key, value, desc, - prevDesc, prevValue, paths, len, idx; + key, value, desc, prevValue, paths, len, idx; // Go through all mixins and hashes passed in, and: // @@ -252,19 +252,7 @@ function applyMixin(obj, mixins, partial) { detectBinding(obj, key, value, m); - // Ember.defineProperty - prevDesc = m.descs[key]; - if (prevDesc && !(key in Object.prototype)) { - prevDesc.teardown(obj, key); - } - - m.descs[key] = desc; - obj[key] = value; - - if (desc) { - desc.setup(obj, key); - } - // Ember.defineProperty + defineProperty(obj, key, desc, value, m); if ('function' === typeof value) { if (paths = value.__ember_observesBefore__) { @@ -285,10 +273,6 @@ function applyMixin(obj, mixins, partial) { req.__ember_count__--; req[key] = false; } - - if (m.watching[key]) { - Ember.overrideChains(obj, key, m); - } } }
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-metal/lib/properties.js
@@ -16,6 +16,8 @@ var GUID_KEY = Ember.GUID_KEY, o_create = Ember.create, objectDefineProperty = Ember.platform.defineProperty; +var MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER; + // .......................................................... // DESCRIPTOR // @@ -69,23 +71,39 @@ var Descriptor = Ember.Descriptor = function() {}; return this.firstName+' '+this.lastName; }).property('firstName', 'lastName').cacheable()); */ -Ember.defineProperty = function(obj, keyName, desc, val) { - var meta = metaFor(obj), - descs = meta.descs, - existingDesc = meta.descs[keyName]; +Ember.defineProperty = function(obj, keyName, desc, val, meta) { + var descs, existingDesc, watching; + + if (!meta) meta = metaFor(obj); + descs = meta.descs; + existingDesc = meta.descs[keyName]; + watching = meta.watching[keyName] > 0; if (existingDesc instanceof Ember.Descriptor) { existingDesc.teardown(obj, keyName); } if (desc instanceof Ember.Descriptor) { descs[keyName] = desc; - obj[keyName] = undefined; // make enumerable + if (MANDATORY_SETTER && watching) { + objectDefineProperty(obj, keyName, { + configurable: true, + enumerable: true, + writable: true, + value: undefined // make enumerable + }); + } else { + obj[keyName] = undefined; // make enumerable + } desc.setup(obj, keyName); } else { descs[keyName] = undefined; // shadow descriptor in proto if (desc == null) { - obj[keyName] = val; + if (MANDATORY_SETTER && watching) { + meta.values[keyName] = val; + } else { + obj[keyName] = val; + } } else { // compatibility with ES5 objectDefineProperty(obj, keyName, desc); @@ -94,7 +112,7 @@ Ember.defineProperty = function(obj, keyName, desc, val) { // if key is being watched, override chains that // were initialized with the prototype - if (meta.watching[keyName]) { Ember.overrideChains(obj, keyName, meta); } + if (watching) { Ember.overrideChains(obj, keyName, meta); } return this; };
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-metal/lib/utils.js
@@ -15,6 +15,8 @@ var o_defineProperty = Ember.platform.defineProperty, numberCache = [], stringCache = {}; +var MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER; + /** @private @static @@ -142,6 +144,8 @@ var EMPTY_META = { watching: {} }; +if (MANDATORY_SETTER) { EMPTY_META.values = {}; } + Ember.EMPTY_META = EMPTY_META; if (Object.freeze) Object.freeze(EMPTY_META); @@ -192,6 +196,8 @@ Ember.meta = function meta(obj, writable) { source: obj }; + if (MANDATORY_SETTER) { ret.values = {}; } + obj[META_KEY] = ret; // make sure we don't accidentally try to create constructor like desc @@ -204,6 +210,8 @@ Ember.meta = function meta(obj, writable) { ret.cache = {}; ret.source = obj; + if (MANDATORY_SETTER) { ret.values = o_create(ret.values); } + obj[META_KEY] = ret; } return ret;
true
Other
emberjs
ember.js
1d03e01b8e6dc7458575a31b6721d643ef8482ba.json
add mandatory setter assertion
packages/ember-metal/lib/watching.js
@@ -26,6 +26,9 @@ var guidFor = Ember.guidFor, // utils.js FIRST_KEY = /^([^\.\*]+)/, IS_PATH = /[\.\*]/; +var MANDATORY_SETTER = Ember.ENV.MANDATORY_SETTER, +o_defineProperty = Ember.platform.defineProperty; + /** @private */ function firstKey(path) { return path.match(FIRST_KEY)[0]; @@ -436,6 +439,25 @@ Ember.watch = function(obj, keyName) { if ('function' === typeof obj.willWatchProperty) { obj.willWatchProperty(keyName); } + + if (MANDATORY_SETTER && keyName in obj) { + m.values[keyName] = obj[keyName]; + o_defineProperty(obj, keyName, { + configurable: true, + enumerable: true, + set: function() { + if (this.isDestroyed) { + Ember.assert('You cannot set observed properties on destroyed objects', false); + } else { + Ember.assert('Must use Ember.set() to access this property', false); + } + }, + get: function() { + var meta = this[META_KEY]; + return meta && meta.values[keyName]; + } + }); + } } else { chainsFor(obj).add(keyName); } @@ -470,6 +492,15 @@ Ember.unwatch = function(obj, keyName) { if ('function' === typeof obj.didUnwatchProperty) { obj.didUnwatchProperty(keyName); } + + if (MANDATORY_SETTER && keyName in obj) { + o_defineProperty(obj, keyName, { + configurable: true, + enumerable: true, + writable: true, + value: m.values[keyName] + }); + } } else { chainsFor(obj).remove(keyName); }
true
Other
emberjs
ember.js
b534482da2bf66e2fd61226ad7026c6e46a16f3b.json
Fix `one` method on evented interface * it should be able to take method as string * it should properly remove listener when using different target
packages/ember-runtime/lib/mixins/evented.js
@@ -28,8 +28,11 @@ Ember.Evented = Ember.Mixin.create( target = null; } + var self = this; var wrapped = function() { - Ember.removeListener(this, name, target, wrapped); + Ember.removeListener(self, name, target, wrapped); + + if ('string' === typeof method) { method = this[method]; } // Internally, a `null` target means that the target is // the first parameter to addListener. That means that
true
Other
emberjs
ember.js
b534482da2bf66e2fd61226ad7026c6e46a16f3b.json
Fix `one` method on evented interface * it should be able to take method as string * it should properly remove listener when using different target
packages/ember-runtime/tests/system/object/events_test.js
@@ -89,3 +89,19 @@ test("binding an event can specify a different target", function() { equal(self, target); }); +test("a listener registered with one can take method as string and can be added with different target", function() { + var count = 0; + var target = {}; + target.fn = function() { count++; }; + + var obj = Ember.Object.create(Ember.Evented); + + obj.one('event!', target, 'fn'); + obj.trigger('event!'); + + equal(count, 1, "the event was triggered"); + + obj.trigger('event!'); + + equal(count, 1, "the event was not triggered again"); +});
true
Other
emberjs
ember.js
526e0c51f581699e179201a0e7a890cc8a9a7230.json
Use Ember.set when cloning keywords - fixes #1062
packages/ember-views/lib/views/view.js
@@ -750,13 +750,13 @@ Ember.View = Ember.Object.extend(Ember.Evented, controller = get(this, 'controller'); var keywords = templateData ? Ember.copy(templateData.keywords) : {}; - keywords.view = get(this, 'concreteView'); + set(keywords, 'view', get(this, 'concreteView')); // If the view has a controller specified, make it available to the // template. If not, pass along the parent template's controller, // if it exists. if (controller) { - keywords.controller = controller; + set(keywords, 'controller', controller); } return keywords;
false
Other
emberjs
ember.js
ac900848c109addd2429b7f8d8ca5f08cb78a2a3.json
simplify defineProperty to match what mixin does
packages/ember-metal/lib/properties.js
@@ -35,12 +35,6 @@ var Descriptor = Ember.Descriptor = function() {}; // DEFINING PROPERTIES API // -/** @private */ -function hasDesc(descs, keyName) { - if (keyName === 'toString') return 'function' !== typeof descs.toString; - else return !!descs[keyName]; -} - /** @private @@ -76,45 +70,21 @@ function hasDesc(descs, keyName) { }).property('firstName', 'lastName').cacheable()); */ Ember.defineProperty = function(obj, keyName, desc, val) { - var meta = obj[META_KEY] || EMPTY_META, - descs = meta && meta.descs, - native = keyName in {}, - watching = !native && meta.watching[keyName], - descriptor = desc instanceof Ember.Descriptor; - - var existingDesc = hasDesc(descs, keyName); - - if (val === undefined && descriptor) { + var meta = metaFor(obj), + descs = meta.descs, + existingDesc = meta.descs[keyName]; - if (existingDesc) { val = descs[keyName].teardown(obj, keyName); } - else { val = obj[keyName]; } - - } else if (existingDesc) { - // otherwise, tear down the descriptor, but use the provided - // value as the new value instead of the descriptor's current - // value. - descs[keyName].teardown(obj, keyName); + if (existingDesc instanceof Ember.Descriptor) { + existingDesc.teardown(obj, keyName); } - if (descriptor) { - meta = metaFor(obj); - descs = meta.descs; - + if (desc instanceof Ember.Descriptor) { descs[keyName] = desc; - obj[keyName] = val; - desc.setup(obj, keyName, val); + obj[keyName] = undefined; // make enumerable + desc.setup(obj, keyName); } else { - if (!native && descs[keyName]) { metaFor(obj).descs[keyName] = null; } - + descs[keyName] = undefined; // shadow descriptor in proto if (desc == null) { - if (existingDesc) { - objectDefineProperty(obj, keyName, { - enumerable: true, - configurable: true, - writable: true, - value: undefined - }); - } obj[keyName] = val; } else { // compatibility with ES5 @@ -124,7 +94,7 @@ Ember.defineProperty = function(obj, keyName, desc, val) { // if key is being watched, override chains that // were initialized with the prototype - if (watching) { Ember.overrideChains(obj, keyName, meta); } + if (meta.watching[keyName]) { Ember.overrideChains(obj, keyName, meta); } return this; };
false
Other
emberjs
ember.js
b3f2c9c3ff07658fc5b31a152ef17952a785a160.json
Add date comparison to Ember.compare
packages/ember-runtime/lib/core.js
@@ -214,6 +214,13 @@ Ember.compare = function compare(v, w) { } return 0; + case 'date': + var vNum = v.getTime(); + var wNum = w.getTime(); + if (vNum < wNum) { return -1; } + if (vNum > wNum) { return 1; } + return 0; + default: return 0; } @@ -329,7 +336,8 @@ Ember.ORDER_DEFINITION = Ember.ENV.ORDER_DEFINITION || [ 'object', 'instance', 'function', - 'class' + 'class', + 'date' ]; /**
true
Other
emberjs
ember.js
b3f2c9c3ff07658fc5b31a152ef17952a785a160.json
Add date comparison to Ember.compare
packages/ember-runtime/tests/core/compare_test.js
@@ -24,6 +24,8 @@ module("Ember.compare()", { v[11] = {a: 'hash'}; v[12] = Ember.Object.create(); v[13] = function (a) {return a;}; + v[14] = new Date('2012/01/01'); + v[15] = new Date('2012/06/06'); } });
true
Other
emberjs
ember.js
7ad0873be294d9d365dea74de9d51e91083b9be5.json
Remove reference to annotated todos - Fixes #583
README.md
@@ -91,8 +91,6 @@ Hopefully you can see how all three of these powerful tools work together: start For new users, we recommend downloading the [Ember.js Starter Kit](https://github.com/emberjs/starter-kit/downloads), which includes everything you need to get started. -We also recommend that you check out the [annotated Todos example](http://annotated-todos.strobeapp.com/), which shows you the best practices for architecting an MVC-based web application. You can also [browse or fork the code on Github](https://github.com/emberjs/todos). - # Building Ember.js NOTE: Due to the rename, these instructions may be in flux
false
Other
emberjs
ember.js
eac3ae1fa2016ade07243afe5971cfdf48577900.json
Fix tests for git version of jQuery
packages/ember-handlebars/tests/views/collection_view_test.js
@@ -148,7 +148,12 @@ test("a block passed to a collection helper defaults to the content property of view.appendTo('#qunit-fixture'); }); - equal(view.$('li:has(label:contains("foo")) + li:has(label:contains("bar")) + li:has(label:contains("baz"))').length, 1, 'one label element is created for each content item'); + equal(view.$('li:nth-child(1) label').length, 1); + equal(view.$('li:nth-child(1) label').text(), 'foo'); + equal(view.$('li:nth-child(2) label').length, 1); + equal(view.$('li:nth-child(2) label').text(), 'bar'); + equal(view.$('li:nth-child(3) label').length, 1); + equal(view.$('li:nth-child(3) label').text(), 'baz'); }); test("a block passed to a collection helper defaults to the view", function() { @@ -164,7 +169,14 @@ test("a block passed to a collection helper defaults to the view", function() { Ember.run(function() { view.appendTo('#qunit-fixture'); }); - equal(view.$('li:has(label:contains("foo")) + li:has(label:contains("bar")) + li:has(label:contains("baz"))').length, 1, 'precond - one aside element is created for each content item'); + + // Preconds + equal(view.$('li:nth-child(1) label').length, 1); + equal(view.$('li:nth-child(1) label').text(), 'foo'); + equal(view.$('li:nth-child(2) label').length, 1); + equal(view.$('li:nth-child(2) label').text(), 'bar'); + equal(view.$('li:nth-child(3) label').length, 1); + equal(view.$('li:nth-child(3) label').text(), 'baz'); Ember.run(function() { set(firstChild(view), 'content', Ember.A());
true
Other
emberjs
ember.js
eac3ae1fa2016ade07243afe5971cfdf48577900.json
Fix tests for git version of jQuery
packages/ember-views/tests/views/view/view_lifecycle_test.js
@@ -152,8 +152,10 @@ test("rerender should work inside a template", function() { Ember.TESTING_DEPRECATION = false; } - ok(view.$('div:contains(2), div:contains(Inside child2').length === 2, - "Rerendering a view causes it to rerender"); + equal(view.$('div:nth-child(1)').length, 1); + equal(view.$('div:nth-child(1)').text(), '2'); + equal(view.$('div:nth-child(2)').length, 1); + equal(view.$('div:nth-child(2)').text(), 'Inside child2'); }); module("views/view/view_lifecycle_test - in DOM", {
true
Other
emberjs
ember.js
531dac71be52d9ec38d990b020a3b0d8f833fcc4.json
Fix TextArea cursor positioning in IE - fixes #1077
packages/ember-handlebars/lib/controls/text_area.js
@@ -36,7 +36,11 @@ Ember.TextArea = Ember.View.extend(Ember.TextSupport, cols: null, _updateElementValue: Ember.observer(function() { - this.$().val(get(this, 'value')); + // We do this check so cursor position doesn't get affected in IE + var value = get(this, 'value'); + if (value !== this.$().val()) { + this.$().val(value); + } }, 'value'), init: function() {
false
Other
emberjs
ember.js
3fb87cf07765307ab6082436abe35bd437135116.json
Prevent proxies from being set to themselves
packages/ember-runtime/lib/system/array_proxy.js
@@ -130,6 +130,8 @@ Ember.ArrayProxy = Ember.Object.extend(Ember.MutableArray, var content = get(this, 'content'), len = content ? get(content, 'length') : 0; + Ember.assert("Can't set ArrayProxy's content to itself", content !== this); + if (content) { content.addArrayObserver(this, { willChange: 'contentArrayWillChange', @@ -156,6 +158,8 @@ Ember.ArrayProxy = Ember.Object.extend(Ember.MutableArray, var arrangedContent = get(this, 'arrangedContent'), len = arrangedContent ? get(arrangedContent, 'length') : 0; + Ember.assert("Can't set ArrayProxy's content to itself", arrangedContent !== this); + if (arrangedContent) { arrangedContent.addArrayObserver(this, { willChange: 'arrangedContentArrayWillChange',
true
Other
emberjs
ember.js
3fb87cf07765307ab6082436abe35bd437135116.json
Prevent proxies from being set to themselves
packages/ember-runtime/lib/system/object_proxy.js
@@ -141,6 +141,10 @@ Ember.ObjectProxy = Ember.Object.extend( */ content: null, /** @private */ + _contentDidChange: Ember.observer(function() { + Ember.assert("Can't set ObjectProxy's content to itself", this.get('content') !== this); + }, 'content'), + /** @private */ delegateGet: function (key) { var content = get(this, 'content'); if (content) {
true
Other
emberjs
ember.js
1c6d434493d566f02cd89c871dd6b3ba3789ffde.json
Add README for how to run benchmarks
benchmarks/README.md
@@ -0,0 +1,7 @@ +# Extremely simple Ember benchmarks + +To run the benchmarks, serve the repository root on a web server (`gem install +asdf; asdf`), run `rake` to build Ember, and open e.g. +`http://localhost:9292/benchmarks/index.html?suitePath=plain_object.js` to run +`benchmarks/suites/plain_object.js`. Run `cp -r dist distold` to benchmark +different versions against each other.
false
Other
emberjs
ember.js
a71efcd69b5a5bd6d202fcddfb89e539ae4803c1.json
Remove old ember_assert call Ember is still undefined, so I'm deleting it instead of using Ember.assert.
benchmarks/iframe_runner.js
@@ -10,7 +10,6 @@ BenchWarmer.evalString = function(string, emberPath, logger, profile) { var benchWarmer = new BenchWarmer(emberPath, logger, profile); var bench = function(name, fn) { - ember_assert("Please pass in a name and function", arguments.length === 2); benchWarmer.bench(name, fn); };
false
Other
emberjs
ember.js
3097ea8f12b53f6e34d559d22f85d81d2f857b1b.json
Fix tests for git version of jQuery
packages/ember-handlebars/tests/views/collection_view_test.js
@@ -172,7 +172,12 @@ test("a block passed to a collection helper defaults to the content property of view.appendTo('#qunit-fixture'); }); - equal(view.$('li:has(label:contains("foo")) + li:has(label:contains("bar")) + li:has(label:contains("baz"))').length, 1, 'one label element is created for each content item'); + equal(view.$('li:nth-child(1) label').length, 1); + equal(view.$('li:nth-child(1) label').text(), 'foo'); + equal(view.$('li:nth-child(2) label').length, 1); + equal(view.$('li:nth-child(2) label').text(), 'bar'); + equal(view.$('li:nth-child(3) label').length, 1); + equal(view.$('li:nth-child(3) label').text(), 'baz'); }); test("a block passed to a collection helper defaults to the view", function() { @@ -188,7 +193,14 @@ test("a block passed to a collection helper defaults to the view", function() { Ember.run(function() { view.appendTo('#qunit-fixture'); }); - equal(view.$('li:has(label:contains("foo")) + li:has(label:contains("bar")) + li:has(label:contains("baz"))').length, 1, 'precond - one aside element is created for each content item'); + + // Preconds + equal(view.$('li:nth-child(1) label').length, 1); + equal(view.$('li:nth-child(1) label').text(), 'foo'); + equal(view.$('li:nth-child(2) label').length, 1); + equal(view.$('li:nth-child(2) label').text(), 'bar'); + equal(view.$('li:nth-child(3) label').length, 1); + equal(view.$('li:nth-child(3) label').text(), 'baz'); Ember.run(function() { set(firstChild(view), 'content', Ember.A());
true
Other
emberjs
ember.js
3097ea8f12b53f6e34d559d22f85d81d2f857b1b.json
Fix tests for git version of jQuery
packages/ember-views/tests/views/view/view_lifecycle_test.js
@@ -151,8 +151,11 @@ test("rerender should work inside a template", function() { } finally { Ember.TESTING_DEPRECATION = false; } - ok(view.$('div:contains(2), div:contains(Inside child2').length === 2, - "Rerendering a view causes it to rerender"); + + equal(view.$('div:nth-child(1)').length, 1); + equal(view.$('div:nth-child(1)').text(), '2'); + equal(view.$('div:nth-child(2)').length, 1); + equal(view.$('div:nth-child(2)').text(), 'Inside child2'); }); module("views/view/view_lifecycle_test - in DOM", {
true
Other
emberjs
ember.js
c28bdec39586de3721c9e1d14a68696f4ac24159.json
give function names
packages/ember-handlebars/lib/helpers/binding.js
@@ -17,7 +17,7 @@ var EmberHandlebars = Ember.Handlebars, helpers = EmberHandlebars.helpers; // Binds a property into the DOM. This will create a hook in DOM that the // KVO system will look for and update if the property changes. /** @private */ -var bind = function(property, options, preserveContext, shouldDisplay, valueNormalizer) { +function bind(property, options, preserveContext, shouldDisplay, valueNormalizer) { var data = options.data, fn = options.fn, inverse = options.inverse, @@ -67,7 +67,7 @@ var bind = function(property, options, preserveContext, shouldDisplay, valueNorm // be done with it. data.buffer.push(getPath(pathRoot, path, options)); } -}; +} /** '_triageMustache' is used internally select between a binding and helper for
true
Other
emberjs
ember.js
c28bdec39586de3721c9e1d14a68696f4ac24159.json
give function names
packages/ember-metal/lib/utils.js
@@ -57,7 +57,7 @@ var GUID_DESC = { @returns {String} the guid */ -Ember.generateGuid = function(obj, prefix) { +Ember.generateGuid = function generateGuid(obj, prefix) { if (!prefix) prefix = 'ember'; var ret = (prefix + (uuid++)); if (obj) { @@ -80,7 +80,7 @@ Ember.generateGuid = function(obj, prefix) { @param obj {Object} any object, string, number, Element, or primitive @returns {String} the unique guid for this instance. */ -Ember.guidFor = function(obj) { +Ember.guidFor = function guidFor(obj) { // special cases where we don't want to add a key to object if (obj === undefined) return "(undefined)"; @@ -253,7 +253,7 @@ Ember.setMeta = function setMeta(obj, property, value) { (or meta property) if one does not already exist or if it's shared with its constructor */ -Ember.metaPath = function(obj, path, writable) { +Ember.metaPath = function metaPath(obj, path, writable) { var meta = Ember.meta(obj, writable), keyName, value; for (var i=0, l=path.length; i<l; i++) {
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/lib/controls/button.js
@@ -16,7 +16,7 @@ Ember.Button = Ember.View.extend(Ember.TargetActionSupport, { propagateEvents: false, - attributeBindings: ['type', 'disabled', 'href'], + attributeBindings: ['type', 'disabled', 'href', 'tabindex'], /** @private Overrides TargetActionSupport's targetObject computed
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/lib/controls/checkbox.js
@@ -42,7 +42,7 @@ Ember.Checkbox = Ember.View.extend({ tagName: 'input', - attributeBindings: ['type', 'checked', 'disabled'], + attributeBindings: ['type', 'checked', 'disabled', 'tabindex'], type: "checkbox", checked: false,
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/lib/controls/select.js
@@ -97,7 +97,7 @@ Ember.Select = Ember.View.extend( tagName: 'select', classNames: ['ember-select'], defaultTemplate: Ember.Handlebars.compile('{{#if view.prompt}}<option value>{{view.prompt}}</option>{{/if}}{{#each view.content}}{{view Ember.SelectOption contentBinding="this"}}{{/each}}'), - attributeBindings: ['multiple'], + attributeBindings: ['multiple', 'tabindex'], /** The `multiple` attribute of the select element. Indicates whether multiple
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/lib/controls/text_support.js
@@ -15,7 +15,7 @@ Ember.TextSupport = Ember.Mixin.create( value: "", - attributeBindings: ['placeholder', 'disabled', 'maxlength'], + attributeBindings: ['placeholder', 'disabled', 'maxlength', 'tabindex'], placeholder: null, disabled: false, maxlength: null,
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/tests/controls/button_test.js
@@ -59,6 +59,17 @@ test("should become disabled if the disabled attribute is changed", function() { ok(button.$().is(":not(:disabled)")); }); +test("should support the tabindex property", function() { + button.set('tabindex', 6); + append(); + + equal(button.$().prop('tabindex'), '6', 'the initial button tabindex is set in the DOM'); + + button.set('tabindex', 3); + equal(button.$().prop('tabindex'), '3', 'the button tabindex changes when it is changed in the view'); +}); + + test("should trigger an action when clicked", function() { var wasClicked = false;
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/tests/controls/checkbox_test.js
@@ -53,6 +53,19 @@ test("should become disabled if the disabled attribute is changed", function() { ok(checkboxView.$().is(":not(:disabled)")); }); +test("should support the tabindex property", function() { + checkboxView = Ember.Checkbox.create({}); + + checkboxView.set('tabindex', 6); + append(); + + equal(checkboxView.$().prop('tabindex'), '6', 'the initial checkbox tabindex is set in the DOM'); + + checkboxView.set('tabindex', 3); + equal(checkboxView.$().prop('tabindex'), '3', 'the checkbox tabindex changes when it is changed in the view'); +}); + + test("checked property mirrors input value", function() { checkboxView = Ember.Checkbox.create({}); Ember.run(function() { checkboxView.append(); });
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/tests/controls/select_test.js
@@ -56,6 +56,18 @@ test("can have options", function() { equal(select.$().text(), "123", "Options should have content"); }); + +test("select tabindex is updated when setting tabindex property of view", function() { + select.set('tabindex', '4'); + append(); + + equal(select.$().attr('tabindex'), "4", "renders select with the tabindex"); + + select.set('tabindex', '1'); + + equal(select.$().attr('tabindex'), "1", "updates select after tabindex changes"); +}); + test("can specify the property path for an option's label and value", function() { select.set('content', Ember.A([ { id: 1, firstName: 'Yehuda' },
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/tests/controls/text_area_test.js
@@ -114,6 +114,19 @@ test("input cols is updated when setting cols property of view", function() { equal(textArea.$().attr('cols'), "40", "updates text area after cols changes"); }); +test("input tabindex is updated when setting tabindex property of view", function() { + Ember.run(function() { + set(textArea, 'tabindex', '4'); + textArea.append(); + }); + + equal(textArea.$().attr('tabindex'), "4", "renders text area with the tabindex"); + + Ember.run(function() { set(textArea, 'tabindex', '1'); }); + + equal(textArea.$().attr('tabindex'), "1", "updates text area after tabindex changes"); +}); + test("value binding works properly for inputs that haven't been created", function() { Ember.run(function() {
true
Other
emberjs
ember.js
b4f4edd67b076fcd91bc1763693611577244b92a.json
Add support for tabindex in Ember Controls. For power users, having a well defined tab order on controls is a must. The 'tabindex' property of HTML adds support for this, however there was no way to add the attribute when using Ember controls. This patch adds tabindex support and tests for all the major HTML controls in Ember.
packages/ember-handlebars/tests/controls/text_field_test.js
@@ -101,6 +101,19 @@ test("input size is updated when setting size property of view", function() { equal(textField.$().attr('size'), "40", "updates text field after size changes"); }); +test("input tabindex is updated when setting tabindex property of view", function() { + Ember.run(function() { + set(textField, 'tabindex', '5'); + textField.append(); + }); + + equal(textField.$().attr('tabindex'), "5", "renders text field with the tabindex"); + + Ember.run(function() { set(textField, 'tabindex', '3'); }); + + equal(textField.$().attr('tabindex'), "3", "updates text field after tabindex changes"); +}); + test("input type is configurable when creating view", function() { Ember.run(function() { set(textField, 'type', 'password');
true
Other
emberjs
ember.js
7f773de4af3f2613fa9ec86d1b0132c6bdd0fcda.json
Remove redundant check for !HAS_THIS Any string matching IS_GLOBAL cannot match HAS_THIS.
packages/ember-metal/lib/accessors.js
@@ -309,5 +309,5 @@ Ember.trySetPath = function(root, path, value) { @returns Boolean */ Ember.isGlobalPath = function(path) { - return !HAS_THIS.test(path) && IS_GLOBAL.test(path); + return IS_GLOBAL.test(path); };
false
Other
emberjs
ember.js
71d1e61c44bbc84ee2a29d7ffc1173406e83cd88.json
Move redundant regex test into assert
packages/ember-metal/lib/accessors.js
@@ -254,7 +254,8 @@ Ember.getPath = function(root, path) { Ember.setPath = function(root, path, value, tolerant) { var keyName; - if (typeof root === 'string' && IS_GLOBAL.test(root)) { + if (typeof root === 'string') { + Ember.assert("Path '" + root + "' must be global if no root is given.", IS_GLOBAL.test(root)); value = path; path = root; root = null;
false
Other
emberjs
ember.js
ca4476adf97e8d869609ded000e660938783040d.json
Fix a stray variable missed in 3d5587
packages/ember-states/lib/state_manager.js
@@ -593,7 +593,7 @@ Ember.StateManager = Ember.State.extend( exitStates.shift(); } - currentState.pathsCache[name] = { + currentState.pathsCache[path] = { exitStates: exitStates, enterStates: enterStates, resolveState: resolveState
false