[Pkg-javascript-commits] [libjs-jquery-dotdotdot] 01/03: Imported Upstream version 1.8.3

Sergio Durigan Junior sergiodj-guest at moszumanska.debian.org
Thu Aug 11 02:12:07 UTC 2016


This is an automated email from the git hooks/post-receive script.

sergiodj-guest pushed a commit to branch master
in repository libjs-jquery-dotdotdot.

commit 76603f39c2b734207ae1ca53de4602d82fdd3b7e
Author: Sergio Durigan Junior <sergiodj at sergiodj.net>
Date:   Tue Aug 9 20:38:56 2016 -0400

    Imported Upstream version 1.8.3
---
 .gitignore              |   9 +
 LICENSE.txt             |   9 +
 README.md               |  93 ++++++
 bower.json              |  29 ++
 dotdotdot.jquery.json   |  18 ++
 gulpfile.js             |  46 +++
 index.html              | 285 ++++++++++++++++++
 package.json            |  21 ++
 src/jquery.dotdotdot.js | 759 ++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 1269 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6defad6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+# Ignore Mac system files.
+._*
+
+# Ignore sass-cache files.
+*.sass-cache*
+*.scssc
+
+# Ignore Gulp modules
+node_modules
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..771a561
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,9 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Fred Heusschen
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5feb4e3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,93 @@
+jQuery.dotdotdot
+================
+
+A jQuery plugin for advanced cross-browser ellipsis on multiple line content.<br />
+Demo's and documentation: http://dotdotdot.frebsite.nl
+
+*Note:*<br />
+Because its performance can not be improved, this plugin is no longer actively maintained.<br />
+Feel free to use it and submit pull requests though.
+
+
+<img src="http://dotdotdot.frebsite.nl/img/preview.png" width="100%" border="0" />
+
+
+## How to use the plugin
+### Integration to your page
+
+Include all necessary .js-files inside the head-tag of the page.
+
+```html
+<head>
+    <script src="jquery.js" type="text/javascript"></script>
+    <script src="jquery.dotdotdot.js" type="text/javascript"></script>
+</head>
+```
+
+Then you can use either CSS or JS approach or use them both.
+
+### CSS approach
+You can add one or several CSS classes to HTML elements to automatically invoke "jQuery.dotdotdot functionality" and some extra features. It allows to use jQuery.dotdotdot only by adding appropriate CSS classes without JS programming.
+
+Available classes and their description:
+* dot-ellipsis - automatically invoke jQuery.dotdotdot to this element. This class must be included if you plan to use other classes below.
+* dot-resize-update - automatically update if window resize event occurs. It's equivalent to option `watch:'window'`.
+* dot-timer-update - automatically update if window resize event occurs. It's equivalent to option `watch:true`.
+* dot-load-update - automatically update after the window has beem completely rendered. Can be useful if your content is generated dynamically using JS and, hence, jQuery.dotdotdot can't correctly detect the height of the element before it's rendered completely.
+* dot-height-XXX - available height of content area in pixels, where XXX is a number, e.g. can be `dot-height-35` if you want to set maximum height for 35 pixels. It's equivalent to option `height:'XXX'`.
+
+*Examples*
+
+Adding jQuery.dotdotdot to element:
+
+```html
+<div class="dot-ellipsis">
+	<p>Lorem Ipsum is simply dummy text.</p>
+</div>
+```
+	
+Adding jQuery.dotdotdot to element with update on window resize:
+    
+```html
+<div class="dot-ellipsis dot-resize-update">
+	<p>Lorem Ipsum is simply dummy text.</p>
+</div>
+```
+	
+Adding jQuery.dotdotdot to element with predefined height of 50px:
+    
+```html
+<div class="dot-ellipsis dot-height-50">
+	<p>Lorem Ipsum is simply dummy text.</p>
+</div>
+```
+
+## Javascript approach
+Create a DOM element and put some text and other HTML markup in this "wrapper".
+
+```html
+<div id="wrapper">
+    <p>Lorem Ipsum is simply dummy text.</p>
+</div>
+```
+
+Fire the plugin onDocumentReady using the wrapper-selector.
+
+```javascript
+$(document).ready(function() {
+    $("#wrapper").dotdotdot({
+        // configuration goes here
+    });
+});
+```
+
+### Authors and Contributors
+* [Fred Heusschen](https://github.com/FrDH) is the author of the jQuery.dotdotdot
+* [Ramil Valitov](https://github.com/rvalitov) added the "CSS approach" functionality
+
+### More info
+Please visit http://dotdotdot.frebsite.nl
+
+### Licence
+The jQuery.dotdotdot plugin is licensed under the MIT license:
+http://en.wikipedia.org/wiki/MIT_License
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..b463000
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,29 @@
+{
+  "name": "jQuery.dotdotdot",
+  "main": "src/jquery.dotdotdot.min.umd.js",
+  "version": "1.8.3",
+  "homepage": "http://dotdotdot.frebsite.nl/",
+  "authors": [
+    "Fred Heusschen <info at frebsite.nl>"
+  ],
+  "description": "A jQuery plugin for advanced cross-browser ellipsis on multiple line content.",
+  "keywords": [
+    "ellipsis",
+    "dotdotdot",
+    "multiline",
+    "text",
+    "text-overflow",
+    "overflow",
+    "dots"
+  ],
+  "ignore": [
+    ".jshintrc",
+    "Guardfile",
+    "index.html",
+    "*.json",
+    "README.md"
+  ],
+  "dependencies": {
+    "jquery": ">= 1.4.3"
+  }
+}
diff --git a/dotdotdot.jquery.json b/dotdotdot.jquery.json
new file mode 100644
index 0000000..f3b46de
--- /dev/null
+++ b/dotdotdot.jquery.json
@@ -0,0 +1,18 @@
+{
+	"name": "dotdotdot",
+	"version": "1.8.3",
+	"title": "jQuery dotdotdot",
+	"description": "A jQuery plugin for advanced cross-browser ellipsis on multiple line content.",
+	"homepage": "http://dotdotdot.frebsite.nl",
+	"author": {
+		"name": "Fred Heusschen",
+		"url": "http://www.frebsite.nl"
+	},
+	"licenses": [{
+		"type": "MIT",
+		"url": "http://opensource.org/licenses/MIT"
+	}],
+	"dependencies": {
+		"jquery": ">= 1.4.3"
+	}
+}
diff --git a/gulpfile.js b/gulpfile.js
new file mode 100644
index 0000000..a22ebec
--- /dev/null
+++ b/gulpfile.js
@@ -0,0 +1,46 @@
+// npm install gulp-uglify gulp-rename gulp-umd --save-dev
+
+var gulp 			= require( 'gulp' ),
+	uglify 			= require( 'gulp-uglify' ),
+	rename 			= require( 'gulp-rename' ),
+	umd				= require( 'gulp-umd' );
+
+
+
+//	Default task 'gulp': Runs JS tasks
+gulp.task( 'default', function() {
+    gulp.start( 'js' );
+});
+
+
+
+//	Watch task 'gulp watch': Starts a watch on JS tasks
+gulp.task( 'watch', function() {
+  gulp.watch( 'src/*.js', [ 'js' ] );
+});
+
+
+
+//	JS task 'gulp js': Runs all JS tasks
+gulp.task( 'js', function() {
+	return gulp.src( 'src/jquery.dotdotdot.js' )
+//		.pipe( jshint('.jshintrc') )
+//		.pipe( jshint.reporter( 'default' ) )
+		.pipe( uglify({ preserveComments: 'license' }) )
+		.pipe( rename({ suffix: '.min' }) )
+		.pipe( gulp.dest( 'src' ) )
+		.pipe( umd({
+			dependencies: function() { return [ 'jQuery' ]; },
+			exports: function() { return true; },
+			namespace: sanitizeNamespaceForUmd
+		}))
+		.pipe( rename({ suffix: '.umd' }) )
+		.pipe( gulp.dest( 'src' ) );
+});
+
+function sanitizeNamespaceForUmd( file ) {
+	path = file.path.split( '\\' ).join( '/' ).split( '/' );
+	path = path[ path.length - 1 ];
+	return path.split( '.' ).join( '_' );
+}
+
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..fb9f666
--- /dev/null
+++ b/index.html
@@ -0,0 +1,285 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
+		<meta name="author" content="www.frebsite.nl" />
+
+		<title>dotdotdot, advanced cross-browser ellipsis for multiple line content.</title>
+
+		<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
+		<script type="text/javascript" language="javascript" src="src/jquery.dotdotdot.js"></script>
+		<script type="text/javascript" language="javascript">
+			$(function() {
+				$('#dot1').dotdotdot();
+
+				$('#dot2').dotdotdot();
+
+				$('#dot3').dotdotdot({
+					after: 'a.readmore'
+				});
+
+				$('#dot4').dotdotdot({
+					watch: 'window'
+				});
+
+				var $dot5 = $('#dot5');
+				$dot5.append( ' <a class="toggle" href="#"><span class="open">[ + ]</span><span class="close">[ - ]</span></a>' );
+
+
+				function createDots()
+				{
+					$dot5.dotdotdot({
+						after: 'a.toggle'
+					});
+				}
+				function destroyDots() {
+					$dot5.trigger( 'destroy' );
+				}
+				createDots();
+
+				$dot5.on(
+					'click',
+					'a.toggle',
+					function() {
+						$dot5.toggleClass( 'opened' );
+
+						if ( $dot5.hasClass( 'opened' ) ) {
+							destroyDots();
+						} else {
+							createDots();
+						}
+						return false;
+					}
+				);
+
+				$('#dot6 .pathname').each(function() {
+					var path = $(this).html().split( '/' );
+					if ( path.length > 1 ) {
+						var name = path.pop();
+						$(this).html( path.join( '/' ) + '<span class="filename">/' + name + '</span>' );
+						$(this).dotdotdot({
+							after: '.filename',
+							wrap: 'letter'
+						});						
+					}
+				});
+
+			});
+		</script>
+		<style type="text/css" media="all">
+			html, body {
+				padding: 0;
+				margin: 0;
+				height: 100%;
+			}
+			body, div, p {
+				font-family: Arial, Helvetica, Verdana;
+				color: #333;
+				-webkit-text-size-adjust: none;
+			}
+			body {
+				background-color: #f3f3f3;
+			}
+			a, a:link, a:active, a:visited {
+				color: black;
+				text-decoration: underline;
+			}
+			a:hover {
+				color: blue;
+			}
+
+
+			#wrapper {
+				background-color: #fff;
+				width: 600px;
+				padding: 50px 50px 0 50px;
+				margin: 0 auto;
+				border: 1px solid #ccc;
+				box-shadow: 0 0 5px #ccc;
+			}
+			#intro {
+				margin-bottom: 60px;
+			}
+			#intro p {
+				font-size: 18px;
+			}
+
+			div.example {
+				padding: 0 0 150px 0;
+			}
+			div.example:after {
+				content: '';
+				display: block;
+				clear: both;
+			}
+			div.example p {
+				margin: 0 0 10px 0;
+			}
+			div.l {
+				width: 275px;
+				float: left;
+			}
+			div.r {
+				width: 275px;
+				float: right;
+			}
+			
+			div.box {
+				border: 1px solid #ccc;
+				height: 160px;
+				padding: 15px 20px 10px 20px;
+/* 				overflow: hidden; */
+			}
+			div.resize {
+				padding-bottom: 250px;
+			}
+			div.resize div.box {
+				position: absolute;
+				width: 40%;
+				height: 100px;
+			}
+			div.resize div.box.before {
+				right: 50%;
+				margin-right: 10px;
+			}
+			div.resize div.box.after {
+				left: 50%;
+				margin-left: 10px;
+			}
+			div.box.opened
+			{
+				height: auto;
+			}
+			div.box .toggle .close,
+			div.box.opened .toggle .open
+			{
+				display: none;
+			}
+			div.box .toggle .opened,
+			div.box.opened .toggle .close
+			{
+				display: inline;
+			}
+			div.box.before {
+				background-color: #ffeeee;
+			}
+			div.box.after {
+				background-color: #eeffee;
+			}
+			p.before {
+				color: #990000;
+			}
+			p.after {
+				color: #006600;
+			}
+			div.box.pathname {
+				height: auto;
+			}
+			.pathname {
+				height: 25px;
+			}
+		</style>
+	</head>
+	<body>
+		<br />
+		<br />
+		<div id="wrapper">
+			<div id="intro">
+				<h1>jQuery.dotdotdot</h1>
+				<p>Advanced cross-browser ellipsis for multiple line content.<br />
+					Demo's and documentation: <a href="http://dotdotdot.frebsite.nl" target="_blank">dotdotdot.frebsite.nl</a></p>
+			</div>
+
+			<div class="example">
+				<p><strong>Text only:</strong></p>
+				<div class="l">
+					<p class="before">before:</p>
+					<div class="box before">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</div>
+				</div>
+				<div class="r">
+					<p class="after">after:</p>
+ 					<div class="box after" id="dot1">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</div>
+				</div>
+			</div>
+
+			<div class="example">
+				<p><strong>Text with markup:</strong></p>
+				<div class="l">
+					<p class="before">before:</p>
+					<div class="box before">
+						<p><em>Lorem Ipsum</em> is simply dummy text of the <strong>printing</strong> and <strong>typesetting industry</strong>.</p>
+						<p><em>Lorem Ipsum</em> has been the industry's standard dummy text ever since <strong>the 1500s</strong>, when an unknown printer took a <em>galley of type</em> and scrambled it to make a type specimen book.</p>
+						<p>It has survived not only <strong>five centuries</strong>, but also the leap into <strong>electronic typesetting</strong>.</p>
+					</div>
+				</div>
+				<div class="r">
+					<p class="after">after:</p>
+					<div class="box after" id="dot2">
+						<p><em>Lorem Ipsum</em> is simply dummy text of the <strong>printing</strong> and <strong>typesetting industry</strong>.</p>
+						<p><em>Lorem Ipsum</em> has been the industry's standard dummy text ever since <strong>the 1500s</strong>, when an unknown printer took a <em>galley of type</em> and scrambled it to make a type specimen book.</p>
+						<p>It has survived not only <strong>five centuries</strong>, but also the leap into <strong>electronic typesetting</strong>.</p>
+					</div>
+				</div>
+			</div>
+
+			<div class="example">
+				<p><strong>With an "after"-element:</strong></p>
+				<div class="l">
+					<p class="before">before:</p>
+					<div class="box before">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
+						<a href="#" class="readmore">Read more »</a></div>
+				</div>
+				<div class="r">
+					<p class="after">after:</p>
+					<div class="box after" id="dot3">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
+						<a href="#" class="readmore">Read more »</a></div>
+				</div>
+			</div>
+
+			<div class="example resize">
+				<p><strong>Updating onWindowResize:</strong></p>
+				<div class="l">
+					<p class="before">before:</p>
+					<div class="box before">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</div>
+				</div>
+				<div class="r">
+					<p class="after">after:</p>
+					<div class="box after" id="dot4">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</div>
+				</div>
+			</div>
+
+			<div class="example">
+				<p><strong>Toggle the full story</strong></p>
+				<div class="l">
+					<p class="before">before:</p>
+					<div class="box before">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</div>
+				</div>
+				<div class="r">
+					<p class="after">after:</p>
+					<div class="box after" id="dot5">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</div>
+				</div>
+			</div>
+
+			<div class="example">
+				<p><strong>Truncate readable pathnames</strong></p>
+				<div class="l">
+					<p class="before">before:</p>
+					<div class="box before pathname">
+						<div class="pathname">www.website.com/file.html</div>
+						<div class="pathname">www.website.com/with/a/long/pathname/file.html</div>
+					</div>
+				</div>
+				<div class="r">
+					<p class="after">after:</p>
+					<div class="box after pathname" id="dot6">
+						<div class="pathname">www.website.com/file.html</div>
+						<div class="pathname">www.website.com/with/a/long/pathname/file.html</div>
+					</div>
+				</div>
+			</div>
+
+		</div>
+		<br />
+		<br />
+	</body>
+</html>
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..f776ac3
--- /dev/null
+++ b/package.json
@@ -0,0 +1,21 @@
+{
+  "name": "jquery.dotdotdot",
+  "main": "src/jquery.dotdotdot.min.umd.js",
+  "version": "1.8.3",
+  "homepage": "http://dotdotdot.frebsite.nl/",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/FrDH/jQuery.dotdotdot.git"
+  },
+  "author": "Fred Heusschen <info at frebsite.nl>",
+  "description": "A jQuery plugin for advanced cross-browser ellipsis on multiple line content.",
+  "keywords": [
+    "ellipsis",
+    "dotdotdot",
+    "multiline",
+    "text",
+    "text-overflow",
+    "overflow",
+    "dots"
+  ]
+}
diff --git a/src/jquery.dotdotdot.js b/src/jquery.dotdotdot.js
new file mode 100644
index 0000000..972282a
--- /dev/null
+++ b/src/jquery.dotdotdot.js
@@ -0,0 +1,759 @@
+/*
+ *	jQuery dotdotdot 1.8.3
+ *
+ *	Copyright (c) Fred Heusschen
+ *	www.frebsite.nl
+ *
+ *	Plugin website:
+ *	dotdotdot.frebsite.nl
+ *
+ *	Licensed under the MIT license.
+ *	http://en.wikipedia.org/wiki/MIT_License
+ */
+
+(function( $, undef )
+{
+	if ( $.fn.dotdotdot )
+	{
+		return;
+	}
+
+	$.fn.dotdotdot = function( o )
+	{
+		if ( this.length == 0 )
+		{
+			$.fn.dotdotdot.debug( 'No element found for "' + this.selector + '".' );
+			return this;
+		}
+		if ( this.length > 1 )
+		{
+			return this.each(
+				function()
+				{
+					$(this).dotdotdot( o );
+				}
+			);
+		}
+
+
+		var $dot = this;
+		var orgContent	= $dot.contents();
+
+		if ( $dot.data( 'dotdotdot' ) )
+		{
+			$dot.trigger( 'destroy.dot' );
+		}
+
+		$dot.data( 'dotdotdot-style', $dot.attr( 'style' ) || '' );
+		$dot.css( 'word-wrap', 'break-word' );
+		if ($dot.css( 'white-space' ) === 'nowrap')
+		{
+			$dot.css( 'white-space', 'normal' );
+		}
+
+		$dot.bind_events = function()
+		{
+			$dot.bind(
+				'update.dot',
+				function( e, c )
+				{
+					$dot.removeClass("is-truncated");
+					e.preventDefault();
+					e.stopPropagation();
+
+					switch( typeof opts.height )
+					{
+						case 'number':
+							opts.maxHeight = opts.height;
+							break;
+
+						case 'function':
+							opts.maxHeight = opts.height.call( $dot[ 0 ] );
+							break;
+
+						default:
+							opts.maxHeight = getTrueInnerHeight( $dot );
+							break;
+					}
+
+					opts.maxHeight += opts.tolerance;
+
+					if ( typeof c != 'undefined' )
+					{
+						if ( typeof c == 'string' || ('nodeType' in c && c.nodeType === 1) )
+						{
+					 		c = $('<div />').append( c ).contents();
+						}
+						if ( c instanceof $ )
+						{
+							orgContent = c;
+						}
+					}
+
+					$inr = $dot.wrapInner( '<div class="dotdotdot" />' ).children();
+					$inr.contents()
+						.detach()
+						.end()
+						.append( orgContent.clone( true ) )
+						.find( 'br' )
+						.replaceWith( '  <br />  ' )
+						.end()
+						.css({
+							'height'	: 'auto',
+							'width'		: 'auto',
+							'border'	: 'none',
+							'padding'	: 0,
+							'margin'	: 0
+						});
+
+					var after = false,
+						trunc = false;
+
+					if ( conf.afterElement )
+					{
+						after = conf.afterElement.clone( true );
+					    after.show();
+						conf.afterElement.detach();
+					}
+
+					if ( test( $inr, opts ) )
+					{
+						if ( opts.wrap == 'children' )
+						{
+							trunc = children( $inr, opts, after );
+						}
+						else
+						{
+							trunc = ellipsis( $inr, $dot, $inr, opts, after );
+						}
+					}
+					$inr.replaceWith( $inr.contents() );
+					$inr = null;
+
+					if ( $.isFunction( opts.callback ) )
+					{
+						opts.callback.call( $dot[ 0 ], trunc, orgContent );
+					}
+
+					conf.isTruncated = trunc;
+					return trunc;
+				}
+
+			).bind(
+				'isTruncated.dot',
+				function( e, fn )
+				{
+					e.preventDefault();
+					e.stopPropagation();
+
+					if ( typeof fn == 'function' )
+					{
+						fn.call( $dot[ 0 ], conf.isTruncated );
+					}
+					return conf.isTruncated;
+				}
+
+			).bind(
+				'originalContent.dot',
+				function( e, fn )
+				{
+					e.preventDefault();
+					e.stopPropagation();
+
+					if ( typeof fn == 'function' )
+					{
+						fn.call( $dot[ 0 ], orgContent );
+					}
+					return orgContent;
+				}
+
+			).bind(
+				'destroy.dot',
+				function( e )
+				{
+					e.preventDefault();
+					e.stopPropagation();
+
+					$dot.unwatch()
+						.unbind_events()
+						.contents()
+						.detach()
+						.end()
+						.append( orgContent )
+						.attr( 'style', $dot.data( 'dotdotdot-style' ) || '' )
+						.removeClass( 'is-truncated' )
+						.data( 'dotdotdot', false );
+				}
+			);
+			return $dot;
+		};	//	/bind_events
+
+		$dot.unbind_events = function()
+		{
+			$dot.unbind('.dot');
+			return $dot;
+		};	//	/unbind_events
+
+		$dot.watch = function()
+		{
+			$dot.unwatch();
+			if ( opts.watch == 'window' )
+			{
+				var $window = $(window),
+					_wWidth = $window.width(),
+					_wHeight = $window.height();
+
+				$window.bind(
+					'resize.dot' + conf.dotId,
+					function()
+					{
+						if ( _wWidth != $window.width() || _wHeight != $window.height() || !opts.windowResizeFix )
+						{
+							_wWidth = $window.width();
+							_wHeight = $window.height();
+
+							if ( watchInt )
+							{
+								clearInterval( watchInt );
+							}
+							watchInt = setTimeout(
+								function()
+								{
+									$dot.trigger( 'update.dot' );
+								}, 100
+							);
+						}
+					}
+				);
+			}
+			else
+			{
+				watchOrg = getSizes( $dot );
+				watchInt = setInterval(
+					function()
+					{
+						if ( $dot.is( ':visible' ) )
+						{
+							var watchNew = getSizes( $dot );
+							if ( watchOrg.width  != watchNew.width ||
+								 watchOrg.height != watchNew.height )
+							{
+								$dot.trigger( 'update.dot' );
+								watchOrg = watchNew;
+							}
+						}
+					}, 500
+				);
+			}
+			return $dot;
+		};
+		$dot.unwatch = function()
+		{
+			$(window).unbind( 'resize.dot' + conf.dotId );
+			if ( watchInt )
+			{
+				clearInterval( watchInt );
+			}
+			return $dot;
+		};
+
+		var	opts 		= $.extend( true, {}, $.fn.dotdotdot.defaults, o ),
+			conf		= {},
+			watchOrg	= {},
+			watchInt	= null,
+			$inr		= null;
+
+
+		if ( !( opts.lastCharacter.remove instanceof Array ) )
+		{
+			opts.lastCharacter.remove = $.fn.dotdotdot.defaultArrays.lastCharacter.remove;
+		}
+		if ( !( opts.lastCharacter.noEllipsis instanceof Array ) )
+		{
+			opts.lastCharacter.noEllipsis = $.fn.dotdotdot.defaultArrays.lastCharacter.noEllipsis;
+		}
+
+
+		conf.afterElement	= getElement( opts.after, $dot );
+		conf.isTruncated	= false;
+		conf.dotId			= dotId++;
+
+
+		$dot.data( 'dotdotdot', true )
+			.bind_events()
+			.trigger( 'update.dot' );
+
+		if ( opts.watch )
+		{
+			$dot.watch();
+		}
+
+		return $dot;
+	};
+
+
+	//	public
+	$.fn.dotdotdot.defaults = {
+		'ellipsis'			: '... ',
+		'wrap'				: 'word',
+		'fallbackToLetter'	: true,
+		'lastCharacter'		: {},
+		'tolerance'			: 0,
+		'callback'			: null,
+		'after'				: null,
+		'height'			: null,
+		'watch'				: false,
+		'windowResizeFix'	: true
+	};
+	$.fn.dotdotdot.defaultArrays = {
+		'lastCharacter'		: {
+			'remove'			: [ ' ', '\u3000', ',', ';', '.', '!', '?' ],
+			'noEllipsis'		: []
+		}
+	};
+	$.fn.dotdotdot.debug = function( msg ) {};
+
+
+	//	private
+	var dotId = 1;
+
+	function children( $elem, o, after )
+	{
+		var $elements 	= $elem.children(),
+			isTruncated	= false;
+
+		$elem.empty();
+
+		for ( var a = 0, l = $elements.length; a < l; a++ )
+		{
+			var $e = $elements.eq( a );
+			$elem.append( $e );
+			if ( after )
+			{
+				$elem.append( after );
+			}
+			if ( test( $elem, o ) )
+			{
+				$e.remove();
+				isTruncated = true;
+				break;
+			}
+			else
+			{
+				if ( after )
+				{
+					after.detach();
+				}
+			}
+		}
+		return isTruncated;
+	}
+	function ellipsis( $elem, $d, $i, o, after )
+	{
+		var isTruncated	= false;
+
+		//	Don't put the ellipsis directly inside these elements
+		var notx = 'a, table, thead, tbody, tfoot, tr, col, colgroup, object, embed, param, ol, ul, dl, blockquote, select, optgroup, option, textarea, script, style';
+
+		//	Don't remove these elements even if they are after the ellipsis
+		var noty = 'script, .dotdotdot-keep';
+
+		$elem
+			.contents()
+			.detach()
+			.each(
+				function()
+				{
+
+					var e	= this,
+						$e	= $(e);
+
+					if ( typeof e == 'undefined' )
+					{
+						return true;
+					}
+					else if ( $e.is( noty ) )
+					{
+						$elem.append( $e );
+					}
+					else if ( isTruncated )
+					{
+						return true;
+					}
+					else
+					{
+						$elem.append( $e );
+						if ( after && !$e.is( o.after ) && !$e.find( o.after ).length  )
+						{
+							$elem[ $elem.is( notx ) ? 'after' : 'append' ]( after );
+						}
+						if ( test( $i, o ) )
+						{
+							if ( e.nodeType == 3 ) // node is TEXT
+							{
+								isTruncated = ellipsisElement( $e, $d, $i, o, after );
+							}
+							else
+							{
+								isTruncated = ellipsis( $e, $d, $i, o, after );
+							}
+						}
+
+						if ( !isTruncated )
+						{
+							if ( after )
+							{
+								after.detach();
+							}
+						}
+					}
+				}
+			);
+		$d.addClass("is-truncated");
+		return isTruncated;
+	}
+	function ellipsisElement( $e, $d, $i, o, after )
+	{
+		var e = $e[ 0 ];
+
+		if ( !e )
+		{
+			return false;
+		}
+
+		var txt			= getTextContent( e ),
+			space		= ( txt.indexOf(' ') !== -1 ) ? ' ' : '\u3000',
+			separator	= ( o.wrap == 'letter' ) ? '' : space,
+			textArr		= txt.split( separator ),
+			position 	= -1,
+			midPos		= -1,
+			startPos	= 0,
+			endPos		= textArr.length - 1;
+
+
+		//	Only one word
+		if ( o.fallbackToLetter && startPos == 0 && endPos == 0 )
+		{
+			separator	= '';
+			textArr		= txt.split( separator );
+			endPos		= textArr.length - 1;
+		}
+
+		while ( startPos <= endPos && !( startPos == 0 && endPos == 0 ) )
+		{
+			var m = Math.floor( ( startPos + endPos ) / 2 );
+			if ( m == midPos )
+			{
+				break;
+			}
+			midPos = m;
+
+			setTextContent( e, textArr.slice( 0, midPos + 1 ).join( separator ) + o.ellipsis );
+			$i.children()
+				.each(
+					function()
+					{
+						$(this).toggle().toggle();
+					}
+				);
+
+			if ( !test( $i, o ) )
+			{
+				position = midPos;
+				startPos = midPos;
+			}
+			else
+			{
+				endPos = midPos;
+
+				//	Fallback to letter
+				if (o.fallbackToLetter && startPos == 0 && endPos == 0 )
+				{
+					separator	= '';
+					textArr		= textArr[ 0 ].split( separator );
+					position	= -1;
+					midPos		= -1;
+					startPos	= 0;
+					endPos		= textArr.length - 1;
+				}
+			}
+		}
+
+		if ( position != -1 && !( textArr.length == 1 && textArr[ 0 ].length == 0 ) )
+		{
+			txt = addEllipsis( textArr.slice( 0, position + 1 ).join( separator ), o );
+			setTextContent( e, txt );
+		}
+		else
+		{
+			var $w = $e.parent();
+			$e.detach();
+
+			var afterLength = ( after && after.closest($w).length ) ? after.length : 0;
+
+			if ( $w.contents().length > afterLength )
+			{
+				e = findLastTextNode( $w.contents().eq( -1 - afterLength ), $d );
+			}
+			else
+			{
+				e = findLastTextNode( $w, $d, true );
+				if ( !afterLength )
+				{
+					$w.detach();
+				}
+			}
+			if ( e )
+			{
+				txt = addEllipsis( getTextContent( e ), o );
+				setTextContent( e, txt );
+				if ( afterLength && after )
+				{
+					var $parent = after.parent();
+
+					$(e).parent().append( after );
+
+					if ( !$.trim( $parent.html() ) )
+					{
+						$parent.remove();
+					}
+				}
+			}
+		}
+
+		return true;
+	}
+	function test( $i, o )
+	{
+		return $i.innerHeight() > o.maxHeight;
+	}
+	function addEllipsis( txt, o )
+	{
+		while( $.inArray( txt.slice( -1 ), o.lastCharacter.remove ) > -1 )
+		{
+			txt = txt.slice( 0, -1 );
+		}
+		if ( $.inArray( txt.slice( -1 ), o.lastCharacter.noEllipsis ) < 0 )
+		{
+			txt += o.ellipsis;
+		}
+		return txt;
+	}
+	function getSizes( $d )
+	{
+		return {
+			'width'	: $d.innerWidth(),
+			'height': $d.innerHeight()
+		};
+	}
+	function setTextContent( e, content )
+	{
+		if ( e.innerText )
+		{
+			e.innerText = content;
+		}
+		else if ( e.nodeValue )
+		{
+			e.nodeValue = content;
+		}
+		else if (e.textContent)
+		{
+			e.textContent = content;
+		}
+
+	}
+	function getTextContent( e )
+	{
+		if ( e.innerText )
+		{
+			return e.innerText;
+		}
+		else if ( e.nodeValue )
+		{
+			return e.nodeValue;
+		}
+		else if ( e.textContent )
+		{
+			return e.textContent;
+		}
+		else
+		{
+			return "";
+		}
+	}
+	function getPrevNode( n )
+	{
+		do
+		{
+			n = n.previousSibling;
+		}
+		while ( n && n.nodeType !== 1 && n.nodeType !== 3 );
+
+		return n;
+	}
+	function findLastTextNode( $el, $top, excludeCurrent )
+	{
+		var e = $el && $el[ 0 ], p;
+		if ( e )
+		{
+			if ( !excludeCurrent )
+			{
+				if ( e.nodeType === 3 )
+				{
+					return e;
+				}
+				if ( $.trim( $el.text() ) )
+				{
+					return findLastTextNode( $el.contents().last(), $top );
+				}
+			}
+			p = getPrevNode( e );
+			while ( !p )
+			{
+				$el = $el.parent();
+				if ( $el.is( $top ) || !$el.length )
+				{
+					return false;
+				}
+				p = getPrevNode( $el[0] );
+			}
+			if ( p )
+			{
+				return findLastTextNode( $(p), $top );
+			}
+		}
+		return false;
+	}
+	function getElement( e, $i )
+	{
+		if ( !e )
+		{
+			return false;
+		}
+		if ( typeof e === 'string' )
+		{
+			e = $(e, $i);
+			return ( e.length )
+				? e
+				: false;
+		}
+		return !e.jquery
+			? false
+			: e;
+	}
+	function getTrueInnerHeight( $el )
+	{
+		var h = $el.innerHeight(),
+			a = [ 'paddingTop', 'paddingBottom' ];
+
+		for ( var z = 0, l = a.length; z < l; z++ )
+		{
+			var m = parseInt( $el.css( a[ z ] ), 10 );
+			if ( isNaN( m ) )
+			{
+				m = 0;
+			}
+			h -= m;
+		}
+		return h;
+	}
+
+
+	//	override jQuery.html
+	var _orgHtml = $.fn.html;
+	$.fn.html = function( str )
+	{
+		if ( str != undef && !$.isFunction( str ) && this.data( 'dotdotdot' ) )
+		{
+			return this.trigger( 'update', [ str ] );
+		}
+		return _orgHtml.apply( this, arguments );
+	};
+
+
+	//	override jQuery.text
+	var _orgText = $.fn.text;
+	$.fn.text = function( str )
+	{
+		if ( str != undef && !$.isFunction( str ) && this.data( 'dotdotdot' ) )
+		{
+			str = $( '<div />' ).text( str ).html();
+			return this.trigger( 'update', [ str ] );
+		}
+		return _orgText.apply( this, arguments );
+	};
+
+
+})( jQuery );
+
+/*
+
+## Automatic parsing for CSS classes
+Contributed by [Ramil Valitov](https://github.com/rvalitov)
+
+### The idea
+You can add one or several CSS classes to HTML elements to automatically invoke "jQuery.dotdotdot functionality" and some extra features. It allows to use jQuery.dotdotdot only by adding appropriate CSS classes without JS programming.
+
+### Available classes and their description
+* dot-ellipsis - automatically invoke jQuery.dotdotdot to this element. This class must be included if you plan to use other classes below.
+* dot-resize-update - automatically update if window resize event occurs. It's equivalent to option `watch:'window'`.
+* dot-timer-update - automatically update if window resize event occurs. It's equivalent to option `watch:true`.
+* dot-load-update - automatically update after the window has beem completely rendered. Can be useful if your content is generated dynamically using using JS and, hence, jQuery.dotdotdot can't correctly detect the height of the element before it's rendered completely.
+* dot-height-XXX - available height of content area in pixels, where XXX is a number, e.g. can be `dot-height-35` if you want to set maximum height for 35 pixels. It's equivalent to option `height:'XXX'`.
+
+### Usage examples
+*Adding jQuery.dotdotdot to element*
+    
+	<div class="dot-ellipsis">
+	<p>Lorem Ipsum is simply dummy text.</p>
+	</div>
+	
+*Adding jQuery.dotdotdot to element with update on window resize*
+    
+	<div class="dot-ellipsis dot-resize-update">
+	<p>Lorem Ipsum is simply dummy text.</p>
+	</div>
+	
+*Adding jQuery.dotdotdot to element with predefined height of 50px*
+    
+	<div class="dot-ellipsis dot-height-50">
+	<p>Lorem Ipsum is simply dummy text.</p>
+	</div>
+	
+*/
+
+jQuery(document).ready(function($) {
+	//We only invoke jQuery.dotdotdot 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");
+		
+		//Checking if update on timer required
+		var watch_timer=$(this).hasClass("dot-timer-update");
+		
+		//Checking if height set
+		var height=0;		
+		var classList = $(this).attr('class').split(/\s+/);
+		$.each(classList, function(index, item) {
+			var matchResult = item.match(/^dot-height-(\d+)$/);
+			if(matchResult !== null)
+				height = Number(matchResult[1]);
+		});
+		
+		//Invoking jQuery.dotdotdot
+		var x = new Object();
+		if (watch_timer)
+			x.watch=true;
+		if (watch_window)
+			x.watch='window';
+		if (height>0)
+			x.height=height;
+		$(this).dotdotdot(x);
+	});
+		
+});
+
+//Updating elements (if any) on window.load event
+jQuery(window).on('load', function(){
+	jQuery(".dot-ellipsis.dot-load-update").trigger("update.dot");
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/libjs-jquery-dotdotdot.git



More information about the Pkg-javascript-commits mailing list