Plugin Directory

Changeset 1043092


Ignore:
Timestamp:
12/11/2014 11:19:44 PM (11 years ago)
Author:
ramsaylanier
Message:

Fixed issue with length of generate tweet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • verbatim/trunk/js/verbatim.js

    r1042882 r1043092  
    1313        var withTwitter = false,
    1414            twitterScriptAdded = false;
     15        var longURL, textURL;
    1516
    1617        var isFirefox = /Firefox/.test(navigator.userAgent);
     
    6667            }
    6768
    68             if (settings.defaultStyling){
    69                 $('.' + settings.highlightedClass).css({
    70                     "background-color": settings.highlightColor
    71                 });
    72             }
     69            // if (settings.defaultStyling){
     70            // $('.' + settings.highlightedClass).css({
     71            //      "background-color": settings.highlightColor
     72            // });
     73            // }
    7374        }
    7475
     
    146147            $('.verbatim-text-area').remove();
    147148
    148             var textURL = selectedText;
    149             var longURL = window.location.origin + window.location.pathname + '#' + encodeURIComponent(textURL);
    150             var twitterURL = window.location.origin + window.location.pathname + '#' + textURL;
    151 
     149            textURL = selectedText;
     150            longURL = window.location.origin + window.location.pathname + '#' + encodeURIComponent(textURL);
     151
     152            if (settings.bitlyToken){
     153                $.getJSON(
     154                    "https://api-ssl.bitly.com/v3/shorten?",
     155                    {
     156                        "access_token": settings.bitlyToken,
     157                        "longUrl": longURL
     158                    },
     159                    function(response)
     160                    {
     161                        if (response.status_code == 200){
     162                            longURL = response.data.url;
     163                            self.generateLink();
     164                        }
     165                    }
     166                );
     167            } else {
     168                longURL = window.location.origin + window.location.pathname + '#' + encodeURIComponent(textURL);
     169                self.generateLink();
     170            }
     171        }
     172
     173        $.fn.generateLink = function(){
    152174            if (withTwitter){
     175                if (textURL.length > 112){
     176                    textURL = textURL.substring(0, 112) + '...';
     177                }
     178
     179                textURL = "\"" + textURL + "\"";
    153180                var twitterLink = document.createElement('a');
    154181                twitterLink.href='https://twitter.com/intent/tweet?url=' + encodeURIComponent(longURL) + '&text=' + encodeURIComponent(textURL);
     
    159186
    160187                textArea.setAttribute("class", "verbatim-text-area");
    161 
    162                 if (settings.defaultStyling){
    163                     textArea.setAttribute("wrap", "off");
    164                 }
     188                textArea.setAttribute("wrap", "off");
     189
    165190                $('.' + settings.buttonClass).append(textArea);
    166191
    167                 if (settings.bitlyToken){
    168                     $.getJSON(
    169                         "https://api-ssl.bitly.com/v3/shorten?",
    170                         {
    171                             "access_token": settings.bitlyToken,
    172                             "longUrl": longURL
    173                         },
    174                         function(response)
    175                         {
    176                             if (response.status_code == 200){
    177                                 longURL = response.data.url;
    178                                 $('.verbatim-text-area').val(longURL); 
    179                                 textArea.select();
    180                             }
    181                         }
    182                     );
    183                 } else{
    184                     $('.verbatim-text-area').val(longURL);
    185                     textArea.select();
    186                 }
     192                $('.verbatim-text-area').val(longURL);
     193                textArea.select();
    187194            }
    188195        }
Note: See TracChangeset for help on using the changeset viewer.