Skip to content

Commit

Permalink
Merge pull request #1731 from montagestudio/ie_fixes
Browse files Browse the repository at this point in the history
Succession, Build-In/Out, ImageGallery
  • Loading branch information
marchant committed Jun 24, 2016
2 parents 3f8cd6c + 0fc0798 commit 1ccca15
Show file tree
Hide file tree
Showing 44 changed files with 2,735 additions and 67 deletions.
31 changes: 18 additions & 13 deletions core/range-controller.js
Expand Up @@ -412,13 +412,12 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R
* The selection may be any collection that supports range change events
* like `Array` or `SortedSet`.
*
* @param {Collection} a collection of values to be set as the selection.
* @returns {?Array|Set|SortedSet}
*
* @deprecated: setting the `selection` will not replace it with the provided.
* Deprecation warning: setting the `selection` will not replace it with the provided.
* collection. Instead, it will empty the selection and then shallow-copy the
* contents of the argument into the existing selection array. This is done to
* maintain the complicated invariants about what the selection can be.
*
* @property {?Array|Set|SortedSet}
*/
selection: {
get: function () {
Expand Down Expand Up @@ -693,7 +692,7 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R
/**
* Creates a content value for this range controller.
* If the backing
* collection has an intrinsict type, uses its `contentConstructor`.
* collection has an intrinsic type, uses its `contentConstructor`.
* Otherwise, creates and returns simple, empty objects.
*
* This property can be set to an alternate content constructor, which will
Expand All @@ -719,6 +718,7 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R
/**
* Dispatched by range changes to the controller's content, arranged in
* constructor.
*
* Reacts to content changes to ensure that content that no
* longer exists is removed from the selection, regardless of whether it is
* from the user or any other entity modifying the backing collection.
Expand All @@ -731,7 +731,13 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R
// remove all values from the selection that were removed (but
// not added back)
minus.deleteEach(plus, equals);
if (this.selection) {

if (this.selection.length) {
// ensure selection always has content
if (this.content.length && this.avoidsEmptySelection && !this.multiSelect) {
// selection can't contain previous content value as content already changed
this.selection.add(this.content[this.content.length - 1]);
}
this.selection.deleteEach(minus);
}
}
Expand All @@ -741,7 +747,9 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R
/**
* Watches changes to the private reflection of the public selection,
* enforcing the `allowsMultipleSelection` and `avoidsEmptySelection` invariants.
*
* @private
* @todo this doesn't seem to be used anywhere
*/
handleSelectionRangeChange : {
value: function (plus, minus, index) {
Expand Down Expand Up @@ -806,13 +814,11 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R
handleAdd: {
value: function (value) {
if (this.selectAddedContent && this.selection) {
if (
!this.allowsMultipleSelection &&
this.selection.length >= 1
) {
this.selection.clear();
if (!this.allowsMultipleSelection && this.selection.length) {
this.selection.swap(0, this.selection.length, [value]);
} else {
this.selection.add(value);
}
this.selection.add(value);
}
}
},
Expand Down Expand Up @@ -849,4 +855,3 @@ var RangeController = exports.RangeController = Montage.specialize( /** @lends R

// TODO @kriskowal decouple such that content controllers can be chained using
// adapter pattern

11 changes: 11 additions & 0 deletions core/tree-controller.js
Expand Up @@ -197,6 +197,17 @@ exports.TreeController = Montage.specialize({
}
},

/**
* Collapses all nodes with children in the tree.
*/
collapseAll: {
value: function () {
this._expansionMap = new WeakMap();
this.handleTreeChange();
return true
}
},

/**
* Gets the node expansion value - boolean - for a given node
*/
Expand Down
3 changes: 1 addition & 2 deletions packages/mr/require.js
Expand Up @@ -782,8 +782,7 @@

Require.JsonCompiler = function (config, compile) {
return function (module) {
var json = (module.location || "").match(/\.json$/);
if (json) {
if (!config.production && (module.location || "").match(/\.json$/)) {
module.exports = JSON.parse(module.text);
return module;
} else {
Expand Down
33 changes: 33 additions & 0 deletions test/core/range-controller-spec.js
Expand Up @@ -190,6 +190,15 @@ describe("core/range-controller-spec", function () {
expect(rangeController.selection.length).toBe(1);
expect(rangeController.selection.toArray()).not.toEqual([0]);
});

it("should contain last element of content, if it would be empty after content change", function () {
rangeController.multiSelect = false;
rangeController.selection = [2];

rangeController.content.delete(2);
expect(rangeController.selection.length).toBe(1);
expect(rangeController.selection.toArray()).toEqual([1]);
});
});

describe("when false", function () {
Expand All @@ -209,6 +218,30 @@ describe("core/range-controller-spec", function () {
});
});

describe("constrained by selectAddedContent", function () {
beforeEach(function () {
rangeController.selectAddedContent = true;
});

describe("when true", function () {
it("should select added content", function () {
rangeController.selection.length = 0;
rangeController.add(3);
expect(rangeController.selection.toArray()).toEqual([3]);
});

it("should use swap to ensure selection isn't cleared then content added", function () {
rangeController.selection = [2];

rangeController.selection.addRangeChangeListener(function (plus, minus, i) {
expect(plus.length).not.toBe(0);
});

rangeController.add(3); // observed change of plus should be [3], not [] then [3]
});
});
});

describe("constrained to always have one selection", function () {
beforeEach(function () {
rangeController.avoidsEmptySelection = false;
Expand Down
8 changes: 8 additions & 0 deletions test/core/tree-controller-spec.js
Expand Up @@ -150,6 +150,14 @@ describe("tree-controller-spec", function () {
expect(treeController.isNodeExpanded(treeData)).toEqual(false);
expect(treeController.isNodeExpanded(treeData.children[0])).toEqual(true);
});
it("collapseAll should work as expected", function () {
treeController.expandAll();
treeController.collapseAll();
expect(treeController.isNodeExpanded(treeData)).toEqual(false);
expect(treeController.isNodeExpanded(treeData.children[0])).toEqual(false);
expect(treeController.isNodeExpanded(treeData.children[0].children[0])).toEqual(false);
expect(treeController.isNodeExpanded(treeData.children[0].children[0].children[0])).toEqual(false);
});
});

describe("handling changes in the tree", function () {
Expand Down
6 changes: 4 additions & 2 deletions ui/base/abstract-text-field.js
Expand Up @@ -100,6 +100,9 @@ var AbstractTextField = exports.AbstractTextField = AbstractControl.specialize(/
},

hasFocus: {
set: function (value) {
this._hasFocus = value;
},
get: function () {
return this._hasFocus;
}
Expand Down Expand Up @@ -188,7 +191,7 @@ var AbstractTextField = exports.AbstractTextField = AbstractControl.specialize(/

willBecomeActiveTarget: {
value: function (event) {
this._hasFocus = true;
this.hasFocus = true;
this.callDelegateMethod("didBeginEditing", this);
}
},
Expand Down Expand Up @@ -236,4 +239,3 @@ var AbstractTextField = exports.AbstractTextField = AbstractControl.specialize(/
}

});

0 comments on commit 1ccca15

Please sign in to comment.