';
return html;
},
filterTable : function(f)
{
var html = '';
if ( f !== null && f !== false )
{
var htmlTable = '';
for ( i in f )
{
htmlTable += '
'+f[i].auto_add_type+' '+(f[i].keyword==''?'<none> ':f[i].keyword)+' '+(f[i].location==''?'<all> ':''+f[i].location+' ('+f[i].range+'mi) » ')+' '+f[i].num_added+'/'+f[i].num_reciprocated+' '+(f[i].is_active==1?'Yes':'No')+' ';
}
html = ''+
'
'+
'Type Keyword Location Stats Active? '+
htmlTable+
'
';
}
else
{
html = '
Please add a filter
';
}
return html;
},
// s = settings object
generalSettings : function(s)
{
var html = ''+
'
'+
'
'+
'
Friend Suggestions
'+
'
'+
'Friend suggestions are active '+
' '+
'
'+
'
'+
'Send friend suggestion notification emails '+
' '+
'
'+
'
'+
'My current follower-to-friend ratio is '+s.my_ratio+'% stop making friend suggestions if it goes below %'+
'
'+
'
'+
'
'+
'
Unfollow Suggestions
'+
'
'+
'Unfollow suggestions are active '+
' '+
'
'+
'
'+
'Send un-follow suggestion notification emails '+
' '+
'
'+
'
'+
'Suggest unfollowing users who don\'t follow me back within days'+
'
'+
// '
'+
// 'Suggest unfollowing users who haven\'t tweeted in over days'+
// '
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
'
return html;
},
// u = user object
suggestionContentItem : function(u,suggestionType)
{
var html = ''+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
@'+u.screen_name+' '+
'
'+u.location+' '+
'
'+u.description+'
'+
'
'+
'
'+
'Followers: '+u.followers_count+' '+
'Following: '+u.friends_count+' '+
'Ratio: '+u.ff_percent+'% '+
'Updates: '+u.statuses_count+
'
'+
'
'+
'
'+
'
';
return html;
}
},
addAccount :
{
addEditApp : function()
{
var appId = tm.accounts.customSig.editingAppId;
var apps = tm.accounts.customSig.loadedApps;
var html = ''+
'
'+
'
' + ( appId === false ? 'Add' : 'Edit' ) + ' Custom Signature
'+
'
'+
'
'+
'
Not sure what to do?
'+
'
'+
'
'+
' '+
' '+
'
'+
'
';
return html;
},
noCustomSigAccess : function()
{
var html = ''+
'
'+
'
Add Twitter Account
'+
'
NEW! With Pluggio Premium you can post your tweets with a custom signature:
'+
''+
'
'+
'
'+
'
OR
'+
'
To add your account in the usual way please click the OK button below. You will be redirected to Twitter to link your account with Pluggio.
'+
'
'+
' '+
' '+
'
'+
'
';
return html;
},
customSigAccessNoSigs : function()
{
var html = ''+
'
'+
'
Add Twitter Account
'+
'
New! You can post your tweets with a custom signature!
'+
''+
'
'+
'
'+
'
OR
'+
'
To add your account in the usual way please click the OK button below. You will be redirected to Twitter to link your account with Pluggio.
'+
'
'+
' '+
' '+
'
'+
'
';
return html;
},
customSigAccessWithSigs : function()
{
var html = ''+
'
'+
'
Add Twitter Account
'+
'
Which signature would like to link the account with?
'+
'
'+
'
'+
'
'+
'
You will now be redirected to Twitter. When you get there please click the "Allow" button.
'+
'
'+
' '+
' '+
'
'+
'
';
return html;
},
customSigList : function(s)
{
var html = '';
for ( i in s )
{
html += ''+
'';
}
return html;
},
customSigSetup : function()
{
var html = ''+
'
'+
'customSigSetup'+
'
';
return html;
}
},
pingFm :
{
checkBoxes : function()
{
var html = '';
var s = tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm;
// This builds services
for ( service in s.services )
{
html += ''+
'
'+
' '+
''+s.services[service].name+' '+
' ';
}
return html;
},
tweetCheckBoxes : function()
{
var html = '
';
var s = tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm;
if ( s !== undefined )
{
if ( s === false || s.services === false )
{
html += ''+
'
'+
''+
'Twitter '+
' '+
'
';
}
else
{
html += tm.templates.pingFm.checkBoxes();
}
}
return html+'
';
}
}
};
tm.feeds =
{
loadedFeeds : [],
curFeedId : [],
gettingFeed : false,
isNewFeed : false,
numFeeds : 0,
reloadFeed : function()
{
if ( tm.feeds.curFeedId[tm.accounts.selectedAccount] === undefined )
{
tm.feeds.getFeeds();
}
else
{
tm.feeds.getFeed(tm.feeds.curFeedId[tm.accounts.selectedAccount]);
}
},
getFeed : function(feedId)
{
if ( tm.feeds.gettingFeed === true )
{
return;
}
tm.nav.setView('rss');
tm.feeds.gettingFeed = true;
tm.feeds.curFeedId[tm.accounts.selectedAccount] = feedId;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
$("#hint-bar").html(tm.templates.feedHintBar());
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'feedId' : feedId,
'action' : 'ajax/get-feed'
},
function(response)
{
tm.feeds.gettingFeed = false;
if (response.error != 'OK')
{
$("#feed-content").addClass('hide');
alert(response.error);
}
else
{
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
(
tm.feeds.loadedFeeds[feedId]['type']=='rss'
?
'
'+tm.feeds.loadedFeeds[feedId]['name']+'
'+s[8]+' '
:
(
tm.feeds.loadedFeeds[feedId]['type']=='blog'
?
'
'+tm.feeds.loadedFeeds[feedId]['name']+'
'+s[9]+' '
:
'
'+tm.feeds.loadedFeeds[feedId]['name']+'
'+s[10]+' '
)
)
);
// If there are no feed results
if ( response.stories === false )
{
$("#feed-content .list").html(tm.templates.emptyFeed());
return;
}
// if there ARE results
for ( i in response.stories )
{
// Put alt i nthere to change styling
response.stories[i].alt = ( i % 2 == 0 ? '' : 'alt') ;
// Insert item into the list
$("#feed-content .list").append
(
tm.templates.feedContentItem(response.stories[i])
);
}
}
}
);
},100);
},
addingFeed : false,
addFeed : function(e)
{
if ( ! tm.tools.isFormTrigger(e) || tm.feeds.addingFeed === true )
{
return;
}
tm.feeds.addingFeed = true;
var error = false;
// todo: trim
var feedInput = $('#feed-input').val();
var feedType = $('#feed-type').val();
var feedName = $('#feed-name').val();
// Send to the server and try to create the account
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'feedId' : tm.feeds.curFeedId[tm.accounts.selectedAccount],
'feedName' : feedName,
'feedType' : feedType,
'feedInput' : feedInput,
'action' : 'ajax/add-feed',
'isNewFeed' : tm.feeds.isNewFeed
},
function(response)
{
tm.feeds.addingFeed = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
$('#feed-input').val('');
tm.feeds.curFeedId[tm.accounts.selectedAccount] = response.feedId;
tm.feeds.getFeeds();
setTimeout("tm.hint(2)",2000);
}
}
);
},
resetFeedContent : function(contentOnly)
{
if ( contentOnly === undefined )
{
$("#feed-content .title-bar .title").html('');
}
$("#feed-content .list").html('
');
$("#hint-bar").html('');
},
getFeeds : function()
{
tm.feeds.resetFeedContent();
if ( tm.accounts.selectedAccount === false )
{
$("#feed-content").addClass('hide');
$("#feeds .list").html
(
'
'+s[11]+'
'
);
return;
}
$("#feeds .list").html('
');
// Send to the server and try to create the account
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-feeds'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// If there are no configured twitter accounts
if ( response.feeds == false )
{
$("#feeds .list").html
(
'
'+s[12]+'
'
);
$("#feed-content").addClass('hide');
return;
}
$("#feeds .list").html('');
tm.feeds.numFeeds=0;
// if there ARE feeds
for ( i in response.feeds )
{
if ( i == 0 && tm.feeds.curFeedId[tm.accounts.selectedAccount] === undefined )
{
tm.feeds.curFeedId[tm.accounts.selectedAccount] = response.feeds[i]['feed_id'];
}
// Store loaded feeds for future use in other dialogs etc.
tm.feeds.loadedFeeds[response.feeds[i]['feed_id']] = response.feeds[i];
// Insert item into the list
$("#feeds .list").append
(
tm.templates.feedListItem
(
response.feeds[i]['type'],
response.feeds[i]['name'],
response.feeds[i]['feed_id'],
response.feeds[i]['url_or_search']
)
);
tm.feeds.numFeeds++;
}
$("#feeds .list").sortable('destroy');
$("#feeds .list").sortable
({
stop: function(event, ui)
{
// This gets feedList[]=1&feedList[]=2&feedList[]=3 ready to send to server
tm.feeds.saveOrder($("#feeds .list").sortable('serialize'));
}
});
tm.feeds.selectFeed(tm.feeds.curFeedId[tm.accounts.selectedAccount]);
}
}
);
},
savingOrder : false,
saveOrder : function(feedIds)
{
if ( tm.curView != 'rss' )
{
return;
}
tm.feeds.savingOrder = true;
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'feedIds' : feedIds,
'action' : 'ajax/save-order-feeds'
},
function(response)
{
tm.feeds.savingOrder = false;
if (response.error != 'OK')
{
alert(response.error);
}
}
);
},
openModalAdd : function()
{
if ( tm.accounts.selectedAccount === false )
{
alert(s[13]);
return;
}
if ( tm.feeds.numFeeds >= tm.maxFeeds )
{
alert(s[14]+tm.maxFeeds+s[15]);
return;
}
tm.feeds.isNewFeed = true;
var pos = $('#feed-plus-sign').offset();
tm.tools.makeModal(tm.templates.addFeed(s[16],s[17]),'callout-tl', 305, pos.left-16, pos.top-2);
tm.tools.textFocus('#feed-name');
},
changeInputType : function()
{
switch ( $('#feed-type').val() )
{
case 'rss':;
$('#feed-icon').attr({'src':'/template/gfx/rss.png'});
$('#feed-input-title').text(s[18]);
break;
case 'blog':;
$('#feed-icon').attr({'src':'/template/gfx/blog.png'});
$('#feed-input-title').text(s[19]);
break;
case 'news':;
$('#feed-icon').attr({'src':'/template/gfx/news.png'});
$('#feed-input-title').text(s[19]);
break;
break;
}
},
unHighlightFeeds : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
highlightFeed : function(feedId)
{
$('#feedList_'+feedId).addClass('selected');
},
selectFeed : function(feedId)
{
if ( tm.feeds.savingOrder )
{
return;
}
tm.feeds.curFeedId[tm.accounts.selectedAccount] = feedId;
tm.feeds.unHighlightFeeds();
tm.feeds.highlightFeed(feedId);
// do it (as long as modal isnt open)
if ( $('#feed-popup').length == 0)
{
tm.feeds.getFeed(feedId);
}
},
openModalEdit : function(feedId)
{
tm.feeds.isNewFeed = false;
// Id the popup will be below the fold
var pos = $('#feedList_' + feedId + ' img').offset();
if ( 180 + pos.top >= $(window).height() )
{
tm.tools.makeModal(tm.templates.addFeed(s[20],s[21],feedId),'callout-bl', 305, pos.left-16, pos.top-175);
}
else
{
tm.tools.makeModal(tm.templates.addFeed(s[20],s[21],feedId),'callout-tl', 305, pos.left-16, pos.top-2);
}
$('#feed-input').val(tm.feeds.loadedFeeds[feedId]['url_or_search']);
$('#feed-type').val(tm.feeds.loadedFeeds[feedId]['type']);
$('#feed-name').val(tm.feeds.loadedFeeds[feedId]['name']);
tm.feeds.changeInputType();
tm.tools.textFocus('#feed-name');
},
deleteFeed : function(feedId)
{
var name = $('#feed-name').val();
tm.prompt(s[1]+name+'?','tm.feeds.doDeleteFeed('+feedId+')');
},
doDeleteFeed : function (feedId)
{
// Send to the server and try to create the account
tm.ajax
(
{
'feedId' : feedId,
'action' : 'ajax/delete-feed'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
tm.tools.closeModal();
tm.feeds.curFeedId[tm.accounts.selectedAccount] = undefined;
tm.feeds.getFeeds();
}
}
);
},
doStarClick : function(storyId)
{
// Mark as not interesting
if ( tm.keyDown == 17 )
{
tm.feeds.markAsNotInteresting(storyId);
}
// Add story to flag feed
else
{
tm.feeds.flagStory(storyId);
}
},
markAsNotInteresting : function(storyId)
{
if ( $('#feedItem'+storyId).hasClass('not-interested') )
{
$('#feedItem'+storyId).removeClass('not-interested');
}
else
{
$('#feedItem'+storyId).addClass('not-interested');
}
setTimeout(function()
{
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/hide-story'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
}
);
},100);
},
flagStory : function(storyId)
{
// Build icon path for alternate bolean state
var iconPath = tm.templates.flaggedIconPath($('#star'+storyId).attr('isFlagged'));
// Apply the new path
$('#star'+storyId).attr({'src':iconPath,'origSrc':iconPath});
// if in the flagged view then remove the item (if it's a remove)
if ( tm.curView == 'flagged' && $('#star'+storyId).attr('isFlagged') == 1 )
{
$('#feedItem'+storyId).remove();
}
setTimeout(function()
{
// Now flag this item
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/flag-story'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( tm.curView == 'flagged' && $("#feed-content .list").text() == '' )
{
tm.nav.go(tm.curView);
return;
}
// Change the isFLagged state so toggle works correctly next time
$('#star'+storyId).attr({'isFlagged': response.isFlagged});
}
}
);
},100);
},
instantTweet : function(storyId)
{
if ( tm.accounts.selectedAccount === false )
{
alert(s[22]);
return;
}
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/bubble-tick.png';
// Apply the new path
$('#bubble'+storyId).attr({'src':iconPath,'origSrc':iconPath});
setTimeout(function()
{
// Now tweet this item
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'storyId' : storyId,
'action' : 'ajax/instant-tweet',
'postTo' : tm.settings.pingFm.getSelectedServices()
},
function(response)
{
if ( response.isInstant == 0 )
{
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/bubble-grey.png';
// Apply the new path
$('#bubble'+storyId).attr({'src':iconPath,'origSrc':iconPath});
}
if (response.error != 'OK')
{
alert(response.error);
}
}
);
}
,100);
},
currentEditUrl : '',
currentEditTweet : '',
openEditTweet : function(storyId)
{
if ( tm.accounts.selectedAccount === false )
{
alert(s[22]);
return;
}
var position = $('#pencil'+storyId).position();
tm.tools.makeModal(tm.templates.feedsTweetDialog(storyId),'callout-bl', 385);
$('#tweet').val(s[23]);
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/get-short-url'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.feeds.currentEditUrl = response.stdUrl;
tm.feeds.currentEditTweet = $('#title'+storyId).text();
$('#tweet').val(tm.feeds.currentEditTweet);
tm.feeds.checkChars();
}
}
);
},
checkChars : function()
{
if ( tm.feeds.curTweetTab == 'linkTab' )
{
$('#chars-left').text('');
tm.feeds.currentEditUrl = $('#tweet').val();
}
else
{
setTimeout(function()
{
var charsLeft = 140 - $('#tweet').val().length;
$('#chars-left').html(charsLeft);
if ( charsLeft >= 0 )
{
$('#chars-left').addClass('enough-chars');
$('#chars-left').removeClass('not-enough-chars');
}
else
{
$('#chars-left').addClass('not-enough-chars');
$('#chars-left').removeClass('enough-chars');
}
tm.feeds.currentEditTweet = $('#tweet').val();
},100);
}
},
editStory : function(storyId,editAndTweet)
{
tm.feeds.checkChars();
if ( tm.feeds.currentEditTweet.length > 140 )
{
alert(s[24]);
return;
}
// Build icon path for alternate bolean state
if ( editAndTweet !== undefined )
{
var iconPath = '/template/gfx/pencil-tick.png';
var loadingMsg = s[25];
}
else
{
var iconPath = '/template/gfx/pencil-hover.png';
var loadingMsg = s[25];
}
// Apply the new path
$('#pencil'+storyId).attr({'src':iconPath,'origSrc':iconPath});
var editVal = $('#tweet').val();
$('#tweet').val(loadingMsg);
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'editAndTweet' : editAndTweet !== undefined ? true : false,
'storyId' : storyId,
'editVal' : tm.feeds.currentEditTweet,
'action' : 'ajax/edit-story'
},
function(response)
{
if (response.error != 'OK')
{
$('#tweet').val(editVal);
alert(response.error);
}
else
{
$('#title'+storyId+' a').text(unescape(response.editVal));
tm.tools.closeModal();
}
}
);
},
editAndTweetStory : function(storyId)
{
tm.feeds.editStory(storyId,true)
},
curTweetTab : '',
switchTweetTab : function (divObj)
{
tm.feeds.curTweetTab = divObj.id;
$('#tweet-bubble-feeds .tabs div').removeClass('selected');
$(divObj).addClass('selected');
if ( tm.feeds.curTweetTab == 'linkTab' )
{
$('#tweet').val(tm.feeds.currentEditUrl);
$('#editTweetButtons').addClass('hide');
$('#editLinkButtons').removeClass('hide');
}
else
{
$('#tweet').val(tm.feeds.currentEditTweet);
$('#editTweetButtons').removeClass('hide');
$('#editLinkButtons').addClass('hide');
}
tm.feeds.checkChars();
},
editLink : function(storyId)
{
tm.feeds.checkChars();
tm.ajax
(
{
'storyId' : storyId,
'newLink' : tm.feeds.currentEditUrl,
'action' : 'ajax/edit-link'
},
function(response)
{
if (response.error != 'OK')
{
$('#tweet').val(tm.feeds.currentEditUrl);
alert(response.error);
}
else
{
$('#link'+storyId).attr({'href':tm.feeds.currentEditUrl});
tm.feeds.currentEditTweet = unescape(response.tweet) + ' ' + response.shortUrl;
alert(s[27]);
}
}
);
},
markStoryAsVisited : function (storyId,url)
{
$('#title'+storyId).addClass('is-read');
setTimeout(function()
{
// Now flag this item
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/flag-as-read'
},
function(response)
{
}
);
},100);
},
showScheduleDropDown : function (storyId,imgObj)
{
// If ctrl key is beign clicked, add to rolling schedule
if ( tm.keyDown == 17 )
{
tm.feeds.addToRollingSchedule(storyId);
return;
}
var pos = $(imgObj).offset();
tm.tools.makeModal(tm.templates.makeFeedScheduleDropDown(storyId),'schedule-drop-down-outer',73,pos.left-10,pos.top-46,0);
// This binds a close modal action to the overlay
$('#overlay'+tm.curModal).bind("mouseover", function(e){tm.tools.closeModal();});
},
addToRollingSchedule : function(storyId,postAt)
{
if ( tm.accounts.selectedAccount === false )
{
alert(s[22]);
return;
}
tm.tools.closeModal();
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/clock-'+(postAt===undefined?'hover-rolling':'hover')+'.png';
// Apply the new path
$('#schedule'+storyId).attr({'src':iconPath,'origSrc':iconPath});
setTimeout(function()
{
// Now tweet this item
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'storyId' : storyId,
'action' : 'ajax/schedule-from-feed',
'postAt' : postAt === undefined ? 0 : postAt,
'postTo' : tm.settings.pingFm.getSelectedServices()
},
function(response)
{
if ( response.isScheduled == 0 )
{
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/clock-grey.png';
// Apply the new path
$('#schedule'+storyId).attr({'src':iconPath,'origSrc':iconPath});
}
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( tm.hiddenHints[5] === undefined )
{
// ctrl + click clock instant add to rolling
setTimeout("tm.hint(5)",500);
}
else if ( tm.hiddenHints[7] === undefined )
{
// ctrl + click star to grey out from schedule
setTimeout("tm.hint(7)",500);
}
}
}
);
}
,100);
},
openScheduleByTime : function(storyId)
{
tm.tools.closeModal();
var pos = $('#schedule'+storyId).offset();
tm.tools.makeModal(tm.templates.scheduleByTime(storyId),'callout-tl', 360,pos.left-14,pos.top,0);
$('#datepicker').datepicker
({
changeMonth: true,
changeYear: true,
showOn: 'both',
buttonImage: '/template/gfx/calender.png',
buttonImageOnly: true
});
},
addToTimedSchedule : function(storyId)
{
var postAt = $('#datepicker').val()+' '+$('#hour').val()+':'+$('#minute').val()+' '+$('#ampm').val();
$('#datepicker').datepicker('destroy');
tm.feeds.addToRollingSchedule(storyId,postAt);
}
};
tm.flagged =
{
gettingFlagged : false,
loadedItems : [],
toggleView : function()
{
// Switch to text view
if ( tm.curView == 'flagged' )
{
tm.nav.go('flaggedText');
}
// Switch to standard view
else
{
tm.nav.go('flagged');
}
},
getFlagged : function()
{
if ( tm.feeds.gettingFlagged === true )
{
return;
}
tm.feeds.gettingFlagged = true;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-flagged'
},
function(response)
{
tm.feeds.gettingFlagged = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
'
'+
'
'+
'
'+response.numItems+' '+s[32]+' '+
'
(List View) '
);
// If there are no feed results
if ( response.stories === false )
{
$("#feed-content .list").html(tm.templates.nothingFlagged());
return;
}
// if there ARE results
for ( i in response.stories )
{
response.stories[i].alt = ( i % 2 == 0 ? '' : 'alt') ;
$("#feed-content .list").append
(
tm.templates.feedContentItem(response.stories[i])
);
}
$("#hint-bar").html(tm.templates.feedHintBar());
}
}
);
},100);
},
getFlaggedTextView : function()
{
if ( tm.feeds.gettingFlagged === true )
{
return;
}
tm.feeds.gettingFlagged = true;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-flagged'
},
function(response)
{
tm.feeds.gettingFlagged = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
'
'+
'
'+
'
'+response.numItems+' '+s[32]+' '+
'
(Text View) '
);
// If there are no feed results
if ( response.stories === false )
{
$("#feed-content .list").html(tm.templates.nothingFlagged());
return;
}
// Put this div in order to format the text view
$("#feed-content .list").append('
');
// if there ARE results
for ( i in response.stories )
{
$("#textarea").val
(
$("#textarea").val()+
unescape(response.stories[i].title)+' '+response.stories[i].short_url+'\n\n'
);
}
}
}
);
},100);
}
};
tm.friendFinder =
{
amGetting : false,
loadedUsers : {},
init : function()
{
tm.friendFinder.showNav('recommendedFriends');
tm.friendFinder.selectOption('suggestedFriends');
// Set the nav to display the current counts
tm.friendFinder.followCount(0);
tm.friendFinder.unfollowCount(0);
},
setTitle : function(optionId)
{
var actionLink = '';
// Hacky way of getting the follow all / unfollow all butons in there
// if ( optionId == 'suggestedFriends' && parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].friend_suggest_count) > 0 )
// {
// actionLink = ' (
Follow All )';
// }
//
// if ( optionId == 'suggestedPurges' && parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count) > 0 )
// {
// actionLink = ' (
Un-follow All )';
// }
$("#feed-content .title-bar .title").html
(
tm.templates.friendFinder.titles[optionId]
// +actionLink
);
},
selectOption : function(optionId)
{
if ( tm.friendFinder.amGetting === true )
{
return;
}
tm.friendFinder.amGetting = true;
tm.friendFinder.unHighlightOptions();
tm.friendFinder.highlightOption(optionId);
tm.feeds.resetFeedContent();
tm.friendFinder.setTitle(optionId);
switch(optionId)
{
default:;
case 'suggestedFriends':
tm.friendFinder.getSuggestedFriends();
break;
case 'suggestedPurges':
tm.friendFinder.getSuggestedPurges();
break;
case 'keywordsLocations':
tm.friendFinder.getKeywordsLocations();
break;
case 'generalSettings':
tm.friendFinder.getGeneralSettings();
break;
case 'pleaseRead':
tm.friendFinder.pleaseRead();
break;
case 'activityLog':
tm.friendFinder.getActivityLog();
break;
}
},
pleaseRead : function()
{
tm.friendFinder.amGetting = false;
$("#feed-content .list").html
(
tm.templates.friendFinder.pleaseRead()
);
},
getSuggestions : function(suggestionType)
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-get-suggested-'+suggestionType
},
function(response)
{
tm.friendFinder.amGetting = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( response.suggestions === null )
{
$("#feed-content .list").html
(
'
'+s[90]+'
'
);
return;
}
tm.accounts.loadedAccounts[tm.accounts.selectedAccount][suggestionType+'_suggest_count'] = response.suggestions.length;
if ( suggestionType == 'friend' )
{
tm.friendFinder.followCount(0);
}
else if ( suggestionType == 'purge' )
{
tm.friendFinder.unfollowCount(0);
}
$("#feed-content .list").html('');
for ( i in response.suggestions )
{
tm.friendFinder.loadedUsers[response.suggestions[i].id] = response.suggestions[i];
$("#feed-content .list").append
(
tm.templates.friendFinder.suggestionContentItem(response.suggestions[i],suggestionType)
);
}
}
}
);
},100);
},
getSuggestedFriends : function()
{
tm.friendFinder.getSuggestions('friend');
},
getSuggestedPurges : function()
{
tm.friendFinder.getSuggestions('purge');
},
initFilterForm : function()
{
tm.friendFinder.currentlyEditingFilter = false;
$('#ff-save-button').val(s[91]);
tm.tools.cleardFields = {};
$('#auto-add-keyword').blur();
$('#auto-add-location').blur();
$('#auto-add-keyword').addClass('fade');
$('#auto-add-location').addClass('fade');
$('#auto-add-keyword').val(s[58]);
$('#auto-add-location').val(s[59]);
$("#auto-add-range").val(5);
},
getKeywordsLocations : function()
{
$("#feed-content .list").html(tm.templates.friendFinder.keywordsLocations());
// Resize inner panel to fit exactly
$(".auto-add-filter-list .scroller").css({'height':($(".listing-panel").height()-190)+'px'});
tm.friendFinder.initFilterForm();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-get-keywords-locations'
},
function(response)
{
tm.friendFinder.amGetting = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.loadedFilters = response.filters;
$('#auto-add-filters').html(tm.templates.friendFinder.filterTable(response.filters));
}
}
);
},100);
},
getGeneralSettings : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-get-general-settings'
},
function(response)
{
tm.friendFinder.amGetting = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
$("#feed-content .list").html
(
tm.templates.friendFinder.generalSettings(response.settings)
);
}
}
);
},100);
},
getActivityLog : function(activityType)
{
$("#feed-content .list").html(tm.templates.friendFinder.activityLog());
// Resize inner panel to fit exactly
$("#activity-log .scroller").css({'height':($(".listing-panel").height()-70)+'px'});
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-get-activity-log',
'activityType' : activityType===undefined?'all':activityType
},
function(response)
{
tm.friendFinder.amGetting = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( response.activity === null || response.activity === false )
{
$('#activity-log .scroller').html('
'+s[60]+'
');
return;
}
$('#activity-log .scroller').html('');
for ( i in response.activity )
{
$('#activity-log .scroller').append
(
'
'+
'
'+
response.activity[i].creation_date+
'
'+
response.activity[i].log+
'
'
);
}
}
}
);
},100);
},
showNav : function(navOption)
{
$("#feeds .list").html
(
tm.templates.friendFinder.navOptions()
);
tm.friendFinder.highlightOption(navOption);
},
highlightOption : function(optionId)
{
$('#'+optionId).addClass('selected');
},
unHighlightOptions : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
currentlyEditingFilter : false,
openEditFilter : function(filterId,event)
{
$('.auto-add-filter-list .scroller tr').removeClass('editing-row');
$('#filterRow'+filterId).addClass('editing-row');
tm.friendFinder.currentlyEditingFilter = filterId;
$('#ff-save-button').val('Save Changes');
var keyword = tm.friendFinder.loadedFilters[filterId].keyword;
var myLocation = tm.friendFinder.loadedFilters[filterId].location;
var range = tm.friendFinder.loadedFilters[filterId].range;
var type = tm.friendFinder.loadedFilters[filterId].auto_add_type;
var isActive = tm.friendFinder.loadedFilters[filterId].is_active;
$('#auto-add-is-active').attr('checked', isActive==1?true:false);
$("#auto-add-range").val(range);
$("#auto-add-type").val(type);
if ( keyword != '' )
{
tm.tools.cleardFields['auto-add-keyword'] = 'is-cleared';
$('#auto-add-keyword').removeClass('fade');
$('#auto-add-keyword').val(keyword);
}
if ( myLocation != '' )
{
tm.tools.cleardFields['auto-add-location'] = 'is-cleared';
$('#auto-add-location').removeClass('fade');
$('#auto-add-location').val(myLocation);
}
},
addFilter : function(event)
{
if ( ! tm.tools.isFormTrigger(event) )
{
return;
}
var keyword = tm.getVal('auto-add-keyword');
if ( keyword == s[58] )
keyword = '';
var myLocation = tm.getVal('auto-add-location');
if ( myLocation == s[59] )
myLocation = '';
var addType = tm.getVal('auto-add-type');
if ( ! tm.friendFinder.validateFilterForm(addType,keyword,myLocation) )
{
return;
}
var origHtml = $('#auto-add-filters').html();
$('#auto-add-filters').html('
');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-add-keyword-location',
'keyword' : keyword,
'location' : myLocation,
'type' : addType,
'isActive' : tm.getVal('auto-add-is-active'),
'range' : tm.getVal('auto-add-range'),
'editFilterId' : tm.friendFinder.currentlyEditingFilter
},
function(response)
{
if (response.error != 'OK')
{
$('#auto-add-filters').html(origHtml);
alert(response.error);
}
else
{
tm.friendFinder.selectOption('keywordsLocations');
}
}
);
},100);
},
validateFilterForm : function(addType,keyword,myLocation)
{
var error = false;
switch(addType)
{
case 'bio':
case 'tweet':
if ( keyword == '' )
error = s[61];
break;
case 'location':
if ( myLocation == '' )
error = s[62];
break;
}
if ( error )
{
alert(error);
return false;
}
return true;
},
deleteFilter : function(filterId,event)
{
tm.prompt(s[63],'tm.friendFinder.doDeleteFilter('+filterId+')');
},
doDeleteFilter : function(filterId)
{
tm.tools.closeModal();
alert(s[64]);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-delete-filter',
'filterId' : filterId
},
function(response)
{
tm.tools.closeModal();
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.selectOption('keywordsLocations');
}
}
);
},100);
},
saveGeneralSettings : function()
{
var parms = {};
var fields =
[
'auto_prune_after_n_days',
// 'auto_prune_if_no_tweet_in_n_days',
'targets_max_days_since_tweet',
'targets_acc_min_days_old',
'targets_max_followers',
'targets_max_friends',
'targets_min_friends',
'targets_min_followers',
'my_min_f_to_f_ratio',
'targets_min_f_to_f_ratio',
'targets_max_f_to_f_ratio',
'auto_add_is_active',
'auto_prune_is_active',
'send_notification_email_friend',
'send_notification_email_purge'
];
// Remove the error status of a field
for ( i in fields )
{
parms[fields[i]] = tm.getVal(fields[i]);
$('#'+fields[i]).removeClass('errorField');
}
/*
* Error testing
*/
var error = false;
var errorField = '';
var rangeTests =
[
['my_min_f_to_f_ratio',0,500],
['auto_prune_after_n_days',1,365],
// ['auto_prune_if_no_tweet_in_n_days',30,365],
['targets_min_f_to_f_ratio',1,500],
['targets_max_f_to_f_ratio',1,500],
['targets_min_friends',1,500],
['targets_max_friends',1,1000000],
['targets_min_followers',1,500],
['targets_max_followers',1,1000000],
['targets_acc_min_days_old',1,365],
['targets_max_days_since_tweet',1,365]
];
// Test that all numerical fields fall within required ranges
for ( i in rangeTests )
{
if ( isNaN(parseInt(parms[rangeTests[i][0]])) || ( parseInt(parms[rangeTests[i][0]]) < rangeTests[i][1] || parseInt(parms[rangeTests[i][0]]) > rangeTests[i][2] ) )
{
errorField = rangeTests[i][0];
error = "Value must be between "+rangeTests[i][1]+" - "+rangeTests[i][2];
break;
}
}
// Check that the between fields lower value is lower!
if ( error == false )
{
var rangeTests =
[
['targets_min_f_to_f_ratio','targets_max_f_to_f_ratio'],
['targets_min_friends','targets_max_friends'],
['targets_min_followers','targets_max_followers'],
];
for ( i in rangeTests )
{
if ( parseInt(parms[rangeTests[i][0]]) >= parseInt(parms[rangeTests[i][1]]) )
{
errorField = rangeTests[i][0];
error = "Value must be smaller than upper range ";
break;
}
}
}
// If error then mark the field as red and popup a notice
if ( error )
{
// Add error status to a field
$('#'+errorField).addClass('errorField');
alert(error);
return;
}
alert('Saving Settings...');
parms['twitAccId'] = tm.accounts.selectedAccount;
parms['action'] = 'ajax/ff-save-general-settings';
setTimeout(function()
{
tm.ajax
(
// big parms obj!
parms,
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
setTimeout(function(){tm.tools.closeModal();},500);
}
}
);
},100);
},
followCount : function(bumpUpDown)
{
var fc = parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].friend_suggest_count) + parseInt(bumpUpDown);
var uc = parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count) ;
tm.accounts.loadedAccounts[tm.accounts.selectedAccount].friend_suggest_count = fc;
if ( fc > 0 )
{
$('.follow-count').text('('+fc+')');
}
else
{
$('.follow-count').text('');
}
if ( fc+uc > 0 )
{
$('#new-suggestions').text(fc+uc);
}
else
{
$('#new-suggestions').text('');
}
if ( fc > 0 && tm.curView != 'friendFinder' )
{
$('img.friend-finder').attr('src','/template/gfx/nav-friend-finder-10.gif');
}
else
{
$('img.friend-finder').attr('src','/template/gfx/nav-friend-finder.png');
}
},
unfollowCount : function(bumpUpDown)
{
var uc = parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count) + parseInt(bumpUpDown);
tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count = uc;
if ( uc > 0 )
$('.unfollow-count').text('('+uc+')');
else
$('.unfollow-count').text('');
},
followAll : function()
{
tm.feeds.resetFeedContent(true);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-follow-all'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.selectOption('suggestedFriends');
tm.accounts.loadedAccounts[tm.accounts.selectedAccount]['friend_suggest_count'] = 0;
tm.friendFinder.followCount(0);
}
}
);
},100);
},
unfollowAll : function()
{
tm.feeds.resetFeedContent(true);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-unfollow-all'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.selectOption('suggestedPurges');
tm.accounts.loadedAccounts[tm.accounts.selectedAccount]['purge_suggest_count'] = 0;
tm.friendFinder.unfollowCount(0);
}
}
);
},100);
},
ffAction : function(tid,theAction)
{
if ( theAction == 'follow' || theAction == 'follow-discard' )
{
tm.friendFinder.followCount(-1);
}
else if ( theAction == 'unfollow' || theAction == 'unfollow-discard' )
{
tm.friendFinder.unfollowCount(-1);
}
$('#ffFollow'+tid).remove();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'screenName' : tm.friendFinder.loadedUsers[tid].screen_name,
'action' : 'ajax/ff-'+theAction
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
if ( $(".ff-item").length == 0 )
{
if ( theAction == 'follow' || theAction == 'follow-discard' )
{
tm.friendFinder.selectOption('suggestedFriends');
}
else if ( theAction == 'unfollow' || theAction == 'unfollow-discard' )
{
tm.friendFinder.selectOption('suggestedPurges');
}
}
}
);
},100);
},
cron :
{
isRunning : false,
iHaveFilters : false,
loadedFilters : {},
start : function(twitAccId)
{
if ( twitAccId === undefined )
{
//console.log('Start for the very first time');
twitAccId = tm.friendFinder.cron.getCurTwitAccId();
}
else
{
//console.log('Standard cycle start');
}
//console.log('twitAccId: '+twitAccId);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : twitAccId,
'action' : 'ajax/ff-get-keywords-locations'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.cron.loadedFilters[twitAccId] = response.filters;
tm.friendFinder.cron.doIt();
}
}
);
},30000);
},
curTwitAccId : false,
getCurTwitAccId : function()
{
var foundId = false;
for ( twitAccId in tm.accounts.loadedAccounts )
{
if (foundId || tm.friendFinder.cron.curTwitAccId === false)
{
tm.friendFinder.cron.curTwitAccId = twitAccId;
return twitAccId;
}
if ( twitAccId == tm.friendFinder.cron.curTwitAccId )
foundId = true;
}
tm.friendFinder.cron.curTwitAccId = false;
return false;
},
curFilterId : false,
getCurFilterId : function()
{
if ( tm.friendFinder.cron.loadedFilters[tm.friendFinder.cron.curTwitAccId] == false )
{
//console.log('No filters in this account');
tm.friendFinder.cron.curFilterId = false;
return false;
}
var foundFilter = false;
for ( filterId in tm.friendFinder.cron.loadedFilters[tm.friendFinder.cron.curTwitAccId] )
{
if (foundFilter || tm.friendFinder.cron.curFilterId === false)
{
tm.friendFinder.cron.curFilterId = filterId;
return filterId;
}
if ( filterId == tm.friendFinder.cron.curFilterId )
foundFilter = true;
}
tm.friendFinder.cron.curFilterId = false;
return false;
},
doIt : function()
{
var filterId = tm.friendFinder.cron.getCurFilterId();
//console.log('filterId: '+filterId);
// This condition inits the long interval cycle again and exits the function
if ( filterId === false )
{
var twitAccId = tm.friendFinder.cron.getCurTwitAccId();
if ( twitAccId === false )
{
//console.log("Now waiting for one hour and cycle back to first account");
// Let user know that all filters have been cycled through
if ( tm.friendFinder.cron.iHaveFilters && tm.hiddenHints[24] === undefined )
{
tm.hint(24);
}
setTimeout(function()
{
tm.friendFinder.cron.start(twitAccId);
},3600000);
}
else
{
//console.log("Now moving to next account");
setTimeout(function()
{
tm.friendFinder.cron.start(twitAccId);
},30000);
}
return;
}
// From this point forwars we perform standard function logic
var filter = tm.friendFinder.cron.loadedFilters[tm.friendFinder.cron.curTwitAccId][filterId];
var parms =
{
rpp:25
};
if ( filter.valid_location == 1)
{
parms['geocode'] = filter.latitude+','+filter.longitude+','+filter.range+'mi';
}
$.twitter.search(filter.keyword,tm.friendFinder.cron.saveStubUsers,parms);
setTimeout(function()
{
tm.friendFinder.cron.doIt();
},30000);
},
saveStubUsers : function(data)
{
if ( data.results === undefined || data.results[0] === undefined )
return;
tm.friendFinder.cron.iHaveFilters = true;
tm.ajax
(
{
'twitAccId' : tm.friendFinder.cron.curTwitAccId,
'action' : 'ajax/ff-save-stub-users',
'tweets' : $.toJSON(data.results),
'filterId' : tm.friendFinder.cron.curFilterId
},
function(response)
{
// Update the friend follower count, just in case there was new people added
//tm.friendFinder.followCount(0);
}
);
}
}
};
tm.twitter =
{
loadedStreams : [],
gettingTweets : false,
streamInfo : [],
curStreamId : [],
loadedUsernames : {},
loadedTweets : {},
lastTweetId : false,
replyToId : false,
directMessageTo : false,
isNewStream : false,
curStreamType: false,
curStreamArgs: false,
amLoadingExtraContent: false,
reachedStreamEnd : false,
streamExists : {},
myLists : false,
streamTitles :
{
'folks-i-follow' : "Home",
'tweets-at-me' : "@mentions",
'retweets-of-me' : "ReTweets Of Me",
'dms-and-ats' : "DM's & @'s",
'my-tweets' : "Tweets I Posted",
'dms-sent-to-me' : "Direct Mesages
(Inbox) ",
'dms-sent-by-me' : "Direct Mesages
(Outbox) ",
'search' : "Search Results For ",
'favorites' : "Favorites"
},
makeStreamTitle : function(streamType,arg1)
{
switch(streamType)
{
case 'search':
return tm.twitter.streamTitles[streamType] + '
' + arg1 + ' ';
case 'tweets-at-me':
return 'Tweets Mentioning @'+tm.accounts.loadedAccounts[tm.accounts.selectedAccount].login;
case 'retweets-of-me':
return 'ReTweets of Me';
case 'get-user-timeline':
return 'Recent tweets by @'+arg1;
case 'group':
return 'Recent tweets @'+arg1;
// In most cases just get it from the titles array
default:
return tm.twitter.streamTitles[streamType];
}
},
setContentTitle : function(title)
{
$("#feed-content .title-bar .title").html
(
'
Auto Refresh '+
''+
(
tm.twitter.streamExists[tm.twitter.curStreamType+tm.twitter.curStreamArgs] === undefined
?
'
'
:
''
)+
' '+
'
'+
title+
' '
);
if ( tm.twitter.autoRefreshHandle !== false )
{
$('#auto-refresh').attr({checked:true});
}
},
pollTweets : function(streamId,streamType,arg1)
{
// Don't poll tweets if this stream is currently being viewed
if ( tm.twitter.curStreamId == streamId )
{
return;
}
// If a rouge poll is happenign because of switching acounts
if ( tm.twitter.loadedStreams[streamId] === undefined )
{
tm.tools.stopPoll(streamId);
return;
}
tm.ajax
(
{
'streamType' : streamType,
'arg1' : arg1 !== undefined && arg1 != false ? arg1 : false,
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/poll-tweets'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( response.isNewTweets == true )
{
$('#sCount'+streamId).text('('+response.numTweets+')');
$('
'+response.numTweets+' new in '+tm.twitter.loadedStreams[streamId].name+'
').toaster();
}
else
{
$('#sCount'+streamId).text('');
}
}
}
);
},
jQuery :
{
search : function(query,maxId)
{
var parms = {rpp:20};
if ( maxId !== undefined )
{
parms.max_id = maxId;
}
else
{
tm.twitter.loadedTweets = {};
}
$.twitter.search(query,tm.twitter.jQuery.doSearchResponse,parms);
},
doSearchResponse : function(data)
{
var tweetIdx = 0;
var tweets = [];
var iBackwards = data.results.length;
for ( var i in data.results )
{
// This stops it from adding duplicate tweets when scrolling back
if ( tm.twitter.loadedTweets[data.results[i].id] === undefined )
{
tweets[tweetIdx] = tm.twitter.jQuery.formatSearchTweet(data.results[i]);
tweetIdx++;
}
}
var response =
{
error : 'OK',
stream : tweets
};
tm.twitter.doGetTweetsResponse
(
tm.twitter.curStreamType,
tm.twitter.curStreamArgs,
tm.twitter.curMaxId,
undefined,
response
);
},
formatSearchTweet : function(tweet)
{
// This removes all the gunk in source
var source = tweet.source.replace(/\<\;a.*\"\;\>\;/gi, '');
source = source.replace('</a>','');
var newTweet =
{
'tweet_type' : 'search',
'date' : prettyDate(tweet.created_at),
'tweet_id' : tweet.id,
'tweet' : tm.twitter.jQuery.formatTweetText(tweet.text),
'tweet_text' : tweet.text,
'source' : source,
'user_id' : tweet.from_user_id,
'username' : tweet.from_user,
'realname' : '',
'thumb' : tweet.profile_image_url,
'followers' : 0,
'following' : 0,
'im_following' : 0,
'in_reply_to_status_id' : 0,
'in_reply_to_user_id' : 0,
'to_user_id' : 0,
'to_username' : '',
'to_realname' : '',
'to_thumb' : '',
'to_followers' : 0,
'to_following' : 0,
'f_ratio' : false
};
tm.twitter.curMaxId = tweet.id;
return newTweet;
},
formatTweetText : function(tweet)
{
var words = tweet.split(' ');
var newTweet = '';
for ( var i in words )
{
words[i] = words[i].replace(/(\w+:\/\/[^\s]+)/g,'
$1 ');
words[i] = words[i].replace(/^(\@|\.\@)([A-Za-z0-9_]+)/g,'
$1$2 ');
words[i] = words[i].replace(/^(\#[A-Za-z0-9_-]+)/g,'
$1 ');
newTweet += words[i] + ' ';
}
return newTweet;
}
},
getTweets : function(streamType,arg1,lastTweetId,autoRefresh)
{
if ( tm.feeds.gettingTweets === true )
{
return;
}
tm.twitter.curStreamType = streamType;
tm.twitter.curStreamArgs = arg1;
tm.twitter.curLastTweetId = lastTweetId;
tm.feeds.gettingTweets = true;
tm.nav.setView('twitter');
$("#feed-content").removeClass('hide');
// If we are NOT getting extra tweets from same stream
if ( lastTweetId === undefined )
{
tm.twitter.reachedStreamEnd = false;
tm.feeds.resetFeedContent();
tm.twitter.setContentTitle('Loading...');
}
else
{
// Let the user know we are loading more stuff
$("#feed-content .list").append('
');
tm.twitter.amLoadingExtraContent = true;
setTimeout(function()
{
$("#feed-content .list").scrollTop($("#feed-content .list").attr("scrollHeight"));
},100);
}
if ( streamType == 'search' )
{
tm.twitter.jQuery.search(arg1,lastTweetId);
return;
}
//arg1 = 'twin_lens'; // nuboat -- twin_lens
//streamType = 'get-user-timeline';
setTimeout(function()
{
tm.ajax
(
{
'streamType' : streamType !== undefined ? streamType : 'folks-i-follow',
'arg1' : arg1 !== undefined && arg1 != false ? arg1 : false,
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-tweets',
'lastTweetId' : lastTweetId === undefined ? false : lastTweetId
},
function(response)
{
tm.twitter.doGetTweetsResponse
(
streamType,
arg1,
lastTweetId,
autoRefresh,
response
);
}
);
},100);
},
doGetTweetsResponse : function(streamType, arg1, lastTweetId, autoRefresh, response)
{
tm.feeds.gettingTweets = false;
tm.twitter.amLoadingExtraContent = false;
if (response.error != 'OK')
{
$("#feed-content").addClass('hide');
alert(response.error);
}
else
{
tm.twitter.setContentTitle(tm.twitter.makeStreamTitle(streamType,arg1));
if ( lastTweetId !== undefined )
{
$('#loading-div').remove();
}
if ( response.stream == false )
{
if ( lastTweetId === undefined )
{
$("#feed-content .list").html
(
'
No Tweets
'
);
}
else
{
tm.twitter.reachedStreamEnd = true;
}
return;
}
// If we are getting extra tweets from same stream
if ( lastTweetId === undefined )
{
$("#feed-content .list").html('');
tm.twitter.loadedUsernames = {};
tm.twitter.loadedTweets = {};
}
// if there ARE results
for ( i in response.stream )
{
response.stream[i].alt = ( i % 2 == 0 ? '' : 'alt') ;
tm.twitter.loadedUsernames[response.stream[i].username] = response.stream[i].username;
tm.twitter.loadedTweets[response.stream[i].tweet_id] = response.stream[i];
tm.twitter.lastTweetId = response.stream[i].tweet_id;
// Insert item into the list
$("#feed-content .list").append
(
tm.templates.twitterContentItem(response.stream[i])
);
}
setTimeout(function()
{
// Teach user about hover over user image
if ( tm.hiddenHints[15] === undefined )
{
tm.hint(15);
}
// Teach user about auto refresh
else if ( tm.hiddenHints[11] === undefined )
{
tm.hint(11);
}
// Teach user about reorder streams ,accounts & feeds
else if ( tm.hiddenHints[19] === undefined )
{
tm.hint(19);
}
},2000);
}
},
unHighlightStreams : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
highlightStream : function(streamId)
{
$('#streamList_'+streamId).addClass('selected');
},
openNewTweetModal : function(parms)
{
if ( $('#tweet').length > 0 ) return;
tm.twitter.directMessageTo = false;
switch(tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].type)
{
case 'search':
tm.twitter.curTweet = 'In '+tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].args+' ';
break;
case 'get-user-timeline':
tm.twitter.curTweet = '@'+tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].args+' ';
break;
}
if ( parms!== undefined && parms.multiAts !== undefined )
{
tm.twitter.curTweet = parms.multiAts;
}
tm.tools.makeModal(tm.templates.tweetDialog('New Tweet'),'callout-bl', 385, undefined, undefined, undefined, true );
$('#popupid'+tm.curModal).draggable();
if ( tm.twitter.curTweet !== false )
{
$('#tweet').val(tm.twitter.curTweet);
}
tm.tools.textFocus('#tweet');
if ( tm.twitter.autoSuggest !== undefined )
{
$("#tweet").autocomplete
(
tm.twitter.autoSuggest,
{
width: 360,
multiple: true,
matchContains: false,
autoFill: false
}
);
}
setTimeout("tm.hint(6)",500);
},
checkChars : function()
{
setTimeout(function()
{
if ( $('#tweet').val() === undefined )
{
return;
}
var charsLeft = 140 - $('#tweet').val().length;
$('#chars-left').html(charsLeft);
if ( charsLeft >= 0 )
{
$('#chars-left').addClass('enough-chars');
$('#chars-left').removeClass('not-enough-chars');
}
else
{
$('#chars-left').addClass('not-enough-chars');
$('#chars-left').removeClass('enough-chars');
}
},100);
},
curTweet : false,
autoCompleteIsOpen : false,
amPostingTweet : false,
postTweet : function(event,addToSchedule,postAt)
{
if ( tm.twitter.amPostingTweet )
{
return;
}
tm.twitter.checkChars();
if ( tm.tools.isFormTrigger(event) && ! tm.twitter.autoCompleteIsOpen )
{
tm.twitter.amPostingTweet = true;
var error = false;
var postTo = tm.settings.pingFm.getSelectedServices();
if ( $('#tweet').val()== '' )
{
error = "Oops! Please enter a Tweet";
}
else if ( $('#tweet').val().length > 140 )
{
error = "Oops! Your Tweet must be less (or equal to) 140 characters";
}
if ( error )
{
tm.twitter.amPostingTweet = false;
alert(error);
return;
}
// Store the current tweet status and close the modal
tm.twitter.curTweet = $('#tweet').val();
tm.tools.closeModal();
// Need to give SOME kind of action status
if ( addToSchedule !== undefined )
{
alert("Scheduling Tweet...");
}
else if ( tm.twitter.directMessageTo )
{
alert("Sending Message...");
}
else
{
alert("Posting Tweet...");
}
// Now post the tweet to twitter
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'tweet' : tm.twitter.curTweet,
'action' : 'ajax/simple-tweet',
'replyToId' : tm.twitter.replyToId !== false ? tm.twitter.replyToId : 0,
'directMessageTo' : tm.twitter.directMessageTo ? tm.twitter.directMessageTo : 0,
'addToSchedule' : addToSchedule === undefined ? 0 : 1,
'postAt' : postAt === undefined ? 0 : postAt,
'postTo' : postTo
},
function(response)
{
tm.twitter.amPostingTweet = false;
if (response.error != 'OK')
{
tm.tools.closeModal();
tm.twitter.openNewTweetModal();
alert(response.error);
}
else
{
tm.tools.closeModal();
if ( response.autoSuggest != false )
{
tm.twitter.autoSuggest = response.autoSuggest;
}
if ( addToSchedule !== undefined )
{
// Tweet Scheduled Successfully
tm.hint(8);
}
else if ( tm.twitter.directMessageTo )
{
// Message Sent Successfully
tm.hint(9);
}
else
{
// Tweet Posted Successfully
tm.hint(10);
}
tm.twitter.curTweet = false;
tm.twitter.replyToId = false;
tm.twitter.directMessageTo = false;
}
}
);
},100);
}
},
shortenLinksInTweet : function()
{
tm.twitter.curTweet = $('#tweet').val();
$('#tweet').val("Shortening links...");
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'tweet' : tm.twitter.curTweet,
'action' : 'ajax/shorten-links-in-tweet'
},
function(response)
{
if (response.error != 'OK')
{
$('#tweet').val(tm.twitter.curTweet);
alert(response.error);
}
else
{
tm.twitter.curTweet = response.newTweet;
$('#tweet').val(response.newTweet);
tm.twitter.checkChars();
}
}
);
},100);
},
putAtIntoTweet : function(selectObj)
{
$('#tweet').val($(selectObj).val()+' '+$('#tweet').val());
selectObj.selectedIndex = 0;
tm.twitter.checkChars();
},
addMultiAt : function(username)
{
if ( $('#tweet').length == 0 )
{
tm.twitter.openNewTweetModal(username);
}
else
{
$('#tweet').val('@'+username+' '+$('#tweet').val());
tm.twitter.checkChars();
tm.tools.textFocus('#tweet');
}
},
showUserDropDown : function (tweetID,divObj)
{
if ( $('#tweet-bubble').length > 0 )
{
return;
}
var myWidth = 0;
var t = tm.twitter.loadedTweets[tweetID];
var streamType = tm.twitter.curStreamType;
if ( t.tweet_type == 'dm-to-me' )
{
streamType = 'dms-sent-to-me';
}
switch(streamType)
{
case 'folks-i-follow' : myWidth = 228; break;
case 'tweets-at-me' : myWidth = 228; break;
case 'retweets-of-me' : myWidth = 228; break;
case 'dms-and-ats' : myWidth = 228; break;
case 'search' : myWidth = 228; break;
case 'favorites' : myWidth = 228; break;
case 'group' : myWidth = 228; break;
case 'my-tweets' : myWidth = 125; break;
case 'dms-sent-to-me' : myWidth = 152; break;
case 'dms-sent-by-me' : myWidth = 75; break;
default: myWidth = 228;
}
var pos = $(divObj).offset();
var myLeft = pos.left-10;
var myTop = pos.top-10;
var myClass = 'callout-tl user-drop-down-outer';
// Test to see if popup will be below the fold
if ( 100 + pos.top >= $(window).height() )
{
myLeft = pos.left-10;
myTop = pos.top-49;
myClass = 'callout-bl user-drop-down-outer-up';
}
// Create the popup
tm.tools.makeModal
(
tm.templates.userDropDown[streamType](tweetID),
myClass,
myWidth,
myLeft,
myTop,
0
);
// This binds a close modal action to the overlay
$('#overlay'+tm.curModal).bind("mouseover", function(e){tm.tools.closeModal();});
},
reply : function(tweetID)
{
if ( $('#tweet').length > 0 ) return;
tm.twitter.directMessageTo = false;
tm.twitter.replyToId = tweetID;
tm.tools.closeModal();
tm.tools.makeModal(tm.templates.tweetDialog('Replying'),'callout-bl', 385, undefined, undefined, undefined, true );
$('#popupid'+tm.curModal).draggable();
$('#tweet').val('@'+tm.twitter.loadedTweets[tweetID].username+' ');
switch(tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].type)
{
case 'search':
$('#tweet').val('@'+tm.twitter.loadedTweets[tweetID].username+' in '+tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].args+' ');
break;
}
tm.twitter.checkChars();
tm.tools.textFocus('#tweet');
},
replyToAll : function(tweetID)
{
if ( $('#tweet').length > 0 ) return;
tm.twitter.directMessageTo = false;
tm.twitter.replyToId = tweetID;
tm.tools.closeModal();
tm.tools.makeModal(tm.templates.tweetDialog('Replying'),'callout-bl', 385, undefined, undefined, undefined, true );
$('#popupid'+tm.curModal).draggable();
var words = tm.twitter.loadedTweets[tweetID].tweet_text.split(' ');
var ats = '';
for ( i in words )
{
if ( words[i].substr(0,1) == '@' && words[i].substr(1,1) != '@')
{
ats += ( '@'+words[i].replace(/[^a-zA-Z0-9_]/g, '')+' ' ) ;
}
}
$('#tweet').val('@'+tm.twitter.loadedTweets[tweetID].username+' '+ats);
switch(tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].type)
{
case 'search':
$('#tweet').val('@'+tm.twitter.loadedTweets[tweetID].username+' in '+tm.twitter.loadedStreams[tm.twitter.curStreamId[tm.accounts.selectedAccount]].args+' '+ats);
break;
}
tm.twitter.checkChars();
tm.tools.textFocus('#tweet');
},
editAndReTweet : function(tweetID)
{
if ( $('#tweet').length > 0 ) return;
tm.twitter.directMessageTo = false;
tm.twitter.replyToId = tweetID;
tm.tools.closeModal();
tm.tools.makeModal(tm.templates.tweetDialog('Edit & Retweet'),'callout-bl', 385, undefined, undefined, undefined, true);
$('#popupid'+tm.curModal).draggable();
$('#tweet').val('RT @'+tm.twitter.loadedTweets[tweetID].username+' '+tm.twitter.loadedTweets[tweetID].tweet_text);
tm.twitter.checkChars();
tm.tools.textFocus('#tweet');
},
instantReTweet : function(tweetID)
{
tm.twitter.directMessageTo = false;
tm.tools.closeModal();
// Now post the tweet to twitter
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'tweet' : 'RT @'+tm.twitter.loadedTweets[tweetID].username+' '+tm.twitter.loadedTweets[tweetID].tweet_text,
'action' : 'ajax/simple-tweet',
'replyToId' : tweetID,
'postTo' : tm.settings.pingFm.getSelectedServices()
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.twitter.replyToId = false;
}
}
);
},100);
},
directMessage : function(tweetID)
{
tm.tools.closeModal();
alert("Testing relationship...");
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'targetUser' : tm.twitter.loadedTweets[tweetID].username,
'action' : 'ajax/can-send-dm'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
if ( response.canSendDm != true )
{
alert("This user needs to follow you before you can send them a direct message.
Send an @reply instead... ");
return;
}
tm.twitter.directMessageTo = tm.twitter.loadedTweets[tweetID].username;
tm.tools.makeModal(tm.templates.tweetDialog('Direct message to @'+tm.twitter.loadedTweets[tweetID].username),'callout-bl', 385);
tm.tools.textFocus('#tweet');
}
}
);
},
showProfile : function(tweetID,screen_name)
{
var targetUser = ( screen_name !== undefined ? screen_name : tm.twitter.loadedTweets[tweetID].username) ;
tm.tools.closeModal();
alert("Loading profile...");
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'targetUser' : targetUser,
'action' : 'ajax/get-twitter-user'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
tm.tools.makeModal(tm.templates.twitterUserProfile(response.twitterUser),'callout-tl', 440);
}
}
);
},
openAddStreamModal : function()
{
if ( tm.accounts.selectedAccount === false )
{
alert("Please add a Twitter account
(See the left hand panel on this screen)");
return;
}
tm.twitter.isNewStream = true;
var pos = $('#feed-plus-sign').offset();
tm.tools.makeModal(tm.templates.addTwitterStream('Add Twitter Stream','Add'),'callout-tl', 305, pos.left-16, pos.top-2);
$('#stream-input').focus();
},
changeInputType : function()
{
if ( tm.twitter.myLists !== false ) $('#my-lists-row').addClass('hide');
switch ( $('#stream-type').val() )
{
case 'get-user-timeline':;
$('#feed-icon').attr({'src':'/template/gfx/user-green.png'});
$('#feed-input-title').text('@user:');
break;
case 'search':;
$('#feed-icon').attr({'src':'/template/gfx/search-green.png'});
$('#feed-input-title').text('Keyword:');
break;
case 'group':;
if ( tm.twitter.myLists !== false ) $('#my-lists-row').removeClass('hide');
$('#feed-icon').attr({'src':'/template/gfx/list.png'});
$('#feed-input-title').text('List/Group:');
break;
}
},
addStream : function(e)
{
if ( ! tm.tools.isFormTrigger(e) || tm.twitter.addingStream === true )
{
return;
}
tm.twitter.addStreamCore();
},
addingStream : false,
addStreamCore : function(streamType,streamInput)
{
tm.twitter.addingStream = true;
var error = false;
// Send to the server and try to create the account
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'streamId' : tm.twitter.curStreamId[tm.accounts.selectedAccount],
'streamType' : $('#stream-type').length > 0 ? $('#stream-type').val() : tm.twitter.curStreamType,
'streamInput' : $('#stream-input').length > 0 ? $('#stream-input').val() : tm.twitter.curStreamArgs,
'isAutoPoll' : $('#is-auto-poll').attr('checked')===undefined?false:$('#is-auto-poll').attr('checked'),
'pollInterval' : $('#poll-interval').val()===undefined?2:$('#poll-interval').val(),
'action' : 'ajax/add-stream',
'isNewStream' : tm.twitter.isNewStream
},
function(response)
{
tm.twitter.addingStream = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
$('#stream-input').val('');
tm.twitter.curStreamId[tm.accounts.selectedAccount] = response.streamId;
tm.twitter.getStreams();
setTimeout("tm.hint(3)",2000);
}
}
);
},
getStreams : function()
{
tm.feeds.resetFeedContent();
if ( tm.accounts.selectedAccount === false )
{
$("#feed-content").addClass('hide');
$("#feeds .list").html
(
'
Please add a twitter account (left panel) to get started.
'
);
return;
}
$("#feeds .list").html('
');
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-streams'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
$("#feeds .list").html('');
for ( i in response.streams )
{
tm.twitter.streamExists[response.streams[i].type+response.streams[i].args] = true;
if ( i == 0 && tm.twitter.curStreamId[tm.accounts.selectedAccount] === undefined )
{
tm.twitter.curStreamId[tm.accounts.selectedAccount] = response.streams[i]['stream_id'];
}
// Store loaded streams for future use in other dialogs etc.
tm.twitter.loadedStreams[response.streams[i]['stream_id']] = response.streams[i];
if ( response.streams[i].name == '@mentions' )
{
response.streams[i].name = '@' + tm.accounts.loadedAccounts[tm.accounts.selectedAccount]['login'];
}
// Insert item into the list
$("#feeds .list").append
(
tm.templates.streamListItem
(
response.streams[i]
)
);
// Always poll tweets @ me
if ( response.streams[i].type == 'tweets-at-me' )
{
tm.twitter.pollTweets(response.streams[i].stream_id,'tweets-at-me','');
}
// Always poll tweets @ me
if ( response.streams[i].type == 'retweets-of-me' )
{
tm.twitter.pollTweets(response.streams[i].stream_id,'retweets-of-me','');
}
// Always poll dms sent to me
if ( response.streams[i].type == 'dms-sent-to-me' )
{
tm.twitter.pollTweets(response.streams[i].stream_id,'dms-sent-to-me','');
}
// This deals with setting/unsetting stream polling
if ( response.streams[i].auto_poll == 0 )
{
tm.tools.stopPoll(response.streams[i].stream_id);
}
else
{
// This triggers auto polling for this stream.
// it ALSO triggers at a random time within the next 30 secs
// so all polling doesnt happen at same moment
setTimeout
(
"tm.tools.startPoll("+response.streams[i].stream_id+");",
Math.floor(Math.random()*11)*1000
);
}
}
$("#feeds .list").sortable('destroy');
$("#feeds .list").sortable
({
stop: function(event, ui)
{
// This gets streamList[]=1&streamList[]=2&streamList[]=3 ready to send to server
tm.twitter.saveOrder($("#feeds .list").sortable('serialize'));
}
});
tm.twitter.selectStream(tm.twitter.curStreamId[tm.accounts.selectedAccount]);
}
}
);
},
getMyLists : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-my-lists'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( response.myLists[0] === undefined )
{
tm.twitter.myLists = false;
}
else
{
tm.twitter.myLists = response.myLists;
}
}
}
);
},100);
},
savingOrder : false,
saveOrder : function(streamIds)
{
if ( tm.curView != 'twitter' )
{
return;
}
tm.twitter.savingOrder = true;
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'streamIds' : streamIds,
'action' : 'ajax/save-order-streams'
},
function(response)
{
tm.twitter.savingOrder = false;
if (response.error != 'OK')
{
alert(response.error);
}
}
);
},
selectStream : function(streamId)
{
if ( tm.twitter.savingOrder )
{
return;
}
tm.twitter.curStreamId[tm.accounts.selectedAccount] = streamId;
tm.twitter.unHighlightStreams();
tm.twitter.highlightStream(streamId);
$('#sCount'+streamId).text('');
if ( tm.twitter.loadedStreams[streamId].type == 'dms-and-ats' )
{
$('.sCount-tweets-at-me').text('');
$('.sCount-dms-sent-to-me').text('');
}
// do it (as long as modal isnt open)
if ( $('#feed-popup').length == 0)
{
setTimeout(function()
{
tm.twitter.getStream(streamId);
},100);
}
},
getStream : function(streamId)
{
var stream = tm.twitter.loadedStreams[streamId];
if ( stream === undefined ) return;
tm.twitter.getTweets(stream.type,stream.args);
},
openTwitterStreamModalEdit : function(streamId)
{
tm.twitter.isNewStream = false;
var title = tm.twitter.loadedStreams[streamId].name;
// If the popup will be below the fold
var pos = $('#streamList_' + streamId + ' img').offset();
if ( 190 + pos.top >= $(window).height() )
{
tm.tools.makeModal(tm.templates.addTwitterStream(title,'Save',streamId),'callout-bl', 305, pos.left-14, pos.top-185);
}
else
{
tm.tools.makeModal(tm.templates.addTwitterStream(title,'Save',streamId),'callout-tl', 305, pos.left-14, pos.top-2);
}
$('#stream-input').val(tm.twitter.loadedStreams[streamId]['args']);
$('#stream-type').val(tm.twitter.loadedStreams[streamId]['type']);
tm.twitter.changeInputType();
$('#stream-input').focus();
},
deleteStream : function(streamId)
{
tm.prompt('Sure you want to delete this stream?','tm.twitter.doDeleteStream('+streamId+')');
},
doDeleteStream : function (streamId)
{
// Send to the server and try to create the account
tm.ajax
(
{
'streamId' : streamId,
'action' : 'ajax/delete-stream'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Stop the auto poll of this stream :)
tm.tools.stopPoll(tm.twitter.curStreamId[tm.accounts.selectedAccount]);
tm.tools.closeModal();
tm.tools.closeModal();
tm.twitter.curStreamId[tm.accounts.selectedAccount] = undefined;
tm.twitter.getStreams();
}
}
);
},
addToRollingSchedule : function(event)
{
tm.twitter.postTweet(event,true);
},
openScheduleByTime : function()
{
var pos = $('#schedule-by-time-button').offset();
tm.tools.makeModal(tm.templates.scheduleByTime(),'callout-br', 360,pos.left-350,pos.top-105);
$('#datepicker').datepicker
({
changeMonth: true,
changeYear: true,
showOn: 'both',
buttonImage: '/template/gfx/calender.png',
buttonImageOnly: true
});
},
addToTimedSchedule : function(event)
{
var postAt = $('#datepicker').val()+' '+$('#hour').val()+':'+$('#minute').val()+' '+$('#ampm').val();
$('#datepicker').datepicker('destroy');
tm.tools.closeModal();
tm.twitter.postTweet(event,true,postAt);
},
followToggle : function(targetUser)
{
// Send to the server and try to create the account
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'amFollowing' : $('#follow-button').val()=='Follow'?0:1,
'targetUser' : targetUser,
'action' : 'ajax/follow-toggle'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( $('#follow-button').val() == 'Follow' )
{
$('#follow-button').val('Stop Following');
}
else
{
$('#follow-button').val('Follow');
}
}
}
);
},
deleteTweet : function(tweetId)
{
tm.tools.closeModal();
$('#tweet'+tweetId).addClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'tweetId' : tweetId,
'tweetType' : tm.twitter.loadedTweets[tweetId].tweet_type,
'action' : 'ajax/delete-tweet'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
$('#tweet'+tweetId).removeClase('hide');
}
else
{
$('#tweet'+tweetId).remove();
}
}
);
},100);
},
saveStream : function()
{
tm.twitter.isNewStream = true;
tm.twitter.addStreamCore();
},
scrollHandler : function(divObj)
{
var maxScroll = $(divObj).attr("scrollHeight");
var curScroll = $(divObj).scrollTop()+$(divObj).height();
setTimeout(function()
{
if ( $('#loading-div').length == 0 && tm.twitter.curTweet === false && tm.twitter.reachedStreamEnd === false && tm.twitter.amLoadingExtraContent === false && curScroll == maxScroll )
{
tm.twitter.getTweets
(
tm.twitter.curStreamType,
tm.twitter.curStreamArgs,
tm.twitter.lastTweetId
);
}
},100);
},
doSearch : function(event,searchField)
{
if ( ! tm.tools.isFormTrigger(event) )
{
return;
}
tm.twitter.unHighlightStreams();
tm.twitter.getTweets('search',searchField.value);
},
autoRefreshHandle : false,
toggleAutoRefresh : function()
{
// Start auto refresh
if ( $('#auto-refresh').attr('checked') )
{
tm.twitter.autoRefreshHandle = window.setInterval
(
function()
{
if ( tm.curView == 'twitter' && $('.user-drop-down').length == 0 )
{
tm.twitter.getTweets
(
tm.twitter.curStreamType,
tm.twitter.curStreamArgs,
undefined,
true
);
}
},
// One min minute
1000*60*2
);
}
// Stop auto refresh
else
{
if ( tm.twitter.autoRefreshHandle !== false )
{
window.clearInterval(tm.twitter.autoRefreshHandle);
tm.twitter.autoRefreshHandle = false;
}
}
},
addFavorite : function(tweetId)
{
tm.tools.closeModal();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'tweetId' : tweetId,
'action' : 'ajax/twitter-favorites-add'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Added successfully
tm.hint(17);
}
}
);
},100);
},
deleteFavorite : function(tweetId)
{
tm.tools.closeModal();
$('#tweet'+tweetId).addClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'tweetId' : tweetId,
'action' : 'ajax/twitter-favorites-remove'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
$('#tweet'+tweetId).removeClase('hide');
}
else
{
$('#tweet'+tweetId).remove();
// Removed successfully
tm.hint(18);
}
}
);
},100);
},
showAddToList : function(tweetId,imgObj)
{
var pos = $(imgObj).offset();
tm.tools.makeModal(tm.templates.makeAddToListDropDown(tweetId),'add-to-list-drop-down-outer',400,pos.left-95,pos.top-40,0);
var adjustWidth = 145;
if ( $.browser.msie ) adjustWidth = 165;
if ( $.browser.safari ) adjustWidth = 155;
$('#popupid'+tm.curModal).css({width: $('#add-to-list-select').width() + adjustWidth + 'px' });
},
addUserToList : function(targetUser)
{
var targetList = $('#add-to-list-select').val();
// 2 modals open at this point
tm.tools.closeModal();
tm.tools.closeModal();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'targetList' : targetList,
'targetUser' : targetUser,
'action' : 'ajax/add-user-to-list'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Added successfully
tm.hint(22);
}
}
);
},100);
},
removeUserFromList : function(tweetId)
{
tm.tools.closeModal();
var targetList = tm.twitter.curStreamArgs;
var targetUser = tm.twitter.loadedTweets[tweetId].username;
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'targetList' : targetList,
'targetUser' : targetUser,
'action' : 'ajax/remove-user-from-list'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Added successfully
tm.hint(23);
}
}
);
},100);
},
toggleMakeNewList : function()
{
if ( $('#make-new-list-panel').hasClass('hide') )
{
$('#make-new-list-panel').removeClass('hide');
$('#add-to-existing-list-panel').addClass('hide');
$('#manage-lists-link').html('« Add To an Existing List/Group');
}
else
{
$('#make-new-list-panel').addClass('hide');
$('#add-to-existing-list-panel').removeClass('hide');
$('#manage-lists-link').html('Create a New List/Group »');
}
},
makeNewList : function(targetUser)
{
var listName = $('#my-new-list').val();
var listType = $('#is-public-list').is(':checked') ? 'public' : 'private' ;
var listDesc = $('#my-new-list-desc').val();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'listName' : listName,
'listType' : listType,
'listDesc' : listDesc,
'action' : 'ajax/list-create-new'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// If new list created succesfully then add target user
$('#add-to-list-select').prepend($("
").text('@'+tm.accounts.curUsername+'/'+response.listName));
$('#add-to-list-select').attr('selectedIndex', 0);
tm.twitter.addUserToList(targetUser);
// re-load lists
setTimeout(function()
{
tm.twitter.getMyLists();
},100);
}
}
);
},100);
},
shareTheLove : function()
{
tm.ajax
(
{
'action' : 'ajax/get-love-quote'
},
function(response)
{
if ( $('#tweet').length > 0 ) return;
tm.twitter.directMessageTo = false;
tm.twitter.replyToId = false;
tm.tools.closeModal();
tm.tools.makeModal(tm.templates.tweetDialog('Tweet'),'callout-bl', 385, undefined, undefined, undefined, true);
$('#popupid'+tm.curModal).draggable();
$('#tweet').val(response.theLove);
tm.twitter.checkChars();
tm.tools.textFocus('#tweet');
}
);
},
getRetweetedBy : function(tweetId)
{
$('#tweet'+tweetId+' .whoRetweetedThis').html('
');
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-retweeted-by',
'tweetId' : tweetId,
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
var users = response.retweetedBy;
var atNames = '';
for ( var i in users )
{
atNames += '@'+users[i].screen_name+' ';
}
var html = '';
for ( var i in users )
{
html +=
'
';
}
$('#tweet'+tweetId+' .whoRetweetedThis').html(html);
}
}
);
},
getTweetThread : function(tweetId,inReplyToId)
{
$('#tweet'+tweetId+' .tweetThread').html('
');
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-tweet-thread',
'inReplyToId' : inReplyToId,
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( response.tweetThread[0] == null )
{
$('#tweet'+tweetId+' .tweetThread').html('Could not get conversation. Hourly Twitter API limit overused? Try again in 60 minutes.');
return;
}
var tweets = response.tweetThread;
var html = '';
for ( var i in tweets )
{
html +=
'';
}
$('#tweet'+tweetId+' .tweetThread').html(html);
}
}
);
}
};
tm.multicol =
{
init : function()
{
// Set up the
$(function()
{
var multiColWidth = $(window).width()-30;
var multiColHeight = $(window).height()-160;
$("#multicol").css({width : multiColWidth+'px'});
$("#multicol-tab-content").css({height : multiColHeight+'px'});
$("#multicol-tabs").sortable
({
stop: function(event, ui)
{
// This gets tab[]=1&tab[]=2&tab[]=3&tab[]=4 ready to send to server
$("#multicol-tabs").sortable('serialize');
}
});
$("#multicol-tabs").disableSelection();
});
}
};
tm.register =
{
is_valid :
{
username : false,
email : false,
password : false,
password2 : false
},
validate : function()
{
var error = false;
if ( ! tm.register.is_valid.username )
{
error = s[66];
}
else if ( ! tm.register.is_valid.email )
{
error = s[67];
}
else if ( ! tm.register.is_valid.password )
{
error = s[68];
}
else if ( ! tm.register.is_valid.password2 )
{
error = s[69];
}
if ( error !== false )
{
alert(error);
return false;
}
// It's validated!
return true;
},
checkField : function(fieldObj)
{
eval('tm.register.check_'+fieldObj.id)(fieldObj.value);
},
check_username : function(username)
{
tm.register.is_valid.username = false;
if ( username.length <= 1 )
{
$('.username span').html('');
return;
}
if ( username.length < 3 )
{
$('.username span').html('
');
return;
}
$('.username span').html('
');
if ( username.match(/[^a-zA-Z0-9\_]/g, '') )
{
$('.username span').html('
'+s[70]+' ');
return;
}
tm.ajax
(
{
'username' : username,
'action' : 'ajax/register-check-username'
},
function(response)
{
if ( response.userAvailable )
{
tm.register.is_valid.username = true;
$('.username span').html('
');
}
else
{
$('.username span').html('
Unavailable ');
}
},
false,
false
);
},
check_email : function(email)
{
tm.register.is_valid.email = false;
if ( email.length <= 3 )
{
$('.email span').html('');
return;
}
if ( email.match(/[_a-z0-9\'-]+(\.[_a-z0-9\'-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/g) )
{
tm.ajax
(
{
'username' : email,
'action' : 'ajax/register-check-username'
},
function(response)
{
if ( response.userAvailable )
{
tm.register.is_valid.email = true;
$('.email span').html('
');
}
else
{
$('.email span').html('
'+s[71]+' ');
}
},
false,
false
);
}
else
{
$('.email span').html('
');
}
},
check_password : function(password)
{
tm.register.is_valid.password = false;
if ( password.length <= 3 )
{
$('.password span').html('');
return;
}
if ( password.length < 6 )
{
$('.password span').html('
');
}
else
{
tm.register.is_valid.password = true;
$('.password span').html('
');
}
},
check_password2 : function(password2)
{
tm.register.is_valid.password2 = false;
if ( password2.length <= 3 )
{
$('.password2 span').html('');
return;
}
if ( password2 != $('#password').val() )
{
$('.password2 span').html('
');
}
else
{
tm.register.is_valid.password2 = true;
$('.password2 span').html('
');
}
}
};
tm.schedule =
{
gettingSchedule : false,
loadedItems : [],
selectedOption : 'scheduleShowAllByAdded',
showNav : function(navOption)
{
$("#feeds .list").html
(
tm.templates.scheduleNavOptions()
);
tm.schedule.highlightOption(navOption);
},
selectOption : function(optionId)
{
tm.schedule.unHighlightOptions();
tm.schedule.highlightOption(optionId);
tm.schedule.getSchedule(undefined,optionId);
},
highlightOption : function(optionId)
{
$('#'+optionId).addClass('selected');
},
unHighlightOptions : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
getSchedule : function(dontDoFeedReset,navOption)
{
if ( tm.schedule.gettingSchedule === true )
{
return;
}
if ( navOption === undefined )
{
navOption = tm.schedule.selectedOption;
}
else
{
tm.schedule.selectedOption = navOption;
}
tm.schedule.showNav(navOption);
tm.schedule.gettingSchedule = true;
if ( dontDoFeedReset === undefined )
{
tm.feeds.resetFeedContent();
}
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'scheduleType' : navOption,
'action' : 'ajax/get-schedule'
},
function(response)
{
tm.schedule.gettingSchedule = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
'
'+
'
'+s[76]+' '+
'
('+response.numToPost+' '+s[77]+') '
);
// If there are no feed results
if ( response.schedule === false )
{
$("#feed-content .list").html(tm.templates.nothingScheduled());
return;
}
tm.schedule.loadedItems = response.schedule;
// if there ARE results
for ( i in response.schedule )
{
response.schedule[i].idx = i;
response.schedule[i].alt = ( i % 2 == 0 ? '' : 'alt') ;
$("#feed-content .list").append
(
tm.templates.scheduleContentItem(response.schedule[i])
);
}
setTimeout("tm.hint(21)",2000);
}
}
);
},100);
},
removeFromSchedule : function(scheduleId)
{
$('#scheduleItem'+scheduleId).remove();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'scheduleId' : scheduleId,
'action' : 'ajax/delete-from-schedule'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
if ( $("#feed-content .list").text() == '' )
{
tm.nav.go(tm.curView);
return;
}
}
);
},100);
},
bumpLock : false,
bumpRollingToLater : function(scheduleId)
{
if ( tm.schedule.bumpLock ) return;
tm.schedule.bumpLock = true;
var startLooking = false;
var prevId = false;
var fromIdx = false;
var toIdx = false;
var toScheduleId = false;
for ( var i = tm.schedule.loadedItems.length - 1 ; i >= 0 ; i-- )
{
if ( startLooking && tm.schedule.loadedItems[i].schedule_type == 'rolling' )
{
toIdx = i;
prevId = tm.schedule.loadedItems[i].schedule_id;
toScheduleId = tm.schedule.loadedItems[i].schedule_id;
break;
}
if ( tm.schedule.loadedItems[i].schedule_id == scheduleId )
{
fromIdx = i;
startLooking = true;
}
}
if ( prevId )
{
// Move the div around in the dom
var clone = $($('#scheduleItem'+scheduleId)).clone(true);
$('#scheduleItem'+scheduleId).remove();
$(clone).insertBefore($('#scheduleItem'+prevId));
$('#s-up'+scheduleId).attr({'src':'/template/gfx/arrow-up.png'});
// Make it easier for the user to see what changed
$('#scheduleItem'+scheduleId).addClass('temp-highlight');
// Trigger ajax call to swap schedule at server level
tm.schedule.swapRollingSchedule(scheduleId,toScheduleId);
}
else
{
tm.schedule.bumpLock = false;
}
},
bumpRollingToSooner : function(scheduleId)
{
if ( tm.schedule.bumpLock ) return;
tm.schedule.bumpLock = true;
var startLooking = false;
var nextId = false;
var fromIdx = false;
var toIdx = false;
var toScheduleId = false;
for ( var i = 0 ; i < tm.schedule.loadedItems.length ; i++ )
{
if ( startLooking && tm.schedule.loadedItems[i].schedule_type == 'rolling' )
{
toIdx = i;
nextId = tm.schedule.loadedItems[i].schedule_id;
toScheduleId = tm.schedule.loadedItems[i].schedule_id;
break;
}
if ( tm.schedule.loadedItems[i].schedule_id == scheduleId )
{
fromIdx = i;
startLooking = true;
}
}
if ( nextId )
{
// Move the div around in the dom
var clone = $($('#scheduleItem'+scheduleId)).clone(true);
$('#scheduleItem'+scheduleId).remove();
$(clone).insertAfter($('#scheduleItem'+nextId));
$('#s-dn'+scheduleId).attr({'src':'/template/gfx/arrow-down.png'});
// Make it easier for the user to see what changed
$('#scheduleItem'+scheduleId).addClass('temp-highlight');
// Trigger ajax call to swap schedule at server level
tm.schedule.swapRollingSchedule(scheduleId,toScheduleId);
}
else
{
tm.schedule.bumpLock = false;
}
},
swapRollingSchedule : function(fromScheduleId,toScheduleId)
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'fromScheduleId' : fromScheduleId,
'toScheduleId' : toScheduleId,
'action' : 'ajax/swap-rolling-schedule'
},
function(response)
{
tm.schedule.bumpLock = false;
if (response.error != 'OK')
{
alert(response.error);
}
tm.schedule.getSchedule(true);
}
);
},100);
},
editingIdx : false,
openEditDialog : function(idx)
{
tm.schedule.editingIdx = idx;
tm.tools.makeModal(tm.templates.scheduleTweetDialog(s[72]),'callout-bl', 385);
$('#tweet').val(tm.schedule.loadedItems[idx].tweet);
tm.twitter.checkChars();
$('#tweet').focus();
},
curTweet : false,
editTweet : function(event)
{
tm.twitter.checkChars();
if ( tm.tools.isFormTrigger(event) )
{
var error = false;
if ( $('#tweet').val()== '' )
{
error = s[73];
}
else if ( $('#tweet').val().length > 140 )
{
error = s[74];
}
if ( error )
{
alert(error);
return;
}
// Store the current tweet status and close the modal
tm.schedule.curTweet = $('#tweet').val();
tm.tools.closeModal();
alert(s[75]);
// Now post the tweet to twitter
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'scheduleId' : tm.schedule.loadedItems[tm.schedule.editingIdx].schedule_id,
'editedTweet' : tm.schedule.curTweet,
'action' : 'ajax/edit-schedule',
'postTo' : tm.settings.pingFm.getSelectedServices()
},
function(response)
{
tm.tools.closeModal();
if (response.error != 'OK')
{
tm.schedule.openEditDialog(tm.schedule.editingIdx);
alert(response.error);
}
else
{
tm.schedule.loadedItems[tm.schedule.editingIdx].tweet = tm.schedule.curTweet;
$('#schTweet'+tm.schedule.loadedItems[tm.schedule.editingIdx].schedule_id).text(tm.schedule.curTweet);
tm.schedule.curTweet = false;
}
}
);
},100);
}
}
};
tm.settings =
{
loadedSettings : false,
selectedOption : 'settingsInfo',
list :
{
amAdding : false,
editingThisList : false,
amSavingEdit : false,
amDeleting : false,
addNew : function(event)
{
tm.settings.list.unHighlightLists();
$('#settings .manage-lists .list-container .list-edit').html
(
tm.templates.settings.newList()
);
},
addNewSave : function()
{
if ( tm.settings.list.amAdding == true )
{
return;
}
alert(s[78]);
tm.settings.list.amAdding = true;
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/list-create-new',
'listName' : $('#edit-list-name').val(),
'listDesc' : $('#edit-list-desc').val(),
'listType' : $('#is-public-list').is(':checked') ? 'public' : 'private'
},
function(response)
{
tm.settings.list.amAdding = false;
tm.tools.closeModal();
if (response.error != 'OK')
{
alert(response.error);
}
else
{
alert(s[79]);
tm.twitter.myLists = false;
tm.nav.go('settings');
setTimeout(function(){tm.tools.closeModal()},1000);
}
}
);
},100);
},
edit : function(internalListID,event)
{
tm.tools.stopEvent(event);
tm.settings.list.editingThisList = internalListID;
tm.settings.list.showInfo(internalListID,true);
},
editSave : function()
{
if ( tm.settings.list.amSavingEdit == true )
{
return;
}
alert(s[80]);
tm.settings.list.amSavingEdit = true;
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/list-edit',
'curListName' : tm.twitter.myLists[tm.settings.list.editingThisList],
'newListName' : $('#edit-list-name').val(),
'newDesc' : $('#edit-list-desc').val(),
'newMode' : $('#is-public-list').is(':checked') ? 'public' : 'private'
},
function(response)
{
tm.settings.list.amSavingEdit = false;
tm.tools.closeModal();
if (response.error != 'OK')
{
alert(response.error);
}
else
{
alert(s[79]);
tm.twitter.myLists = false;
tm.nav.go('settings');
setTimeout(function(){tm.tools.closeModal()},1000);
}
}
);
},100);
},
deleteList : function(internalListID,event)
{
tm.tools.stopEvent(event);
tm.prompt
(
s[81],
"tm.settings.list.deleteForReal('"+internalListID+"')"
);
},
deleteForReal : function(internalListID)
{
if ( tm.settings.list.amDeleting == true )
{
return;
}
tm.settings.list.amDeleting = true;
tm.tools.closeModal();
alert(s[82]);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/list-delete',
'listName' : tm.twitter.myLists[internalListID]
},
function(response)
{
tm.settings.list.amDeleting = false;
tm.tools.closeModal();
if (response.error != 'OK')
{
alert(response.error);
}
else
{
alert(s[83]);
tm.twitter.myLists = false;
tm.nav.go('settings');
setTimeout(function(){tm.tools.closeModal()},1000);
}
}
);
},100);
},
showInfo : function(internalListID,inEditMode)
{
if ( tm.twitter.myLists[internalListID] === undefined )
{
$('#settings .manage-lists .list-container .list-edit').html('
'+s[84]+'
');
return;
}
$('#settings .manage-lists .list-container .list-edit').html('
');
tm.settings.list.unHighlightLists();
tm.settings.list.highlightList(internalListID);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/list-get',
'listName' : tm.twitter.myLists[internalListID]
},
function(response)
{
// Spoof response
// response = {"error":"OK","limits":{"remaining":2999},"listInfo":{"mode":"public","description":"","uri":"\/justinvincent\/tweetminers","member_count":4,"slug":"tweetminers","subscriber_count":1,"full_name":"@justinvincent\/tweetminers","user":{"description":"Web Developer. ezSQL Author. Tech. Podcaster. http:\/\/pluggio.com http:\/\/techzinglive.com","notifications":false,"favourites_count":8,"profile_sidebar_fill_color":"F0EAE4","verified":false,"geo_enabled":false,"time_zone":"London","profile_sidebar_border_color":"D2BAA5","following":false,"profile_text_color":"1D7996","profile_background_image_url":"http:\/\/a1.twimg.com\/profile_background_images\/2789754\/gold.jpg","protected":false,"url":"http:\/\/pluggio.com","profile_link_color":"1D7996","followers_count":4636,"profile_image_url":"http:\/\/a3.twimg.com\/profile_images\/181645579\/IMG_0293_normal.jpg","location":"Los Angeles","name":"Justin Vincent","statuses_count":3882,"profile_background_tile":true,"id":14626880,"utc_offset":0,"created_at":"Fri May 02 15:22:47 +0000 2008","friends_count":3407,"profile_background_color":"7B4A20","screen_name":"justinvincent"},"name":"tweetminers","id":4244550}};
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( inEditMode === undefined )
{
$('#settings .manage-lists .list-container .list-edit').html
(
tm.templates.settings.listInfo(response.listInfo)
);
}
else
{
$('#settings .manage-lists .list-container .list-edit').html
(
tm.templates.settings.editList(response.listInfo)
);
}
}
}
);
},100);
},
highlightList : function(internalListID)
{
$('#list-select-'+internalListID).addClass('now-viewing');
},
unHighlightLists : function()
{
$("#settings .manage-lists .list-container .list-scroller .item").removeClass('now-viewing');
}
},
selectOption : function(optionId)
{
tm.schedule.unHighlightOptions();
tm.schedule.highlightOption(optionId);
switch(optionId)
{
case 'settingsAutoAddPrefs':
tm.settings.selectSetting('autoAdd');
tm.settings.autoAdd.select('aaKeywords');
break;
case 'settingsAutoAddFilters':
tm.settings.selectSetting('autoAddFilters');
break;
case 'settingsTimezone':
tm.settings.selectSetting('timezone');
break;
case 'settingsRollingSchedule':
tm.settings.selectSetting('rollingSchedule');
break;
case 'settingsPingFm':
tm.settings.pingFm.loadSettingsScreen();
break;
case 'settingsBitly':
tm.settings.selectSetting('bitly');
break;
case 'settingsManageLists':
tm.settings.selectSetting('manageLists');
tm.settings.list.showInfo(0);
break;
case 'settingsInfo':;
default:;
tm.settings.selectSetting('info');
break;
}
},
pingFm :
{
loadSettingsScreen : function()
{
$('#cur-setting').html('
');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ping-fm-get-settings'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm = response.settings;
tm.settings.selectSetting('pingFm');
$('#post-to-panel .scroller').html(tm.templates.pingFm.tweetCheckBoxes());
}
}
);
},100);
},
connect : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'apiKey' : $('#api-key').val(),
'action' : 'ajax/ping-fm-connect'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.pingFm.loadSettingsScreen();
}
}
);
},100);
},
getSelectedServices : function()
{
var s = tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm;
var selectedServices = '';
// Because side panel and root is open at same time
var rootSelector = '';
if ( $('#settings').length > 0 )
{
rootSelector = '#settings ';
}
else if ( $('#tweet-bubble').length > 0 )
{
rootSelector = '#tweet-bubble ';
}
if ( s === false )
{
selectedServices = 'twitter,';
}
// If there is a dialog with checkboxes then get from that.
else if ( $(rootSelector+'#service_twitter').length > 0 )
{
// Work out which services have been selected as default
for ( service in s.services )
{
if ( $(rootSelector+'#service_'+service).is(':checked') )
{
selectedServices += service + ',';
}
}
}
// If not then take the value from memory
else
{
for ( service in s.services )
{
if ( s.services[service]['selected'] == true )
{
selectedServices += service + ',';
}
}
}
return selectedServices;
},
saveSettings : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'defaultServices' : tm.settings.pingFm.getSelectedServices('#settings'),
'action' : 'ajax/ping-fm-save-settings'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.pingFm.loadSettingsScreen();
}
}
);
},100);
},
unConnect : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ping-fm-unconnect'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.pingFm.loadSettingsScreen();
}
}
);
},100);
}
},
showNav : function(navOption)
{
$("#feeds .list").html
(
tm.templates.settingsNavOptions()
);
tm.settings.highlightOption(navOption);
},
highlightOption : function(optionId)
{
$('#'+optionId).addClass('selected');
},
unHighlightOptions : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
showFineTuneTimes : function()
{
if ( $('#fine-tune-times').hasClass('hide') )
{
$('#fine-tune-times').removeClass('hide');
}
else
{
$('#fine-tune-times').addClass('hide');
}
},
getSettings : function(navOption)
{
if ( tm.settings.gettingSettings === true )
{
return;
}
if ( tm.twitter.myLists === false )
{
tm.twitter.getMyLists();
}
if ( navOption === undefined )
{
navOption = tm.settings.selectedOption;
}
else
{
tm.settings.selectedOption = navOption;
}
tm.settings.showNav(navOption);
tm.settings.gettingSettings = true;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-settings'
},
function(response)
{
tm.settings.gettingSettings = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.loadedSettings = response.settings;
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
'
@'+tm.accounts.loadedAccounts[tm.accounts.selectedAccount].login+' '+s[85]+' '
);
// Open the settings home
$("#feed-content .list").html
(
tm.templates.settings.home()
);
tm.settings.selectSetting('info');
}
}
);
},100);
},
selectSetting : function(settingTemplate)
{
if ( settingTemplate == 'bitly' && ! tm.canUseBitly )
{
alert(s[86]);
return;
}
$("#cur-setting").html
(
tm.templates.settings[settingTemplate]()
);
},
saveBitly : function()
{
alert('Saving...');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'bitlyLogin' : $('#bitly-login').val(),
'bitlyApiKey' : $('#bitly-api-key').val(),
'useMyBitly' : $('#use-my-bitly').attr('checked'),
'action' : 'ajax/save-bitly'
},
function(response)
{
if (response.error != 'OK')
{
tm.tools.closeModal();
alert(response.error);
}
else
{
tm.tools.closeModal();
alert(s[87]);
tm.settings.getSettings();
}
}
);
},100);
},
saveRolling : function()
{
alert(s[26]);
var parms =
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/save-rolling-prefs',
'post_every_n_mins' : $('#post-every').val(),
'rolling_pause' : $('#rolling_pause').attr('checked')
};
var days = ['mon','tue','wed','thu','fri','sat','sun'];
for ( i in days )
{
parms['rolling_'+days[i]] = $('#rolling_'+days[i]).attr('checked');
parms['tw_'+days[i]+'_on'] = $('#tw_'+days[i]+'_on').attr('checked');
parms['tw_'+days[i]+'_from'] = $('#tw_'+days[i]+'_from').val();
parms['tw_'+days[i]+'_from_ampm'] = $('#tw_'+days[i]+'_from_ampm').val();
parms['tw_'+days[i]+'_to'] = $('#tw_'+days[i]+'_to').val();
parms['tw_'+days[i]+'_to_ampm'] = $('#tw_'+days[i]+'_to_ampm').val();
}
setTimeout(function()
{
tm.ajax
(
parms,
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
alert(s[88]);
tm.settings.getSettings();
}
}
);
},100);
},
saveTimeZone : function()
{
alert(s[26]);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'timezone' : $('#timezone').val(),
'action' : 'ajax/save-tz-prefs'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
alert(s[89]);
tm.settings.getSettings();
}
}
);
},100);
}
};
tm.hints =
{
1 : s[34],
2 : s[35],
3 : s[36],
4 : s[37],
5 : s[38],
6 : s[39],
7 : s[40],
8 : s[41],
9 : s[42],
10 : s[43],
11 : s[44],
12 : s[45],
13 : s[46],
14 : s[47],
15 : s[48],
16 : s[49],
17 : s[50],
18 : s[51],
19 : s[52],
20 : s[53],
21 : s[54],
22 : s[55],
23 : s[56],
24 : s[57],
// Unused - but meakes it easy not to worry about closing ,
1000 : ""
};
$.fn.selectRange = function(start, end) {
return this.each(function() {
if(this.setSelectionRange) {
this.focus();
this.setSelectionRange(start, end);
} else if(this.createTextRange) {
var range = this.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
}
});
};
if ($.ui) {
$.widget('ui.toaster', {
_init: function(){
var self = this;
var wrapper = '#ui-toaster-'+ self.options.position;
if (!$(wrapper).get(0)) {
$('
').attr('id', 'ui-toaster-'+ self.options.position).appendTo('body');
}
self.toaster = $('
')
.append($('
'))
.append($('
').html($('
').append($(self.element).html())))
.append($('
'))
.width(self.options.width)
.hover(function(){ self.pause.apply(self)}, function(){ self.resume.apply(self)})
[(self.options.position.match(/bl|br/)) ? 'prependTo': 'appendTo'](wrapper);
// Closable
if (self.options.closable) {
self.toaster.addClass('ui-toaster-closable');
if ($(self.toaster).find('.ui-toaster-close').length > 0) {
$('.ui-toaster-close', $(self.toaster)).click(function(){ self.hide.apply(self); });
}
else {
$(self.toaster).click(function(){ self.hide.apply(self); });
}
}
// Sticky
if (self.options.sticky) {
$(self.toaster).addClass('ui-toaster-sticky');
}
else {
self.resume();
}
// Delay
if (!!self.options.delay) {
setTimeout(function(){
self.open.apply(self);
}, self.options.delay * 1000);
}
else {
self.open.apply(self);
}
},
open: function() {
this.options.show.apply(this.toaster);
},
hide: function(){
if (this.options.onHide) this.options.onHide.apply(this.toaster);
this.close(this.options.hide);
},
close: function(effect) {
var self = this;
var effect = effect || self.options.close;
if (self.options.onClose) {
effect.apply(self.toaster);
}
effect.apply(self.toaster, [self.options.speed, function(){
if (self.options.onClosed) self.options.onClosed.apply(self.toaster);
$(self.toaster).remove();
}]);
},
resume: function() {
var self = this;
self.timer = setTimeout(function(){
self.close.apply(self);
}, self.options.timeout * 1000 + self.options.delay * 1000);
},
pause: function() { clearTimeout(this.timer); }
});
$.ui.toaster.defaults = {
delay: 0, // delay before showing (seconds)
timeout: 3, // time before hiding (seconds)
width: 200, // toast width in pixel
position: 'br', // tl, tr, bl, br
speed: 'slow', // animations speed
closable: true, // allow user to close it
sticky: false, // show until user close it
onClose: false, // callback before closing
onClosed: false, // callback after closing
onOpen: false, // callback before opening
onOpened: false, // callback after opening
onHide: false, // callback when closed by user
show: $.fn.slideDown, // showing effect
hide: $.fn.fadeOut, // closing effect (by user)
close: $.fn.slideUp // hiding effect (timeout)
};
}