Skip to content

Commit

Permalink
Use selected text for insertion. Button is disabled until text is sel…
Browse files Browse the repository at this point in the history
…ected.
  • Loading branch information
tjstankus committed Jun 15, 2009
1 parent 29b1dd4 commit bc6a03f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 2 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ TinyMCE.
Example
=======

Example goes here.
script/generate aftfilr ArticleFile


Copyright (c) 2008 TJ Stankus, released under the MIT license.
Copyright (c) 2008-2009 TJ Stankus, released under the MIT license.
14 changes: 10 additions & 4 deletions generators/aftfilr/templates/tinymce_plugin/editor_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@
image : url + '/img/<%= singular_name %>.png'
});

// Add a node change handler, selects the button in the UI when a image is selected
ed.onNodeChange.add(function(ed, cm, n) {
cm.setActive('<%= singular_name %>', n.nodeName == 'IMG');
// Listen to onNodeChange event.
// Parameters
// ed: tinymce.Editor
// cm: tinymce.ControlManager,
// el: Element
// collapsed: Boolean tinymce.dom.Selection/isCollapsed
ed.onNodeChange.add(function(ed, cm, el, collapsed) {
cm.setDisabled('<%= singular_name %>', collapsed && el.nodeName != 'A');
cm.setActive('<%= singular_name %>', el.nodeName == 'A' && !el.name);
});
},

Expand Down Expand Up @@ -61,7 +67,7 @@
return {
longname : '<%= model_class_name %> plugin',
author : 'TJ Stankus',
authorurl : 'http://www.haikuwebdev.com',
authorurl : 'http://tj.stank.us',
version : "0.1"
};
}
Expand Down
5 changes: 3 additions & 2 deletions generators/aftfilr/templates/tinymce_plugin/js/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ tinyMCEPopup.requireLangPack();
var <%= tinymce_dialog_name %> = {
init : function() {},

insert : function(document_url, document_filename) {
link_html = '<a href="' + document_url + '>' + document_filename + '</a>';
insert : function(document_url) {
var link_content = tinyMCEPopup.editor.selection.getContent();
var link_html = '<a href="' + document_url + '>' + link_content + '</a>';
tinyMCEPopup.editor.execCommand('mceInsertContent', false, link_html);
tinyMCEPopup.close();
}
Expand Down
2 changes: 1 addition & 1 deletion generators/aftfilr/templates/views/_document.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="document_link">
<div class="document_icon"
onclick="<%%= "javascript:<%= tinymce_dialog_name %>.insert('#{document.public_filename}', '#{document.filename}');return false;" %>">
onclick="<%%= "javascript:<%= tinymce_dialog_name %>.insert('#{document.public_filename}');return false;" %>">
<%%= image_tag 'document_icon.png' %>
</div>
<div class="document_filename">
Expand Down

0 comments on commit bc6a03f

Please sign in to comment.