CreateLinkDialog.js
资源名称:oa.rar [点击查看]
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:3k
源码类别:
OA系统
开发平台:
Java
- /*
- Copyright (c) 2004-2006, The Dojo Foundation
- All Rights Reserved.
- Licensed under the Academic Free License version 2.1 or above OR the
- modified BSD license. For more information on Dojo licensing, see:
- http://dojotoolkit.org/community/licensing.shtml
- */
- dojo.provide("dojo.widget.Editor2Plugin.CreateLinkDialog");
- dojo.widget.defineWidget("dojo.widget.Editor2CreateLinkDialog", dojo.widget.Editor2DialogContent, {templateString:"<table>n<tr><td>URL</td><td> <input type="text" dojoAttachPoint="link_href" name="dojo_createLink_href"/></td></tr>n<tr><td>Target </td><td><select dojoAttachPoint="link_target">nt<option value="">Self</option>nt<option value="_blank">New Window</option>nt<option value="_top">Top Window</option>nt</select></td></tr>n<tr><td>Class </td><td><input type="text" dojoAttachPoint="link_class" /></td></tr>n<tr><td colspan="2">nt<table><tr>nt<td><button dojoType='Button' dojoAttachEvent='onClick:ok'>OK</button></td>nt<td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Cancel</button></td>nt</tr></table>nt</td></tr>n</table>n", editableAttributes:["href", "target", "class"], loadContent:function () {
- var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
- curInst.saveSelection();
- this.linkNode = dojo.withGlobal(curInst.window, "getAncestorElement", dojo.html.selection, ["a"]);
- var linkAttributes = {};
- this.extraAttribText = "";
- if (this.linkNode) {
- var attrs = this.linkNode.attributes;
- for (var i = 0; i < attrs.length; i++) {
- if (dojo.lang.find(this.editableAttributes, attrs[i].name.toLowerCase()) > -1) {
- linkAttributes[attrs[i].name] = attrs[i].value;
- } else {
- if (attrs[i].specified == undefined || attrs[i].specified) {
- this.extraAttribText += attrs[i].name + "="" + attrs[i].value + "" ";
- }
- }
- }
- } else {
- var html = dojo.withGlobal(curInst.window, "getSelectedText", dojo.html.selection);
- if (html == null || html.length == 0) {
- alert("Please select some text to create a link.");
- return false;
- }
- }
- for (var i = 0; i < this.editableAttributes.length; ++i) {
- name = this.editableAttributes[i];
- this["link_" + name].value = (linkAttributes[name] == undefined) ? "" : linkAttributes[name];
- }
- return true;
- }, ok:function () {
- var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
- curInst.restoreSelection();
- if (!this.linkNode) {
- var html = dojo.withGlobal(curInst.window, "getSelectedHtml", dojo.html.selection);
- } else {
- var html = this.linkNode.innerHTML;
- dojo.withGlobal(curInst.window, "selectElement", dojo.html.selection, [this.linkNode]);
- }
- var attstr = "";
- for (var i = 0; i < this.editableAttributes.length; ++i) {
- name = this.editableAttributes[i];
- var value = this["link_" + name].value;
- if (value.length > 0) {
- attstr += name + "="" + value + "" ";
- }
- }
- curInst.execCommand("inserthtml", "<a " + attstr + this.extraAttribText + ">" + html + "</a>");
- this.cancel();
- }});