Permalink
Browse files

new feature: status updates

  • Loading branch information...
Aleksandr Gornostal
Aleksandr Gornostal committed May 20, 2012
1 parent 34202e3 commit dd7a95c28574ae987ae9462cc03326a64585bc27
View
@@ -1,2 +1,3 @@
.idea
+nbproject
!.gitignore
View
@@ -16,6 +16,7 @@ a:hover {
a.external:visited {
color: #61C;
}
+
::-webkit-scrollbar {
width: 6px;
}
@@ -35,6 +36,7 @@ a.external:visited {
max-height: 550px;
overflow-x: hidden;
overflow-y: scroll;
+ position: relative;
}
.timeline .tweets {
@@ -153,7 +155,7 @@ a.external:visited {
text-decoration: none;
margin: 3px 0;
margin-right: 10px;
- cursor: url(../images/magnify.cur), pointer;
+ cursor: url(../img/magnify.cur), pointer;
}
.tweet a.media:hover {
-webkit-box-shadow: 1px 1px 3px 0px rgba(0, 0, 0, 0.5);
@@ -189,7 +191,7 @@ a.external:visited {
}
.tweet .rt_by i {
display: inline-block;
- background: url('../images/twitter_sprite.png') no-repeat -78px -4px;
+ background: url('../img/twitter_sprite.png') no-repeat -78px -4px;
width: 14px;
height: 8px;
}
@@ -217,7 +219,7 @@ a.external:visited {
display: block;
}
.tweet .actions .retweet {
- background: url('../images/twitter_sprite.png') no-repeat -78px 0;
+ background: url('../img/twitter_sprite.png') no-repeat -78px 0;
}
.tweet .actions .retweet:hover {
background-position: -94px 0;
@@ -230,7 +232,7 @@ a.external:visited {
display: block !important;
}
.tweet .actions .favorite {
- background: url('../images/twitter_sprite.png') no-repeat -30px 0;
+ background: url('../img/twitter_sprite.png') no-repeat -30px 0;
width: 15px;
height: 15px;
}
@@ -248,7 +250,7 @@ a.external:visited {
display: block !important;
}
.tweet .actions .delete{
- background: url('../images/twitter_sprite.png') no-repeat -125px 0;
+ background: url('../img/twitter_sprite.png') no-repeat -125px 0;
}
.tweet .actions .delete:hover {
background-position: -139px 0;
@@ -329,7 +331,7 @@ a.external:visited {
padding: 10px;
box-sizing: border-box;
color: #999;
- background: url(../images/ajax-loader.gif) 50% 50% no-repeat;
+ background: url(../img/ajax-loader.gif) 50% 50% no-repeat;
padding-top: 18px;
font-size: 13px;
}
@@ -368,4 +370,100 @@ body.sign-in .timeline {
}
body.sign-in .sign_in_with_twitter {
display: block !important;
-}
+}
+
+.new-tweet {
+ height: 0;
+ margin-top: -1px;
+ position: relative;
+ border-bottom: 1px solid rgba(0, 0, 0, 0.16);
+ box-shadow: 0 0 1px rgba(0, 0, 0, 0.18);
+ -webkit-transition: height 0.3s ease-out;
+ -moz-transition: height 0.3s ease-out;
+ transition: height 0.3s ease-out;
+ background: -moz-linear-gradient(top, rgba(0, 0, 0, 0.01) 0%, rgba(0, 0, 0, 0.05) 100%);
+ background: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.01) 0%, rgba(0, 0, 0, 0.05) 100%);
+}
+.new-tweet .padding {
+ padding: 10px;
+}
+.new-tweet .whats-happening {
+ padding-bottom: 5px;
+}
+.new-tweet.opened {
+ height: 110px;
+}
+.new-tweet .remain {
+ float: left;
+ margin-left: 5px;
+ margin-top: 12px;
+}
+.new-tweet.opened .new-tweet-toggle {
+ display: none;
+}
+.new-tweet .tweet-editor {
+ width: 355px;
+ height: 55px;
+ float: left;
+ resize: none;
+ margin-right: 5px;
+}
+.new-tweet .tweeting {
+ position: absolute;
+ display: none;
+ top: 60px;
+ left: 200px;
+ width: 16px;
+ height: 16px;
+ background: url(../img/tweeting.gif) no-repeat;
+}
+.new-tweet h4 {
+ float: left;
+}
+.new-tweet .flash-msg {
+ float: left;
+ display: block;
+ margin-left: 15px;
+ font-size: 13px;
+}
+.new-tweet .flash-msg.success {
+ color: #468847;
+}
+.new-tweet .flash-msg.error {
+ color: #B94A48;
+}
+.new-tweet .btn {
+ margin: 0 0 5px 5px;
+ width: 42px;
+}
+.new-tweet .inner {
+ overflow: hidden;
+ position: absolute;
+ top: 0;
+ right: 0;
+ left: 0;
+ bottom: 0;
+}
+.new-tweet-toggle {
+ z-index: 100;
+ position: absolute;
+ width: 16px;
+ height: 16px;
+ border-radius: 4px;
+ border: 1px solid #aaa;
+ border-top: none;
+ padding: 3px;
+ bottom: -22px;
+ right: 90px;
+ opacity: 0.4;
+ background: white;
+ box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.12);
+ -webkit-transition: all 0.3s ease-out;
+ -moz-transition: all 0.3s ease-out;
+ transition: all 0.3s ease-out;
+ outline: none !important;
+}
+.new-tweet-toggle:hover {
+ border-color: #444;
+ opacity: 0.8;
+}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Binary file not shown.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -63,6 +63,7 @@ define(['underscore', 'backbone'], function(_, Backbone){
},
destroyAll: function(){
+ this.data = {};
localStorage.removeItem(this.name);
}
View
@@ -11,7 +11,8 @@ require.config({
entities: 'twitter/entities',
streaming: 'twitter/streaming',
oauth: 'twitter/oauth',
- bootstrap: 'libs/twitter/bootstrap'
+ bootstrap: 'libs/twitter/bootstrap',
+ twitterText: 'twitter/text'
}
});
View
@@ -4,9 +4,9 @@ define([], function () {
var bgColor = bgColor || [225, 0, 0, 200],
icon = {
- normal: 'images/icon_19.png',
- unread: 'images/icon_19_unread.png',
- noauth: 'images/icon_19_noauth.png'
+ normal: 'img/icon_19.png',
+ unread: 'img/icon_19_unread.png',
+ noauth: 'img/icon_19_noauth.png'
};
chrome.browserAction.setBadgeBackgroundColor({color: bgColor});
View
@@ -51,6 +51,18 @@ define(['underscore', 'streaming'], function (_, TwitterStreaming) {
method: 'post',
success: callback
});
+ },
+ send: function (text, callback, error) {
+ oauth.sendRequest({
+ url: '1/statuses/update.json',
+ method: 'post',
+ params: {
+ status: text,
+ include_entities: true
+ },
+ success: callback,
+ error: error
+ });
}
};
};
View
@@ -141,6 +141,7 @@ define([
var sign = getSign(request);
$.ajax({
type: request.method,
+ dataType: 'json',
url: request.url,
timeout: request.timeout || 30e3,
data: request.params,
@@ -150,6 +151,10 @@ define([
dataType: request.dataType || 'json',
success: request.success,
error: function (xhr) {
+ if (typeof request.error == 'function') {
+ var response = JSON.parse(xhr.responseText);
+ request.error(response);
+ }
if (xhr.status == 401) {
$.publish('error.unauthorized');
}
View
@@ -0,0 +1,35 @@
+define(['underscore'], function (_) {
+
+ // replacement for urls
+ var urlReplacement = (function(){
+ var r=[];
+ for (var i = 0; i < 21; i++) {
+ r[i]='x';
+ }
+ return r.join('');
+ }());
+ urlReplacement = '$1' + urlReplacement;
+
+ // @todo: Improve regex. Now it gives evry inaccurate calculation
+ return function (text) {
+ var hasUrls = false,
+ maxLength = 140,
+ valid = false,
+ remain = maxLength,
+ regex = /(^|\s|\()(www\.[a-z0-9\-\.]+\.[a-z]+|http(s?):\/\/)[a-z0-9.\/\?\=\-\%\#|\(\)]+/ig;
+
+ text = text.replace(regex, urlReplacement);
+
+ remain -= text.length;
+ if (remain >= 0 && remain < maxLength) {
+ valid = true;
+ }
+
+ return {
+ length: text.length,
+ remain: remain,
+ valid: valid,
+ hasUrls: hasUrls
+ };
+ };
+});
View
@@ -9,8 +9,10 @@ define([
'oauth',
'modules/preprocessTweet',
'models/tweet',
- 'modules/lastReadTime'
-], function ($, _, Backbone, tweets, TweetView, Badge, TwitterApi, OAuth, preprocessTweet, Tweet, LastReadTime) {
+ 'modules/lastReadTime',
+ 'twitterText'
+], function ($, _, Backbone, tweets, TweetView, Badge, TwitterApi, OAuth,
+ preprocessTweet, Tweet, LastReadTime, twitterText) {
var oauth = new OAuth(),
twitter = new TwitterApi(oauth),
@@ -52,6 +54,8 @@ define([
badge.resetUnread();
}
});
+
+ this.initNewTweet();
new Badge().resetUnread();
new LastReadTime().set(Math.round(new Date().getTime() / 1000));
@@ -138,6 +142,91 @@ define([
method: 'authorize'
});
window.close();
+ },
+
+ initNewTweet: function () {
+ var $newTweet = $('.new-tweet'),
+ keyPressTimeout,
+ tweeting = false,
+ $tweeting = $newTweet.find('.tweeting'),
+ $send = $newTweet.find('.send'),
+ $remain = $newTweet.find('.remain'),
+ $tweetHolder = $('#home-timeline'),
+ $flashMsg = $newTweet.find('.flash-msg'),
+ $input = $newTweet.find('.tweet-editor');
+
+ $('.new-tweet-toggle')
+ .tooltip({placement: 'bottom'})
+ .click(function(){
+ $(this).tooltip('hide');
+ $newTweet.toggleClass('opened');
+ return false;
+ });
+ $newTweet.find('a.cancel').click(function(){
+ $newTweet.toggleClass('opened');
+ $flashMsg.hide();
+ return false;
+ });
+
+ var updateRemainNum = function () {
+ var text = twitterText($input.val());
+ $remain.text(text.remain);
+ if (text.valid) {
+ $send.removeClass('disabled');
+ } else {
+ $send.addClass('disabled');
+ }
+ };
+
+ var flashMessage = function (message, isError) {
+ $flashMsg
+ .removeClass('success error')
+ .text(message)
+ .addClass(isError ? 'error' : 'success')
+ .fadeIn(100);
+ setTimeout(function(){
+ $flashMsg.fadeOut(100);
+ }, 15e3);
+ }
+
+ var enableInputs = function () {
+ $send.removeClass('disabled');
+ tweeting = false;
+ $tweeting.hide();
+ $input.prop('disabled', false);
+ };
+
+ var success = function (resp) {
+ enableInputs();
+ flashMessage('Sent');
+ $input.val('');
+ updateRemainNum();
+ var tweet = new Tweet(preprocessTweet(resp)),
+ view = new TweetView({model: tweet});
+ $tweetHolder.prepend(view.render().el);
+ };
+
+ var error = function (resp) {
+ enableInputs();
+ flashMessage('Error: ' + resp.error, true);
+ };
+
+ $send.click(function(){
+ var text = twitterText($input.val());
+ if (text.valid && !tweeting) {
+ $send.addClass('disabled');
+ tweeting = true;
+ $tweeting.show();
+ $input.prop('disabled', true);
+ twitter.send($input.val(), success, error);
+ }
+ return false;
+ });
+
+ $input.bind('keyup', function(){
+ clearTimeout(keyPressTimeout);
+ keyPressTimeout = setTimeout(updateRemainNum, 100);
+ });
}
});
Oops, something went wrong.

0 comments on commit dd7a95c

Please sign in to comment.