MediaWiki:Gadget-gsnews.js: Difference between revisions
Created page with "//<nowiki> →global jQuery, mediaWiki, mw, gs, gswiki, moment, ga: 'use strict'; ;(function($, mw, gs){ var portletLink, $popup, $arrow, $content, $list, news_it..." |
mNo edit summary |
||
| Line 47: | Line 47: | ||
function init() { | function init() { | ||
$content = $('<div>').addClass('gsw- | $content = $('<div>').addClass('gsw-gsnews-content'); | ||
$list = $('<ul>').addClass('news-list'); | $list = $('<ul>').addClass('news-list'); | ||
| Line 55: | Line 55: | ||
'', | '', | ||
'', | '', | ||
'pt- | 'pt-gsnews', | ||
'Gemini Staion News', | 'Gemini Staion News', | ||
null, | null, | ||
| Line 71: | Line 71: | ||
// Google analytics tracker | // Google analytics tracker | ||
if (typeof ga === 'function') { | if (typeof ga === 'function') { | ||
ga('gtag_UA_126479006_1.send', 'event', 'Gadget- | ga('gtag_UA_126479006_1.send', 'event', 'Gadget-gsnews', 'Open', 'Normal'); | ||
} | } | ||
| Line 78: | Line 78: | ||
}); | }); | ||
$arrow = $('<div>').addClass('gsw- | $arrow = $('<div>').addClass('gsw-gsnews-arrow'); | ||
$popup = $('<div>').addClass('gsw- | $popup = $('<div>').addClass('gsw-gsnews').css({ | ||
'max-width': '500px' | 'max-width': '500px' | ||
}).append( | }).append( | ||
$arrow, | $arrow, | ||
$('<h2>').html('Latest Gemini Station News'), | $('<h2>').html('Latest Gemini Station News'), | ||
$('<div>').addClass('gsw- | $('<div>').addClass('gsw-gsnews-help').html('Curated by trusted community members. <a href="/w/Help:Gadget-gsnews" target="_blank">Learn more</a>. View this feed <a href="/w/GSWiki:News" target="_blank">on a page</a>.'), | ||
$content | $content | ||
); | ); | ||
| Line 96: | Line 96: | ||
// Close popup when anywhere else is clicked | // Close popup when anywhere else is clicked | ||
$(document).click(function(e) { | $(document).click(function(e) { | ||
if (isopen && !$(e.target).closest('.gsw- | if (isopen && !$(e.target).closest('.gsw-gsnews').length) { | ||
$popup.hide(); | $popup.hide(); | ||
isopen = false; | isopen = false; | ||
| Line 109: | Line 109: | ||
// If we're on the standalone page, we should show the feed there | // If we're on the standalone page, we should show the feed there | ||
if ($('.' + standaloneClass).length) { | if ($('.' + standaloneClass).length) { | ||
$('.' + standaloneClass).addClass('gsw- | $('.' + standaloneClass).addClass('gsw-gsnews').html($content); | ||
// change the click handler on the portlet link because | // change the click handler on the portlet link because | ||
| Line 116: | Line 116: | ||
$(portletLink).find('a').off('click').click(function(e) { | $(portletLink).find('a').off('click').click(function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
mw.notify( 'You are on the standalone page for the feed already. You do not need to open this popup.', { tag: ' | mw.notify( 'You are on the standalone page for the feed already. You do not need to open this popup.', { tag: 'gsnews' } ); | ||
}) | }) | ||
} | } | ||
| Line 168: | Line 168: | ||
function setLoading () { | function setLoading () { | ||
mw.log('Setting | mw.log('Setting gsnews as loading'); | ||
$('.gsw- | $('.gsw-gsnews-content').addClass('gsw-social-loading'); | ||
} | } | ||
function setLoadingDone () { | function setLoadingDone () { | ||
mw.log('Setting | mw.log('Setting gsnews as loading done'); | ||
$('.gsw- | $('.gsw-gsnews-content').removeClass('gsw-social-loading'); | ||
} | } | ||
| Line 185: | Line 185: | ||
function trackClick( e ) { | function trackClick( e ) { | ||
if (typeof ga === 'function') { | if (typeof ga === 'function') { | ||
ga('gtag_UA_126479006_1.send', 'event', 'Gadget- | ga('gtag_UA_126479006_1.send', 'event', 'Gadget-gsnews', 'Open link', e.data.type); | ||
} | } | ||
} | } | ||
| Line 390: | Line 390: | ||
if (itemId !== parseInt(lastItem)) { | if (itemId !== parseInt(lastItem)) { | ||
$(portletLink).find('a.oo-ui-icon-feedback') | $(portletLink).find('a.oo-ui-icon-feedback') | ||
.addClass('gsw- | .addClass('gsw-gsnews-hasunread') | ||
} else { | } else { | ||
$(portletLink).find('a.oo-ui-icon-feedback') | $(portletLink).find('a.oo-ui-icon-feedback') | ||
.removeClass('gsw- | .removeClass('gsw-gsnews-hasunread') | ||
} | } | ||
} | } | ||