Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #52 upgrade to turbolinks v5 #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
isolate namespace and load on ready
  • Loading branch information
mfrederickson committed Mar 2, 2017
commit 3bd6bf0d0d925f8814404fe4389fe57efd470d91
108 changes: 56 additions & 52 deletions app/assets/javascripts/concerto_simple_rss/simple_rss.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
function toggleSimpleRssConditionalInputs() {
if ($('select#simple_rss_config_output_format').val() == 'xslt') {
$('div#simple_rss_maxitems').hide();
$('div#simple_rss_xslmarkup').show();
} else {
$('div#simple_rss_maxitems').show();
$('div#simple_rss_xslmarkup').hide();
}
}
var ConcertoSimpleRss = {
_initialized: false,

function previewSimpleRss() {
var url = $('input#simple_rss_config_url').data('url');
if (url) {
rss_url = $('input#simple_rss_config_url').val();
userid = $('input#simple_rss_config_url_userid').val();
password = $('input#simple_rss_config_url_password').val();
output_format = $('select#simple_rss_config_output_format').val();
max_items = $('input#simple_rss_config_max_items').val();
reverse_order = $('select#simple_rss_config_reverse_order').val();
xsl = $('textarea#simple_rss_config_xsl').val();
sanitize_tags = $('input#simple_rss_config_sanitize_tags').val();
if (max_items == '') {
max_items = '0';
toggleSimpleRssConditionalInputs: function () {
if ($('select#simple_rss_config_output_format').val() == 'xslt') {
$('div#simple_rss_maxitems').hide();
$('div#simple_rss_xslmarkup').show();
} else {
$('div#simple_rss_maxitems').show();
$('div#simple_rss_xslmarkup').hide();
}
$("#preview_div").load(url, { data: {
url: rss_url,
url_userid: userid,
url_password: password,
output_format: output_format,
max_items: max_items,
reverse_order: reverse_order,
xsl: xsl,
sanitize_tags: sanitize_tags
}, type: 'SimpleRss' });
}
}
},

var initializedSimpleRssHandlers = false;
function initializeSimpleRssHandlers() {
if (!initializedSimpleRssHandlers) {
$('select#simple_rss_config_output_format').on('change', toggleSimpleRssConditionalInputs);
toggleSimpleRssConditionalInputs();
previewSimpleRss: function () {
var url = $('input#simple_rss_config_url').data('url');
if (url) {
rss_url = $('input#simple_rss_config_url').val();
userid = $('input#simple_rss_config_url_userid').val();
password = $('input#simple_rss_config_url_password').val();
output_format = $('select#simple_rss_config_output_format').val();
max_items = $('input#simple_rss_config_max_items').val();
reverse_order = $('select#simple_rss_config_reverse_order').val();
xsl = $('textarea#simple_rss_config_xsl').val();
sanitize_tags = $('input#simple_rss_config_sanitize_tags').val();
if (max_items == '') {
max_items = '0';
}
$("#preview_div").load(url, { data: {
url: rss_url,
url_userid: userid,
url_password: password,
output_format: output_format,
max_items: max_items,
reverse_order: reverse_order,
xsl: xsl,
sanitize_tags: sanitize_tags
}, type: 'SimpleRss' });
}
},

// on blur and change of url, display format, reverse_order, max items, and xsl
// not on keyup (poor man's debouncing technique?)
$('input#simple_rss_config_url').on('blur', previewSimpleRss);
$('input#simple_rss_config_url_userid').on('blur', previewSimpleRss);
$('input#simple_rss_config_url_password').on('blur', previewSimpleRss);
$('select#simple_rss_config_output_format').on('change', previewSimpleRss);
$('input#simple_rss_config_max_items').on('blur', previewSimpleRss);
$('select#simple_rss_config_reverse_order').on('change', previewSimpleRss);
$('textarea#simple_rss_config_xsl').on('blur', previewSimpleRss);
$('input#simple_rss_config_sanitize_tags').on('blur', previewSimpleRss);
initHandlers: function () {
if (!ConcertoSimpleRss._initialized) {
$('select#simple_rss_config_output_format').on('change', ConcertoSimpleRss.toggleSimpleRssConditionalInputs);
ConcertoSimpleRss.toggleSimpleRssConditionalInputs();

initializedSimpleRssHandlers = true;
// on blur and change of url, display format, reverse_order, max items, and xsl
// not on keyup (poor man's debouncing technique?)
$('input#simple_rss_config_url').on('blur', ConcertoSimpleRss.previewSimpleRss);
$('input#simple_rss_config_url_userid').on('blur', ConcertoSimpleRss.previewSimpleRss);
$('input#simple_rss_config_url_password').on('blur', ConcertoSimpleRss.previewSimpleRss);
$('select#simple_rss_config_output_format').on('change', ConcertoSimpleRss.previewSimpleRss);
$('input#simple_rss_config_max_items').on('blur', ConcertoSimpleRss.previewSimpleRss);
$('select#simple_rss_config_reverse_order').on('change', ConcertoSimpleRss.previewSimpleRss);
$('textarea#simple_rss_config_xsl').on('blur', ConcertoSimpleRss.previewSimpleRss);
$('input#simple_rss_config_sanitize_tags').on('blur', ConcertoSimpleRss.previewSimpleRss);

ConcertoSimpleRss._initialized = true;
}
}
}
};

$(document).on('turbolinks:load', initializeSimpleRssHandlers);
$(document).ready(ConcertoSimpleRss.initHandlers);
$(document).on('turbolinks:load', ConcertoSimpleRss.initHandlers);