-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IE에서도 js 방식으로 단어별 줄바꿈을 할 수 있도록 옵션을 추가함.
- Loading branch information
Showing
4 changed files
with
69 additions
and
29 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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
/*! | ||
* jQuery word-break keep-all Plugin | ||
* ver 1.2.3 | ||
* ver 1.3.0 | ||
* | ||
* Copyright 2012, Ahn Hyoung-woo ([email protected]) | ||
* Dual licensed under the MIT or GPL Version 2 licenses. | ||
* http://jquery.org/license | ||
* | ||
* http://code.google.com/p/jquery-word-break-keep-all-plugin/ | ||
* https://github.com/mytory/jquery-word-break-keep-all | ||
* http://mytory.co.kr/archives/2801 | ||
* | ||
* Date: 2013-01-07 | ||
* Date: 2013-09-04 | ||
*/ | ||
|
||
jQuery.fn.wordBreakKeepAll = function(option) { | ||
|
@@ -27,32 +27,34 @@ jQuery.fn.wordBreakKeepAll = function(option) { | |
}; | ||
|
||
var defaultOption = { | ||
OffForIE: false // If IE, turn off plugin. | ||
OffForIE: false, // If IE, turn off plugin. | ||
useCSSonIE: true // on IE, use CSS word-break: keep-all | ||
}; | ||
|
||
var opt = $.extend(defaultOption,option); | ||
|
||
if( /MSIE/.test(navigator.userAgent) ){ | ||
if( /MSIE/.test(navigator.userAgent) && opt.OffForIE == false && opt.useCSSonIE == true){ | ||
var addWordBreakKeepAll = function(obj){ | ||
if(opt.OffForIE == false){ | ||
$(obj).css({ | ||
'word-break': 'keep-all', | ||
'word-wrap': 'break-word' | ||
}); | ||
if($(obj).css('display') == 'inline'){ | ||
$(obj).css('display','block'); | ||
} | ||
$(obj).css({ | ||
'word-break': 'keep-all', | ||
'word-wrap': 'break-word' | ||
}); | ||
if($(obj).css('display') == 'inline'){ | ||
$(obj).css('display','block'); | ||
} | ||
}; | ||
}else{ | ||
}else if( ! /MSIE/.test(navigator.userAgent) || /MSIE/.test(navigator.userAgent) && opt.OffForIE == false && opt.useCSSonIE == false ){ | ||
var addWordBreakKeepAll = function(obj){ | ||
|
||
var html = $(obj).html(); | ||
//줄바꿈 보존을 위한 처리 | ||
|
||
// to store line break | ||
html = html.replace(/(\r\n|\n|\r)/gm, ' #&*@§ '); | ||
|
||
// .html() 로 집어 넣었을 때, 여는 태그만 있으면 브라우저가 자동으로 닫는 태그를 집어 넣기 때문에 <,>를 다 없앤다. | ||
var textArr = html.split(' '); | ||
//빈 배열 제거 | ||
|
||
// remove empty array | ||
textArr = textArr.filter(function(e){return e;}); | ||
$(obj).text(''); | ||
var skip = false; | ||
|
@@ -83,7 +85,7 @@ jQuery.fn.wordBreakKeepAll = function(option) { | |
} | ||
if(is_there_end_angle_bracket(str)){ | ||
skip = false; | ||
} | ||
} | ||
}; | ||
$(obj).html(full_str.replace(/#&*@§/g, "\n")); | ||
}; | ||
|
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 |
---|---|---|
@@ -1,2 +1,16 @@ | ||
//ver 1.2.3, http://code.google.com/p/jquery-word-break-keep-all-plugin/ | ||
jQuery.fn.wordBreakKeepAll=function(e){var t=function(e){return e.lastIndexOf("<")<e.lastIndexOf(">")};var n=function(e){return e.lastIndexOf(">")<e.lastIndexOf("<")};var r=function(e){return e.lastIndexOf(">")==e.lastIndexOf("<")};var i={OffForIE:false};var s=$.extend(i,e);if(/MSIE/.test(navigator.userAgent)){var o=function(e){if(s.OffForIE==false){$(e).css({"word-break":"keep-all","word-wrap":"break-word"});if($(e).css("display")=="inline"){$(e).css("display","block")}}}}else{var o=function(e){var i=$(e).html();i=i.replace(/(\r\n|\n|\r)/gm," #&*@§ ");var s=i.split(" ");s=s.filter(function(e){return e});$(e).text("");var o=false;var u="";for(var a=0,f=s.length;a<f;a++){var l=s[a];if(o==false&&r(l)&&l.indexOf("#&*@§")==-1){u+='<span style="white-space: nowrap">'+l+"</span> "}else{u+=l+" "}if(n(l)){o=true}if(t(l)){o=false}}$(e).html(u.replace(/#&*@§/g,"\n"))}}return this.each(function(){o(this)})} | ||
/*! | ||
jQuery word-break keep-all Plugin | ||
ver 1.3.0 | ||
Copyright 2012, Ahn Hyoung-woo ([email protected]) | ||
Dual licensed under the MIT or GPL Version 2 licenses. | ||
http://jquery.org/license | ||
https://github.com/mytory/jquery-word-break-keep-all | ||
http://mytory.co.kr/archives/2801 | ||
Date: 2013-09-04 | ||
*/jQuery.fn.wordBreakKeepAll=function(option){var is_there_end_angle_bracket=function(str){return str.lastIndexOf('<')<str.lastIndexOf('>');};var is_there_start_angle_bracket=function(str){return str.lastIndexOf('>')<str.lastIndexOf('<');};var is_there_no_angle_bracket=function(str){return str.lastIndexOf('>')==str.lastIndexOf('<');};var defaultOption={OffForIE:false,useCSSonIE:true};var opt=$.extend(defaultOption,option);if(/MSIE/.test(navigator.userAgent)&&opt.OffForIE==false&&opt.useCSSonIE==true){var addWordBreakKeepAll=function(obj){$(obj).css({'word-break':'keep-all','word-wrap':'break-word'});if($(obj).css('display')=='inline'){$(obj).css('display','block');}};}else if(!/MSIE/.test(navigator.userAgent)||/MSIE/.test(navigator.userAgent)&&opt.OffForIE==false&&opt.useCSSonIE==false){var addWordBreakKeepAll=function(obj){var html=$(obj).html();html=html.replace(/(\r\n|\n|\r)/gm,' #&*@§ ');var textArr=html.split(' ');textArr=textArr.filter(function(e){return e;});$(obj).text('');var skip=false;var full_str='';for(var i=0,j=textArr.length;i<j;i++){var str=textArr[i];if(skip==false&&is_there_no_angle_bracket(str)&&str.indexOf('#&*@§')==-1){full_str+='<span style="white-space: nowrap">'+str+'</span> ';}else{full_str+=str+' ';} | ||
if(is_there_start_angle_bracket(str)){skip=true;} | ||
if(is_there_end_angle_bracket(str)){skip=false;}};$(obj).html(full_str.replace(/#&*@§/g,"\n"));};} | ||
return this.each(function(){addWordBreakKeepAll(this);});}; |
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