BUGFIX: the anchor dropdown now works in IE. Also fixes other anchor-related problems as described in ticket #4961 (from r97673)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102525 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-12 23:11:28 +00:00
parent caebfe6ea3
commit 876c760331

View File

@ -54,62 +54,78 @@ LinkForm.prototype = {
$('Form_EditorToolbarLinkForm_TargetBlank').checked = (linkType == 'file'); $('Form_EditorToolbarLinkForm_TargetBlank').checked = (linkType == 'file');
} }
} }
},
getAnchors: function() { if (jQuery('#Form_EditorToolbarLinkForm_AnchorSelector')) {
var raw = tinyMCE.activeEditor.getContent().match(/name="([a-zA-Z0-9-_]+?)"/gim); if ( linkType=='anchor' ) {
if (raw && raw.length) { jQuery('#Form_EditorToolbarLinkForm_AnchorSelector').show();
var anchors = new Array(); jQuery('#Form_EditorToolbarLinkForm_AnchorRefresh').show();
for(var i = 0; i < raw.length; i++) { } else {
anchors.push(raw[i].substr(6).replace(/"$/, '')); jQuery('#Form_EditorToolbarLinkForm_AnchorSelector').hide();
jQuery('#Form_EditorToolbarLinkForm_AnchorRefresh').hide();
} }
return anchors; }
} else { return false; }
}, },
drawAnchorHelpers: function(anchors) { addAnchorSelector: function() {
(function($) {
if (!$('#Form_EditorToolbarLinkForm_AnchorSelector').length) {
// this function collects the anchors in the currently active editor and regenerates the dropdown
var refreshAnchors = function(selector) {
var anchors = new Array();
var raw = tinyMCE.activeEditor.getContent().match(/name="([a-zA-Z0-9-_]+?)"/gim);
if (raw && raw.length) {
for(var i = 0; i < raw.length; i++) {
anchors.push(raw[i].substr(6).replace(/"$/, ''));
}
}
if (!$('Form_EditorToolbarLinkForm_AnchorSelector')) { selector.empty();
var fieldHolder = $('Form_EditorToolbarLinkForm_Anchor').parentNode; selector.append($('<option value="" selected="1">Select an anchor</option>'));
var anchorSelector = document.createElement('select'); for (var i = 0; i < anchors.length; i++) {
anchorSelector.id = 'Form_EditorToolbarLinkForm_AnchorSelector'; selector.append($('<option value="'+anchors[i]+'">'+anchors[i]+'</option>'));
fieldHolder.appendChild(anchorSelector); }
} else {
var anchorSelector = $('Form_EditorToolbarLinkForm_AnchorSelector');
if (anchorSelector.hasChildNodes()) {
while (anchorSelector.childNodes.length >= 1) {
anchorSelector.removeChild(anchorSelector.firstChild);
} }
// refresh the anchor selector on click, or in case of IE - button click
if( !tinymce.isIE ) {
var anchorSelector = $('<select id="Form_EditorToolbarLinkForm_AnchorSelector"></select>');
$('#Form_EditorToolbarLinkForm_Anchor').parent().append(anchorSelector);
anchorSelector.focus(function(e) {
refreshAnchors($(this));
});
} else {
var buttonRefresh = $('<a id="Form_EditorToolbarLinkForm_AnchorRefresh" title="Refresh the anchor list" alt="Refresh the anchor list" class="buttonRefresh"><span></span></a>');
var anchorSelector = $('<select id="Form_EditorToolbarLinkForm_AnchorSelector" class="hasRefreshButton"></select>');
$('#Form_EditorToolbarLinkForm_Anchor').parent().append(buttonRefresh).append(anchorSelector);
// :hover class does not work on IE6 on dynamically created elements, have to simulate
buttonRefresh.mouseover(function(e) {
buttonRefresh.addClass('buttonRefreshHover');
});
buttonRefresh.mouseout(function(e) {
buttonRefresh.removeClass('buttonRefreshHover');
});
buttonRefresh.click(function(e) {
var anchorSelector = $('#Form_EditorToolbarLinkForm_AnchorSelector');
refreshAnchors(anchorSelector);
});
}
// initialization
refreshAnchors(anchorSelector);
// copy the value from dropdown to the text field
anchorSelector.change(function(e) {
$('#Form_EditorToolbarLinkForm_Anchor').val($(this).val());
});
} }
} })(jQuery);
var opt = document.createElement('option');
opt.value = '';
opt.appendChild(document.createTextNode('Select an anchor'));
anchorSelector.appendChild(opt);
anchorSelector.onchange = function(e) {
if (!e) e = window.event;
$('Form_EditorToolbarLinkForm_Anchor').value = e.target.options[e.target.selectedIndex].value;
}
for (var i = 0; i < anchors.length; i++) {
var opt = document.createElement('option');
opt.value = anchors[i];
opt.appendChild(document.createTextNode(anchors[i]));
anchorSelector.appendChild(opt);
}
}, },
toggle: function(ed) { toggle: function(ed) {
var anchors = this.getAnchors(); this.addAnchorSelector();
// Change this to false to disable anchor hinting
if (anchors && true) {
// Draw anchors list
this.drawAnchorHelpers(anchors);
}
this.ToolbarForm.toggle(ed); this.ToolbarForm.toggle(ed);
this.respondToNodeChange(ed); this.respondToNodeChange(ed);
}, },