Skip to content

Commit

Permalink
add CreateItemInBetween();
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 4, 2013
1 parent 46adbee commit b185762
Show file tree
Hide file tree
Showing 7 changed files with 1,588 additions and 1,240 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
assets assets
sketch
deploy deploy
.DS_Store .DS_Store
test.sh test.sh
Expand Down
2 changes: 1 addition & 1 deletion css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion css/style.less
Expand Up @@ -369,7 +369,7 @@ html, body {
.inner { .inner {
.transform-style(preserve-3d); .transform-style(preserve-3d);
.transition(.3s @ease); .transition(.3s @ease);
.transform(translate3d(0, 0, -@itemHeight / 2 + 5px)); .transform(translate3d(0, -@itemHeight / 2, -@itemHeight / 2 + 5px));
height: 100%; height: 100%;
} }
.unfold { .unfold {
Expand Down
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -41,6 +41,7 @@
<script src="js/db.js"></script> <script src="js/db.js"></script>
<script src="js/touch.js"></script> <script src="js/touch.js"></script>
<script src="js/item.js"></script> <script src="js/item.js"></script>
<script src="js/unfold-dummy.js"></script>
<script src="js/collection.js"></script> <script src="js/collection.js"></script>
<script src="js/list-collection.js"></script> <script src="js/list-collection.js"></script>
<script src="js/list-item.js"></script> <script src="js/list-item.js"></script>
Expand Down
51 changes: 51 additions & 0 deletions js/collection.js
Expand Up @@ -513,6 +513,57 @@ C.Collection = (function (raf) {
}, },


createItemInBetween: function () { createItemInBetween: function () {

var newData = {
title: '',
order: this.count
};

C.db.addItem(newData, this.data);

var newItem = this.addItem(newData);
this.updateColor();
this.updateBounds();

// push done items 1 slot down
var i = this.items.length,
item;

while (i--) {
item = this.items[i];
if (item.data.done) {
item.data.order++;
item.moveY(item.y + C.ITEM_HEIGHT);
}
}

// dummy
var lastUndone = this.getItemByOrder(this.count - 1),
color = lastUndone.el.find('.slider').css('background-color'),
dummy = new C.UnfoldDummy({
order: this.count,
color: color
});
this.el.append(dummy.el);

newItem.el
.addClass('drag')
.css('opacity', .01); // hack hack hack...
newItem.el.find('.field').show().focus();

setTimeout(function () {
dummy.el.addClass('open');
dummy.el.on(C.client.transitionEndEvent, function () {
dummy.el.off(C.client.transitionEndEvent);
newItem.el.css('opacity', '');
setTimeout(function () {
newItem.el.removeClass('drag')
newItem.onEditStart();
dummy.el.remove();
dummy = null;
}, 0);
});
}, 0);


}, },


Expand Down
24 changes: 14 additions & 10 deletions js/unfold-dummy.js
Expand Up @@ -3,22 +3,26 @@ C.UnfoldDummy = function (options) {
this.el = $('<div class="item unfold-dummy">\ this.el = $('<div class="item unfold-dummy">\
<div class="inner">\ <div class="inner">\
<div class="unfold top">\ <div class="unfold top">\
<div class="item" style="padding-left: 12px"></div> <div class="item" style="padding-left: 12px"></div>\
</div>\ </div>\
<div class="unfold bot">\ <div class="unfold bot">\
<div class="item" style="padding-left: 12px"></div> <div class="item" style="padding-left: 12px"></div>\
</div>\ </div>\
</div>\ </div>');
')


this.top = this.el.find('.top') this.style = this.el[0].style;
this.bot = this.el.find('.bot')
this.content = this.el.find('.item')


} this.top = this.el.find('.top');
this.bot = this.el.find('.bot');
this.content = this.el.find('.item');


C.UnfoldDummy.prototype = { if (options.content) {
this.content.text(options.content);
}


this.content.css('background-color', options.color);
this.moveY((options.order - 1) * C.ITEM_HEIGHT - 1);


};


} C.UnfoldDummy.prototype.moveY = C.Item.moveY;

0 comments on commit b185762

Please sign in to comment.