Newsletter: Add custom link to media/post
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
<script type="text/javascript">
|
||||
oSpot.onSamePageMove = function(asHash) {
|
||||
if(self.tmp('first_exec')) initPage(asHash);
|
||||
else {
|
||||
else if(asHash.items[0] != self.vars(['project', 'codename'])) {
|
||||
self.tmp('map').remove();
|
||||
self.tmp('$Map').empty();
|
||||
self.tmp('map', null);
|
||||
@@ -181,11 +181,12 @@ function initPage(asHash) {
|
||||
initSettings();
|
||||
|
||||
//project Bootstrap
|
||||
initProject(asHash.items[0]);
|
||||
var oFocusPost = asHash.items[1]?{type: asHash.items[1], id: asHash.items[2]}:null;
|
||||
initProject(asHash.items[0], oFocusPost);
|
||||
}
|
||||
}
|
||||
|
||||
function initProject(sProjectCodeName){
|
||||
function initProject(sProjectCodeName, oFocusPost){
|
||||
self.tmp('first_exec', false);
|
||||
self.vars('project', self.vars(['projects', sProjectCodeName]));
|
||||
|
||||
@@ -220,9 +221,9 @@ function initProject(sProjectCodeName){
|
||||
$('#poster').toggle(!bHistoMode);
|
||||
|
||||
//Feed auto-update
|
||||
updateFeed(true, false, function(){focusOnPost(oFocusPost);});
|
||||
self.tmp('simple-bar').getScrollElement().scrollTop = 0;
|
||||
if(!bHistoMode) onAutoUpdate(true);
|
||||
else updateFeed(true);
|
||||
}
|
||||
|
||||
function initPosts() {
|
||||
@@ -320,10 +321,8 @@ function setUserInterface() {
|
||||
}
|
||||
}
|
||||
|
||||
function onAutoUpdate(bFirstExec) {
|
||||
bFirstExec = bFirstExec || false;
|
||||
if(bFirstExec) updateFeed(true);
|
||||
else if(self.tmp('simple-bar').getScrollElement().scrollTop == 0) updateFeed(true, true);
|
||||
function onAutoUpdate(bStart) {
|
||||
if(!bStart && self.tmp('simple-bar').getScrollElement().scrollTop == 0) updateFeed(true, true);
|
||||
setFeedUpdateTimer(60, onAutoUpdate);
|
||||
}
|
||||
|
||||
@@ -381,7 +380,7 @@ function initSpotMessages(aoMessages, aoTracks, bNoFeed) {
|
||||
$.each(self.vars('projects'), function(sCodeName, asProject){
|
||||
var asRadioAttrs = {'type': 'radio', 'class': 'leaflet-control-layers-selector', 'name':'project', 'value': sCodeName};
|
||||
if(asProject.id == self.vars(['project', 'id'])) asRadioAttrs.checked = 'checked';
|
||||
var $Radio =$('<input>', asRadioAttrs).change(function(){
|
||||
var $Radio = $('<input>', asRadioAttrs).change(function(){
|
||||
toggleSettingsPanel(false);
|
||||
self.setHash(self.vars('page'), [$(this).val()]);
|
||||
});
|
||||
@@ -620,9 +619,10 @@ function onFeedScroll() {
|
||||
if(($Box.scrollTop() + $(window).height()) / $BoxContent.height() >= 0.8) updateFeed();
|
||||
}
|
||||
|
||||
function updateFeed(bFirstChunk, bDiscrete) {
|
||||
function updateFeed(bFirstChunk, bDiscrete, fCallback) {
|
||||
bFirstChunk = bFirstChunk || false;
|
||||
bDiscrete = bDiscrete || false;
|
||||
fCallback = fCallback || function(){};
|
||||
|
||||
if(self.tmp('updatable')) {
|
||||
if(!self.tmp('out-of-data') || bFirstChunk) {
|
||||
@@ -635,29 +635,52 @@ function updateFeed(bFirstChunk, bDiscrete) {
|
||||
self.tmp('news_chunk', 0);
|
||||
}
|
||||
|
||||
self.get('feed', function(asData) {
|
||||
$('#loading').hide();
|
||||
|
||||
$.each(asData, function(iKey, asPost){
|
||||
$Posts.append(getPost(asPost));
|
||||
});
|
||||
|
||||
self.tmp('news_chunk', self.tmp('news_chunk') + 1);
|
||||
self.tmp('out-of-data', Object.keys(asData).length != self.vars('chunk_size'));
|
||||
|
||||
if(bFirstChunk===true) self.tmp('$PostList').empty();
|
||||
self.tmp('$PostList').append($Posts.children());
|
||||
|
||||
self.tmp('updatable', true);
|
||||
}, {
|
||||
'project_id': self.vars(['project', 'id']),
|
||||
'chunk': self.tmp('news_chunk')
|
||||
});
|
||||
self.get(
|
||||
'feed',
|
||||
function(asData) {
|
||||
$('#loading').hide();
|
||||
|
||||
$.each(asData, function(iKey, asPost){
|
||||
$Posts.append(getPost(asPost));
|
||||
});
|
||||
|
||||
self.tmp('news_chunk', self.tmp('news_chunk') + 1);
|
||||
self.tmp('out-of-data', Object.keys(asData).length != self.vars('chunk_size'));
|
||||
|
||||
if(bFirstChunk===true) self.tmp('$PostList').empty();
|
||||
self.tmp('$PostList').append($Posts.children());
|
||||
|
||||
self.tmp('$PostList').find('img').waitForImages(true).done(fCallback);
|
||||
|
||||
self.tmp('updatable', true);
|
||||
}, {
|
||||
'project_id': self.vars(['project', 'id']),
|
||||
'chunk': self.tmp('news_chunk')
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
else if(bFirstChunk) setFeedUpdateTimer(0.2);
|
||||
}
|
||||
|
||||
function focusOnPost(oFocusPost) {
|
||||
if(oFocusPost) {
|
||||
var sElemId = '#'+oFocusPost.type+'-'+oFocusPost.id;
|
||||
var $Post = oSpot.tmp('$PostList').find(sElemId);
|
||||
var bGetToTop = (oSpot.tmp('$PostList').height() - (($Post.length > 0)?$Post.position().top:0) >= $(window).height());
|
||||
if($Post.length > 0 && (bGetToTop || self.tmp('out-of-data'))) {
|
||||
self.tmp('simple-bar').getScrollElement().scrollTop = $Post.position().top;
|
||||
if(oFocusPost.type=='media' || oFocusPost.type=='message') $Post.find('a.drill').click();
|
||||
}
|
||||
else if(!self.tmp('out-of-data')) updateFeed(false, false, function() {focusOnPost(oFocusPost);});
|
||||
else console.log('Missing element ID '+sElemId);
|
||||
|
||||
//Reset Hash
|
||||
var asHash = self.getHash();
|
||||
self.setHash(asHash.page, [asHash.items[0]]);
|
||||
}
|
||||
}
|
||||
|
||||
function setFeedUpdateTimer(iSeconds, fCallback) {
|
||||
fCallback = fCallback || function(){updateFeed(true);};
|
||||
if(typeof self.tmp('update_timer') != 'undefined') clearTimeout(self.tmp('update_timer'));
|
||||
@@ -666,7 +689,10 @@ function setFeedUpdateTimer(iSeconds, fCallback) {
|
||||
|
||||
function getPost(asPost) {
|
||||
asPost.headerless = asPost.headerless || false;
|
||||
|
||||
var $Post = $('<div>', {'class':'post '+asPost.type+(asPost.headerless?' headerless':'')});
|
||||
if(asPost.id) $Post.prop('id', asPost.type+'-'+asPost.id);
|
||||
|
||||
var sRelTime = (asPost.relative_time!='')?((self.vars('project') && self.vars(['project', 'mode'])==self.consts.modes.histo)?asPost.formatted_time.substr(0, 10):asPost.relative_time):'';
|
||||
var sAbsTime = asPost.formatted_time;
|
||||
var sType = asPost.subtype || asPost.type;
|
||||
|
||||
Reference in New Issue
Block a user