Sha256: c58ec8ef1aac075fdb2cd3c0e3286b46e993c10e1f13ecd479182e76ed5984cf
Contents?: true
Size: 1.65 KB
Versions: 11
Compression:
Stored size: 1.65 KB
Contents
(function($) { const COMPONENT_SELECTOR = '[data-thredded-user-preferences-form]'; const NOTIFY_ON_MENTION_SELECTOR = ':checkbox[name="user_preferences_form[notify_on_mention]"]'; const MESSAGEBOARD_NOTIFY_ON_MENTION_SELECTOR = '[name="user_preferences_form[messageboard_notify_on_mention]"]'; class UserPreferencesForm { constructor(form) { this.$form = $(form); this.$notifyOnMention = this.$form.find(NOTIFY_ON_MENTION_SELECTOR); this.$messageboardNotifyOnMention = this.$form.find(MESSAGEBOARD_NOTIFY_ON_MENTION_SELECTOR); this.messageboardNotifyOnMentionCheckedWas = this.$messageboardNotifyOnMention.prop('checked'); this.$messageboardNotifyOnMention.on('change', () => { this.rememberMessageboardNotifyOnMentionChecked(); }); this.rememberMessageboardNotifyOnMentionChecked(); this.$notifyOnMention.on('change', () => { this.updateMessageboardNotifyOnMention(); }); this.updateMessageboardNotifyOnMention(); } rememberMessageboardNotifyOnMentionChecked() { this.messageboardNotifyOnMentionCheckedWas = this.$messageboardNotifyOnMention.filter(':checkbox').prop('checked'); } updateMessageboardNotifyOnMention() { const enabled = this.$notifyOnMention.prop('checked'); this.$messageboardNotifyOnMention .prop('disabled', !enabled) .filter(':checkbox').prop('checked', enabled ? this.messageboardNotifyOnMentionCheckedWas : false); } } $(function() { const $forms = $(COMPONENT_SELECTOR); if ($forms.length) { $forms.each(function() { new UserPreferencesForm(this); }); } }); })(jQuery);
Version data entries
11 entries across 11 versions & 1 rubygems