if (!$.lui.widget) $.lui.widget = {};
$.lui.newguid () generates a random 32-bit ID
If the jquery object is generated multiple times in this way, the HTML code string will be repeated over and over in memory, consuming additional content and leaking. and $ ("<span></span>"). attr (' id ', _id) does not have this problem.
$.lui.widget.__clean$ = $ ("<span id= '" + $.lui.newguid () + "' ></span>");
* Free jquery object, no return value. This method is used to solve the memory leak problem of jquery
$.fn.del =function (Selector, keepdata) {
if (!selector | | $.filter (SELECTOR, [this]). length) {
Varclearitem = $.lui.widget.__clean$;
Item.appendto (Clearitem);
$ (' * ', clearitem). Each (function (I, e) {
(Events = $.data (this, ' events ')) && $.each (Events,function (i, E1) {
$ (E). Unbind (i + '. * ');
clearitem[0].innerhtml = ';
* Calculates the length of a string that is not broken on an element
* @param {jquery} $Element jquery elements
* @param {string} str string
* @returns {Number} string length (px)
$.lui.widget.clacstrlength =function ($Element, str) {
var_id = $.lui.newguid ();
Var$tmpspan = $ ("<span></span>"). attr (' id ', _id). CSS ({
' Position ': ' absolute ',
Var_width = $tmpSpan. css ({
' font-family ': $Element. css (' font-family '),
' Font-size ': $Element. css (' font-size '),
' letter-spacing ': $Element. css (' letter-spacing '),
' word-spacing ': $Element. css (' word-spacing '),
' Text-indent ': $Element. css (' text-indent ')
}). text (str). Innerwidth ();
* On an element on a pixel intercept string (using the browser default processing whitespace, not for complex scenes, only in the case of a pixel-by-line interception of strings)
* @param $Element jquery elements (the font settings for this element must already be determined)
* @param limit pixel value
* @returns the string captured by pixel
$.LUI.WIDGET.SUBSTRBYPX =function ($Element, Str,limit) {
if ($Element = = Undefined | |! $Elementinstanceof $) return ';
if (str = = Undefined | | Typeofstr!= ' string ') return ';
if (limit = = undefined) returnstr;
if (!str | | limit <=0) return ";
Var_str =newstring (str);
var_id = $.lui.newguid ();
Var$tmpspan = $ ("<span></span>"). attr (' id ', _id). CSS ({
' Position ': ' absolute ',
Var_width = $tmpSpan. css ({
' font-family ': $Element. css (' font-family '),
' Font-size ': $Element. css (' font-size '),
' letter-spacing ': $Element. css (' letter-spacing '),
' word-spacing ': $Element. css (' word-spacing '),
' Text-indent ': $Element. css (' text-indent ')
}). text (str). Innerwidth ();
_str = _str.substring (0, _str.length-1);
_width = $tmp. Text (_STR). Innerwidth ();