Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
|
|
@ -0,0 +1,95 @@
|
|||
(function() {
|
||||
var debug = false;
|
||||
var headerHeight = 50;
|
||||
var maxItemCount = 28;
|
||||
|
||||
var endEvent = ('ontouchstart' in window) ? 'touchend' : 'mouseup';
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
var listContainer = document.querySelector('section');
|
||||
|
||||
var source = new BaconSource();
|
||||
var list = new FastList(listContainer, source);
|
||||
var dialog = document.querySelector('gaia-dialog-alert');
|
||||
|
||||
function updateHeader() {
|
||||
return scheduler.mutation(function() {
|
||||
var h1 = document.querySelector('h1');
|
||||
h1.textContent = 'Main List (' + source.fullLength() + ')';
|
||||
h1.scrollTop; // flush
|
||||
});
|
||||
}
|
||||
updateHeader();
|
||||
|
||||
function clearNewIndicator() {
|
||||
var h1After = document.querySelector('#h1-after');
|
||||
|
||||
if (h1After.dataset.anim == 'reveal') {
|
||||
scheduler.transition(function() {
|
||||
h1After.dataset.anim = 'hide';
|
||||
}, h1After, 'animationend');
|
||||
}
|
||||
}
|
||||
listContainer.addEventListener('top-reached', clearNewIndicator);
|
||||
|
||||
function updateNewIndicator() {
|
||||
var h1After = document.querySelector('#h1-after');
|
||||
if (h1After.dataset.anim == 'reveal') {
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler.transition(function() {
|
||||
h1After.dataset.anim = 'reveal';
|
||||
}, h1After, 'animationend');
|
||||
}
|
||||
listContainer.addEventListener('hidden-new-content', updateNewIndicator);
|
||||
|
||||
function openGaiaDialog(evt) {
|
||||
scheduler.mutation(function() {
|
||||
var detail = evt.detail;
|
||||
var li = source.getRecordAt(detail.index);
|
||||
dialog.textContent = li.title + ' item clicked!';
|
||||
dialog.open(detail.clickEvt);
|
||||
});
|
||||
}
|
||||
list.list.addEventListener('item-selected', openGaiaDialog);
|
||||
|
||||
function newContentHandler() {
|
||||
var newContent = {
|
||||
title: 'NEW Bacon ' + Date.now().toString().slice(7, -1),
|
||||
body: 'Turkey BLT please.'
|
||||
};
|
||||
|
||||
source.insertAtIndex(0, newContent);
|
||||
list.insertedAtIndex(0);
|
||||
|
||||
updateHeader();
|
||||
}
|
||||
|
||||
setInterval(newContentHandler, 15000);
|
||||
window.addEventListener('new-content', newContentHandler);
|
||||
|
||||
window.pushNewContent = function() {
|
||||
window.dispatchEvent(new CustomEvent('new-content'));
|
||||
};
|
||||
|
||||
var button = document.querySelector('button');
|
||||
button.addEventListener(endEvent, function() {
|
||||
Promise.all([toggleTransitioning(), list.toggleEditMode()])
|
||||
.then(updateText)
|
||||
.then(toggleTransitioning);
|
||||
});
|
||||
|
||||
function updateText(text) {
|
||||
return scheduler.mutation(function() {
|
||||
button.textContent = list.editing ? 'Exit' : 'Edit';
|
||||
});
|
||||
}
|
||||
|
||||
function toggleTransitioning() {
|
||||
return scheduler.feedback(function() {
|
||||
button.classList.toggle('transitioning');
|
||||
}, button, 'transitionend');
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
(function(exports) {
|
||||
var listSize = 1042;
|
||||
var sectionCount = 25;
|
||||
|
||||
var headerHeight = 32;
|
||||
var itemHeight = 88;
|
||||
|
||||
function makeContent(prefix, name) {
|
||||
return {
|
||||
title: prefix + ' Bacon ipsum dolor ' +
|
||||
Date.now().toString().slice(7, -1),
|
||||
body: 'Turkey pig boudin ' + name.toLowerCase() +
|
||||
' de mignon drums and all ' + prefix + '.'
|
||||
}
|
||||
}
|
||||
|
||||
exports.BaconSource = function BaconSource() {
|
||||
this.sections = [];
|
||||
this.contentMap = new Map();
|
||||
this._cachedLength = null;
|
||||
|
||||
for (var i = 0; i < sectionCount; i++) {
|
||||
this.sections.push('Section ' + i);
|
||||
}
|
||||
|
||||
this.sections.forEach(function(name) {
|
||||
var content = [];
|
||||
for (var i = 0; i < (Math.random() * listSize); i++) {
|
||||
content.push(makeContent(i, name));
|
||||
}
|
||||
this.contentMap.set(name, content);
|
||||
}, this);
|
||||
};
|
||||
|
||||
exports.BaconSource.prototype = {
|
||||
populateItem: function(item, i) {
|
||||
// Simulates the data source not being ready to populate
|
||||
/*if (parseInt(Date.now() / 10) % 8 === 0) {*/
|
||||
/*return new Promise(function(resolve, reject) {*/
|
||||
/*setTimeout(resolve, Math.random() * 1000);*/
|
||||
/*});*/
|
||||
/*}*/
|
||||
|
||||
var title = item.firstChild;
|
||||
var body = title.nextSibling;
|
||||
var record = this.getRecordAt(i);
|
||||
|
||||
title.firstChild.data = record.title;
|
||||
body.firstChild.data = record.body;
|
||||
},
|
||||
|
||||
getSections: function() {
|
||||
return this.contentMap.keys();
|
||||
},
|
||||
|
||||
sectionHeaderHeight: function() {
|
||||
return headerHeight;
|
||||
},
|
||||
|
||||
fullSectionHeight: function(key) {
|
||||
return this.contentMap.get(key).length * itemHeight;
|
||||
},
|
||||
|
||||
fullSectionLength: function(key) {
|
||||
return this.contentMap(key).length;
|
||||
},
|
||||
|
||||
getRecordAt: function(index) {
|
||||
for (var section of this.contentMap.values()) {
|
||||
if (index < section.length) {
|
||||
return section[index];
|
||||
}
|
||||
index -= section.length;
|
||||
}
|
||||
},
|
||||
|
||||
getSectionFor: function(index) {
|
||||
for (var entry of this.contentMap.entries()) {
|
||||
if (index < entry[1].length) {
|
||||
return entry[0];
|
||||
}
|
||||
index -= entry[1].length;
|
||||
}
|
||||
},
|
||||
|
||||
indexAtPosition: function(pos) {
|
||||
var index = 0;
|
||||
for (var section of this.contentMap.values()) {
|
||||
pos -= headerHeight;
|
||||
var sectionHeight = section.length * itemHeight;
|
||||
if (pos > sectionHeight) {
|
||||
pos -= sectionHeight;
|
||||
index += section.length;
|
||||
continue;
|
||||
}
|
||||
for (var item of section) {
|
||||
pos -= itemHeight;
|
||||
index++;
|
||||
if (pos <= 0 || index === this.fullLength() - 1) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
positionForIndex: function(index) {
|
||||
var top = 0;
|
||||
for (var section of this.contentMap.values()) {
|
||||
top += headerHeight;
|
||||
if (index < section.length) {
|
||||
top += index * itemHeight;
|
||||
return top;
|
||||
}
|
||||
index -= section.length;
|
||||
top += section.length * itemHeight;
|
||||
}
|
||||
},
|
||||
|
||||
fullLength: function() {
|
||||
if (this._cachedLength) {
|
||||
return this._cachedLength;
|
||||
}
|
||||
|
||||
var length = 0;
|
||||
for (var section of this.contentMap.values()) {
|
||||
length += section.length;
|
||||
}
|
||||
this._cachedLength = length;
|
||||
return length;
|
||||
},
|
||||
|
||||
itemHeight: function() {
|
||||
return itemHeight;
|
||||
},
|
||||
|
||||
fullHeight: function() {
|
||||
var height = 0;
|
||||
for (var section of this.contentMap.values()) {
|
||||
height += headerHeight + section.length * itemHeight;
|
||||
}
|
||||
return height;
|
||||
},
|
||||
|
||||
insertAtIndex: function(index, record, toSection) {
|
||||
this._cachedLength = null;
|
||||
for (var entry of this.contentMap.entries()) {
|
||||
if (index < entry[1].length || entry[0] === toSection) {
|
||||
return entry[1].splice(index, 0, record);
|
||||
}
|
||||
index -= entry[1].length;
|
||||
}
|
||||
},
|
||||
|
||||
replaceAtIndex: function(index, record) {
|
||||
for (var section of this.contentMap.values()) {
|
||||
if (index < section.length) {
|
||||
return section.splice(index, 1, record);
|
||||
}
|
||||
index -= section.length;
|
||||
}
|
||||
},
|
||||
|
||||
removeAtIndex: function(index) {
|
||||
this._cachedLength = null;
|
||||
|
||||
for (var section of this.contentMap.values()) {
|
||||
if (index < section.length) {
|
||||
return section.splice(index, 1)[0];
|
||||
}
|
||||
index -= section.length;
|
||||
}
|
||||
}
|
||||
};
|
||||
})(window);
|
||||
|
||||
Loading…
Reference in a new issue