웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
게시판 글쓰기에서 자동링크의 target을 _blank로 일괄 적용
2011.08.23 17:21
게시판에 url을 쓰면 <a href="url">내용</a> 처럼 기본으로 자동 링크가 걸립니다.
문제는 target이 지정되어 있지 않아 해당 url을 클릭하면 현재 창에 뜬다는 것이죠. 전 이게 불편하더군요.
[HTML 편집기]로 직접 target을 지정하거나, URL 버튼을 이용해도 되지만, url이 많을 경우 버겁습니다. 귀찮기도 하구요. -_-;
그래서, XE 기본 편집기인 'xpresseditor'를 수정했습니다. 혹시나, 필요하신 분이 계실까 해서 올려 봅니다.
1. 에디터의 'URL' 버튼을 클릭하면 아래 그림처럼 나타나며, '_blank' 버튼을 클릭하면 본문 내용에 있는 A 태그 중에서 target이 지정되지 않은 링크에 target="_blank" 를 설정합니다.
2. 수정한 파일
|
3. editor.html
4. default.css
./modules/editor/skins/xpresseditor/img/ 에 'btn_layer_blank.gif' 버튼 이미지를 만들어 업로드.
- .xpress-editor .tool .layer .btn_area button.confirm{ width:38px; height:21px; background:url(../img/btn_layer_confirm.gif) no-repeat;}
- .xpress-editor .tool .layer .btn_area button.cancel{ width:38px; height:21px; background:url(../img/btn_layer_cancel.gif) no-repeat;}
- .xpress-editor .tool .layer .btn_area button.blank{ width:41px; height:21px; background:url(../img/btn_layer_blank.gif) no-repeat;}
5. Xpress_Editor.js
- xe.XE_Hyperlink = $.Class({
- name : "XE_Hyperlink",
- sATagMarker : "HTTP://HUSKY_TMP.MARKER/",
- $init : function(elAppContainer){
- this._assignHTMLObjects(elAppContainer);
- this.sRXATagMarker = this.sATagMarker.replace(/\//g, "\\/").replace(/\./g, "\\.");
- },
- _assignHTMLObjects : function(elAppContainer){
- this.oHyperlinkLayer = $("DIV.xpress_xeditor_hyperlink_layer", elAppContainer).get(0);
- this.oLinkInput = $("INPUT[type=text]", this.oHyperlinkLayer).get(0);
- this.oBtnConfirm = $("BUTTON.confirm", this.oHyperlinkLayer).get(0);
- this.oBtnCancel = $("BUTTON.cancel", this.oHyperlinkLayer).get(0);
- this.oBtnBlank = $("BUTTON.blank", this.oHyperlinkLayer).get(0); // add by 무얼까 mooin@hitel.net 2011-8-23
- this.oCbNewWin = $("INPUT[type=checkbox]", this.oHyperlinkLayer).get(0);
- },
- $ON_MSG_APP_READY : function(){
- this.oApp.exec("REGISTER_HOTKEY", ["ctrl+k", "XE_TOGGLE_HYPERLINK_LAYER", []]);
- this.oApp.registerBrowserEvent(this.oBtnConfirm, "mousedown", "XE_APPLY_HYPERLINK");
- this.oApp.registerBrowserEvent(this.oBtnCancel, "mousedown", "HIDE_ACTIVE_LAYER");
- this.oApp.registerBrowserEvent(this.oBtnBlank, "mousedown", "XE_MAKE_BLANK"); // add by 무얼까 mooin@hitel.net 2011-8-23
- this.oApp.registerBrowserEvent(this.oLinkInput, "keydown", "EVENT_XE_HYPERLINK_KEYDOWN");
- this.oApp.exec("REGISTER_UI_EVENT", ["hyperlink", "click", "XE_TOGGLE_HYPERLINK_LAYER"]);
- },
- $ON_XE_TOGGLE_HYPERLINK_LAYER : function(){
- // hotkey may close the layer right away so delay here
- this.oApp.delayedExec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.oHyperlinkLayer, null, "XE_RESET_HYPERLINK_LAYER", []], 0);
- },
- $ON_XE_RESET_HYPERLINK_LAYER : function(){
- this.oApp.exec("FOCUS", []);
- this.oSelection = this.oApp.getSelection();
- var oAnchor = this.oSelection.findAncestorByTagName("A");
- this.oCbNewWin.checked = true; // 무얼까가 'true'로 수정 2011-08-23
- if(oAnchor){
- this.oSelection.selectNode(oAnchor);
- this.oSelection.select();
- var sTarget = oAnchor.target;
- if(sTarget && sTarget == "_blank") this.oCbNewWin.checked = true;
- this.oLinkInput.value = oAnchor.href?oAnchor.href:"http://";
- }else{
- this.oLinkInput.value = "http://";
- }
- this.oLinkInput.focus();
- this.oLinkInput.value = this.oLinkInput.value;
- },
- $ON_XE_APPLY_HYPERLINK : function(){
- var sURL = this.oLinkInput.value, newWin = this.oCbNewWin.checked, sTarget = newWin?'_blank':'';
- this.oApp.exec("FOCUS", []);
- this.oSelection = this.oApp.getSelection();
- if(this.oSelection.collapsed){
- var str = "<a href=" + sURL + "' target="+sTarget+">" + sURL + "</a>";
- this.oSelection.pasteHTML(str);
- }else{
- var nSession = Math.ceil(Math.random()*10000);
- var sMarker = this.sATagMarker+nSession;
- var arg = ( sURL == "" ? ["unlink"] : ["createLink", false, sMarker+sURL] );
- this.oApp.exec("EXECCOMMAND", arg);
- try { this.oSelection.setFromSelection() }catch(e){};
- var oDoc = this.oApp.getWYSIWYGDocument();
- $(oDoc.body.getElementsByTagName("A"))
- .filter('[href^="'+sMarker+'"]')
- .attr('href', function(){
- var rx = new RegExp('^'+sMarker.replace(/([\.\\])/g, '\\$1'), 'i');
- if (sTarget) $(this).attr('target', sTarget);
- else $(this).removeAttr('target'+ ');
- return this.href.replace(rx, '');
- });
- }
- this.oApp.exec("HIDE_ACTIVE_LAYER");
- setTimeout($.fnBind(function(){try{this.oSelection.select()}catch(e){}}, this), 0);
- },
- /* add by 무얼까 mooin@hitel.net 2011-8-23
- * a 태그에 target 속성이 없으면 target="_blank"로 설정
- */
- $ON_XE_MAKE_BLANK : function(){
- var doc = this.oApp.getWYSIWYGDocument();
- var oA = doc.getElementsByTagName("a");
- for(var i=0;i<oA.length;i++) {
- if( !oA[i].hasAttribute('target') ) {
- oA[i].setAttribute('target', '_blank');
- }
- }
- this.oApp.exec("HIDE_ACTIVE_LAYER");
- },
- _validateURL : function(sURL){
- return /^(http|https|ftp|mailto):(?:\/\/)?((\w|-)+(?:[\.:@](\w|-))+)(?:\/|@)?([^"\?]*?)(?:\?([^\?"]*?))?$/.test(sURL);
- },
- $ON_EVENT_XE_HYPERLINK_KEYDOWN : function(oEvent){
- if (oEvent.keyCode == 13){
- this.oApp.exec("XE_APPLY_HYPERLINK");
- oEvent.preventDefault(); oEvent.stopPropagation();
- }
- }
- });
6. 추가로 위 하이퍼링크 설정 창의 '새 창으로' 체크박스가 기본으로 체크되어 있게 수정했습니다.
위 Xpress_Editor.js 파일 소스 중 4673 라인 참고
댓글 0
제목 | 글쓴이 | 날짜 |
---|---|---|
CSS 와 HTML 과 연결하기 [5] | Topy | 2002.02.21 |
CSS에 클래스에 관한거 추가 [4] | DearMai | 2002.02.21 |
웹사이트 로딩속도 높혀주는 10가지 방법 [32] | 秀 | 2001.07.25 |
익스플로어 즐겨찾기에 아이콘 추가하기 [7] | rolly™ | 2001.12.13 |
홈페이지에 Fade-in 적용하기~ [5] | remy | 2002.01.08 |
[1차패치] 내 msn 현재상태를 보여주자! + 캡처없앰 -ㅂ- [18] | 티르 | 2002.01.04 |
새로운필터를 적용한 칼라버튼.[ie5.5 sp2이상] [26] | 술도짱 | 2001.11.15 |
글입력상자에서 자동으로 한글, 영문 바뀌게 하기 [6] | 이경두 | 2001.11.15 |
글씨를 세로로 써봅시다...^_^ [6] | 술도짱 | 2001.11.14 |
익스플로러의 자동완성 기능 off 하기 [7] | WOWpc | 2001.10.23 |
(table)에서 HTML 태그를 적용시켜 보기 [16] | 정후니 | 2001.08.31 |
스크롤바 색깔 바꾸는 스타일... [8] | 잔디 | 2001.01.05 |
웹페이지에서 ICQ 번호 자동으로 추가하기... [1] | 잔디 | 2001.01.05 |
XE 공식 게시판에 (다운로드) 같은 '임의목록' 집어 넣기 (확장변수x) [1] | 999 | 2010.12.30 |
좋은 PHP 강좌 사이트들 [1] | HolyJohn | 2010.12.29 |
[생초보팁] 레이아웃 스킨 강좌 사이트 [2] | HolyJohn | 2010.12.29 |
애드온에서 모바일 환경 구분 코드 | misol | 2010.12.24 |
회원가입후 1주일이 지나지 않은 계정에 한하여 탈퇴 제한하기 [1] | Arp | 2010.12.23 |
우분투 apm에서 "쉬운 설치" 에러시 팁 [4] | 김상호 | 2010.12.22 |
심플한 XML 플래시 이미지 갤러리 [7] | maxtabby | 2010.12.21 |