Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @preserve jQuery Text Alignment v0.02 | ||
* | ||
* Licensed under the new BSD License. | ||
* Copyright 2009, Bram Stein | ||
* All rights reserved. | ||
*/ | ||
/*global jQuery*/ | ||
(function ($) { | ||
$.extend($.fn, { | ||
textAlign: function (string) { | ||
var items = $(this), | ||
maxLeft = 0, | ||
maxRight = 0; | ||
|
||
if (string === 'start' || string === 'end' || string === 'left' || string === 'right' || string === 'justify' || string === 'center') { | ||
return items.css({textAlign: string}); | ||
} else if (string.length === 1) { | ||
items.each(function () { | ||
var that = $(this), | ||
str = that.text(), | ||
left, right; | ||
|
||
if (str.indexOf(string) !== -1) { | ||
left = $('<span>' + str.slice(0, str.indexOf(string)) + '</span>'); | ||
right = $('<span>' + str.slice(str.indexOf(string)) + '</span>'); | ||
} else { | ||
left = $('<span>' + str + '</span>'); | ||
right = $('<span/>'); | ||
} | ||
|
||
left.css({display: 'inline-block', textAlign: 'right'}); | ||
right.css({display: 'inline-block', textAlign: 'left'}); | ||
|
||
$(this).empty().append(left).append(right); | ||
|
||
maxLeft = Math.max(maxLeft, left.width()); | ||
maxRight = Math.max(maxRight, right.width()); | ||
}); | ||
|
||
items.each(function () { | ||
var children = $(this).children(), | ||
left = $(children[0]), | ||
right = $(children[1]); | ||
|
||
left.width(maxLeft); | ||
right.width(maxRight); | ||
}); | ||
} | ||
return items; | ||
} | ||
}); | ||
}(jQuery)); |