Report abuse

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
53
54
55
56
57
58
59
60
61
var MinURL = function()
{
    var _host = (('https:' == document.location.protocol) ? 'https://': 'http://') + 'minurl.fr.s3.amazonaws.com';
    var _config = {
          img: _host + '/twitter.gif'
        , target: 'minurl_lien'
        , id: 'minurl_twitter'
        , alt: 'Envoyer sur Twitter'
        , title: 'Envoyer un lien vers Twitter'
    };
    var _target, _pub = {};

    function _isObj(o)
    {
        return (typeof o === 'object' && typeof o.splice !== 'function');
    }; // _isObj

    function _html2Dom(html)
    {
        var frag = document.createDocumentFragment(),
            tmp  = document.createElement('div');
        tmp.innerHTML = html;
        while (tmp.firstChild)
        {
            frag.appendChild(tmp.firstChild);
        }

        return frag;
    }; // _html2Dom

    function _setOptions(o)
    {
        for (var i in o)
        {
            _config[i] = o[i];
        }
    }; // _setOptions

    function _init(o)
    {
        _setOptions(o);
        _target = document.getElementById(_config.target);
        if (!_target)
        {
            throw new Error('Target not found!');
        }
    }; // init

    _pub.run = function(o)
    {
        var o = (_isObj(o)) ? o : {}, link;
        _init(o);
        link = _html2Dom('<a id="' + _config.id + '" title="' + _config.title + '" href="http://minurl.fr/?twitter&amp;url='
                + encodeURIComponent(location.href)
                + '&amp;titrelien=' + encodeURIComponent(document.title)
                + '"><img src="' + _config.img + '" alt="' + _config.alt + '"/></a>');
        _target.appendChild(link);
    }; // run

    return _pub;
}();