Upgrade to 1.8.1: So long, metamorphs!

This commit is contained in:
Robin Ward 2014-12-01 12:54:59 -05:00
parent b4363de280
commit 39fde5b9fb
15 changed files with 13494 additions and 10660 deletions

View File

@ -1,12 +1,5 @@
<%
if Rails.env.development?
require_asset ("development/list-view.js")
else
require_asset ("production/list-view.js")
end
require_asset("main_include_admin.js")
DiscoursePluginRegistry.admin_javascripts.each { |js| require_asset(js) }
%>

View File

@ -8,7 +8,7 @@
**/
Discourse.CategoryList = Ember.ArrayProxy.extend({
init: function() {
this.content = [];
this.set('content', []);
this._super();
}
});

View File

@ -527,7 +527,7 @@ Discourse.PostStream = Em.Object.extend({
this.get('stream').removeObjects(postIds);
this.get('posts').removeObjects(posts);
postIds.forEach(function(id){
identityMap.remove(id);
identityMap.delete(id);
});
},

View File

@ -73,7 +73,7 @@
{{loading-spinner condition=postStream.loadingAbove}}
{{#unless postStream.loadingFilter}}
{{cloaked-collection cloakView="post"
{{cloaked-collection itemViewClass="post"
idProperty="post_number"
defaultHeight="200"
content=postStream.posts

View File

@ -1,10 +1,3 @@
/**
Lists previous posts in the history of a post.
@class ReplyHistory
@namespace Discourse
@module Discourse
**/
export default Em.CollectionView.extend({
tagName: 'section',
classNameBindings: [':embedded-posts', ':top', ':topic-body', ':offset2', 'hidden'],
@ -12,5 +5,3 @@ export default Em.CollectionView.extend({
hidden: Em.computed.equal('content.length', 0),
previousPost: true
});

View File

@ -1,3 +1,4 @@
//= require list-view
//= require admin/models/user-field
//= require admin/controllers/admin-email-skipped
//= require admin/controllers/change-site-customization-details

View File

@ -92,3 +92,6 @@ pre code {
.row:after {clear: both;}
#offscreen-content {
display: none;
}

View File

@ -61,6 +61,9 @@
<section id='main'>
</section>
<div id='offscreen-content'>
</div>
<% unless current_user %>
<form id='hidden-login-form' method="post" action="<%=login_path%>" style="display: none;">
<input name="username" type="text" id="signin_username">

View File

@ -49,12 +49,6 @@ var Poll = Discourse.Model.extend({
var PollView = Ember.View.extend({
templateName: "poll",
classNames: ['poll-ui'],
replaceElement: function(target) {
this._insertElementLater(function() {
target.replaceWith(this.$());
});
}
});
function initializePollView(self) {
@ -70,13 +64,9 @@ function initializePollView(self) {
postController: self.get('controller')
});
var pollView = self.createChildView(PollView, {
controller: pollController
});
return pollView;
return self.createChildView(PollView, { controller: pollController });
}
export default {
name: 'poll',
@ -90,13 +80,14 @@ export default {
}
var view = initializePollView(this);
var pollContainer = $post.find(".poll-ui:first");
if (pollContainer.length === 0) {
pollContainer = $post.find("ul:first");
}
view.replaceElement(pollContainer);
var $div = $('<div>');
pollContainer.replaceWith($div);
view.constructor.renderer.appendTo(view, $div[0]);
this.set('pollView', view);
}.on('postViewInserted'),
@ -108,4 +99,4 @@ export default {
}.on('willClearRender')
});
}
}
};

View File

@ -233,7 +233,7 @@ test("storePost", function() {
var postWithoutId = Discourse.Post.create({raw: 'hello world'});
stored = postStream.storePost(postWithoutId);
equal(stored, postWithoutId, "it returns the same post back");
equal(postStream.get('postIdentityMap.length'), 1, "it does not add a new entry into the identity map");
equal(postStream.get('postIdentityMap.size'), 1, "it does not add a new entry into the identity map");
});

File diff suppressed because it is too large Load Diff

View File

@ -8,10 +8,13 @@
@namespace Ember
**/
Ember.CloakedCollectionView = Ember.CollectionView.extend({
cloakView: Ember.computed.alias('itemViewClass'),
topVisible: null,
bottomVisible: null,
offsetFixedTopElement: null,
offsetFixedBottomElement: null,
loadingHTML: 'Loading...',
scrollDebounce: 10,
init: function() {
var cloakView = this.get('cloakView'),
@ -25,7 +28,7 @@
this.set('itemViewClass', Ember.CloakedView.extend({
classNames: [cloakView + '-cloak'],
cloaks: cloakView,
preservesContext: this.get('preservesContext') === "true",
preservesContext: this.get('preservesContext') === 'true',
cloaksController: this.get('itemController'),
defaultHeight: this.get('defaultHeight'),
@ -199,12 +202,11 @@
var checkView = childViews[j];
if (!checkView._containedView) {
if (!checkView.get('loading')) {
checkView.$().html(this.get('loadingHTML') || "Loading...");
checkView.$().html(this.get('loadingHTML'));
}
return;
}
}
},
uncloakQueue: function(){
@ -248,8 +250,9 @@
var self = this,
offsetFixedTop = this.get('offsetFixedTop') || this.get('offsetFixed'),
offsetFixedBottom = this.get('offsetFixedBottom'),
scrollDebounce = this.get('scrollDebounce'),
onScrollMethod = function() {
Ember.run.debounce(self, 'scrollTriggered', 10);
Ember.run.debounce(self, 'scrollTriggered', scrollDebounce);
};
if (offsetFixedTop) {
@ -291,6 +294,49 @@
**/
Ember.CloakedView = Ember.View.extend({
attributeBindings: ['style'],
_containedView: null,
_scheduled: null,
init: function() {
this._super();
this._scheduled = false;
this._childViews = [];
},
setContainedView: function(cv) {
if (this._childViews[0]) {
this._childViews[0].destroy();
}
this._childViews[0] = cv;
this.setupChildView(cv);
if (!this._elementCreated || this._scheduled) return;
this._scheduled = true;
this.set('_containedView', cv);
Ember.run.schedule('render', this, this.updateChildView);
},
setupChildView: function (childView) {
if (childView) {
childView.set('_parentView', this);
childView.set('templateData', this.get('templateData'));
}
},
render: function (buffer) {
var el = buffer.element();
this._childViewsMorph = buffer.dom.createMorph(el, null, null, el);
},
updateChildView: function () {
this._scheduled = false;
if (!this._elementCreated || this.isDestroying || this.isDestroyed) { return; }
var childView = this._containedView;
if (childView && !childView._elementCreated) {
this._renderer.renderTree(childView, this, 0);
}
},
/**
Triggers the set up for rendering a view that is cloaked.
@ -343,8 +389,7 @@
loading: false
});
this._containedView = this.createChildView(this.get('cloaks'), createArgs);
this.rerender();
this.setContainedView(this.createChildView(this.get('cloaks'), createArgs));
}
},
@ -361,25 +406,15 @@
this.set('style', style);
this.$().prop('style', style);
// We need to remove the container after the height of the element has taken
// effect.
Ember.run.schedule('afterRender', function() {
if(self._containedView){
self._containedView.remove();
self._containedView = null;
}
self.setContainedView(null);
});
}
},
_removeContainedView: function(){
if(this._containedView){
this._containedView.remove();
this._containedView = null;
}
this._super();
}.on('willDestroyElement'),
_setHeights: function(){
if (!this._containedView) {
// setting default height
@ -393,36 +428,8 @@
this.$().css('height', defaultHeight);
}
}
}.on('didInsertElement'),
/**
Render the cloaked view if applicable.
@method render
*/
render: function(buffer) {
var containedView = this._containedView, self = this;
if (containedView && (containedView._state || containedView.state) !== 'inDOM') {
containedView.triggerRecursively('willInsertElement');
containedView.renderToBuffer(buffer);
if (Ember.View.prototype._transitionTo) {
containedView._transitionTo('inDOM');
} else {
containedView.transitionTo('inDOM');
}
Em.run.schedule('afterRender', function() {
if(self._containedView) {
self._containedView.triggerRecursively('didInsertElement');
}
}.on('didInsertElement')
});
}
}
});
Ember.Handlebars.registerHelper('cloaked-collection', function(options) {
var hash = options.hash,

View File

@ -159,79 +159,6 @@ define("list-view/list_item_view",
var get = Ember.get, set = Ember.set;
function backportedInnerString(buffer) {
var content = [], childBuffers = buffer.childBuffers;
Ember.ArrayPolyfills.forEach.call(childBuffers, function(buffer) {
var stringy = typeof buffer === 'string';
if (stringy) {
content.push(buffer);
} else {
buffer.array(content);
}
});
return content.join('');
}
function willInsertElementIfNeeded(view) {
if (view.willInsertElement) {
view.willInsertElement();
}
}
function didInsertElementIfNeeded(view) {
if (view.didInsertElement) {
view.didInsertElement();
}
}
function rerender() {
var element, buffer, context, hasChildViews;
element = get(this, 'element');
if (!element) { return; }
context = get(this, 'context');
// releases action helpers in contents
// this means though that the ListItemView itself can't use classBindings or attributeBindings
// need support for rerender contents in ember
this.triggerRecursively('willClearRender');
if (this.lengthAfterRender > this.lengthBeforeRender) {
this.clearRenderedChildren();
this._childViews.length = this.lengthBeforeRender; // triage bug in ember
}
if (context) {
buffer = Ember.RenderBuffer();
buffer = this.renderToBuffer(buffer);
// check again for childViews, since rendering may have added some
hasChildViews = this._childViews.length > 0;
if (hasChildViews) {
this.invokeRecursively(willInsertElementIfNeeded, false);
}
element.innerHTML = buffer.innerString ? buffer.innerString() : backportedInnerString(buffer);
set(this, 'element', element);
var transitionTo = this._transitionTo ? this._transitionTo : this.transitionTo;
transitionTo.call(this, 'inDOM');
if (hasChildViews) {
this.invokeRecursively(didInsertElementIfNeeded, false);
}
} else {
element.innerHTML = ''; // when there is no context, this view should be completely empty
}
}
/**
The `Ember.ListItemView` view class renders a
[div](https://developer.mozilla.org/en/HTML/Element/div) HTML element
@ -261,6 +188,7 @@ define("list-view/list_item_view",
__exports__["default"] = Ember.View.extend(ListItemViewMixin, {
updateContext: function(newContext){
var context = get(this, 'context');
Ember.instrument('view.updateContext.render', this, function() {
if (context !== newContext) {
set(this, 'context', newContext);
@ -270,10 +198,19 @@ define("list-view/list_item_view",
}
}, this);
},
rerender: function () {
Ember.run.scheduleOnce('render', this, rerender);
// todo: work around for tests. investigate a real fix.
if(get(this, 'isDestroying') || get(this, 'isDestroyed')) {
return;
}
return this._super.apply(this, arguments);
},
_contextDidChange: Ember.observer(rerender, 'context', 'controller')
_contextDidChange: Ember.observer(function () {
Ember.run.once(this, this.rerender);
}, 'context', 'controller')
});
});
define("list-view/list_item_view_mixin",
@ -282,7 +219,7 @@ define("list-view/list_item_view_mixin",
"use strict";
// jshint validthis: true
var get = Ember.get, set = Ember.set;
var get = Ember.get;
function samePosition(a, b) {
return a && b && a.x === b.x && a.y === b.y;
@ -296,28 +233,41 @@ define("list-view/list_item_view_mixin",
position = this.position;
_position = this._position;
if (!position || !element) { return; }
if (!position || !element) {
return;
}
// TODO: avoid needing this by avoiding unnecessary
// calls to this method in the first place
if (samePosition(position, _position)) { return; }
Ember.run.schedule('render', this, this._parentView.applyTransform, element, position.x, position.y);
// // TODO: avoid needing this by avoiding unnecessary
// // calls to this method in the first place
if (samePosition(position, _position)) {
return;
}
Ember.run.schedule('render', this, this._parentView.applyTransform, this, position.x, position.y);
this._position = position;
}, this);
}
__exports__["default"] = Ember.Mixin.create({
var TransformMixin = Ember.Mixin.create({
style: '',
attributeBindings: ['style'],
});
__exports__.TransformMixin = TransformMixin;
__exports__["default"] = Ember.Mixin.create(TransformMixin, {
_position: null,
classNames: ['ember-list-item-view'],
_positionElement: positionElement,
init: function(){
this._super();
this.one('didInsertElement', positionElement);
},
classNames: ['ember-list-item-view'],
_position: null,
updatePosition: function(position) {
this.position = position;
this._positionElement();
},
_positionElement: positionElement
}
});
});
define("list-view/list_view",
@ -500,24 +450,45 @@ define("list-view/list_view_helper",
"use strict";
// TODO - remove this!
var el = document.createElement('div'), style = el.style;
var set = Ember.set;
var propPrefixes = ['Webkit', 'Moz', 'O', 'ms'];
function testProp(prop) {
if (prop in style) return prop;
function testProp (prop) {
var uppercaseProp = prop.charAt(0).toUpperCase() + prop.slice(1);
for (var i=0; i<propPrefixes.length; i++) {
var prefixedProp = propPrefixes[i] + uppercaseProp;
if (prefixedProp in style) {
return prefixedProp;
var dic = {
webkit: '-webkit-' + prop,
moz: '-moz-' + prop,
ms: 'ms' + uppercaseProp
};
var props = [
prop,
'webkit' + prop,
'webkit' + uppercaseProp,
'Moz' + uppercaseProp,
'moz' + uppercaseProp,
'ms' + uppercaseProp,
'ms' + prop
];
for (var i=0; i < props.length; i++) {
var property = props[i];
var prefix;
if (property in style) {
prefix = property.toLowerCase().replace(prop, '');
if (prefix && dic[prefix]) {
return dic[prefix];
}
return property;
}
}
return null;
}
var transformProp = testProp('transform');
var perspectiveProp = testProp('perspective');
var supports2D = transformProp !== null;
var supports3D = perspectiveProp !== null;
@ -525,29 +496,27 @@ define("list-view/list_view_helper",
transformProp: transformProp,
applyTransform: (function(){
if (supports2D) {
return function(element, x, y){
element.style[transformProp] = 'translate(' + x + 'px, ' + y + 'px)';
return function(childView, x, y){
set(childView, 'style', transformProp + ': translate(' + x + 'px, ' + y + 'px);');
};
} else {
return function(element, x, y){
element.style.top = y + 'px';
element.style.left = x + 'px';
return function(childView, x, y){
set(childView, 'style', 'top: ' + y + 'px; left: ' + x + 'px;');
};
}
})(),
apply3DTransform: (function(){
if (supports3D) {
return function(element, x, y){
element.style[transformProp] = 'translate3d(' + x + 'px, ' + y + 'px, 0)';
return function(childView, x, y){
set(childView, 'style', transformProp + ': translate3d(' + x + 'px, ' + y + 'px, 0);');
};
} else if (supports2D) {
return function(element, x, y){
element.style[transformProp] = 'translate(' + x + 'px, ' + y + 'px)';
return function(childView, x, y){
set(childView, 'style', transformProp + ': translate(' + x + 'px, ' + y + 'px);');
};
} else {
return function(element, x, y){
element.style.top = y + 'px';
element.style.left = x + 'px';
return function(childView, x, y){
set(childView, 'style', 'top: ' + y + 'px; left: ' + x + 'px;');
};
}
})()
@ -624,13 +593,6 @@ define("list-view/list_view_mixin",
this.unshiftObject(emptyView);
}
var domManager = Ember.create(Ember.ContainerView.proto().domManager);
domManager.prepend = function(view, html) {
view.$('.ember-list-container').prepend(html);
notifyMutationListeners();
};
function enableProfilingOutput() {
function before(name, time, payload) {
console.time(name);
@ -662,7 +624,6 @@ define("list-view/list_view_mixin",
classNames: ['ember-list-view'],
attributeBindings: ['style'],
classNameBindings: ['_isGrid:ember-list-view-grid:ember-list-view-list'],
domManager: domManager,
scrollTop: 0,
bottomPadding: 0, // TODO: maybe this can go away
_lastEndingIndex: 0,
@ -706,9 +667,15 @@ define("list-view/list_view_mixin",
@param {Ember.RenderBuffer} buffer The render buffer
*/
render: function(buffer) {
buffer.push('<div class="ember-list-container">');
buffer.push('<div class="ember-list-container"></div>');
this._super(buffer);
buffer.push('</div>');
},
createChildViewsMorph: function (element) {
var children = element.children;
element = children[0];
this._childViewsMorph = this._renderer._dom.createMorph(element, children[children.length - 1], null);
return element;
},
willInsertElement: function() {
@ -1435,7 +1402,9 @@ define("list-view/list_view_mixin",
},
destroy: function () {
if (!this._super()) { return; }
if (!this._super()) {
return;
}
if (this._createdEmptyView) {
this._createdEmptyView.destroy();
@ -1548,7 +1517,9 @@ define("list-view/virtual_list_scroller_events",
} else {
startEvent = 'mousedown';
handleStart = function (e) {
if (e.which !== 1) return;
if (e.which !== 1) {
return;
}
var target = e.target;
// avoid e.preventDefault() on fields
if (target && fieldRegex.test(target.tagName)) {
@ -1569,7 +1540,9 @@ define("list-view/virtual_list_scroller_events",
};
cancelEvent = 'mouseout';
handleCancel = function (e) {
if (e.relatedTarget) return;
if (e.relatedTarget) {
return;
}
unbindWindow(this.scrollerEventHandlers);
this.endScroll(e.timeStamp);
};
@ -1647,16 +1620,17 @@ define("list-view/virtual_list_scroller_events",
}
});
define("list-view/virtual_list_view",
["list-view/list_view_mixin","list-view/list_view_helper","list-view/virtual_list_scroller_events","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
["list-view/list_view_mixin","list-view/list_item_view_mixin","list-view/list_view_helper","list-view/virtual_list_scroller_events","exports"],
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) {
"use strict";
/*
global Scroller
*/
var ListViewMixin = __dependency1__["default"];
var ListViewHelper = __dependency2__["default"];
var VirtualListScrollerEvents = __dependency3__["default"];
var TransformMixin = __dependency2__.TransformMixin;
var ListViewHelper = __dependency3__["default"];
var VirtualListScrollerEvents = __dependency4__["default"];
var max = Math.max, get = Ember.get, set = Ember.set;
@ -1704,7 +1678,9 @@ define("list-view/virtual_list_view",
// Support old and new Ember versions
var state = view._state || view.state;
if (state !== 'inDOM') { return; }
if (state !== 'inDOM') {
return;
}
if (view.listContainerElement) {
view._scrollerTop = top;
@ -1722,17 +1698,23 @@ define("list-view/virtual_list_view",
updateScrollerDimensions(view);
},
setupPullToRefresh: function() {
if (!this.pullToRefreshViewClass) { return; }
if (!this.pullToRefreshViewClass) {
return;
}
this._insertPullToRefreshView();
this._activateScrollerPullToRefresh();
},
_insertPullToRefreshView: function(){
this.pullToRefreshView = this.createChildView(this.pullToRefreshViewClass);
var pulldownClass = this.pullToRefreshViewClass.extend(TransformMixin);
this.pullToRefreshView = this.createChildView(pulldownClass);
this.insertAt(0, this.pullToRefreshView);
var view = this;
this.pullToRefreshView.on('didInsertElement', function(){
Ember.run.schedule('afterRender', this, function(){
view.applyTransform(this.get('element'), 0, -1 * view.pullToRefreshViewHeight);
view.applyTransform(this, 0, -1 * view.pullToRefreshViewHeight);
});
});
},

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long