Created
January 16, 2012 04:19
-
-
Save Patabugen/1619044 to your computer and use it in GitHub Desktop.
WYMEditor Plugin to add a list of selectable links to the Link dialog box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint evil: true */ | |
/** | |
WYMeditor.site_links | |
==================== | |
A plugin to add a dropdown of links to the Links dialog, especially for | |
making it easier to link to your own site (or any other predefined set). | |
This plugin will attempt to inject a dropdown box into the dialogLinkHtml | |
which will pre-fill the existing text box with a URL. | |
Todo: | |
- Make this more flexible (currently it overwrites dialogLinkHTml with a default) | |
- Don't create the select until the dialog is launched (so we can modify the list | |
of links after init) | |
by Patabugen ( patabugen.co.uk ) | |
*/ | |
WYMeditor.editor.prototype.site_links = function() { | |
var wym = this; | |
var links = wym._options.dialogLinkSiteLinks; | |
// Check the options | |
if (links == undefined) { | |
WYMeditor.console.warn( | |
"You should define the WYMeditor option dialogLinkSiteLinks for the site_links." | |
); | |
// With no links it's best to do nothing than show an empty dropdown | |
return; | |
} | |
if ( typeof links == 'function') { | |
links = links(); | |
} | |
if (links.length == 0) { | |
WYMeditor.console.warn( | |
"WYMeditor option dialogLinkSiteLinks contains no links for the site_links plugin. Not showing select." | |
); | |
// With no links it's best to do nothing than show an empty dropdown | |
return; | |
} | |
// Build the new Select | |
var select = '<select class="wym_href_site_links"><option val=""> - </option>'; | |
$.each(links, function(index, item) { | |
select = select + '<option value="' + item.url + '">' + item.name + '</option>'; | |
}); | |
select = select + '</select>' | |
// Write some JS to bind to the select | |
var script = String() + | |
'<script type="text/javascript">' + | |
'jQuery(function(){' + | |
'jQuery("select.wym_href_site_links").live("change", function(){' + | |
'jQuery(".wym_href").val(jQuery(this).val()); ' + | |
' });' + | |
' });' + | |
'</script>'; | |
// Put together the whole dialog script | |
wym._options.dialogLinkHtml = String() + | |
'<body class="wym_dialog wym_dialog_link" ' + | |
' onload="WYMeditor.INIT_DIALOG(' + WYMeditor.INDEX + ')">' + | |
'<form>' + | |
'<fieldset>' + | |
'<input type="hidden" class="wym_dialog_type" ' + | |
'value="' + WYMeditor.DIALOG_LINK + '" />' + | |
'<div class="row">' + | |
'<label>{Preset}</label>' + | |
select + | |
'</div>' + | |
'<legend>{Link}</legend>' + | |
'<div class="row">' + | |
'<label>{URL}</label>' + | |
'<input type="text" class="wym_href" value="" ' + | |
'size="40" autofocus="autofocus" />' + | |
'</div>' + | |
'<div class="row">' + | |
'<label>{Title}</label>' + | |
'<input type="text" class="wym_title" value="" ' + | |
'size="40" />' + | |
'</div>' + | |
'<div class="row">' + | |
'<label>{Relationship}</label>' + | |
'<input type="text" class="wym_rel" value="" ' + | |
'size="40" />' + | |
'</div>' + | |
'<div class="row row-indent">' + | |
'<input class="wym_submit" type="submit" ' + | |
'value="{Submit}" />' + | |
'<input class="wym_cancel" type="button" ' + | |
'value="{Cancel}" />' + | |
'</div>' + | |
'</fieldset>' + | |
'</form>' + | |
script + | |
'</body>'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment