diff options
-rw-r--r-- | glifestream/static/js/glifestream.js | 2981 |
1 files changed, 1570 insertions, 1411 deletions
diff --git a/glifestream/static/js/glifestream.js b/glifestream/static/js/glifestream.js index 0354fcc..8dd7720 100644 --- a/glifestream/static/js/glifestream.js +++ b/glifestream/static/js/glifestream.js @@ -15,1467 +15,1626 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -/*jshint indent: 2, white: true, browser: true */ +/*jshint indent: 4, white: true, browser: true */ /*global $, FB, tinymce, settings, gettext_msg, stream_data */ -(function () { - function parse_id (id) { - var p = id.indexOf ('-'); - if (p == -1) - return [id]; - return [id.substring (0, p), id.substr (p + 1)]; - } - - function play_video () { - var a = parse_id ($(this).data ('id') || this.id); - var type = a[0]; - var id = a[1]; - - if (type in video_embeds) - var embed = video_embeds[type].replace (/{ID}/g, id); - else - return true; - - $('.playbutton', this).removeClass ('playbutton').addClass ('stopbutton'); - $VC (this).after ('<div class="player video ' + - type + '">' + embed + '</div>'); - $('a', this).blur (); - scroll_to_element (this); - return false; - } - - function stop_video () { - $('.player', $VC (this).parent ()).remove (); - $('.stopbutton', this).removeClass ('stopbutton').addClass ('playbutton'); - $('a', this).blur (); - return false; - } - - function toggle_video () { - var $this = $(this); - if (!$this.hasClass ('video-inline')) { - if ($('.playbutton', this).length) - play_video.call (this); - else - stop_video.call (this); +(function() { + function parse_id(id) { + var p = id.indexOf('-'); + if (p == -1) + return [id]; + return [id.substring(0, p), id.substr(p + 1)]; } - else { - if (!$this.data ('play')) { - $this.data ('play', true); - play_video.call (this); - } - else { - stop_video.call (this); - $this.data ('play', false); - } + + function play_video() { + var a = parse_id($(this).data('id') || this.id); + var type = a[0]; + var id = a[1]; + + if (type in video_embeds) + var embed = video_embeds[type].replace(/{ID}/g, id); + else + return true; + + $('.playbutton', this).removeClass('playbutton').addClass('stopbutton'); + $VC(this).after('<div class="player video ' + + type + '">' + embed + '</div>'); + $('a', this).blur(); + scroll_to_element(this); + return false; } - return false; - } - - /* find VC block */ - function $VC (obj) { - if (obj.parentNode.tagName == 'TD') { - obj = obj.parentNode.parentNode.parentNode.parentNode; - if (obj.className == 'vc') - return $(obj); + + function stop_video() { + $('.player', $VC(this).parent()).remove(); + $('.stopbutton', this).removeClass('stopbutton').addClass('playbutton'); + $('a', this).blur(); + return false; } - return $(obj); - } - - function play_audio (e) { - if (e.which && e.which !== 1) - return false; - var a = parse_id ($(this).data ('id') || this.id); - var type = a[0]; - $('a', this).blur (); - - if ($('.player', this.parentNode).length) { - $('.player', this.parentNode).remove (); - return false; + + function toggle_video() { + var $this = $(this); + if (!$this.hasClass('video-inline')) { + if ($('.playbutton', this).length) + play_video.call(this); + else + stop_video.call(this); + } + else { + if (!$this.data('play')) { + $this.data('play', true); + play_video.call(this); + } + else { + stop_video.call(this); + $this.data('play', false); + } + } + return false; } - if (type == 'audio') - var embed = '<audio src="'+ $('a', this).attr ('href') +'" controls="true">'+ _('Your browser does not support it.') +'</audio>'; - else if (type in audio_embeds) - var embed = audio_embeds[type]; - else - return true; - - if (type == 'thesixtyone') { - var data = a[1].split ('-'); - var artist = data[0]; - var id = data[1]; - embed = embed.replace ('{ARTIST}', artist); + /* find VC block */ + function $VC(obj) { + if (obj.parentNode.tagName == 'TD') { + obj = obj.parentNode.parentNode.parentNode.parentNode; + if (obj.className == 'vc') + return $(obj); + } + return $(obj); } - else if (type == 'mp3') - var id = $('a', this).attr ('href'); - else - var id = a[1]; - - embed = embed.replace (/{ID}/g, id); - - $('.player').remove (); - $(this.parentNode).append ('<div class="player audio">' + embed + '</div>'); - if (type == 'audio') { - var $au = $(this.parentNode).find ('audio'); - if ($au.length) $au[0].play (); + + function play_audio(e) { + if (e.which && e.which !== 1) + return false; + var a = parse_id($(this).data('id') || this.id); + var type = a[0]; + $('a', this).blur(); + + if ($('.player', this.parentNode).length) { + $('.player', this.parentNode).remove(); + return false; + } + + var embed; + if (type == 'audio') + embed = '<audio src="' + $('a', this).attr('href') + + '" controls="true">' + _('Your browser does not support it.') + + '</audio>'; + else if (type in audio_embeds) + embed = audio_embeds[type]; + else + return true; + + var id; + if (type == 'thesixtyone') { + var data = a[1].split('-'); + var artist = data[0]; + id = data[1]; + embed = embed.replace('{ARTIST}', artist); + } + else if (type == 'mp3') + id = $('a', this).attr('href'); + else + id = a[1]; + + embed = embed.replace(/{ID}/g, id); + + $('.player').remove(); + $(this.parentNode).append('<div class="player audio">' + + embed + '</div>'); + if (type == 'audio') { + var $au = $(this.parentNode).find('audio'); + if ($au.length) $au[0].play(); + } + return false; } - return false; - } - - /* find menu */ - function $M (entry) { - return $('.entry-controls-switch', entry.parentNode.parentNode.parentNode)[0]; - } - - function load_entries () { - var that = this; - if (that.busy) return false; - that.busy = true; - if (articles.length >= continuous_reading) - return follow_href.call (this); - show_spinner (this); - var url = this.href; - url += (url.indexOf ('?') != -1) ? '&' : '?'; - url += 'format=html-pure'; - $.getJSON (url, function (json) { - hide_spinner (); - that.busy = false; - var num = articles.length; - $(articles[num - 1]).after (json.stream); - nav_next.each (function () { - var s = this.href.indexOf ('start='); - if (s != -1 && json.next) - this.href = this.href.substring (0, s + 6) + json.next; - else { - s = this.href.indexOf ('page='); - if (s != -1 && json.next) - this.href = this.href.substring (0, s + 5) + json.next; - else - $(this).remove (); - } - }); - articles = $('#stream article'); - num = articles.length - num; - var latest = $('#stream article').slice (-num); - Graybox.scan (latest); - alter_html (latest); - $('a.map', latest).each (render_map); - scaledown_images ($('img', latest)); - scroll_to_element (latest[0], 25); - }); - return false; - } - - function hide_entry (e) { - if (e) e.preventDefault (); - if (($('span.favorite', $M (this).parentNode).length)) { - alert (_('Unfavorite this entry before hiding it.')); - return false; + + /* find menu */ + function $M(entry) { + return $('.entry-controls-switch', + entry.parentNode.parentNode.parentNode)[0]; } - var id = this.id.split ('-')[1]; - show_spinner ($M (this)); - $.post (baseurl + 'api/hide', { entry: id }, function () { - hide_spinner (); - $('#entry-' + id).fadeOut ('normal', function () { - $(this).after ('<div id="hidden-'+ id +'" class="entry-hidden"><em>'+ _('Entry hidden') +'</em> - <a href="#" onclick="return gls.unhide_entry.call(this)">'+ _('Undo') +'</a></div>'); - }); - }); - } - - function unhide_entry () { - var id = this.parentNode.id.split ('-')[1]; - show_spinner (this); - $.post (baseurl + 'api/unhide', { entry: id }, function () { - hide_spinner (); - $('#hidden-' + id).remove (); - $('#entry-' + id).fadeIn (); - }); - return false; - } - - function favorite_entry (e) { - if (e) e.preventDefault (); - var that = this; - var id = this.id.split ('-')[1]; - show_spinner ($M (this)); - if (!$(this).hasClass ('fav')) { - $.post (baseurl + 'api/favorite', { entry: id }, function () { - hide_spinner (); - $($M (that)).before ('<span class="favorite"></span>'); - $(that).addClass ('fav').html (_('Unfavorite')); - }); + + function load_entries() { + var that = this; + if (that.busy) return false; + that.busy = true; + if (articles.length >= continuous_reading) + return follow_href.call(this); + show_spinner(this); + var url = this.href; + url += (url.indexOf('?') != -1) ? '&' : '?'; + url += 'format=html-pure'; + $.getJSON(url, function(json) { + hide_spinner(); + that.busy = false; + var num = articles.length; + $(articles[num - 1]).after(json.stream); + nav_next.each(function() { + var s = this.href.indexOf('start='); + if (s != -1 && json.next) + this.href = this.href.substring(0, s + 6) + json.next; + else { + s = this.href.indexOf('page='); + if (s != -1 && json.next) + this.href = this.href.substring(0, s + 5) + json.next; + else + $(this).remove(); + } + }); + articles = $('#stream article'); + num = articles.length - num; + var latest = $('#stream article').slice(-num); + Graybox.scan(latest); + alter_html(latest); + $('a.map', latest).each(render_map); + scaledown_images($('img', latest)); + scroll_to_element(latest[0], 25); + }); + return false; } - else { - $.post (baseurl + 'api/unfavorite', { entry: id }, function () { - hide_spinner (); - $('span.favorite', $M (that).parentNode).remove (); - $(that).removeClass ('fav').html (_('Favorite')); - }); + + function hide_entry(e) { + if (e) e.preventDefault(); + if (($('span.favorite', $M(this).parentNode).length)) { + alert(_('Unfavorite this entry before hiding it.')); + return false; + } + var id = this.id.split('-')[1]; + show_spinner($M(this)); + $.post(baseurl + 'api/hide', { + entry: id + }, function() { + hide_spinner(); + $('#entry-' + id).fadeOut('normal', function() { + $(this).after('<div id="hidden-' + id + '" class="entry-hidden"><em>' + _('Entry hidden') + '</em> - <a href="#" onclick="return gls.unhide_entry.call(this)">' + _('Undo') + '</a></div>'); + }); + }); } - } - - function reshare_entry () { - if (!confirm (_('You are about to re-share this entry at your stream. Confirm?'))) - return false; - var as_me = !confirm (_('Keep the original author?')); - var id = this.id.split ('-')[1]; - show_spinner (this); - $.post (baseurl + 'api/reshare', { entry: id, as_me: as_me ? 1 : 0 }, - function (html) { - hide_spinner (); - Shareitbox.close (); - jump_to_top (); - $('#stream').prepend (html); - $('#stream article:first a.map').each (render_map); - scaledown_images ('#stream article:first img'); - }); - return false; - } - - function shareit_entry () { - var that = this.parentNode.parentNode; - var id = this.id.split ('-')[1]; - var url = $('.entry-published a:eq(1)', that); - if ($(that).hasClass ('private') && url.length) - url = url.attr ('href'); - else { - url = $('a[rel=bookmark]', that).attr ('href'); - if (window.location.href.indexOf (url) != -1) - url = window.location.href; - else - url = 'http://' + window.location.host + url; + + function unhide_entry() { + var id = this.parentNode.id.split('-')[1]; + show_spinner(this); + $.post(baseurl + 'api/unhide', { + entry: id + }, function() { + hide_spinner(); + $('#hidden-' + id).remove(); + $('#entry-' + id).fadeIn(); + }); + return false; } - var title = $('.entry-title', that); - if (title.length) - title = strip_tags_trim (title.html ()); - else - title = strip_tags_trim ($('.entry-content', that).html ()); - if (title.length > 137) - title = title.substr (0, 137) + '...'; - Shareitbox.open ({ id: id, url: url, title: title, - reshareit: $(this).hasClass ('reshareit') }); - return false; - } - - function edit_entry (e) { - if (e) e.preventDefault (); - var that = this; - var id = this.id.split ('-')[1]; - show_spinner ($M (this)); - $.post (baseurl + 'api/getcontent', {entry: id, raw: 1}, function (html) { - hide_spinner (); - var ec = $(that).closest ('article').find ('.entry-content'); - var editor = $('#entry-editor'); - $('#edited-content').val (html); - ec.after (editor); - editor.fadeIn ('normal', function () { - scroll_to_element (editor, 400); - }); - }); - } - - function editor_handler (e) { - var op = this.getAttribute ('name'); - if (op == 'cancel') - $('#entry-editor').fadeOut (); - else if (op == 'save') { - show_spinner (this); - var article = $(this).closest ('article').get (0); - var id = parse_id (article.id)[1]; - $.post (baseurl + 'api/putcontent', - { entry: id, content: $('#edited-content').val () }, - function (html) { - hide_spinner (); - $('#entry-'+ id +' .entry-content').html (html); - }); + + function favorite_entry(e) { + if (e) e.preventDefault(); + var that = this; + var id = this.id.split('-')[1]; + show_spinner($M(this)); + if (!$(this).hasClass('fav')) { + $.post(baseurl + 'api/favorite', { + entry: id + }, function() { + hide_spinner(); + $($M(that)).before('<span class="favorite"></span>'); + $(that).addClass('fav').html(_('Unfavorite')); + }); + } + else { + $.post(baseurl + 'api/unfavorite', { + entry: id + }, function() { + hide_spinner(); + $('span.favorite', $M(that).parentNode).remove(); + $(that).removeClass('fav').html(_('Favorite')); + }); + } + } + + function reshare_entry() { + if (!confirm(_('You are about to re-share this entry at your stream. Confirm?'))) + return false; + var as_me = !confirm(_('Keep the original author?')); + var id = this.id.split('-')[1]; + show_spinner(this); + $.post(baseurl + 'api/reshare', { + entry: id, + as_me: as_me ? 1 : 0 + }, function(html) { + hide_spinner(); + Shareitbox.close(); + jump_to_top(); + $('#stream').prepend(html); + $('#stream article:first a.map').each(render_map); + scaledown_images('#stream article:first img'); + }); + return false; + } + + function shareit_entry() { + var that = this.parentNode.parentNode; + var id = this.id.split('-')[1]; + var url = $('.entry-published a:eq(1)', that); + if ($(that).hasClass('private') && url.length) + url = url.attr('href'); + else { + url = $('a[rel=bookmark]', that).attr('href'); + if (window.location.href.indexOf(url) != -1) + url = window.location.href; + else + url = 'http://' + window.location.host + url; + } + var title = $('.entry-title', that); + if (title.length) + title = strip_tags_trim(title.html()); + else + title = strip_tags_trim($('.entry-content', that).html()); + if (title.length > 137) + title = title.substr(0, 137) + '...'; + Shareitbox.open({ + id: id, + url: url, + title: title, + reshareit: $(this).hasClass('reshareit') + }); + return false; + } + + function edit_entry(e) { + if (e) e.preventDefault(); + var that = this; + var id = this.id.split('-')[1]; + show_spinner($M(this)); + $.post(baseurl + 'api/getcontent', { + entry: id, + raw: 1 + }, function(html) { + hide_spinner(); + var ec = $(that).closest('article').find('.entry-content'); + var editor = $('#entry-editor'); + $('#edited-content').val(html); + ec.after(editor); + editor.fadeIn('normal', function() { + scroll_to_element(editor, 400); + }); + }); + } + + function editor_handler(e) { + var op = this.getAttribute('name'); + if (op == 'cancel') + $('#entry-editor').fadeOut(); + else if (op == 'save') { + show_spinner(this); + var article = $(this).closest('article').get(0); + var id = parse_id(article.id)[1]; + $.post(baseurl + 'api/putcontent', { + entry: id, + content: $('#edited-content').val() + }, function(html) { + hide_spinner(); + $('#entry-' + id + ' .entry-content').html(html); + }); + } + } + + function change_theme() { + var cookie_name = 'glifestream_theme'; + var cs = read_cookie(cookie_name); + var idx = $.inArray(cs, settings.themes); + + if (!cs || idx == -1) { + idx = 0; + cs = settings.themes[idx]; + } + if (idx < settings.themes.length - 1) idx++; + else idx = 0; + cs = settings.themes[idx]; + + var date = new Date(); + date.setTime(date.getTime() + (365 * 86400000)); + var expires = '; expires=' + date.toGMTString(); + document.cookie = cookie_name + '=' + cs + expires + + '; path=' + baseurl; + jump_to_top(); + window.location.reload(); + return false; + } + + function show_spinner(el) { + if (el.blur) el.blur(); + $(el).after('<span id="spinner"></span>'); + } + + function hide_spinner() { + $('#spinner').remove(); } - } - function change_theme () { - var cookie_name = 'glifestream_theme'; - var cs = read_cookie (cookie_name); - var idx = $.inArray (cs, settings.themes); + function read_cookie(name) { + var nameEq = name + '='; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') + c = c.substring(1, c.length); + if (c.indexOf(nameEq) == 0) + return c.substring(nameEq.length, c.length); + } + return null; + } - if (!cs || idx == -1) { - idx = 0; - cs = settings.themes[idx]; + function alter_html(ctx) { + $('.thumbnails a', ctx) + .each(function(i) { + var id = false; + try { + if (this.href.indexOf('http://www.youtube.com/watch') === 0) + id = 'youtube-' + this.href.substr(31); + else if (this.href.indexOf('http://vimeo.com/') === 0) + id = 'vimeo-' + this.href.substr(17); + else if (this.href.indexOf('http://www.collegehumor.com/video') === 0) + id = 'chtv-' + this.href.substr(34).split('/')[0]; + else if (this.href.indexOf('http://www.facebook.com/video/video.php?v=') === 0) + id = 'facebook-' + this.href.substr(42); + if (id) { + $(this).wrap('<table class="vc"><tr><td><div id="' + id + '" class="play-video"></div></td></tr></table>'); + $(this).after('<div class="playbutton"></div>'); + } + } + catch (e) {} + }); + if (typeof window.user_alter_html == 'function') + window.user_alter_html(ctx); } - if (idx < settings.themes.length - 1) idx++; - else idx = 0; - cs = settings.themes[idx]; - - var date = new Date (); - date.setTime (date.getTime () + (365 * 86400000)); - var expires = '; expires=' + date.toGMTString (); - document.cookie = cookie_name +'='+ cs + expires + '; path=' + baseurl; - jump_to_top (); - window.location.reload (); - return false; - } - - function show_spinner (el) { - if (el.blur) el.blur (); - $(el).after ('<span id="spinner"></span>'); - } - - function hide_spinner () { - $('#spinner').remove (); - } - - function read_cookie (name) { - var nameEq = name + '='; - var ca = document.cookie.split (';'); - for (var i = 0; i < ca.length; i++) { - var c = ca[i]; - while (c.charAt (0) == ' ') - c = c.substring (1, c.length); - if (c.indexOf (nameEq) == 0) - return c.substring (nameEq.length, c.length); + + var gsc_load = false; + var gsc_done = false; + + function open_sharing() { + $('#share .fieldset').slideDown('normal', function() { + $('#status').focus(); + if (!gsc_done) + get_selfposts_classes(); + }); + return false; } - return null; - } - - function alter_html (ctx) { - $('.thumbnails a', ctx) - .each (function (i) { - var id = false; - try { - if (this.href.indexOf ('http://www.youtube.com/watch') === 0) - id = 'youtube-' + this.href.substr (31); - else if (this.href.indexOf ('http://vimeo.com/') === 0) - id = 'vimeo-' + this.href.substr (17); - else if (this.href.indexOf ('http://www.collegehumor.com/video') === 0) - id = 'chtv-' + this.href.substr (34).split ('/')[0]; - else if (this.href.indexOf ('http://www.facebook.com/video/video.php?v=') === 0) - id = 'facebook-' + this.href.substr (42); - if (id) { - $(this).wrap ('<table class="vc"><tr><td><div id="'+ id +'" class="play-video"></div></td></tr></table>'); - $(this).after ('<div class="playbutton"></div>'); - } - } catch (e) {} - }); - if (typeof window.user_alter_html == 'function') - window.user_alter_html (ctx); - } - - var gsc_load = false; - var gsc_done = false; - - function open_sharing () { - $('#share .fieldset').slideDown ('normal', function () { - $('#status').focus (); - if (!gsc_done) - get_selfposts_classes (); - }); - return false; - } - - function show_selfposts_classes () { - var sc = $('#status-class').get (0); - for (var i in gsc_load) { - sc.options[sc.options.length] = new Option (gsc_load[i]['cls'], gsc_load[i]['id']); + + function show_selfposts_classes() { + var sc = $('#status-class').get(0); + for (var i in gsc_load) { + sc.options[sc.options.length] = new Option(gsc_load[i]['cls'], + gsc_load[i]['id']); + } + gsc_done = true; } - gsc_done = true; - } - - function get_selfposts_classes () { - if (!gsc_load) { - $.getJSON (baseurl + 'api/gsc', function (json) { - gsc_load = json; - show_selfposts_classes (); - }); + + function get_selfposts_classes() { + if (!gsc_load) { + $.getJSON(baseurl + 'api/gsc', function(json) { + gsc_load = json; + show_selfposts_classes(); + }); + } + else + show_selfposts_classes(); } - else - show_selfposts_classes (); - } - - function open_more_sharing_options () { - $(this).hide (); - $('#more-sharing-options').fadeIn (); - return false; - } - - function share () { - $(this).attr ('disabled', 'disabled'); - var docs = $('input[name=docs]'); - if (docs.length && docs.get (0).files && docs.get (0).files.length) - return true; - if (window.tinymce) - var content = tinymce.get ('status').getContent (); - else - var content = $('#status').val (); - if ($.trim (content) != '') { - show_spinner (this); - $.post (baseurl + 'api/share', { sid: $('#status-class').val (), - content: content, - draft: $('#draft').attr ('checked') ? 1 : 0, - friends_only: $('#friends-only').attr ('checked') ? 1 : 0 }, - function (html) { - hide_spinner (); - $('#stream').prepend (html); - $('#stream article:first a.map').each (render_map); - if (window.tinymce) - tinymce.get ('status').setContent (''); - else - $('#status').val (''); - $('#post').removeAttr ('disabled'); - $('#share .fieldset').slideUp (); - scaledown_images ('#stream article:first img'); - }); + + function open_more_sharing_options() { + $(this).hide(); + $('#more-sharing-options').fadeIn(); + return false; } - else - $('#post').removeAttr ('disabled'); - return false; - } - - function get_map_embed (lat, lng) { - if (settings.maps_engine == 'google') { - return '<img src="https://maps.googleapis.com/maps/api/staticmap?sensor=false&zoom=12&size=175x120&markers='+ lat +','+ lng +'" alt="Map" width="175" height="120" />'; + + function share() { + $(this).attr('disabled', 'disabled'); + var docs = $('input[name=docs]'); + if (docs.length && docs.get(0).files && docs.get(0).files.length) + return true; + var content; + if (window.tinymce) + content = tinymce.get('status').getContent(); + else + content = $('#status').val(); + if ($.trim(content) != '') { + show_spinner(this); + $.post(baseurl + 'api/share', { + sid: $('#status-class').val(), + content: content, + draft: $('#draft').attr('checked') ? 1 : 0, + friends_only: $('#friends-only').attr('checked') ? 1 : 0 + }, function(html) { + hide_spinner(); + $('#stream').prepend(html); + $('#stream article:first a.map').each(render_map); + if (window.tinymce) + tinymce.get('status').setContent(''); + else + $('#status').val(''); + $('#post').removeAttr('disabled'); + $('#share .fieldset').slideUp(); + scaledown_images('#stream article:first img'); + }); + } + else + $('#post').removeAttr('disabled'); + return false; } - return ''; - } - - function render_map (i) { - var lat = $('.latitude', this).html (); - var lng = $('.longitude', this).html (); - this.target = '_blank'; - this.parentNode.style.paddingLeft = 0; - this.parentNode.style.background = 'none'; - $(this).html (get_map_embed (lat, lng)); - } - - function show_map () { - this.blur (); - if (this.folded) - return true; - var lat = $('.latitude', this).html (); - var lng = $('.longitude', this).html (); - this.target = '_blank'; - - if (settings.maps_engine == 'google') { - this.href = 'http://maps.google.com/?q=' + lat +','+ lng; + + function get_map_embed(lat, lng) { + if (settings.maps_engine == 'google') { + return '<img src="https://maps.googleapis.com/maps/api/staticmap?sensor=false&zoom=12&size=175x120&markers=' + lat + ',' + lng + '" alt="Map" width="175" height="120" />'; + } + return ''; } - var p = this.parentNode; - $('a', p).html (get_map_embed (lat, lng)); - $(p).css ('paddingLeft', '0'); - this.folded = true; - return false; - } - - function expand_content () { - var that = this; - var article = this.parentNode.parentNode; - if (article.content_loaded) { - if (article.content_expanded) { - $('div.entry-content', article).slideUp (); - article.content_expanded = false; - } - else { - $('div.entry-content', article).slideDown (); - article.content_expanded = true; - } + function render_map(i) { + var lat = $('.latitude', this).html(); + var lng = $('.longitude', this).html(); + this.target = '_blank'; + this.parentNode.style.paddingLeft = 0; + this.parentNode.style.background = 'none'; + $(this).html(get_map_embed(lat, lng)); } - else { - var id = parse_id (article.id)[1]; - show_spinner (this); - $.post (baseurl + 'api/getcontent', { entry: id }, function (html) { - hide_spinner (); - $('div.entry-content', article).html (html).slideDown (); - article.content_loaded = true; - article.content_expanded = true; - scaledown_images ($('img', article)); - }); + + function show_map() { + this.blur(); + if (this.folded) + return true; + var lat = $('.latitude', this).html(); + var lng = $('.longitude', this).html(); + this.target = '_blank'; + + if (settings.maps_engine == 'google') { + this.href = 'https://maps.google.com/?q=' + lat + ',' + lng; + } + + var p = this.parentNode; + $('a', p).html(get_map_embed(lat, lng)); + $(p).css('paddingLeft', '0'); + this.folded = true; + return false; } - return false; - } - - var eco = null; - function show_menu_controls () { - hide_menu_controls (); - var that = this; - var s = $('.entry-controls', this.parentNode); - var pos = $(this).position (); - s.addClass ('menu-expanded') - .css ({top: pos.top + 17, left: pos.left}).show (); - eco = s[0]; - document.onclick = hide_menu_controls; - - var y_bottom = pos.top + s.height (); - var y_diff = y_bottom - $(window).height () - $(document).scrollTop (); - if (y_diff > -20) - s.css ('top', (pos.top - y_diff - 15) + 'px'); - - return false; - } - - function hide_menu_controls () { - if (eco) - $(eco).hide ().removeClass ('menu-expanded'); - document.onclick = null; - } - - function scaledown_images (sel) { - var maxwidth = $('#stream').width () - 80; - $(sel || '#stream img').each (function (i) { - if (this.complete) { - if (this.width > maxwidth) { - this.width = maxwidth; - if (this.style.width) { - var p = maxwidth * 100 / parseInt (this.style.width, 10); - this.style.width = maxwidth + 'px'; - this.style.height = (this.height * p / 100) + 'px'; - } - } - } - else { - this.onload = function () { - if (this.width > maxwidth) { - this.width = maxwidth; - if (this.style.width) { - var p = maxwidth * 100 / parseInt (this.style.width, 10); - this.style.width = maxwidth + 'px'; - this.style.height = (this.height * p / 100) + 'px'; - } - } - this.onload = null; - }; - } - }); - } - - var articles = []; - var current_article = -1; - - function kshortcuts (e) { - var code; - if (!e) e = window.event; - if (e.keyCode) code = e.keyCode; - else if (e.which) code = e.which; - if (e.ctrlKey || e.metaKey || e.altKey) - return true; - - switch (code) { - case 97: /* a */ - open_sharing (); - break; - case 106: /* j */ - if ((current_article + 1) == articles.length) - nav_next.trigger ('click'); - else - highlight_article (articles[++current_article]); - break; - case 107: /* k */ - if ((current_article - 1) < 0) { - var prev = $('#stream a.prev'); - if (prev.length) - window.location = prev.attr ('href'); - } - else - highlight_article (articles[--current_article]); - break; - case 102: /* f */ - var ent = articles[current_article]; - if (ent) { - var c = $('span.favorite-control', ent); - if (c.length) favorite_entry.call (c[0]); - } - break; - case 104: /* h */ - var ent = articles[current_article]; - if (ent) { - var id = ent.id.split ('-')[1]; - var c = $('#hidden-' + id + ' a'); - if (c.length) - unhide_entry.call (c[0]); - else { - var c = $('span.hide-control', ent); - if (c.length) hide_entry.call (c[0]); - } - } - break; + + function expand_content() { + var that = this; + var article = this.parentNode.parentNode; + if (article.content_loaded) { + if (article.content_expanded) { + $('div.entry-content', article).slideUp(); + article.content_expanded = false; + } + else { + $('div.entry-content', article).slideDown(); + article.content_expanded = true; + } + } + else { + var id = parse_id(article.id)[1]; + show_spinner(this); + $.post(baseurl + 'api/getcontent', { + entry: id + }, function(html) { + hide_spinner(); + $('div.entry-content', article).html(html).slideDown(); + article.content_loaded = true; + article.content_expanded = true; + scaledown_images($('img', article)); + }); + } + return false; } - } - - function highlight_article (article) { - $('a:first', article).focus ().blur (); - articles.removeClass ('entry-highlight'); - $(article).addClass ('entry-highlight'); - scroll_to_element (article, 24); - } - - function scroll_to_element (t, offset) { - offset = offset || 16; - var toffset = $(t).offset ().top - offset; - $('html,body').animate ({scrollTop: toffset}, 200); - } - - function jump_to_top () { - if (document.body && document.body.scrollTop) - document.body.scrollTop = 0; - else if (document.documentElement && document.documentElement.scrollTop) - document.documentElement.scrollTop = 0; - } - - function gen_archive_calendar (year) { - if (typeof stream_data == 'undefined') - return; - year = year || stream_data.view_date.split ('/')[0]; - var month = 1; - var cal = '<table>'; - cal += '<tr><th colspan="3">' - + '<a href="#" class="fleft prev"> </a>'; - if (parseInt (year, 10) < stream_data.year_now) - cal += '<a href="#" class="fright next"> </a>'; - else - cal += '<span class="fright" style="width:25px"> </span>'; - cal += '<span class="year">'+ year +'</span> ' - + '</th></tr>'; - for (var row = 0; row < 4; row++) { - cal += '<tr>' |