jQuery URL shortener

Hi y’all,

My first jQuery plugin. Your welcome to use it (including commerical), re-code it and provide suggestions, please just keep reference to myself and to Uzbekjon.

It uses the http://bit.ly API so you’ll need your own account and API key. The code format is based on Mike Alsup’s Plugin Development Pattern.

Download/fork from Github: https://github.com/Kwozzie/jquery-url-shortener

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* jQuery Bit.Ly Shorten Url Plugin
* 2010 Justin Swan
* License: Creative Commons Attribution-Share Alike 3.0 Australia Licence
* Original Author: Uzbekjon (http://jquery-howto.blogspot.com/2009/04/shorten-long-urls-with-jquery-bitly.html)
* Version: 1.0.0
*
* Grateful for any feedback on improvements.
*
* Call: $(input field).shorten_url(long url)
* Returns: shortened url as value for input field.
*
*/
 
//
// start closure
//
(function($){
$.fn.shorten_url = function(url,options){
// Extend our default options with those provided.
var opts = $.extend($.fn.shorten_url.defaults, options);
 
return this.each(function(){
$this = $(this);
 
// format url to request
var daurl = "http://api.bit.ly/shorten?"
+"version="+opts.version
+"&longUrl="+url
+"&login="+opts.login
+"&apiKey="+opts.apiKey
+"&history="+opts.history
+"&format=json&callback=?";
 
// Utilize the bit.ly API
$.getJSON(daurl, function(data){
// Make a good use of short URL
$this.val(data.results[url].shortUrl);
});
});
};
 
$.fn.shorten_url.defaults = {
version: '2.0.1',
login: 'bitlyapidemo', // your bit.ly account login
apiKey: 'R_0da49e0a9118ff35f52f629d2d71bf07', // your api key here
history: '0',
};
//
// end of closure
//
})(jQuery);

 

Thunderbird – RSS showing snippet rather than html page

Having image/html troubles with Thunderbird? RSS account showing brief description instead of the full html web page? This may not be the only solution but it was the one I discovered worked for me and was from my own actions that caused it.

Did you happen to change your email settings to display messages as simple HTML at some stage? If so, turn it back to Original HTML. Hey presto! Thunderbird’s RSS reader displays the full web page again and also, displays images in your email again.

For more information, see http://kb.mozillazine.org/Images_in_messages_do_not_appear

jQuery email obfuscation

Was looking for a way to hide or obfuscate email addresses from spam bots and found this Google groups page which was pretty much what I was after for a solution, however this plugin isn’t quite complete. Javascripts .replace only works once, normally, so an email address with multiple ‘ DOT ‘ s will not deobfuscate correctly.

A quick Google later… here’s my solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
jQuery.fn.deobfuscate = function()
{
return this.each(function()
{
var content = $(this).text();</code>
 
/* grab the part inside the braces, swap out placeholders, and trim
*/
var obfuscated = content.match(/\[(.*)\]/);
/*
for(var i=0;i<obfuscated.length();i++){
alert(obfuscated[i]);
}
*/
var address = obfuscated[1]
.replace(' AT ', '@')
.replace(new RegExp(' DOT ', 'g'), '.')
.replace(/^\s+|\s+$/g, '');
 
/* get everything before the braces and trim
*/
var text = content.match(/.?[^[]+/);
 
text = (text[0] != content)
? text[0].replace(/^\s+|\s+$/g, '')
: address;      // if there's no text part, use the address
 
var title = $(this).attr('title') || '';
 
$(this).replaceWith($('<a href="mailto:' + address + '" title="' +
title + '">' + text + '</a>'));
});
 
};

note the second .replace now contains a new Regex() command which looks for all occurrances of ‘ DOT ‘. Works a treat.

Flash CS4 unexpectedly quits

What a pain in the arse this was… reinstalled CS4 design premium twice to try and resolve but everytime I opened up an Adobe CS3 or CS4 file the Flash would unexpectedly quit. If I tried opening Flash CS4 first then opening the file, Flash would just hang and become non responsive.

It turns out the solution is quite simple, but perhaps time consuming. After reading http://jobemakar.wordpress.com/2008/10/18/how-to-crash-flash-cs4-with-a-single-click/ I attempted the suggested fix of looking for corrupt fonts. Actually, I skipped the looking part and removed all the fonts from my fonts folder that Windows would allow me, then added the fonts from a work mates PC. All working happily now, the migration from CS3 to CS4 is complete.

Litecommerce breaks with new Google Analytics code

Google have updated their Analytics code again, this time adding a javascript try statement to prevent Javascript errors being displayed in the browser. This is a good thing, however, as provided by Google, this new code breaks the LiteCommerce template parser. The only solution I currently have is to wrap the Javascript statements in html comments. I had tried wrapping the Google Stats code with the CDATA method but this still breaks the LiteCommerce template parser as well (see http://javascript.about.com/library/blxhtml.htm for Javascript validation fixes).

Here is my current solution (in skins/default/main.tpl) where ****** is your Google Analytics account number and ** is your site number:

1
2
3
4
5
6
7
8
9
10
<span style="color: #0000ff;"><script type="text/javascript">// <![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]></script>
<script type="text/javascript">// <![CDATA[
try{
var pageTracker = _gat._getTracker("UA-******-**");
pageTracker._trackPageview();
} catch(err) {}
// ]]></script></span>