Browse Source

rewrite of options.js to get it more useful and faster, move localizeLabels() to theme_option.js of nin, introduce playSound(), clean up a bit trailing spaces

master
Simon Grim 10 years ago
parent
commit
ede178eb32
  1. 52
      js/interface_common.js
  2. 28
      js/interface_home.js
  3. 20
      js/interface_localization.js
  4. 46
      js/mobile_abstract.js
  5. 928
      js/options.js
  6. 4
      js/twister_actions.js
  7. 2
      js/twister_directmsg.js
  8. 8
      js/twister_formatpost.js
  9. 9
      js/twister_io.js
  10. 8
      js/twister_newmsgs.js
  11. 15
      js/twister_timeline.js
  12. 6
      options.html
  13. 11
      theme_nin/js/theme_option.js

52
js/interface_common.js

@ -208,8 +208,8 @@ function updateHashtagModal(postboard,hashtag,timeoutArgs) { @@ -208,8 +208,8 @@ function updateHashtagModal(postboard,hashtag,timeoutArgs) {
requestHashtag(postboard,hashtag,resource,timeoutArgs);
if( _hashtagPendingPostsUpdated ) {
if (resource != 'mention' && $.Options.getShowDesktopNotifPostsModalOpt() === 'enable') {
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t("new_posts", _hashtagPendingPostsUpdated)+' '+polyglot.t('in search result')+'.', false,'twister_notification_new_posts_modal', $.Options.getShowDesktopNotifPostsModalTimerOpt(), function() {
if (resource != 'mention' && $.Options.showDesktopNotifPostsModal.val === 'enable') {
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t("new_posts", _hashtagPendingPostsUpdated)+' '+polyglot.t('in search result')+'.', false,'twister_notification_new_posts_modal', $.Options.showDesktopNotifPostsModalTimer.val, function() {
$(".postboard-news").hide();
displayHashtagPending($(".hashtag-modal .postboard-posts"));
}, false)
@ -231,8 +231,7 @@ function openMentionsModal(e) @@ -231,8 +231,7 @@ function openMentionsModal(e)
e.preventDefault();
}
if(!defaultScreenName)
{
if (!defaultScreenName) {
alert(polyglot.t("No one can mention you because you are not logged in."));
return;
}
@ -501,7 +500,7 @@ var reTwistPopup = function( e ) @@ -501,7 +500,7 @@ var reTwistPopup = function( e )
if(!defaultScreenName)
{
e.stopPropagation();
alert(polyglot.t("You have to log in to retransmit messages."));
alert(polyglot.t('You have to log in to retransmit messages.'));
return;
}
@ -628,7 +627,7 @@ var postExpandFunction = function( e, postLi ) @@ -628,7 +627,7 @@ var postExpandFunction = function( e, postLi )
$postExpandedContent.slideDown( "fast" );
if ($.Options.getShowPreviewOpt() == 'enable'){
if ($.Options.showPreview.val === 'enable') {
var previewContainer=$postExpandedContent.find(".preview-container")[0];
/* was the preview added before... */
if ($(previewContainer).children().length == 0) {
@ -677,7 +676,7 @@ var postReplyClick = function( e ) @@ -677,7 +676,7 @@ var postReplyClick = function( e )
if(!defaultScreenName)
{
e.stopPropagation();
alert(polyglot.t("You have to log in to post replies."));
alert(polyglot.t('You have to log in to post replies.'));
return;
}
var post = $(this).closest(".post");
@ -703,14 +702,13 @@ var composeNewPost = function( e, postAreaNew ) @@ -703,14 +702,13 @@ var composeNewPost = function( e, postAreaNew )
//se o usuário clicar fora é pra fechar
postAreaNew.clickoutside( unfocusThis );
if ($.Options.getSplitPostsOpt() === "enable")
if ($.Options.splitPosts.val === 'enable')
usePostSpliting = true;
else if ($.Options.getSplitPostsOpt() === "only-new") {
else if ($.Options.splitPosts.val === 'only-new') {
var $postOrig = postAreaNew.closest(".post-data");
if (!$postOrig.length) {
if (!$postOrig.length)
$postOrig = postAreaNew.closest(".modal-content").find(".post-data");
}
if ($postOrig.length)
usePostSpliting = false;
@ -749,7 +747,7 @@ function replyTextInput(e) { @@ -749,7 +747,7 @@ function replyTextInput(e) {
var $this = $( this );
var tweetForm = $this.parents("form");
if( tweetForm != undefined ) {
if ($.Options.getUnicodeConversionOpt() !== "disable")
if ($.Options.unicodeConversion.val !== 'disable')
$this.val(convert2Unicodes($this.val(), $this));
if (usePostSpliting && !$this.parents('.directMessages').length) {
@ -933,14 +931,14 @@ function replyTextKeySend(e) { @@ -933,14 +931,14 @@ function replyTextKeySend(e) {
var tweetAction = tweetForm.find(".post-submit");
if( !tweetAction.length ) tweetAction = tweetForm.find(".dm-submit");
if( $.Options.keyEnterToSend() && $('.dropdown-menu').css('display') == 'none'){
if ($.Options.keysSend.val === 'enter' && $('.dropdown-menu').css('display') == 'none') {
if (e.keyCode === 13 && (!e.metaKey && !e.ctrlKey)) {
$this.val($this.val().trim());
if( !tweetAction.hasClass("disabled")) {
tweetAction.click();
}
}
} else if( !$.Options.keyEnterToSend() ){
} else if ($.Options.keysSend.val === 'ctrlenter') {
if (e.keyCode === 13 && (e.metaKey || e.ctrlKey)) {
$this.val($this.val().trim());
if( !tweetAction.hasClass("disabled") ) {
@ -1295,37 +1293,29 @@ function convert2Unicodes(s, ta) @@ -1295,37 +1293,29 @@ function convert2Unicodes(s, ta)
ta.data("disabledUnicodeRules", []);
var ranges = getRangesForUnicodeConversion(s);
var list;
if ($.Options.getUnicodeConversionOpt() === "enable" || $.Options.getConvertPunctuationsOpt())
{
if ($.Options.unicodeConversion.val === 'enable' || $.Options.convertPunctuations.val) {
list = unicodeConversionList.punctuation;
s = getUnicodeReplacement(s, list, ranges, ta);
}
if ($.Options.getUnicodeConversionOpt() === "enable"|| $.Options.getConvertEmotionsOpt())
{
if ($.Options.unicodeConversion.val === 'enable' || $.Options.convertEmotions.val) {
list = unicodeConversionList.emotions;
s = getUnicodeReplacement(s, list, ranges, ta);
}
if ($.Options.getUnicodeConversionOpt() === "enable"|| $.Options.getConvertSignsOpt())
{
if ($.Options.unicodeConversion.val === 'enable' || $.Options.convertSigns.val) {
list = unicodeConversionList.signs;
s = getUnicodeReplacement(s, list, ranges, ta);
}
if ($.Options.getUnicodeConversionOpt() === "enable"|| $.Options.getConvertFractionsOpt())
{
if ($.Options.unicodeConversion.val === 'enable' || $.Options.convertFractions.val) {
list = unicodeConversionList.fractions;
s = getUnicodeReplacement(s, list, ranges, ta);
}
if (ta.data("unicodeConversionStack").length > 0)
{
if (ta.data("unicodeConversionStack").length > 0) {
var ub = ta.closest(".post-area-new").find(".undo-unicode");
ub.text(polyglot.t("undo") + ": " + ta.data("unicodeConversionStack")[0].u);
$.MAL.enableButton(ub);
}
else
{
} else
$.MAL.disableButton(ta.closest(".post-area-new").find(".undo-unicode"));
}
return s;
}
@ -1471,7 +1461,7 @@ var retweetSubmit = function(e) @@ -1471,7 +1461,7 @@ var retweetSubmit = function(e)
function changeStyle() {
var style, profile, menu;
var theme = $.Options.getTheme();
var theme = $.Options.theme.val;
if(theme == 'nin')
{
@ -1582,7 +1572,7 @@ function initInterfaceCommon() { @@ -1582,7 +1572,7 @@ function initInterfaceCommon() {
$( ".modal-propagate").click( retweetSubmit );
$( ".expanded-content .show-more").bind('click', openConversationClick);
if ($.Options.getUnicodeConversionOpt() === "disable")
if ($.Options.unicodeConversion.val === 'disable')
$( ".undo-unicode" ).click( undoLastUnicode ).css("display", "none");
else
$( ".undo-unicode" ).click( undoLastUnicode );
@ -1601,7 +1591,7 @@ function initInterfaceCommon() { @@ -1601,7 +1591,7 @@ function initInterfaceCommon() {
replaceDashboards();
$( window ).resize(replaceDashboards);
if ($.Options.getWhoToFollowOpt() === 'enable')
if ($.Options.WhoToFollow.val === 'enable')
initWhoToFollow();
else
killInterfaceModule('who-to-follow');

28
js/interface_home.js

@ -6,8 +6,7 @@ @@ -6,8 +6,7 @@
//***********************************************
//******************* DECLARATIONS **************
//***********************************************
var InterfaceFunctions = function()
{
var InterfaceFunctions = function() {
//faço os binds no init
this.init = function()
{
@ -115,18 +114,17 @@ var InterfaceFunctions = function() @@ -115,18 +114,17 @@ var InterfaceFunctions = function()
});
});
}
if ($.Options.getTopTrendsOpt() === 'enable')
if ($.Options.TopTrends.val === 'enable')
initTopTrends();
else
killInterfaceModule('toptrends');
if ($.Options.getTwistdayReminderOpt() === 'enable')
if ($.Options.TwistdayReminder.val === 'enable')
initTwistdayReminder();
else
killInterfaceModule('twistday-reminder');
}
};
}
function initTopTrends() {
var $tt = initInterfaceModule('toptrends');
@ -148,9 +146,9 @@ function updateTrendingHashtags() { @@ -148,9 +146,9 @@ function updateTrendingHashtags() {
function(args, ret) {
//console.log('hashtags trends: '+ret);
for( var i = 0; i < ret.length; i++ ) {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangForTopTrendsOpt())
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangForTopTrends.val)
var langFilterData = filterLang(ret[i]);
if (typeof(langFilterData) === 'undefined' || langFilterData['pass'] || $.Options.getFilterLangSimulateOpt()) {
if (typeof(langFilterData) === 'undefined' || langFilterData['pass'] || $.Options.filterLangSimulate.val) {
var $li = $('<li>');
var hashtagLinkTemplate = $('#hashtag-link-template').clone(true);
@ -159,7 +157,7 @@ function updateTrendingHashtags() { @@ -159,7 +157,7 @@ function updateTrendingHashtags() {
hashtagLinkTemplate.text('#'+ret[i]);
$li.append(hashtagLinkTemplate);
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangSimulateOpt()) {
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangSimulate.val) {
if (typeof(langFilterData) !== 'undefined') {
$li.append(' <span class="langFilterSimData"><em>'+((langFilterData['pass']) ? polyglot.t('passed') : polyglot.t('blocked'))+'</em>: '+langFilterData['prob'][0].toString()+'</span>');
} else {
@ -180,10 +178,10 @@ function updateTrendingHashtags() { @@ -180,10 +178,10 @@ function updateTrendingHashtags() {
console.log('Error with gettrendinghashtags. Older twister daemon?');
}, {}
);
if ($list.children().length && $.Options.getTopTrendsAutoUpdateOpt() === 'enable' && $.Options.getTopTrendsAutoUpdateTimerOpt() > 0)
setTimeout(updateTrendingHashtags, $.Options.getTopTrendsAutoUpdateTimerOpt()*1000);
if ($list.children().length && $.Options.TopTrendsAutoUpdate.val === 'enable' && $.Options.TopTrendsAutoUpdateTimer.val > 0)
setTimeout(updateTrendingHashtags, $.Options.TopTrendsAutoUpdateTimer.val * 1000);
}
}
};
function initTwistdayReminder() {
var $module = initInterfaceModule('twistday-reminder');
@ -235,7 +233,7 @@ function refreshTwistdayReminder() { @@ -235,7 +233,7 @@ function refreshTwistdayReminder() {
list.find('[data-screen-name='+lucky+']').closest('li').remove();
}
var showUpcomingTimer = ($.Options.getTwistdayReminderShowUpcomingOpt() === 'enable') ? $.Options.getTwistdayReminderShowUpcomingTimerOpt() *3600 : 0;
var showUpcomingTimer = ($.Options.TwistdayReminderShowUpcoming.val === 'enable') ? $.Options.TwistdayReminderShowUpcomingTimer.val * 3600 : 0;
var listCurrent = $module.find('.current .list');
var listUpcoming = $module.find('.upcoming .list');
var d = new Date();
@ -283,8 +281,8 @@ function refreshTwistdayReminder() { @@ -283,8 +281,8 @@ function refreshTwistdayReminder() {
function(arg, ret) { console.log('ajax error:' + ret); }, null);
}
}
if ($.Options.getTwistdayReminderAutoUpdateOpt() === 'enable' && $.Options.getTwistdayReminderAutoUpdateTimerOpt() > 0)
setTimeout(refreshTwistdayReminder, $.Options.getTwistdayReminderAutoUpdateTimerOpt()*1000);
if ($.Options.TwistdayReminderAutoUpdate.val === 'enable' && $.Options.TwistdayReminderAutoUpdateTimer.val > 0)
setTimeout(refreshTwistdayReminder, $.Options.TwistdayReminderAutoUpdateTimer.val * 1000);
}
}

20
js/interface_localization.js

@ -6,24 +6,22 @@ @@ -6,24 +6,22 @@
// translators: add your language code here such as "es" for Spanish, "ru" for Russian
var knownLanguages = ["en","es","nl","it","fr","ru","de","zh-CN","ja","pt-BR","tr","uk","cs"];
if( $.Options.getOption('locLang','auto') == 'auto'){
if ($.Options.locLang.val === 'auto') {
// detect language with JavaScript
preferredLanguage = window.navigator.userLanguage || window.navigator.language || "en";
preferredLanguage = window.navigator.userLanguage || window.navigator.language || 'en';
if (knownLanguages.indexOf(preferredLanguage) > -1) {
// en for en or similar
preferredLanguage = preferredLanguage;
}
else if(knownLanguages.indexOf(preferredLanguage.split("-")[0]) > -1){
} else if (knownLanguages.indexOf(preferredLanguage.split('-')[0]) > -1) {
// en for en-US or similar
preferredLanguage = preferredLanguage.split("-")[0];
}
else{
// did not find match
preferredLanguage = "en";
}
preferredLanguage = preferredLanguage.split('-')[0];
} else {
preferredLanguage = $.Options.getOption('locLang','en');
// did not find match
preferredLanguage = 'en';
}
} else
preferredLanguage = $.Options.locLang.val;
// set up Polyglot
polyglot = new Polyglot();
var wordset = {};

46
js/mobile_abstract.js

@ -103,8 +103,8 @@ var MAL = function() @@ -103,8 +103,8 @@ var MAL = function()
newTweetsBarMenu.text(String(newPosts));
newTweetsBarMenu.addClass("show");
if ($.Options.getShowDesktopNotifPostsOpt() === 'enable') {
this.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_posts', newPosts)+' '+polyglot.t('in postboard')+'.', false,'twister_notification_new_posts', $.Options.getShowDesktopNotifPostsTimerOpt(), (function() {
if ($.Options.showDesktopNotifPosts.val === 'enable') {
this.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_posts', newPosts)+' '+polyglot.t('in postboard')+'.', false,'twister_notification_new_posts', $.Options.showDesktopNotifPostsTimer.val, (function() {
requestTimelineUpdate('pending',this,followingUsers,promotedPostsOnly);
}).bind(newPosts), false)
}
@ -400,18 +400,20 @@ var MAL = function() @@ -400,18 +400,20 @@ var MAL = function()
}
this.soundNotifyMentions = function() {
if( $.hasOwnProperty("mobile") ) {
if ($.mobile) {
} else {
$.Options.mensNotif();
}
if ($.Options.sndMention.val !== 'false')
playSound('player', $.Options.sndMention.val);
}
};
this.soundNotifyDM = function() {
if( $.hasOwnProperty("mobile") ) {
if ($.mobile) {
} else {
$.Options.DMsNotif();
}
if ($.Options.sndDM.val !== 'false')
playSound('playerSec', $.Options.sndDM.val);
}
};
this.showDesktopNotif = function(notifyTitle, notifyBody, notifyIcon, notifyTag, notifyTimer, actionOnClick, actionOnPermDenied) {
function doNotification() {
@ -451,7 +453,7 @@ var MAL = function() @@ -451,7 +453,7 @@ var MAL = function()
} else {
doNotification();
}
}
};
this.reqRepAfterCB = function(postLi, postsFromJson) {
if ($.hasOwnProperty("mobile")) {
@ -488,18 +490,38 @@ var MAL = function() @@ -488,18 +490,38 @@ var MAL = function()
jQuery.MAL = new MAL;
function playSound(player, sound) {
if ($.mobile) {
} else {
var player = $('#'+player);
if (player.length) {
player[0].pause();
//player.empty();
if (player[0].canPlayType('audio/mpeg;'))
player.attr({type: 'audio/mpeg', src: 'sound/' + sound + '.mp3'});
else
player.attr({type: 'audio/ogg', src: 'sound/' + sound + '.ogg'});
player[0].volume = $.Options.playerVol.val;
player[0].play();
} else
console.warn('cannot find player to play sound, selector: #'+player);
}
}
function filterLang(string) {
var langFilterMode = $.Options.getFilterLangOpt();
var langFilterMode = $.Options.filterLang.val;
if (langFilterMode !== 'disable') {
var langFilterSubj = '';
var langFilterProb = [];
var langFilterPass = true;
var langFilterReason = '';
var langFilterList = $.Options.getFilterLangListOpt();
var langFilterList = $.Options.filterLangList.val;
if (langFilterList.length > 0) {
var langFilterAccuracy = $.Options.getFilterLangAccuracyOpt();
var langFilterAccuracy = $.Options.filterLangAccuracy.val;
langFilterPass = (langFilterMode === 'whitelist') ? false : true;
langFilterReason = polyglot.t('this doesnt contain that', {'this': polyglot.t(langFilterMode), 'that': polyglot.t('language of this')});

928
js/options.js

@ -1,691 +1,353 @@ @@ -1,691 +1,353 @@
$(function() {
function twisterOptions() {
this.add({
name: 'locLang',
selector: '#language',
valDefault: 'auto',
tickMethod: function (elem) {
if (elem.value !== 'auto')
twisterRpc('setpreferredspamlang', [elem.value]);
location.reload();
},
tickNotOnInit: 1
});
var _desktopNotificationTimeout = 10; // it should be an option
var TwisterOptions = function()
{
this.getOption = function(optionName, defaultValue) {
var keyName = "options:" + optionName;
if( $.localStorage.isSet(keyName) )
return $.localStorage.get(keyName);
else
return defaultValue;
}
this.setOption = function(optionName, value) {
var keyName = "options:" + optionName;
$.localStorage.set(keyName, value);
}
this.soundNotifOptions = function() {
$('#notifyForm select').each(function() {
this.value = $.Options.getOption(this.id, 'false');
this.add({
name: 'theme',
valDefault: 'original',
tickMethod: function () {location.reload();},
tickNotOnInit: 1
});
var player = $('#player');
player[0].pause();
$('#player').empty();
$('form#notifyForm').on('change', 'select', function() {
$.Options.setOption(this.id, this.value);
if(this.value == false) {player[0].pause(); return;}
if (player[0].canPlayType('audio/mpeg;')) {
player.attr('type', 'audio/mpeg');
player.attr('src', 'sound/'+this.value+'.mp3');
} else {
player.attr('type', 'audio/ogg');
player.attr('src', 'sound/'+this.value+'.ogg');
this.add({
name: 'TopTrends',
valDefault: 'enable',
tickMethod: function (elem) {
$('#TopTrendsCont').css('display', (elem.value === 'enable') ? 'block' : 'none');
}
player[0].play();
});
this.add({
name: 'TopTrendsAutoUpdate',
valDefault: 'enable',
tickMethod: function (elem) {
$('#TopTrendsAutoUpdateOpt').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
this.volumeControl = function() {
var playerVol = $('#playerVol');
playerVol[0].value = this.getOption(playerVol[0].id, 1);
$('.volValue').text((playerVol[0].value * 100).toFixed());
playerVol.on('change', function() {
$.Options.setOption(this.id, this.value);
$('#player')[0].volume = (this.value);
$('.volValue').text((this.value * 100).toFixed());
});
}
this.DMsNotif = function() {
var sndDM = this.getOption('sndDM', 'false');
if ( sndDM === 'false') return;
var player = $('#player');
$('#player').empty();
if (player[0].canPlayType('audio/mpeg;')) {
player.attr('type', 'audio/mpeg');
player.attr('src', 'sound/'+sndDM+'.mp3');
} else {
player.attr('type', 'audio/ogg');
player.attr('src', 'sound/'+sndDM+'.ogg');
}
player[0].volume = this.getOption('playerVol',1);
player[0].play();
}
this.mensNotif = function() {
var sndMention = this.getOption('sndMention', 'false');
if (sndMention === 'false') return;
var player = $('#playerSec');
$('#playerSec').empty();
if (player[0].canPlayType('audio/mpeg;')) {
player.attr('type', 'audio/mpeg');
player.attr('src', 'sound/'+sndMention+'.mp3');
} else {
player.attr('type', 'audio/ogg');
player.attr('src', 'sound/'+sndMention+'.ogg');
}
player[0].volume = this.getOption('playerVol',1);
player[0].play();
}
this.getShowDesktopNotifPostsOpt = function() {
return this.getOption('showDesktopNotifPosts', 'enable');
}
this.setShowDesktopNotifPostsOpt = function () {
function showDesktopNotifPostsDesc() {
if ($.Options.getShowDesktopNotifPostsOpt() === 'enable')
$('#showDesktopNotifPostsDesc').css('display', 'inline');
else
$('#showDesktopNotifPostsDesc').css('display', 'none');
}
$('#showDesktopNotifPosts').val( this.getShowDesktopNotifPostsOpt() );
showDesktopNotifPostsDesc();
$('#showDesktopNotifPosts').on('change', function() {
$.Options.setOption(this.id, this.value);
showDesktopNotifPostsDesc();
this.add({
name: 'TopTrendsAutoUpdateTimer',
type: 'numeric',
valDefault: '120',
valMes: 'second(s)',
getMethod: function (val) {return parseInt(val);}
});
}
this.getShowDesktopNotifPostsTimerOpt = function () {
return parseInt(this.getOption('showDesktopNotifPostsTimer', '6'));
}
this.setShowDesktopNotifPostsTimerOpt = function () {
$('#showDesktopNotifPostsTimer').val( this.getShowDesktopNotifPostsTimerOpt().toString() );
$('#showDesktopNotifPostsTimer').on('keyup', function () { setElemValNumeric(this, polyglot.t('second(s)')); });
}
this.getShowDesktopNotifPostsModalOpt = function() {
return this.getOption('showDesktopNotifPostsModal', 'enable');
}
this.setShowDesktopNotifPostsModalOpt = function () {
function showDesktopNotifPostsModalDesc() {
if ($.Options.getShowDesktopNotifPostsModalOpt() === 'enable')
$('#showDesktopNotifPostsModalDesc').css('display', 'inline');
else
$('#showDesktopNotifPostsModalDesc').css('display', 'none');
}
$('#showDesktopNotifPostsModal').val( this.getShowDesktopNotifPostsModalOpt() );
showDesktopNotifPostsModalDesc();
$('#showDesktopNotifPostsModal').on('change', function() {
$.Options.setOption(this.id, this.value);
showDesktopNotifPostsModalDesc();
this.add({
name: 'WhoToFollow',
valDefault: 'enable'
});
this.add({
name: 'TwistdayReminder',
valDefault: 'enable',
tickMethod: function (elem) {
$('#TwistdayReminderCont').css('display', (elem.value === 'enable') ? 'block' : 'none');
}
this.getShowDesktopNotifPostsModalTimerOpt = function () {
return parseInt(this.getOption('showDesktopNotifPostsModalTimer', '6'));
}
this.setShowDesktopNotifPostsModalTimerOpt = function () {
$('#showDesktopNotifPostsModalTimer').val( this.getShowDesktopNotifPostsModalTimerOpt().toString() );
$('#showDesktopNotifPostsModalTimer').on('keyup', function () { setElemValNumeric(this, polyglot.t('second(s)')); });
}
this.getShowDesktopNotifMentionsOpt = function() {
return this.getOption('showDesktopNotifMentions', 'enable');
}
this.setShowDesktopNotifMentionsOpt = function () {
function showDesktopNotifMentionsDesc() {
if ($.Options.getShowDesktopNotifMentionsOpt() === 'enable')
$('#showDesktopNotifMentionsDesc').css('display', 'inline');
else
$('#showDesktopNotifMentionsDesc').css('display', 'none');
}
$('#showDesktopNotifMentions').val( this.getShowDesktopNotifMentionsOpt() );
showDesktopNotifMentionsDesc();
$('#showDesktopNotifMentions').on('change', function() {
$.Options.setOption(this.id, this.value);
showDesktopNotifMentionsDesc();
});
this.add({
name: 'TwistdayReminderAutoUpdate',
valDefault: 'enable',
tickMethod: function (elem) {
$('#TwistdayReminderAutoUpdateOpt').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
this.getShowDesktopNotifMentionsTimerOpt = function () {
return parseInt(this.getOption('showDesktopNotifMentionsTimer', '60'));
}
this.setShowDesktopNotifMentionsTimerOpt = function () {
$('#showDesktopNotifMentionsTimer').val( this.getShowDesktopNotifMentionsTimerOpt().toString() );
$('#showDesktopNotifMentionsTimer').on('keyup', function () {setElemValNumeric(this, polyglot.t('second(s)'));});
}
this.getShowDesktopNotifDMsOpt = function() {
return this.getOption('showDesktopNotifDMs', 'enable');
}
this.setShowDesktopNotifDMsOpt = function () {
function showDesktopNotifDMsDesc() {
if ($.Options.getShowDesktopNotifDMsOpt() === 'enable')
$('#showDesktopNotifDMsDesc').css('display', 'inline');
else
$('#showDesktopNotifDMsDesc').css('display', 'none');
}
$('#showDesktopNotifDMs').val( this.getShowDesktopNotifDMsOpt() );
showDesktopNotifDMsDesc();
$('#showDesktopNotifDMs').on('change', function() {
$.Options.setOption(this.id, this.value);
showDesktopNotifDMsDesc();
});
}
this.getShowDesktopNotifDMsTimerOpt = function () {
return parseInt(this.getOption('showDesktopNotifDMsTimer', '60'));
}
this.setShowDesktopNotifDMsTimerOpt = function () {
$('#showDesktopNotifDMsTimer').val( this.getShowDesktopNotifDMsTimerOpt().toString() );
$('#showDesktopNotifDMsTimer').on('keyup', function () { setElemValNumeric(this, polyglot.t('second(s)')); });
}
this.setTestDesktopNotif = function() {
$('#testDesktopNotif').on('click', function() {
$.MAL.showDesktopNotif(false, polyglot.t('notify_desktop_test'), false,'twister_notification_test', false, false, function() { alert(polyglot.t('notify_desktop_perm_denied', {'this_domain': document.domain})) })
})
}
this.keysSendDefault = 'ctrlenter';
this.keysSend = function() {
$('#keysOpt select').val( this.getOption('keysSend',this.keysSendDefault) );
$('#keysOpt select').on('change', function() { $.Options.setOption(this.id, this.value); });
}
this.keyEnterToSend = function() {
return this.getOption('keysSend', this.keysSendDefault) === 'enter';
}
this.setLang = function() {
$('#language').val( this.getOption('locLang', 'auto') );
$('#language').on('change', function() {
$.Options.setOption('locLang', $(this).val());
if($(this).val() != 'auto') {
twisterRpc("setpreferredspamlang", [$(this).val()]);
}
location.reload();
})
}
this.getTheme = function() {
return this.getOption('theme', 'original');
}
this.setTheme = function() {
$('#theme').val( this.getTheme() )
$('#theme').on('change', function() {
$.Options.setOption('theme', $(this).val());
location.reload();
this.add({
name: 'TwistdayReminderAutoUpdateTimer',
type: 'numeric',
valDefault: '3600',
valMes: 'second(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'TwistdayReminderShowUpcoming',
valDefault: 'enable',
tickMethod: function (elem) {
$('#TwistdayReminderShowUpcomingOpt').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
this.getLineFeedsOpt = function() {
return this.getOption('displayLineFeeds', 'disable');
}
this.setLineFeedsOpt = function() {
$('#lineFeedsOpt select').val( this.getLineFeedsOpt() );
$('#lineFeedsOpt select').on('change', function() { $.Options.setOption(this.id, this.value); });
}
this.getShowPreviewOpt = function() {
return this.getOption('displayPreview', 'disable');
}
this.setShowPreviewOpt = function () {
$('#showPreviewOpt select').val( this.getShowPreviewOpt() );
$('#showPreviewOpt select').on('change', function() { $.Options.setOption(this.id, this.value); });
}
this.getUnicodeConversionOpt = function () {
return this.getOption('unicodeConversion', 'disable');
}
this.setUnicodeConversionOpt = function () {
$('#unicodeConversion').val( this.getUnicodeConversionOpt() );
if (this.getUnicodeConversionOpt() === 'custom')
$('#unicodeConversionOpt .suboptions').css('height', 'auto');
$('#unicodeConversion').on('change', function () {
$.Options.setOption(this.id, this.value);
if (this.value === 'custom')
$('#unicodeConversionOpt .suboptions').css('height', 'auto');
else
$('#unicodeConversionOpt .suboptions').css('height', '0px');
});
}
this.getConvertPunctuationsOpt = function() {
return this.getOption('convertPunctuationsOpt', false);
}
this.setConvertPunctuationsOpt = function () {
$('#convertPunctuationsOpt').prop('checked', this.getConvertPunctuationsOpt());
$('#convertPunctuationsOpt').on('change', function() { $.Options.setOption(this.id, this.checked); });
}
this.getConvertEmotionsOpt = function() {
return this.getOption('convertEmotionsOpt', false);
}
this.setConvertEmotionsOpt = function () {
$('#convertEmotionsOpt').prop('checked', this.getConvertEmotionsOpt());
$('#convertEmotionsOpt').on('change', function() { $.Options.setOption(this.id, this.checked); });
}
this.getConvertSignsOpt = function() {
return this.getOption('convertSignsOpt', false);
}
this.setConvertSignsOpt = function () {
$('#convertSignsOpt').prop('checked', this.getConvertSignsOpt());
$('#convertSignsOpt').on('change', function() { $.Options.setOption(this.id, this.checked); });
}
this.getConvertFractionsOpt = function() {
return this.getOption('convertFractionsOpt', false);
}
this.setConvertFractionsOpt = function () {
$('#convertFractionsOpt').prop('checked', this.getConvertFractionsOpt());
$('#convertFractionsOpt').on('change', function() { $.Options.setOption(this.id, this.checked); });
}
this.getUseProxyOpt = function () {
return this.getOption('useProxy', 'disable');
}
this.setUseProxyOpt = function () {
$('#useProxy').val( this.getUseProxyOpt() );
if (this.getUseProxyOpt() === 'disable')
$('#useProxyForImgOnly').attr('disabled', 'disabled');
$('#useProxy').on('change', function () {
$.Options.setOption(this.id, this.value);
if (this.value === 'disable')
$('#useProxyForImgOnly').attr('disabled', 'disabled');
else
$('#useProxyForImgOnly').removeAttr('disabled');
this.add({
name: 'TwistdayReminderShowUpcomingTimer',
type: 'numeric',
valDefault: '72',
valMes: 'hour(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'showDesktopNotifPosts',
valDefault: 'enable',
tickMethod: function (elem) {
$('#showDesktopNotifPostsDesc').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
this.getUseProxyForImgOnlyOpt = function () {
return this.getOption('useProxyForImgOnly', false);
}
this.setUseProxyForImgOnlyOpt = function () {
$('#useProxyForImgOnly').prop('checked', this.getUseProxyForImgOnlyOpt());
$('#useProxyForImgOnly').on('change', function () { $.Options.setOption(this.id, this.checked); });
}
this.getTopTrendsOpt = function() {
return this.getOption('TopTrends', 'enable');
}
this.setTopTrendsOpt = function () {
function TopTrendsCfg() {
if ($.Options.getTopTrendsOpt() === 'enable')
$('#TopTrendsCont').show();
else
$('#TopTrendsCont').hide();
}
$('#TopTrends').val( this.getTopTrendsOpt() );
TopTrendsCfg();
$('#TopTrends').on('change', function() {
$.Options.setOption(this.id, this.value);
TopTrendsCfg();
});
}
this.getTopTrendsAutoUpdateOpt = function() {
return this.getOption('TopTrendsAutoUpdate', 'enable');
}
this.setTopTrendsAutoUpdateOpt = function () {
function TopTrendsAutoUpdateCfg() {
if ($.Options.getTopTrendsAutoUpdateOpt() === 'enable')
$('#TopTrendsAutoUpdateOpt').css('display', 'inline');
else
$('#TopTrendsAutoUpdateOpt').css('display', 'none');
}
$('#TopTrendsAutoUpdate').val( this.getTopTrendsAutoUpdateOpt() );
TopTrendsAutoUpdateCfg();
$('#TopTrendsAutoUpdate').on('change', function() {
$.Options.setOption(this.id, this.value);
TopTrendsAutoUpdateCfg();
this.add({
name: 'showDesktopNotifPostsTimer',
type: 'numeric',
valDefault: '6',
valMes: 'second(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'showDesktopNotifPostsModal',
valDefault: 'enable',
tickMethod: function (elem) {
$('#showDesktopNotifPostsModalDesc').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
this.getTopTrendsAutoUpdateTimerOpt = function () {
return parseInt(this.getOption('TopTrendsAutoUpdateTimer', '120'));
}
this.setTopTrendsAutoUpdateTimerOpt = function () {
$('#TopTrendsAutoUpdateTimer').val( this.getTopTrendsAutoUpdateTimerOpt().toString() );
$('#TopTrendsAutoUpdateTimer').on('keyup', function () { setElemValNumeric(this, polyglot.t('second(s)')); });
}
this.getTwistdayReminderOpt = function() {
return this.getOption('TwistdayReminder', 'enable');
}
this.setTwistdayReminderOpt = function () {
function TwistdayReminderCfg() {
if ($.Options.getTwistdayReminderOpt() === 'enable')
$('#TwistdayReminderCont').show();
else
$('#TwistdayReminderCont').hide();
}
$('#TwistdayReminder').val( this.getTwistdayReminderOpt() );
TwistdayReminderCfg();
$('#TwistdayReminder').on('change', function() {
$.Options.setOption(this.id, this.value);
TwistdayReminderCfg();
});
}
this.getTwistdayReminderAutoUpdateOpt = function() {
return this.getOption('TwistdayReminderAutoUpdate', 'enable');
}
this.setTwistdayReminderAutoUpdateOpt = function () {
function TwistdayReminderAutoUpdateCfg() {
if ($.Options.getTwistdayReminderAutoUpdateOpt() === 'enable')
$('#TwistdayReminderAutoUpdateOpt').css('display', 'inline');
else
$('#TwistdayReminderAutoUpdateOpt').css('display', 'none');
}
$('#TwistdayReminderAutoUpdate').val( this.getTwistdayReminderAutoUpdateOpt() );
TwistdayReminderAutoUpdateCfg();
$('#TwistdayReminderAutoUpdate').on('change', function() {
$.Options.setOption(this.id, this.value);
TwistdayReminderAutoUpdateCfg();
this.add({
name: 'showDesktopNotifPostsModalTimer',
type: 'numeric',
valDefault: '6',
valMes: 'second(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'showDesktopNotifMentions',
valDefault: 'enable',
tickMethod: function (elem) {
$('#showDesktopNotifMentionsDesc').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
this.getTwistdayReminderAutoUpdateTimerOpt = function () {
return parseInt(this.getOption('TwistdayReminderAutoUpdateTimer', '3600'));
}
this.setTwistdayReminderAutoUpdateTimerOpt = function () {
$('#TwistdayReminderAutoUpdateTimer').val( this.getTwistdayReminderAutoUpdateTimerOpt().toString() );
$('#TwistdayReminderAutoUpdateTimer').on('keyup', function () { setElemValNumeric(this, polyglot.t('second(s)')); });
}
this.getTwistdayReminderShowUpcomingOpt = function() {
return this.getOption('TwistdayReminderShowUpcoming', 'enable');
}
this.setTwistdayReminderShowUpcomingOpt = function () {
function TwistdayReminderShowUpcomingCfg() {
if ($.Options.getTwistdayReminderShowUpcomingOpt() === 'enable')
$('#TwistdayReminderShowUpcomingOpt').css('display', 'inline');
else
$('#TwistdayReminderShowUpcomingOpt').css('display', 'none');
});
this.add({
name: 'showDesktopNotifMentionsTimer',
type: 'numeric',
valDefault: '60',
valMes: 'second(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'showDesktopNotifDMs',
valDefault: 'enable',
tickMethod: function (elem) {
$('#showDesktopNotifDMsDesc').css('display', (elem.value === 'enable') ? 'inline' : 'none');
}
$('#TwistdayReminderShowUpcoming').val( this.getTwistdayReminderShowUpcomingOpt() );
TwistdayReminderShowUpcomingCfg();
$('#TwistdayReminderShowUpcoming').on('change', function() {
$.Options.setOption(this.id, this.value);
TwistdayReminderShowUpcomingCfg();
});
this.add({
name: 'showDesktopNotifDMsTimer',
type: 'numeric',
valDefault: '60',
valMes: 'second(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'displayLineFeeds',
valDefault: 'enable'
});
this.add({
name: 'displayPreview',
valDefault: 'disable'
});
this.add({
name: 'unicodeConversion',
valDefault: 'disable',
tickMethod: function (elem) {
$('#unicodeConversionOpt .suboptions').css('height', (elem.value === 'custom') ? 'auto' : '0');
}
this.getTwistdayReminderShowUpcomingTimerOpt = function () {
return parseInt(this.getOption('TwistdayReminderShowUpcomingTimer', '72'));
});
this.add({
name: 'convertPunctuationsOpt',
type: 'checkbox',
valDefault: false
});
this.add({
name: 'convertEmotionsOpt',
type: 'checkbox',
valDefault: false
});
this.add({
name: 'convertSignsOpt',
type: 'checkbox',
valDefault: false
});
this.add({
name: 'convertFractionsOpt',
type: 'checkbox',
valDefault: false
});
this.add({
name: 'useProxy',
valDefault: 'disable',
tickMethod: function (elem) {
$('#useProxyForImgOnly').attr('disabled', (elem.value === 'disable') ? true : false);
}
this.setTwistdayReminderShowUpcomingTimerOpt = function () {
$('#TwistdayReminderShowUpcomingTimer').val( this.getTwistdayReminderShowUpcomingTimerOpt().toString() );
$('#TwistdayReminderShowUpcomingTimer').on('keyup', function () { setElemValNumeric(this, polyglot.t('hour(s)')); });
});
this.add({
name: 'useProxyForImgOnly',
type: 'checkbox',
valDefault: false
});
this.add({
name: 'splitPosts',
valDefault: 'disable'
});
this.add({
name: 'isFollowingMe',
valDefault: 'in-profile'
});
this.add({
name: 'dmCopySelf',
valDefault: 'enable'
});
this.add({
name: 'hideReplies',
valDefault: 'following'
});
this.add({
name: 'hideCloseRTs',
valDefault: 'disable',
tickMethod: function (elem) {
$('#hideCloseRTsDesc').css('display', (elem.value === 'show-if') ? 'inline' : 'none');
}
this.getWhoToFollowOpt = function() {
return this.getOption('WhoToFollow', 'enable');
});
this.add({
name: 'hideCloseRtsHour',
type: 'numeric',
valDefault: '1',
valMes: 'hour(s)',
getMethod: function (val) {return parseInt(val);}
});
this.add({
name: 'filterLang',
valDefault: 'disable',
tickMethod: function (elem) {
$('#filterLangListCont').css('display', (elem.value === 'disable') ? 'none' : 'block');
}
this.setWhoToFollowOpt = function () {
$('#WhoToFollow').val(this.getWhoToFollowOpt());
$('#WhoToFollow').on('change', function() { $.Options.setOption(this.id, this.value); });
});
this.add({
name: 'filterLangList',
valDefault: '',
getMethod: function (val) {return val.split(/\s*,\s*/);}
});
this.add({
name: 'filterLangAccuracy',
valDefault: '0.82',
getMethod: function (val) {return parseFloat(val);},
tickMethod: function (elem) {$('#filterLangAccuracyVal').text(elem.value);}
});
this.add({
name: 'filterLangForPostboard',
type: 'checkbox',
valDefault: true
});
this.add({
name: 'filterLangForSearching',
type: 'checkbox',
valDefault: true
});
this.add({
name: 'filterLangForTopTrends',
type: 'checkbox',
valDefault: true
});
this.add({
name: 'filterLangSimulate',
type: 'checkbox',
valDefault: true
});
this.add({
name: 'keysSend',
valDefault: 'ctrlenter'
});
this.add({
name: 'sndMention',
valDefault: 'false',
tickMethod: function () {$.MAL.soundNotifyMentions();}, // FIXME it's wrapped because $.MAL may be not loaded yet; $.MAL methods should be static
tickNotOnInit: 1
});
this.add({
name: 'sndDM',
valDefault: 'false',
tickMethod: function () {$.MAL.soundNotifyDM();}, // FIXME it's wrapped because $.MAL may be not loaded yet; $.MAL methods should be static
tickNotOnInit: 1
});
this.add({
name: 'playerVol',
valDefault: 1,
getMethod: function (val) {return parseFloat(val);},
tickMethod: function (elem) {$('.volValue').text((elem.value * 100).toFixed());}
});
}
this.getSplitPostsOpt = function () {
return this.getOption('splitPosts', 'disable');
}
twisterOptions.prototype.add = function (option) {
if (option.name && !this[option.name])
this[option.name] = new twisterOption(option);
};
this.setSplitPostsOpt = function () {
$('#splitPosts').val( this.getSplitPostsOpt() );
$('#splitPosts').on('change', function () { $.Options.setOption(this.id, this.value); });
twisterOptions.prototype.initControls = function () {
for (var option in this) {
if (typeof this[option] === 'object') {
var elem = $(this[option].option.selector);
if (elem.length) {
if (elem.attr('type') && elem.attr('type').toLowerCase() === 'checkbox')
elem.prop('checked', /^\s*1|true\s*$/i.test(this[option].val))
.on('change', (this[option].tick).bind(this[option]))
;
else {
elem.val(this[option].val)
.on((elem[0].tagName === 'SELECT') ? 'change' : 'input', (this[option].tick).bind(this[option]))
;
}
this.getHideRepliesOpt = function () {
return this.getOption('hideReplies', 'following');
if (!this[option].option.tickNotOnInit && typeof this[option].option.tickMethod === 'function')
this[option].option.tickMethod(elem[0]);
} else
console.warn('cannot find option \''+option+'\' controls, selector: '+this[option].option.selector);
}
this.setHideRepliesOpt = function () {
$('#hideReplies').val( this.getHideRepliesOpt() );
$('#hideReplies').on('change', function () { $.Options.setOption(this.id, this.value); });
}
this.getHideCloseRTsOpt = function () {
return this.getOption('hideCloseRTs', 'disable');
};
this.setHideCloseRTsOpt = function () {
function hideCloseRTsCfg() {
if ($.Options.getHideCloseRTsOpt() === 'disable')
$('#hideCloseRTsDesc').css('display', 'none');
else
$('#hideCloseRTsDesc').css('display', 'inline');
}
$('#hideCloseRTs').val( this.getHideCloseRTsOpt() );
hideCloseRTsCfg();
$('#hideCloseRTs').on('change', function () {
$.Options.setOption(this.id, this.value);
hideCloseRTsCfg();
$('#testDesktopNotif').on('click', function() {
$.MAL.showDesktopNotif(false, polyglot.t('notify_desktop_test'), false,'twister_notification_test', false, false, function() { alert(polyglot.t('notify_desktop_perm_denied', {'this_domain': document.domain})) })
});
};
this.getHideCloseRTsHourOpt = function () {
return parseInt(this.getOption('hideCloseRtsHour', '1'));
};
this.setHideCloseRTsHourOpt = function () {
$('#hideCloseRtsHour').val( this.getHideCloseRTsHourOpt().toString() );
$('#hideCloseRtsHour').on('keyup', function () { setElemValNumeric(this, polyglot.t('hour(s)')); });
};
this.getFilterLangOpt = function() {
return this.getOption('filterLang', 'disable');
}
function twisterOption(option) {
this.option = option;
this.setFilterLangOpt = function () {
function filterLangListCont() {
if ( $.Options.getFilterLangOpt() !== 'disable' )
$('#filterLangListCont').css('display', 'block');
if (!option.selector)
this.option.selector = '#' + option.name;
if (option.valRaw) {
this.set(option.valRaw);
} else {
var keyName = 'options:' + option.name;
if ($.localStorage.isSet(keyName))
this.option.valRaw = $.localStorage.get(keyName);
else
$('#filterLangListCont').css('display', 'none');
}
$('#filterLang').val( this.getFilterLangOpt() );
filterLangListCont();
$('#filterLang').on('change', function() {
$.Options.setOption(this.id, this.value);
filterLangListCont();
});
}
this.getFilterLangListOpt = function () {
return this.getOption('filterLangList', '').replace(/\s+/g, '').split(/\s*,\s*/);
}
this.setFilterLangListOpt = function () {
$('#filterLangList').val( this.getFilterLangListOpt() );
$('#filterLangList').on('keyup', function () { $.Options.setOption(this.id, this.value); });
}
this.getFilterLangAccuracyOpt = function () {
return parseFloat(this.getOption('filterLangAccuracy', '0.82'));
}
this.setFilterLangAccuracyOpt = function () {
$('#filterLangAccuracy').val( this.getFilterLangAccuracyOpt() );
$('#filterLangAccuracyVal').text( this.getFilterLangAccuracyOpt() );
$('#filterLangAccuracy').on('change', function () {
$.Options.setOption(this.id, this.value);
$('#filterLangAccuracyVal').text(this.value);
});
}
this.getFilterLangForPostboardOpt = function () {
return this.getOption('filterLangForPostboard', true);
}
this.setFilterLangForPostboardOpt = function () {
$('#filterLangForPostboard').prop('checked', this.getFilterLangForPostboardOpt());
$('#filterLangForPostboard').on('click', function () { $.Options.setOption(this.id, this.checked); });
}
this.getFilterLangForSearchingOpt = function () {
return this.getOption('filterLangForSearching', true);
}
this.setFilterLangForSearchingOpt = function () {
$('#filterLangForSearching').prop('checked', this.getFilterLangForSearchingOpt());
$('#filterLangForSearching').on('click', function () { $.Options.setOption(this.id, this.checked); });
this.option.valRaw = option.valDefault;
this.val = (this.option.getMethod) ? this.option.getMethod(this.option.valRaw) : this.option.valRaw;
}
this.getFilterLangForTopTrendsOpt = function () {
return this.getOption('filterLangForTopTrends', true);
}
this.setFilterLangForTopTrendsOpt = function () {
$('#filterLangForTopTrends').prop('checked', this.getFilterLangForTopTrendsOpt());
$('#filterLangForTopTrends').on('click', function () { $.Options.setOption(this.id, this.checked); });
}
this.getFilterLangSimulateOpt = function () {
return this.getOption('filterLangSimulate', true);
}
twisterOption.prototype.val = undefined;
this.setFilterLangSimulateOpt = function () {
$('#filterLangSimulate').prop('checked', this.getFilterLangSimulateOpt());
$('#filterLangSimulate').on('click', function () { $.Options.setOption(this.id, this.checked); });
}
twisterOption.prototype.set = function (val) {
this.val = (this.option.getMethod) ? this.option.getMethod(val) : val;
this.option.valRaw = val;
this.getIsFollowingMeOpt = function () {
return this.getOption('isFollowingMe', 'in-profile');
$.localStorage.set('options:' + this.option.name, val);
};
this.setIsFollowingMeOpt = function () {
$('#isFollowingMe').val( this.getIsFollowingMeOpt() );
$('#isFollowingMe').on('change', function () { $.Options.setOption(this.id, this.value); });
twisterOption.prototype.tick = function (event) {
if (this.option.type !== 'numeric' || checkForNumeric(event.target)) {
this.set((this.option.type === 'checkbox') ? event.target.checked : event.target.value);
if (this.option.valMes)
$(event.target).next('span').text(polyglot.t(this.option.valMes));
if (typeof this.option.tickMethod === 'function')
this.option.tickMethod(event.target);
}
};
this.getDMCopySelfOpt = function() {
return this.getOption('dmCopySelf', 'enable');
}
jQuery.Options = new twisterOptions();
this.setDMCopySelfOpt = function () {
$('#dmCopySelfOpt select').val( this.getDMCopySelfOpt() );
$('#dmCopySelfOpt select').on('change', function() { $.Options.setOption(this.id, this.value); });
}
this.InitOptions = function() {
this.soundNotifOptions();
this.volumeControl();
this.keysSend();
this.setLang();
this.setTheme();
this.setShowDesktopNotifPostsOpt();
this.setShowDesktopNotifPostsTimerOpt();
this.setShowDesktopNotifPostsModalOpt();
this.setShowDesktopNotifPostsModalTimerOpt();
this.setShowDesktopNotifMentionsOpt();
this.setShowDesktopNotifMentionsTimerOpt();
this.setShowDesktopNotifDMsOpt();
this.setShowDesktopNotifDMsTimerOpt();
this.setTestDesktopNotif();
this.setLineFeedsOpt();
this.setShowPreviewOpt();
this.setUnicodeConversionOpt();
this.setConvertPunctuationsOpt();
this.setConvertEmotionsOpt();
this.setConvertSignsOpt();
this.setConvertFractionsOpt();
this.setUseProxyOpt();
this.setUseProxyForImgOnlyOpt();
this.setTopTrendsOpt();
this.setTopTrendsAutoUpdateOpt();
this.setTopTrendsAutoUpdateTimerOpt();
this.setTwistdayReminderOpt();
this.setTwistdayReminderAutoUpdateOpt();
this.setTwistdayReminderAutoUpdateTimerOpt();
this.setTwistdayReminderShowUpcomingOpt();
this.setTwistdayReminderShowUpcomingTimerOpt();
this.setWhoToFollowOpt();
this.setSplitPostsOpt();
this.setHideRepliesOpt();
this.setHideCloseRTsHourOpt();
this.setHideCloseRTsOpt();
this.setFilterLangOpt();
this.setFilterLangListOpt();
this.setFilterLangAccuracyOpt();
this.setFilterLangForPostboardOpt();
this.setFilterLangForSearchingOpt();
this.setFilterLangForTopTrendsOpt();
this.setFilterLangSimulateOpt();
this.setIsFollowingMeOpt();
this.setDMCopySelfOpt();
}
function setElemValNumeric(elem, mes) {
//var elem = $(elem_nm);
if (/^\d+$/.test(elem.value) && parseFloat(elem.value) > 0) {
function checkForNumeric(elem) {
if (/^\d+\.?\d*$/.test(elem.value) && parseFloat(elem.value) > 0) {
elem.style.backgroundColor = '';
$.Options.setOption(elem.id, elem.value);
$(elem).next('span').text(mes);
return true;
} else {
elem.style.backgroundColor = '#f00';
$(elem).next('span').text(polyglot.t('only positive numbers!'));
return false;
}
};
}
jQuery.Options = new TwisterOptions;
function localizeLabels()
{
$("label[for=tab_language]").text(polyglot.t("Language"));
$("label[for=t-2]").text(polyglot.t("Theme"));
$("label[for=t-3]").text(polyglot.t("Notifications"));
$("label[for=t-4]").text(polyglot.t("Keys"));
$("label[for=t-5]").text(polyglot.t("Appearance"));
$("label[for=t-6]").text(polyglot.t("Users"));
}
$(document).ready(localizeLabels);

4
js/twister_actions.js

@ -345,14 +345,14 @@ function processHashtag(postboard, hashtag, data) { @@ -345,14 +345,14 @@ function processHashtag(postboard, hashtag, data) {
if( !(key in _hashtagProcessedMap) ) {
_hashtagProcessedMap[key] = true;
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangForSearchingOpt()) {
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangForSearching.val) {
if (typeof(userpost['rt']) !== 'undefined') {
var msg = userpost['rt']['msg'];
} else {
var msg = userpost['msg'];
}
langFilterData = filterLang(msg);
if ($.Options.getFilterLangSimulateOpt()) {
if ($.Options.filterLangSimulate.val) {
data[i]['langFilter'] = langFilterData;
} else {
if (!langFilterData['pass'])

2
js/twister_directmsg.js

@ -121,7 +121,7 @@ function newDirectMsg(msg, dm_screenname) { @@ -121,7 +121,7 @@ function newDirectMsg(msg, dm_screenname) {
if( lastPostId != undefined ) {
var paramsOrig = [defaultScreenName, lastPostId + 1, dm_screenname, msg]
var paramsOpt = paramsOrig
var copySelf = ($.Options.getDMCopySelfOpt() === 'enable')
var copySelf = ($.Options.dmCopySelf.val === 'enable')
if( copySelf && dm_screenname[0] !== '*' ) {
paramsOpt = paramsOrig.concat(true)
}

8
js/twister_formatpost.js

@ -122,7 +122,7 @@ function postToElem( post, kind, promoted ) { @@ -122,7 +122,7 @@ function postToElem( post, kind, promoted ) {
if (typeof(promoted) !== 'undefined' && promoted) {
elem.find('.post-propagate').remove();
} else {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangSimulateOpt()) {
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangSimulate.val) {
// FIXME it's must be stuff from template actually
if (typeof(post['langFilter']) !== 'undefined') {
if (typeof(post['langFilter']['prob'][0]) !== 'undefined')
@ -253,8 +253,8 @@ function htmlFormatMsg(msg, mentions) { @@ -253,8 +253,8 @@ function htmlFormatMsg(msg, mentions) {
}
function proxyURL(url) {
var proxyOpt = $.Options.getUseProxyOpt();
if (proxyOpt !== 'disable' && !$.Options.getUseProxyForImgOnlyOpt()) {
var proxyOpt = $.Options.useProxy.val;
if (proxyOpt !== 'disable' && !$.Options.useProxyForImgOnly.val) {
// proxy alternatives may be added to options page
if (proxyOpt === 'ssl-proxy-my-addr') {
url = ['https://ssl-proxy.my-addr.org/myaddrproxy.php/',
@ -270,7 +270,7 @@ function proxyURL(url) { @@ -270,7 +270,7 @@ function proxyURL(url) {
// TODO: add options for emotions; msg = $.emotions(msg);
// TODO: add at least basic markdown (optional) like *text* -> bold text and _text_ -> italic text
function _formatText(msg) {
if ($.Options.getLineFeedsOpt() === 'enable')
if ($.Options.displayLineFeeds.val === 'enable')
msg = msg.replace(/\n/g, '<br />');
return msg;

9
js/twister_io.js

@ -217,7 +217,7 @@ function getFullname( username, item ){ @@ -217,7 +217,7 @@ function getFullname( username, item ){
}
}, {item: item} );
if (typeof(twisterFollowingO) !== 'undefined' &&
($.Options.getIsFollowingMeOpt() === 'everywhere' || item.hasClass('profile-name'))) {
($.Options.isFollowingMe.val === 'everywhere' || item.hasClass('profile-name'))) {
if (twisterFollowingO.knownFollowers.indexOf(username) > -1) {
item.addClass('isFollowing');
item.attr("title", polyglot.t("follows you"));
@ -332,10 +332,9 @@ function _putResourceIntoStorage(locator, data) { @@ -332,10 +332,9 @@ function _putResourceIntoStorage(locator, data) {
// get avatar and set it in img.attr("src")
function getAvatar( username, img ){
var theme = $.Options.getTheme();
if( username == "nobody" ) {
if(theme == 'nin') {img.attr('src', "theme_nin/img/tornado_avatar.png");}
else {img.attr('src', "img/tornado_avatar.png");}
if (username === 'nobody') {
img.attr('src', ($.Options.theme.val === 'nin') ?
'theme_nin/img/tornado_avatar.png' : 'img/tornado_avatar.png');
return;
}

8
js/twister_newmsgs.js

@ -102,8 +102,8 @@ function requestMentionsCount() { @@ -102,8 +102,8 @@ function requestMentionsCount() {
if ( _newMentions ) {
$.MAL.soundNotifyMentions();
if ($.Options.getShowDesktopNotifMentionsOpt() === 'enable') {
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_mentions', _newMentions)+'.', false,'twister_notification_new_mentions', $.Options.getShowDesktopNotifMentionsTimerOpt(), function(){$.MAL.showMentions(defaultScreenName)}, false)
if ($.Options.showDesktopNotifMentions.val === 'enable') {
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_mentions', _newMentions)+'.', false,'twister_notification_new_mentions', $.Options.showDesktopNotifMentionsTimer.val, function(){$.MAL.showMentions(defaultScreenName)}, false)
}
}
}
@ -117,8 +117,8 @@ function requestMentionsCount() { @@ -117,8 +117,8 @@ function requestMentionsCount() {
if ( newDMs ) {
$.MAL.soundNotifyDM();
if ($.Options.getShowDesktopNotifDMsOpt() === 'enable') {
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_direct_messages', newDMs)+'.', false, 'twister_notification_new_DMs', $.Options.getShowDesktopNotifDMsTimerOpt(), function(){$.MAL.showDMchat()}, false)
if ($.Options.showDesktopNotifDMs.val === 'enable') {
$.MAL.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_direct_messages', newDMs)+'.', false, 'twister_notification_new_DMs', $.Options.showDesktopNotifDMsTimer.val, function(){$.MAL.showDMchat()}, false)
}
}
}

15
js/twister_timeline.js

@ -365,9 +365,9 @@ function willBeHidden(post){ @@ -365,9 +365,9 @@ function willBeHidden(post){
if (post['userpost']['rt']['n'] === defaultScreenName)
return false;
if ($.Options.getHideCloseRTsOpt() != 'disable' &&
if ($.Options.hideCloseRTs.val !== 'disable' &&
followingUsers.indexOf(post['userpost']['rt']['n']) > -1 &&
parseInt(post['userpost']['time']) - parseInt(post['userpost']['rt']['time']) < $.Options.getHideCloseRTsHourOpt() * 3600)
parseInt(post['userpost']['time']) - parseInt(post['userpost']['rt']['time']) < $.Options.hideCloseRTsHour.val * 3600)
{
return true;
}
@ -376,12 +376,11 @@ function willBeHidden(post){ @@ -376,12 +376,11 @@ function willBeHidden(post){
} else {
var msg = post['userpost']['msg'];
if ($.Options.getHideRepliesOpt() !== 'disable' &&
/^\@/.test(msg) &&
if ($.Options.hideReplies.val !== 'disable' && /^\@/.test(msg) &&
!(new RegExp('@' + defaultScreenName + '( |,|;|\\.|:|\\/|\\?|\\!|\\\\|\'|"|\\n|\\t|$)').test(msg)))
{
if ($.Options.getHideRepliesOpt() === 'only-me' ||
($.Options.getHideRepliesOpt() === 'following' &&
if ($.Options.hideReplies.val === 'only-me' ||
($.Options.hideReplies.val === 'following' &&
followingUsers.indexOf(msg.substring(1, msg.search(/ |,|;|\.|:|\/|\?|\!|\\|'|"|\n|\t|$/))) === -1 ))
{
return true;
@ -389,9 +388,9 @@ function willBeHidden(post){ @@ -389,9 +388,9 @@ function willBeHidden(post){
}
}
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangForPostboardOpt()) {
if ($.Options.filterLang.val !== 'disable' && $.Options.filterLangForPostboard.val) {
post['langFilter'] = filterLang(msg);
if (!post['langFilter']['pass'] && !$.Options.getFilterLangSimulateOpt()) {
if (!post['langFilter']['pass'] && !$.Options.filterLangSimulate.val) {
// TODO maybe we need a counter of posts blocked by language filter and even caching of them and button to show?
//console.log('post by @'+post['userpost']['n']+' was hidden because it didn\'t passed by language filter:');
return true;

6
options.html

@ -21,9 +21,11 @@ @@ -21,9 +21,11 @@
<script src="js/polyglot.min.js"></script>
<script src="js/interface_localization.js"></script>
<script>$(function(){
<script>
$(function() {
initInterfaceCommon();
$.Options.InitOptions();})
$.Options.initControls();
})
changeStyle();
</script>
</head>

11
theme_nin/js/theme_option.js

@ -46,5 +46,16 @@ $(function(){ @@ -46,5 +46,16 @@ $(function(){
$(this).text('').attr('title', polyglot.t('Unfollow'));
});
if (/\/options.html$/i.test(document.location))
$(document).ready(localizeLabels);
});
function localizeLabels() {
$("label[for=tab_language]").text(polyglot.t("Language"));
$("label[for=t-2]").text(polyglot.t("Theme"));
$("label[for=t-3]").text(polyglot.t("Notifications"));
$("label[for=t-4]").text(polyglot.t("Keys"));
$("label[for=t-5]").text(polyglot.t("Appearance"));
$("label[for=t-6]").text(polyglot.t("Users"));
}

Loading…
Cancel
Save