mirror of
https://github.com/moodle/moodle.git
synced 2025-03-17 14:10:08 +01:00
Merge branch 'MDL-45008-master' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
19a1a68e45
@ -85,8 +85,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
|
||||
});
|
||||
|
||||
// And then the unlink button.
|
||||
this.addBasicButton({
|
||||
exec: 'unlink',
|
||||
this.addButton({
|
||||
buttonName: 'unlink',
|
||||
callback: this._unlink,
|
||||
icon: 'e/remove_link',
|
||||
title: 'unlink',
|
||||
|
||||
@ -291,6 +292,52 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
|
||||
}
|
||||
|
||||
return this._content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unlinks the current selection.
|
||||
* If the selection is empty (e.g. the cursor is placed within a link),
|
||||
* then the whole link is unlinked.
|
||||
*
|
||||
* @method _unlink
|
||||
* @private
|
||||
*/
|
||||
_unlink: function() {
|
||||
var host = this.get('host'),
|
||||
range = host.getSelection();
|
||||
|
||||
if (range && range.length) {
|
||||
if (range[0].startOffset === range[0].endOffset) {
|
||||
// The cursor was placed in the editor but there was no selection - select the whole parent.
|
||||
var nodes = host.getSelectedNodes();
|
||||
if (nodes) {
|
||||
// We need to unlink each anchor individually - we cannot select a range because it may only consist of a
|
||||
// fragment of an anchor. Selecting the parent would be dangerous because it may contain other links which
|
||||
// would then be unlinked too.
|
||||
nodes.each(function(node) {
|
||||
// We need to select the whole anchor node for this to work in some browsers.
|
||||
// We only need to search up because getSeletedNodes returns all Nodes in the selection.
|
||||
var anchor = node.ancestor('a', true);
|
||||
if (anchor) {
|
||||
// Set the selection to the whole of the first anchro.
|
||||
host.setSelection(host.getSelectionFromNode(anchor));
|
||||
|
||||
// Call the browser unlink.
|
||||
document.execCommand('unlink', false, null);
|
||||
}
|
||||
}, this);
|
||||
|
||||
// And mark the text area as updated.
|
||||
this.markUpdated();
|
||||
}
|
||||
} else {
|
||||
// Call the browser unlink.
|
||||
document.execCommand('unlink', false, null);
|
||||
|
||||
// And mark the text area as updated.
|
||||
this.markUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1 +1 @@
|
||||
YUI.add("moodle-atto_link-button",function(e,t){var n="atto_link",r={NEWWINDOW:"atto_link_openinnewwindow"},i='<form class="atto_form"><label for="{{elementid}}_atto_link_urlentry">{{get_string "enterurl" component}}</label><input class="fullwidth url" type="url" id="{{elementid}}_atto_link_urlentry" size="32"/><br/>{{#if showFilepicker}}<button class="openlinkbrowser">{{get_string "browserepositories" component}}</button><br/>{{/if}}<input type="checkbox" class="newwindow" id="{{elementid}}_{{CSS.NEWWINDOW}}"/><label class="sameline" for="{{elementid}}_{{CSS.NEWWINDOW}}">{{get_string "openinnewwindow" component}}</label><br/><div class="mdl-align"><br/><button type="submit" class="submit">{{get_string "createlink" component}}</button></div></form>';e.namespace("M.atto_link").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_content:null,initializer:function(){this.addButton({icon:"e/insert_edit_link",callback:this._displayDialogue,tags:"a"}),this.addBasicButton({exec:"unlink",icon:"e/remove_link",title:"unlink",tags:"a"})},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1||this._currentSelection.collapsed)return;var e=this.getDialogue({headerContent:M.util.get_string("createlink",n),focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()),this._resolveAnchors(),e.show()},_resolveAnchors:function(){var t=this.get("host").getSelectionParentNode(),n,r,i,s;if(!t)return;n=this._findSelectedAnchors(e.one(t)),n.length>0&&(r=n[0],this._currentSelection=this.get("host").getSelectionFromNode(r),i=r.getAttribute("href"),s=r.getAttribute("target"),i!==""&&this._content.one(".url").setAttribute("value",i),s==="_blank"?this._content.one(".newwindow").setAttribute("checked","checked"):this._content.one(".newwindow").removeAttribute("checked"))},_filepickerCallback:function(e){this.getDialogue().set("focusAfterHide",null).hide(),e.url!==""&&(this.get("host").setSelection(this._currentSelection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,e.url))},_setLink:function(t){var n,r,i,s,o,u=this.get("host");t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=this._content.one(".url"),o=n.get("value");if(o!==""){this.editor.focus(),u.setSelection(this._currentSelection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,o),i=u.getSelectionParentNode();if(!i)return;s=this._findSelectedAnchors(e.one(i)),e.Array.each(s,function(e){r=this._content.one(".newwindow"),r.get("checked")?e.setAttribute("target","_blank"):e.removeAttribute("target")},this),this.markUpdated()}},_findSelectedAnchors:function(e){var t=e.get("tagName"),n,r;return t&&t.toLowerCase()==="a"?[e]:(r=[],e.all("a").each(function(e){!n&&this.get("host").selectionContainsNode(e)&&r.push(e)}),r.length>0?r:(n=e.ancestor("a"),n?[n]:[]))},_getDialogueContent:function(){var t=this.get("host").canShowFilepicker("link"),s=e.Handlebars.compile(i);return this._content=e.Node.create(s({showFilepicker:t,component:n,CSS:r})),this._content.one(".submit").on("click",this._setLink,this),t&&this._content.one(".openlinkbrowser").on("click",function(e){e.preventDefault(),this.get("host").showFilepicker("link",this._filepickerCallback,this)},this),this._content}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
|
||||
YUI.add("moodle-atto_link-button",function(e,t){var n="atto_link",r={NEWWINDOW:"atto_link_openinnewwindow"},i='<form class="atto_form"><label for="{{elementid}}_atto_link_urlentry">{{get_string "enterurl" component}}</label><input class="fullwidth url" type="url" id="{{elementid}}_atto_link_urlentry" size="32"/><br/>{{#if showFilepicker}}<button class="openlinkbrowser">{{get_string "browserepositories" component}}</button><br/>{{/if}}<input type="checkbox" class="newwindow" id="{{elementid}}_{{CSS.NEWWINDOW}}"/><label class="sameline" for="{{elementid}}_{{CSS.NEWWINDOW}}">{{get_string "openinnewwindow" component}}</label><br/><div class="mdl-align"><br/><button type="submit" class="submit">{{get_string "createlink" component}}</button></div></form>';e.namespace("M.atto_link").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_content:null,initializer:function(){this.addButton({icon:"e/insert_edit_link",callback:this._displayDialogue,tags:"a"}),this.addButton({buttonName:"unlink",callback:this._unlink,icon:"e/remove_link",title:"unlink",tags:"a"})},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1||this._currentSelection.collapsed)return;var e=this.getDialogue({headerContent:M.util.get_string("createlink",n),focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()),this._resolveAnchors(),e.show()},_resolveAnchors:function(){var t=this.get("host").getSelectionParentNode(),n,r,i,s;if(!t)return;n=this._findSelectedAnchors(e.one(t)),n.length>0&&(r=n[0],this._currentSelection=this.get("host").getSelectionFromNode(r),i=r.getAttribute("href"),s=r.getAttribute("target"),i!==""&&this._content.one(".url").setAttribute("value",i),s==="_blank"?this._content.one(".newwindow").setAttribute("checked","checked"):this._content.one(".newwindow").removeAttribute("checked"))},_filepickerCallback:function(e){this.getDialogue().set("focusAfterHide",null).hide(),e.url!==""&&(this.get("host").setSelection(this._currentSelection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,e.url))},_setLink:function(t){var n,r,i,s,o,u=this.get("host");t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=this._content.one(".url"),o=n.get("value");if(o!==""){this.editor.focus(),u.setSelection(this._currentSelection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,o),i=u.getSelectionParentNode();if(!i)return;s=this._findSelectedAnchors(e.one(i)),e.Array.each(s,function(e){r=this._content.one(".newwindow"),r.get("checked")?e.setAttribute("target","_blank"):e.removeAttribute("target")},this),this.markUpdated()}},_findSelectedAnchors:function(e){var t=e.get("tagName"),n,r;return t&&t.toLowerCase()==="a"?[e]:(r=[],e.all("a").each(function(e){!n&&this.get("host").selectionContainsNode(e)&&r.push(e)}),r.length>0?r:(n=e.ancestor("a"),n?[n]:[]))},_getDialogueContent:function(){var t=this.get("host").canShowFilepicker("link"),s=e.Handlebars.compile(i);return this._content=e.Node.create(s({showFilepicker:t,component:n,CSS:r})),this._content.one(".submit").on("click",this._setLink,this),t&&this._content.one(".openlinkbrowser").on("click",function(e){e.preventDefault(),this.get("host").showFilepicker("link",this._filepickerCallback,this)},this),this._content},_unlink:function(){var e=this.get("host"),t=e.getSelection();if(t&&t.length)if(t[0].startOffset===t[0].endOffset){var n=e.getSelectedNodes();n&&(n.each(function(t){var n=t.ancestor("a",!0);n&&(e.setSelection(e.getSelectionFromNode(n)),document.execCommand("unlink",!1,null))},this),this.markUpdated())}else document.execCommand("unlink",!1,null),this.markUpdated()}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
|
||||
|
@ -85,8 +85,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
|
||||
});
|
||||
|
||||
// And then the unlink button.
|
||||
this.addBasicButton({
|
||||
exec: 'unlink',
|
||||
this.addButton({
|
||||
buttonName: 'unlink',
|
||||
callback: this._unlink,
|
||||
icon: 'e/remove_link',
|
||||
title: 'unlink',
|
||||
|
||||
@ -291,6 +292,52 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
|
||||
}
|
||||
|
||||
return this._content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unlinks the current selection.
|
||||
* If the selection is empty (e.g. the cursor is placed within a link),
|
||||
* then the whole link is unlinked.
|
||||
*
|
||||
* @method _unlink
|
||||
* @private
|
||||
*/
|
||||
_unlink: function() {
|
||||
var host = this.get('host'),
|
||||
range = host.getSelection();
|
||||
|
||||
if (range && range.length) {
|
||||
if (range[0].startOffset === range[0].endOffset) {
|
||||
// The cursor was placed in the editor but there was no selection - select the whole parent.
|
||||
var nodes = host.getSelectedNodes();
|
||||
if (nodes) {
|
||||
// We need to unlink each anchor individually - we cannot select a range because it may only consist of a
|
||||
// fragment of an anchor. Selecting the parent would be dangerous because it may contain other links which
|
||||
// would then be unlinked too.
|
||||
nodes.each(function(node) {
|
||||
// We need to select the whole anchor node for this to work in some browsers.
|
||||
// We only need to search up because getSeletedNodes returns all Nodes in the selection.
|
||||
var anchor = node.ancestor('a', true);
|
||||
if (anchor) {
|
||||
// Set the selection to the whole of the first anchro.
|
||||
host.setSelection(host.getSelectionFromNode(anchor));
|
||||
|
||||
// Call the browser unlink.
|
||||
document.execCommand('unlink', false, null);
|
||||
}
|
||||
}, this);
|
||||
|
||||
// And mark the text area as updated.
|
||||
this.markUpdated();
|
||||
}
|
||||
} else {
|
||||
// Call the browser unlink.
|
||||
document.execCommand('unlink', false, null);
|
||||
|
||||
// And mark the text area as updated.
|
||||
this.markUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -83,8 +83,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
|
||||
});
|
||||
|
||||
// And then the unlink button.
|
||||
this.addBasicButton({
|
||||
exec: 'unlink',
|
||||
this.addButton({
|
||||
buttonName: 'unlink',
|
||||
callback: this._unlink,
|
||||
icon: 'e/remove_link',
|
||||
title: 'unlink',
|
||||
|
||||
@ -289,5 +290,51 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
|
||||
}
|
||||
|
||||
return this._content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unlinks the current selection.
|
||||
* If the selection is empty (e.g. the cursor is placed within a link),
|
||||
* then the whole link is unlinked.
|
||||
*
|
||||
* @method _unlink
|
||||
* @private
|
||||
*/
|
||||
_unlink: function() {
|
||||
var host = this.get('host'),
|
||||
range = host.getSelection();
|
||||
|
||||
if (range && range.length) {
|
||||
if (range[0].startOffset === range[0].endOffset) {
|
||||
// The cursor was placed in the editor but there was no selection - select the whole parent.
|
||||
var nodes = host.getSelectedNodes();
|
||||
if (nodes) {
|
||||
// We need to unlink each anchor individually - we cannot select a range because it may only consist of a
|
||||
// fragment of an anchor. Selecting the parent would be dangerous because it may contain other links which
|
||||
// would then be unlinked too.
|
||||
nodes.each(function(node) {
|
||||
// We need to select the whole anchor node for this to work in some browsers.
|
||||
// We only need to search up because getSeletedNodes returns all Nodes in the selection.
|
||||
var anchor = node.ancestor('a', true);
|
||||
if (anchor) {
|
||||
// Set the selection to the whole of the first anchro.
|
||||
host.setSelection(host.getSelectionFromNode(anchor));
|
||||
|
||||
// Call the browser unlink.
|
||||
document.execCommand('unlink', false, null);
|
||||
}
|
||||
}, this);
|
||||
|
||||
// And mark the text area as updated.
|
||||
this.markUpdated();
|
||||
}
|
||||
} else {
|
||||
// Call the browser unlink.
|
||||
document.execCommand('unlink', false, null);
|
||||
|
||||
// And mark the text area as updated.
|
||||
this.markUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user