aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js
diff options
context:
space:
mode:
authorAlexandr Danilov <bitbucket@modos189.ru>2016-08-25 16:22:47 +0300
committerAlexandr Danilov <bitbucket@modos189.ru>2016-08-25 16:22:47 +0300
commit538587855a72be5b49962132b976816295a05ebc (patch)
tree33430bddcc460f1fa80865b86615461f705368a2 /src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js
parent5aba43d92c6b9fafb589420496737594ca3f3f1f (diff)
downloadwallabag-538587855a72be5b49962132b976816295a05ebc.tar.gz
wallabag-538587855a72be5b49962132b976816295a05ebc.tar.zst
wallabag-538587855a72be5b49962132b976816295a05ebc.zip
A new version of the plugin tinydot with update on window resize
Diffstat (limited to 'src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js')
-rw-r--r--src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js94
1 files changed, 79 insertions, 15 deletions
diff --git a/src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js b/src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js
index d2bf7fb6..bf9eadef 100644
--- a/src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js
+++ b/src/Wallabag/CoreBundle/Resources/public/themes/material/js/jquery.tinydot.js
@@ -1,14 +1,14 @@
1/* 1/*
2 * jQuery tinydot 0.1 2 * jQuery tinydot 0.2.0
3 * 3 *
4 * Copyright (c) Alexander Danilov 4 * Copyright (c) Alexander Danilov
5 * www.modos189.ru 5 * modos189.ru
6 * 6 *
7 * Plugin repository: 7 * Plugin website:
8 * https://gitlab.com/modos189/tinydot 8 * tinydot.modos189.ru
9 * 9 *
10 * Licensed under the MIT license. 10 * Licensed under the MIT license.
11 * http://en.wikipedia.org/wiki/MIT_License 11 * http://en.wikipedia.org/wiki/MIT_License
12 */ 12 */
13 13
14(function( $, undef ) 14(function( $, undef )
@@ -19,21 +19,85 @@
19 } 19 }
20 20
21 $.fn.tinydot = function( o ) { 21 $.fn.tinydot = function( o ) {
22 var p=$(this).children('a'); 22
23 var divh=$(this).height(); 23 var $dot = this;
24 while ($(p).outerHeight()>divh) { 24 $dot.child = getChildOrDie($dot);
25 $(p).text(function (index, text) { 25 $dot.orgContent = $($dot.child).html();
26 return text.replace(/\W*\s(\S)*$/, '...'); 26 ellipsis( $dot );
27
28 $dot.watch = function()
29 {
30 $(window).on('resize', function(){
31 if ( watchInt )
32 {
33 clearInterval( watchInt );
34 }
35 watchInt = setTimeout(
36 function()
37 {
38 reinitialize($dot);
39 }, 100
40 );
27 }); 41 });
42
43 return $dot;
44 };
45
46 var opts = $.extend( true, {}, $.fn.tinydot.defaults, o ),
47 watchInt = null;
48
49 if ( opts.watch )
50 {
51 $dot.watch();
28 } 52 }
29 } 53 }
54
55 // public
56 $.fn.tinydot.defaults = {
57 'watch' : false
58 };
59
60 function getChildOrDie( $elem )
61 {
62 var childrens = $elem.children();
63 if (childrens.length == 0) {
64 // create children
65 var data = $($elem).html();
66 $elem.html('');
67 $elem.append('<span />');
68 return $elem.children('span').html(data);
69 } else {
70 return childrens[0];
71 }
72 }
73
74 function reinitialize( $elem )
75 {
76 $($elem.child).html($elem.orgContent);
77 ellipsis( $elem );
78 }
79
80 function ellipsis( $elem ) {
81 var divh=$($elem).height();
82 while ($($elem.child).outerHeight()>divh) {
83 $($elem.child).html(function (index, html) {
84 return html.replace(/\W*\s(\S)*$/, '...');
85 });
86 }
87 }
88
30})( jQuery ); 89})( jQuery );
31 90
32jQuery(document).ready(function($) { 91jQuery(document).ready(function($) {
33 //We only invoke jQuery.tinydot on elements that have dot-ellipsis class 92 //We only invoke jQuery.tinydot on elements that have dot-ellipsis class
34 $(".dot-ellipsis").each(function(){ 93 $(".dot-ellipsis").each(function(){
35 var x = new Object(); 94 //Checking if update on window resize required
36 $(this).tinydot(x); 95 var watch_window=$(this).hasClass("dot-resize-update");
96
97 //Invoking jQuery.tinydot
98 var x = new Object();
99 if (watch_window)
100 x.watch='window';
101 $(this).tinydot(x);
37 }); 102 });
38
39}); 103});