PageSourceSearch

https://kbrainc.com/weven_service/asset/js/bm2/com/toolset/ToolText.js

js kbrainc.com collected 2026-10-04 11:42:39 UTC 7,726 bytes, 243 lines download raw bytes

1/**
2 * created by WEVEN on 2020-03-02
3 * 아래의 소스는 WEVEN에 저작권이 있으므로 무단 사용 및 재 배포를 금합니다.
4 */
5var ToolText = function(){
6
7
8    this.targetImage = null;
9    this.prevTargetElement = null;
10    this.eventTargetListforImage = [];
11    this.elementType = 'text';
12
13    this.hideBtnList = ['ToolBtnTextFont', 'ToolBtnTextLetterSpacing'];
14
15    this.quickEdit = function( data ){
16        if( this.status ){
17
18            switch ( data ){
19                case "image" :
20                    $(this.toolBtnList[ "ToolBtnTextImage" ].btnList[data]).trigger( "click" );
21                    break;
22                case "source" :
23                    $(this.toolBtnList[ "ToolBtnSource" ].btnList[data]).trigger( "click" );
24                    break;
25            }
26        }
27    }
28
29}
30
31bm.extend( ToolBase , ToolText );
32
33
34ToolText.prototype.onChangeTarget = function(target, e, toolMode) {
35    this.removeEvent();
36    this.addEvent();
37    if(toolMode === 'side' || toolMode === 'expert') {
38        this.isShow = false;
39        this.show(true, this.elementType);
40    }else {
41        if(window.toolMode === 'design') {
42            var type = $(target).attr('data-wv-layout-element-type');
43            if(type && (type === 'text' || type.indexOf('table') > -1)) {
44                this.show();
45                this.reposition();
46            }else {
47                this.hide();
48            }
49        }else {
50            
51        }
52    }
53}
54
55/**
56 * 재정의해서 사용
57 */
58ToolText.prototype.addEvent = function () {
59    var _this = this;
60
61    if( this.targetElement ){
62        $(this.targetElement).off("paste");
63        $(this.targetElement).on("paste" , function(e){
64
65            var clipboardData = e.originalEvent && e.originalEvent.clipboardData ? e.originalEvent.clipboardData :  window.clipboardData;
66            if( clipboardData.getData( "Text" ) || clipboardData.files.length == 0 ){
67                return;
68            }
69
70
71            var currentData = clipboardData.items[0];
72            if( currentData.type.indexOf( "image" ) == -1 ){
73                return;
74            }
75
76            var imageFile = currentData.getAsFile();
77            var reader = new FileReader();
78            reader.readAsDataURL(imageFile);
79
80
81            reader.onload = function(){
82                var imageSrc = reader.result;
83                var ext = "png";
84                var fileName = "paste_" + app.uniqueCode();
85                var o = {"defaultPath" : "clipboardData/"
86                    , "isOverride" : 1
87                    , "name" : fileName + "." + ext
88                    , "type" : "image/jpeg"
89                    , "filedata" : imageSrc
90                };
91
92
93                bm.httpSendJsonPost( WEB_ROOT + "filemanager/" + "uploadSimpleAjaxImage", o , function (result) {
94                    if(result.result == true ){
95                        var img = new Image();
96                        img.src = result.data.file.src;
97
98
99                        bm.selectionManager.getRange().insertNode( img );
100
101                        return;
102                    }
103                })
104            }
105
106            return false;
107        })
108    }
109
110}
111
112/**
113 * 재정의 해서 사용
114 */
115ToolText.prototype.removeEvent = function () {
116
117    if( this.targetElement ) {
118        $(this.targetElement).off("paste");
119    }
120}
121
122/**
123 * 경우에 따라 정해진 버튼리스트 숨김처리
124 */
125ToolText.prototype.hideBtn = function () {
126    var _this = bm.toolManager['toolList']['ToolText'];
127
128    for(let i=0; i< _this.hideBtnList.length; i++) {
129        $(_this['toolBtnList'][_this.hideBtnList[i]]['btnList']['mainBtn']).hide();
130    }
131
132}
133
134/**
135*  버튼리스트 숨김처리해제
136*/
137ToolText.prototype.showBtn = function () {
138    var _this = bm.toolManager['toolList']['ToolText'];
139
140   for(let i=0; i< _this.hideBtnList.length; i++) {
141    $(_this['toolBtnList'][_this.hideBtnList[i]]['btnList']['mainBtn']).show();
142   }
143
144}
145
146/**
147*  버튼리스트 보이기 컨트롤
148*/
149ToolText.prototype.btnShowHideControl = function () {
150    var _this = bm.toolManager['toolList']['ToolText'];
151
152    const currentResponsiveSize = window.parent.wvAdminIFrameBridge._WVAdminTopBar.currentResponsiveSizeVal;
153
154    if ( currentResponsiveSize === '480' || currentResponsiveSize === 'default') {
155        _this.hideBtn();
156    } else {
157        _this.showBtn();
158    }
159 
160 }
161
162ToolText.prototype.reposition = function ( target ) {
163    if( this.targetElement ){
164
165        const narrowedMenuWidth = 426;
166        var targetElement = this.targetElement;
167
168        if( target ) targetElement = target;
169
170        // ymg 임시 수정 - layoutkit 영역 상단에 붙는 것들과 위치 겹침을 피하기 위함
171        if(!this.layoutKit) this.layoutKit = wvAdminIFrameBridge._WVLayoutKit;
172
173        // layoutkit 영역 상단에 붙는 것들
174        var posTopKitList = [this.layoutKit.blockSpaceCloseBtn, this.layoutKit.resetPosBtn, this.layoutKit.moveBtn, this.layoutKit.wvPosDisplayCon];
175
176        var verticalOffset = 2;
177
178        // for(var i = 0; i < posTopKitList.length; i++) {
179        //     if($(posTopKitList[i]).is(":visible")) {
180        //         // kit요소 각각의 높이를 계산하지 않고 임의값으로 고정
181        //         verticalOffset = 25;
182        //         break;
183        //     }
184        // }
185
186        if(targetElement.length && targetElement.length > 1) {
187            targetElement = targetElement[targetElement.length - 1];
188        }
189
190        var isTable = false;
191        var isTableCellActive = false;
192        var table = $(targetElement).closest('[data-wv-layout-element="block"]').find('table');
193        if( table.length > 0 ) {
194            isTable = true;
195            if(table.find('td.active').length > 0 ) isTableCellActive = true;
196        }
197
198
199        var top = $(targetElement).offset().top - this.element.offsetHeight - verticalOffset;
200        // var top = targetElement.getBoundingClientRect()['top'] - this.element.offsetHeight - verticalOffset;
201        var left = $(targetElement).offset().left;
202        var scrollTop = $(this.innerWindow.document).scrollTop();
203
204        if(isTableCellActive) {
205            top += (targetElement.offsetHeight + this.element.offsetHeight);
206        }
207
208        if( top < 0 || top < scrollTop ) {
209            top = $(targetElement).offset().top + targetElement.offsetHeight + verticalOffset;
210            //그래도 top이 음수면 강제로 0으로 세팅한다
211            if(top < 0) {
212                top = 0;
213            }
214        }
215
216        // 화면을 벗어나는 경우
217        if(window["wvAdminIFrameBridge"] && window["wvAdminIFrameBridge"].contentSizeCon.width() - $(this.element)[0].offsetWidth < left){
218            left = $(targetElement).offset().left + targetElement.offsetWidth - $(this.element)[0].offsetWidth;
219        }
220
221        // 화면이 메뉴보다 작은 경우
222        // 이미 고정된 메뉴width를 써야함
223        const viewWidth = wvAdminIFrameBridge._WVContentArea.$contentBody.width();
224        if(viewWidth < $(this.element)[0].offsetWidth || viewWidth < 500) {
225            left = viewWidth / 2 - narrowedMenuWidth / 2;
226        }
227
228        $(this.element).css( { "top" : top , "left" : left });
229        if(isTable) {
230            if(isTableCellActive) {
231                $(this.element).css('visibility','');
232            } else {
233                $(this.element).css('visibility','hidden');
234            }
235        }
236
237        // ToolText.prototype.btnShowHideControl();
238    }
239}
240
241
242
243

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.