Skip to content

Commit

Permalink
BUGFIX Stop "Insert Link" or "Insert Image" header disappearing insid…
Browse files Browse the repository at this point in the history
…e the HtmlEditorField toolbar

when clicking a link type
  • Loading branch information
Sean Harvey committed Apr 17, 2012
1 parent f3137e5 commit 5bb31c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion forms/HtmlEditorField.php
Expand Up @@ -302,7 +302,7 @@ function LinkForm() {
new FieldList( new FieldList(
new LiteralField( new LiteralField(
'Heading', 'Heading',
sprintf('<h3>%s</h3>', _t('HtmlEditorField.LINK', 'Link')) sprintf('<h3>%s</h3>', _t('HtmlEditorField.LINK', 'Insert Link'))
), ),
$contentComposite = new CompositeField( $contentComposite = new CompositeField(
new OptionsetField( new OptionsetField(
Expand Down
26 changes: 12 additions & 14 deletions javascript/HtmlEditorField.js
Expand Up @@ -345,7 +345,6 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
// Move title from headline to (jQuery compatible) title attribute // Move title from headline to (jQuery compatible) title attribute
var titleEl = this.find(':header:first'); var titleEl = this.find(':header:first');
this.getDialog().attr('title', titleEl.text()); this.getDialog().attr('title', titleEl.text());
titleEl.remove();


this.setEditor(ss.editorWrappers['default']()); this.setEditor(ss.editorWrappers['default']());
}, },
Expand Down Expand Up @@ -400,7 +399,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
this.addAnchorSelector(); this.addAnchorSelector();


// Toggle field visibility and state based on type selection // Toggle field visibility and state based on type selection
this.find('.field').hide(); this.find('div.content .field').hide();
this.find('.field#LinkType').show(); this.find('.field#LinkType').show();
this.find('.field#' + linkType).show(); this.find('.field#' + linkType).show();
if(linkType == 'internal' || linkType == 'anchor') this.find('.field#Anchor').show(); if(linkType == 'internal' || linkType == 'anchor') this.find('.field#Anchor').show();
Expand Down Expand Up @@ -481,20 +480,20 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
this.find(':input[name=Anchor]').parent().append(anchorSelector); this.find(':input[name=Anchor]').parent().append(anchorSelector);


anchorSelector.focus(function(e) { anchorSelector.focus(function(e) {
self.refreshAnchors($(this)); self.refreshAnchors();
}); });
} else { } else {
var buttonRefresh = $('<a id="Form_EditorToolbarLinkForm_AnchorRefresh" title="Refresh the anchor list" alt="Refresh the anchor list" class="buttonRefresh"><span></span></a>'); var buttonRefresh = $('<a id="Form_EditorToolbarLinkForm_AnchorRefresh" title="Refresh the anchor list" alt="Refresh the anchor list" class="buttonRefresh"><span></span></a>');
anchorSelector = $('<select id="Form_EditorToolbarLinkForm_AnchorSelector" class="hasRefreshButton" name="AnchorSelector"></select>'); anchorSelector = $('<select id="Form_EditorToolbarLinkForm_AnchorSelector" class="hasRefreshButton" name="AnchorSelector"></select>');
this.find(':input[name=Anchor]').parent().append(buttonRefresh).append(anchorSelector); this.find(':input[name=Anchor]').parent().append(buttonRefresh).append(anchorSelector);


buttonRefresh.click(function(e) { buttonRefresh.click(function(e) {
refreshAnchors(anchorSelector); self.refreshAnchors();
}); });
} }


// initialization // initialization
this.refreshAnchors(); self.refreshAnchors();


// copy the value from dropdown to the text field // copy the value from dropdown to the text field
anchorSelector.change(function(e) { anchorSelector.change(function(e) {
Expand All @@ -503,13 +502,16 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
}, },
// this function collects the anchors in the currently active editor and regenerates the dropdown // this function collects the anchors in the currently active editor and regenerates the dropdown
refreshAnchors: function() { refreshAnchors: function() {
var selector = this.find(':input[name=AnchorSelector]'), anchors = []; var selector = this.find(':input[name=AnchorSelector]'), anchors = [], ed = this.getEditor();
// name attribute is defined as CDATA, should accept all characters and entities // name attribute is defined as CDATA, should accept all characters and entities
// http://www.w3.org/TR/1999/REC-html401-19991224/struct/links.html#h-12.2 // http://www.w3.org/TR/1999/REC-html401-19991224/struct/links.html#h-12.2
var raw = this.getEditor().getContent().match(/name="([^"]+?)"|name='([^']+?)'/gim);
if (raw && raw.length) { if(ed) {
for(var i = 0; i < raw.length; i++) { var raw = ed.getContent().match(/name="([^"]+?)"|name='([^']+?)'/gim);
anchors.push(raw[i].substr(6).replace(/"$/, '')); if (raw && raw.length) {
for(var i = 0; i < raw.length; i++) {
anchors.push(raw[i].substr(6).replace(/"$/, ''));
}
} }
} }


Expand Down Expand Up @@ -670,10 +672,6 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
} }


this.redraw(); this.redraw();

// HACK: Hide selected node in IE because its drag handles on potentially selected elements
// don't respect the z-index of the dialog overlay.
// jQuery(ed.getContainer()).hide();
}, },
redraw: function() { redraw: function() {
this._super(); this._super();
Expand Down
2 changes: 1 addition & 1 deletion lang/en.yml
Expand Up @@ -260,7 +260,7 @@ en:
IMAGEHEIGHTPX: Height IMAGEHEIGHTPX: Height
IMAGETITLE: 'Title text (tooltip) - for additional information about the image' IMAGETITLE: 'Title text (tooltip) - for additional information about the image'
IMAGEWIDTHPX: Width IMAGEWIDTHPX: Width
LINK: Link LINK: 'Insert Link'
LINKANCHOR: 'Anchor on this page' LINKANCHOR: 'Anchor on this page'
LINKDESCR: 'Link description' LINKDESCR: 'Link description'
LINKEMAIL: 'Email address' LINKEMAIL: 'Email address'
Expand Down

0 comments on commit 5bb31c4

Please sign in to comment.