This is a migrated thread and some comments may be shown as answers.

[Solved] Using jquery to show/hide the editor toolbar

3 Answers 77 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gordon
Top achievements
Rank 1
Gordon asked on 24 Jan 2011, 02:51 PM
Am intending on showing/hiding the editor toolbar when the editor gains focus.

Not haivng much luck on binding to the focus at the moment.  I assume jquery doesn't register an event for focus on the body tag.

Anyone have any tips on how i can achieve this?
$('iframe..t-content').contents().find('body').bind({
  focus: function() {
    alert('focus');
  },
  focusout: function() {
    alert('focusout');
  }
});

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Jan 2011, 04:34 PM
Hello Gordon,

 You can try this instead:

var editor = $("#Editor").data("tEditor");
 
$(editor.window).bind("focus", function() {
     $("#Editor .t-editor-toolbar").show();
}).bind("blur", function() {
     $("#Editor .t-editor-toolbar").hide();
});

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gordon
Top achievements
Rank 1
answered on 24 Jan 2011, 06:06 PM
Thanks for that.

The script works fine when running it in firequery....

However it doesn't work in document ready, where should the code go?
$(document).ready(function () {
  var editor = $("#Description").data("tEditor");
  if (editor==null) {
    $('#footer').append('editornull');
  }
  else {
    $(editor.window).bind({
      focus: function() {
        $("#Description .t-editor-toolbar").slideDown();
      },
      blur: function() {
        $("#Description .t-editor-toolbar").slideUp();
      }
    }); //bind
  }//else
});//docready
0
Gordon
Top achievements
Rank 1
answered on 24 Jan 2011, 06:47 PM
I've used the grid onload.  Which is obvious, but it'd be nice to be able to use docready the same as all my other initialisation script.

For those who are interested;

function tEditorLoaded(e) {
     var editorId =  e.target.id;
     var editor = $("#" + editorId).data("tEditor");
    
     if (editor == null) {
       $('#footer').append(editorId + '=null');
     }
     else {
       $('#' + editorId).attr('cellspacing','1px');
 
       var editorIframe = $("#" + editorId).find('.t-content');
       editorIframe.attr('id', 'tEditContent_' + editorId);
        
       $(editor.window).bind({
         focus: function() {
           var myId = editor.window.frameElement.id;
           var editorId = myId.replace('tEditContent_','');
 
           $("#" + editorId + " .t-editor-toolbar").slideDown();
         },
         blur: function() {
           var myId = editor.window.frameElement.id;
           var editorId = myId.replace('tEditContent_','');
           $("#" + editorId + " .t-editor-toolbar").slideUp();
         }
       }); //bind
     } //else
   } //function
Tags
Editor
Asked by
Gordon
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gordon
Top achievements
Rank 1
Share this question
or