#19519025 x.js 코드 교체

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@8098 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
bnu 2011-02-15 06:54:48 +00:00
parent 73b22bab38
commit e1797a4860
2 changed files with 163 additions and 143 deletions

View file

@ -86,7 +86,7 @@
</table>
</div>
<div id="popFooter" class="tCenter">
<a href="#" onclick="insertImage()" class="button black strong"><span>{$lang->cmd_insert}</span></a>
<a href="#" id="btn_insert" class="button black strong"><span>{$lang->cmd_insert}</span></a>
<a href="#" onclick="winopen('./?module=editor&amp;act=dispEditorComponentInfo&amp;component_name={$component_info->component_name}','ComponentInfo','left=10,top=10,width=10,height=10,resizable=no,scrollbars=no,toolbars=no');return false;" class="button"><span>{$lang->about_component}</span></a>
</div>

View file

@ -1,156 +1,176 @@
/**
* popup으로 열렸을 경우 부모창의 위지윅에디터에 select된 이미지가 있는지 체크하여
* 있으면 가져와서 원하는 곳에 삽입
**/
var orig_width = 0;
var orig_height = 0;
function getImage() {
// 부모 위지윅 에디터에서 선택된 영역이 있는지 확인
if(typeof(opener)=="undefined") return;
;(function($) {
var orig_width = 0;
var orig_height = 0;
var $form = $;
// url이 미리 입력되어 있을 경우 scale구해줌
if(xGetElementById("image_url").value) {
getImageScale();
return;
function getImage() {
var image_url = $form.find('#image_url').val();
// url이 미리 입력되어 있을 경우 scale구해줌
if(image_url) {
getImageScale();
return;
}
// 부모 위지윅 에디터에서 선택된 영역이 있으면 처리
var node = opener.editorPrevNode;
if(!node || node.nodeName != 'IMG') {
return;
}
var src = node.getAttribute('src');
var border = (node.style.borderWidth) ? node.style.borderWidth.match('[0-9]+') : node.getAttribute('border');
var align = (node.style.cssFloat) ? node.style.cssFloat : node.style.styleFloat;
var margin = (node.style.margin) ? node.style.margin.match('[0-9]+') : node.getAttribute('margin');
var alt = node.getAttribute('alt');
var width = $(node).width();
var height = $(node).height();
var link_url = node.getAttribute('link_url');
var open_window = node.getAttribute('open_window');
orig_width = width;
orig_height = height;
if(!align) {
align = (node.style.verticalAlign) ? node.style.verticalAlign : node.getAttribute('align');
}
$form.find('#image_url').val(src);
$form.find('#image_alt').val(alt);
if(link_url) {
link_url = link_url.replace(/<([^>]*)>/ig,'').replace(/&lt;/ig,'<').replace(/&gt;/ig,'>').replace(/&amp;/ig,'&');
$form.find('#link_url').val(link_url);
}
if(open_window == 'Y') $form.find('#open_window').attr('checked', true);
switch(align) {
case 'left' : $form.find('#align_left').attr('checked', true); break;
case 'middle' : $form.find('#align_middle').attr('checked', true); break;
case 'right' : $form.find('#align_right').attr('checked', true); break;
default : $form.find('#align_normal').attr('checked', true); break;
}
if(margin) {
$form.find('#image_margin').val(margin);
}
if(border) {
$form.find('#image_border').val(border);
}
$form.find('#width').val(width);
$form.find('#height').val(height);
}
// 부모 위지윅 에디터에서 선택된 영역이 있으면 처리
var node = opener.editorPrevNode;
if(!node || node.nodeName != "IMG") {
return;
}
var src = node.getAttribute("src");
var border = node.style.borderWidth ?
node.style.borderWidth.match("[0-9]+") : node.getAttribute("border");
var align = node.style.cssFloat ?
node.style.cssFloat : node.style.styleFloat;
if(!align) align = node.style.verticalAlign?
node.style.verticalAlign : node.getAttribute("align");
var margin = node.style.margin ?
node.style.margin.match("[0-9]+") : node.getAttribute("margin");
var alt = node.getAttribute("alt");
var width = xWidth(node);
var height = xHeight(node);
orig_width = width;
orig_height = height;
var link_url = node.getAttribute("link_url");
var open_window = node.getAttribute("open_window");
function insertImage() {
if(typeof(opener) == "undefined") return;
xGetElementById("image_url").value = src;
xGetElementById("image_alt").value = alt;
var text = '';
var link_url = $form.find('#link_url').val();
var open_window = 'N';
if(link_url) {
link_url = link_url.replace(/<([^>]*)>/ig,'').replace(/&lt;/ig,'<').replace(/&gt;/ig,'>').replace(/&amp;/ig,'&');
xGetElementById('link_url').value = link_url;
}
if(open_window == 'Y') xGetElementById('open_window').checked = "true";
if(link_url) link_url = link_url.replace(/&/ig,'&amp;').replace(/</ig,'&lt;').replace(/>/ig,'&gt;');
if($form.find('#open_window').attr('checked')) open_window = 'Y';
switch(align) {
case 'left' : xGetElementById("align_left").checked = true; break;
case 'middle' : xGetElementById("align_middle").checked = true; break;
case 'right' : xGetElementById("align_right").checked = true; break;
default : xGetElementById("align_normal").checked = true; break;
var url = $form.find('#image_url').val();
var alt = $form.find('#image_alt').val();
var align = '';
var border = parseInt($form.find('#image_border').val(), 10);
var margin = parseInt($form.find('#image_margin').val(), 10);
if($form.find('#align_normal').attr('checked') == true) align = '';
else if($form.find('#align_left').attr('checked') == true) align = 'float: left';
else if($form.find('#align_middle').attr('checked') == true) align = 'vertical-align: middle';
else if($form.find('#align_right').attr('checked') == true) align = 'float: right';
var width = $form.find('#width').val();
var height = $form.find('#height').val();
if(!url) {
window.close();
return;
}
url = url.replace(request_uri,'');
var $component = $('<span><img editor_component="image_link" /></span>');
var img_attrs = {};
var img_style = {};
img_attrs.src = url;
if(alt) img_attrs.alt = alt;
if(width) {
img_attrs.width = width;
img_style.width = width;
}
if(height) {
img_attrs.height = height;
img_style.height = height;
}
if(link_url) img_attrs.link_url = link_url;
if(open_window == 'Y') img_attrs.open_window = 'Y';
if(border) {
img_attrs.border = border;
img_style.border = border+'px solid';
}
if(margin) img_attrs.margin = margin;
$component.find('img').attr(img_attrs);
$component.find('img').css(img_style);
text = $component.html();
opener.editorFocus(opener.editorPrevSrl);
var iframe_obj = opener.editorGetIFrame(opener.editorPrevSrl)
opener.editorReplaceHTML(iframe_obj, text);
opener.editorFocus(opener.editorPrevSrl);
window.close();
}
if(margin) {
xGetElementById('image_margin').value = margin;
function getImageScale() {
var url = $form.find('#image_url').val();
if(!url) return;
var img = new Image();
img.src = url;
$form.find('#width').val(img.width);
$form.find('#height').val(img.height);
orig_width = img.width;
orig_height = img.height;
}
if(border) {
xGetElementById("image_border").value = border;
function setScale(type) {
switch(type) {
case 'width' :
if(!orig_height) return;
var n_width = $form.find('#width').val();
var p = n_width / orig_width;
var n_height = parseInt(orig_height * p, 10);
$form.find('#height').val(n_height);
break;
case 'height' :
if(!orig_width) return;
var n_height = $form.find('#height').val();
var p = n_height / orig_height;
var n_width = parseInt(orig_width * p, 10);
$form.find('#width').val(n_width);
break;
}
}
xGetElementById("width").value = width;
xGetElementById("height").value = height;
/* DOM READY */
$(function() {
$form = $('#fo');
$form.find('#btn_insert').click(insertImage);
if(typeof(opener) != "undefined") getImage();
});
}
function getImageScale() {
var url = xGetElementById("image_url").value;
if(!url) return;
var img = new Image();
img.src = url;
xGetElementById("width").value = img.width;
xGetElementById("height").value = img.height;
orig_width = img.width;
orig_height = img.height;
}
function insertImage(obj) {
if(typeof(opener)=="undefined") return;
var link_url = xGetElementById('link_url').value;
if(link_url) link_url = link_url.replace(/&/ig,'&amp;').replace(/</ig,'&lt;').replace(/>/ig,'&gt;');
var open_window = 'N';
if(xGetElementById('open_window').checked) open_window = 'Y';
var url = xGetElementById("image_url").value;
var alt = xGetElementById("image_alt").value;
var align = "";
if(xGetElementById("align_normal").checked==true) align = "";
else if(xGetElementById("align_left").checked==true) align = "float: left";
else if(xGetElementById("align_middle").checked==true) align = "vertical-align: middle";
else if(xGetElementById("align_right").checked==true) align = "float: right";
var border = parseInt(xGetElementById("image_border").value,10);
var margin = parseInt(xGetElementById("image_margin").value,10);
var width = xGetElementById("width").value;
var height = xGetElementById("height").value;
if(!url) {
window.close();
return;
}
url = url.replace(request_uri,'');
var text = "<img editor_component=\"image_link\" src=\""+url+"\"";
if(alt) text+= " alt=\""+alt+"\"";
if(width) text+= " width=\""+width+"\"";
if(height) text+= " height=\""+height+"\"";
if(link_url) text+= " link_url=\""+link_url+"\"";
if(open_window=='Y') text+= " open_window=\"Y\"";
if(align || border || margin){
text+= " style=\"";
if(align) text+= align+"; ";
if(border) text+= "border: solid "+border+"px; ";
if(margin) text+= "margin: "+margin+"px; ";
text+= "\" ";
}
if(border) text+= " border=\""+border+"\""
if(margin) text+= " margin=\""+margin+"\""
text+= " />";
opener.editorFocus(opener.editorPrevSrl);
var iframe_obj = opener.editorGetIFrame(opener.editorPrevSrl)
opener.editorReplaceHTML(iframe_obj, text);
opener.editorFocus(opener.editorPrevSrl);
window.close();
}
xAddEventListener(window, "load", getImage);
function setScale(type) {
switch(type) {
case 'width' :
if(!orig_height) return;
var n_width = xGetElementById('width').value;
var p = n_width/orig_width;
var n_height = parseInt(orig_height * p,10);
xGetElementById('height').value = n_height;
break;
case 'height' :
if(!orig_width) return;
var n_height = xGetElementById('height').value;
var p = n_height/orig_height;
var n_width = parseInt(orig_width * p,10);
xGetElementById('width').value = n_width;
break;
}
}
}) (jQuery);