--- a/web/client.php Thu Jan 10 18:53:10 2019 +0100
+++ b/web/client.php Fri Jan 11 01:19:45 2019 +0100
@@ -96,6 +96,7 @@
<script type="text/javascript" src="<?php echo(registry_url('underscore','js'))?>"></script>
<script type="text/javascript" src="<?php echo(registry_url('raphael','js'))?>"></script>
<script type="text/javascript" src="<?php echo(registry_url('fancybox','js'))?>"></script>
+ <script type="text/javascript" src="<?php echo(registry_url('twitter-text','js'))?>"></script>
<?php if( isset($config['additional_js']) && !empty($config['additional_js'])) {
foreach ($config['additional_js'] as $jsUrl) {?>
<script type="text/javascript" src="<?php echo($jsUrl)?>"></script>
@@ -181,16 +182,17 @@
const TWEET_LENGTH = <?php echo(TWEET_LENGTH)?>;
function updateCounter() {
var _v = $("#status").val();
- if (_v.length > TWEET_LENGTH) {
- _v = _v.substr(0,TWEET_LENGTH);
- $("#status").val(_v);
- }
- $('#tweetCounter').html(TWEET_LENGTH-_v.length);
- if(TWEET_LENGTH-_v.length < 0) {
+ var _tRes = twttr.txt.parseTweet(_v);
+ if(_tRes.valid) {
+ $('#tweetCounter').removeClass("tweetCounterNegative");
+ $('#sendTweet').prop("disabled",false);
+ $('#sendTweet').removeClass("sendTweetDisabled");
+ $('#tweetCounter').html("");
+ } else {
$('#tweetCounter').addClass("tweetCounterNegative");
- }
- else {
- $('#tweetCounter').removeClass("tweetCounterNegative");
+ $('#sendTweet').prop("disabled",true);
+ $('#sendTweet').addClass("sendTweetDisabled");
+ $('#tweetCounter').html(_tRes.validRangeEnd - _tRes.displayRangeEnd);
}
$(".tweetButton").each(function(_i, _e) {
if (_v.search($(_e).find('span.twbSyntax').text().replace(/(\W)/g, '\\$1')) > -1) {
@@ -200,6 +202,7 @@
}
});
}
+ updateCounter();
// BUTTONS
$(".tweetButton").click(function() {
@@ -208,7 +211,10 @@
})
// SEND TWEETS
- $("#sendTweet").click(function(){
+ $("#sendTweet").click(function(e){
+ if($('#sendTweet').prop('disabled')) {
+ return;
+ }
var MyStatus = $('#status').val();
$.post('tweet_ajax.php', {status:MyStatus}
,function(data) {