aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js
blob: bf9eadef2cf9a16a2c6445a4b973aa734fa84d8c (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *    jQuery tinydot 0.2.0
 *
 *    Copyright (c) Alexander Danilov
 *    modos189.ru
 *
 *    Plugin website:
 *    tinydot.modos189.ru
 *
 *    Licensed under the MIT license.
 *    http://en.wikipedia.org/wiki/MIT_License
 */

(function( $, undef )
{
    if ( $.fn.tinydot )
    {
            return;
    }

    $.fn.tinydot = function( o ) {
        
        var $dot = this;
        $dot.child = getChildOrDie($dot);
        $dot.orgContent = $($dot.child).html();
        ellipsis( $dot );

        $dot.watch = function()
        {
            $(window).on('resize', function(){
                if ( watchInt )
                {
                    clearInterval( watchInt );
                }
                watchInt = setTimeout(
                    function()
                    {
                        reinitialize($dot);
                    }, 100
                );
            });
            
            return $dot;
        };
    
        var opts = $.extend( true, {}, $.fn.tinydot.defaults, o ),
            watchInt = null;

        if ( opts.watch )
        {
            $dot.watch();
        }
    }
    
    // public
    $.fn.tinydot.defaults = {
        'watch'               : false
    };
    
    function getChildOrDie( $elem )
    {
        var childrens = $elem.children();
        if (childrens.length == 0) {
            // create children
            var data = $($elem).html();
            $elem.html('');
            $elem.append('<span />');
            return $elem.children('span').html(data);
        } else {
            return childrens[0];
        }
    }
    
    function reinitialize( $elem )
    {
        $($elem.child).html($elem.orgContent);
        ellipsis( $elem );
    }
    
    function ellipsis( $elem ) {
        var divh=$($elem).height();
        while ($($elem.child).outerHeight()>divh) {
            $($elem.child).html(function (index, html) {
                return html.replace(/\W*\s(\S)*$/, '...');
            });
        }
    }
    
})( jQuery );

jQuery(document).ready(function($) {
    //We only invoke jQuery.tinydot on elements that have dot-ellipsis class
    $(".dot-ellipsis").each(function(){
        //Checking if update on window resize required
        var watch_window=$(this).hasClass("dot-resize-update");

        //Invoking jQuery.tinydot
        var x = new Object();
        if (watch_window)
                x.watch='window';
        $(this).tinydot(x);
    });
});