(
function
($){
if
(!$.lui.widget) $.lui.widget = {};
$.lui.widget.__clean$ = $(
"<span id='"
+ $.lui.newGuid()+
"'></span>"
);
$.fn.del =
function
( SELECTor, keepData ) {
if
( !SELECTor || $.filter( SELECTor, [
this
] ).length ) {
var
item = $(
this
);
var
clearItem = $.lui.widget.__clean$;
item.appendTo(clearItem);
$(
'*'
,clearItem).each(
function
(i, e) {
(events = $.data(
this
,
'events'
)) && $.each(events,
function
(i, e1) {
$(e).unbind(i +
'.*'
);
});
$.event.remove(
this
);
$.removeData(
this
);
});
clearItem[0].innerHTML =
''
;
item =
null
;
}
};
$.lui.widget.clacStrLength =
function
($Element,str){
var
_id = $.lui.newGuid();
var
$tmpSpan = $(
"<span></span>"
).attr(
'id'
,_id).css({
'position'
:
'absolute'
,
'top'
:
'-1000px'
}).appendTo(
'body'
);
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();
$tmpSpan.del();
$tmpSpan =
null
;
return
_width;
};
$.lui.widget.substrByPx =
function
($Element,str,limit){
if
($Element === undefined || !$Element
instanceof
$)
return
''
;
if
(str === undefined ||
typeof
str !=
'string'
)
return
''
;
if
(limit === undefined)
return
str;
if
(!str || limit <=0 )
return
''
;
var
_str =
new
String(str);
var
_id = $.lui.newGuid();
var
$tmpSpan = $(
"<span></span>"
).attr(
'id'
,_id).css({
'position'
:
'absolute'
,
'top'
:
'-1000px'
}).appendTo(
'body'
);
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();
while
( _width >limit){
_str = _str.substring(0, _str.length-1);
_width = $tmp.text(_str).innerWidth();
}
$tmpSpan.del();
$tmpSpan =
null
;
return
_str;
};
})(jQuery);