user-pic

YUI Editor Question

Vote 0 Votes

This question is about the YUI Editor plugin. I was curious if there was a way to have both the YUI Image button to add images via URL AND the MTAssets upload button in the same tool bar? Currently I can only have one or the other...

I have a few users that don't want to be bothered with learning HTML but would like to insert images from the web into their blogs as well as upload images to the server. Just wondering if there was a way to use both.

Reported on Movable Type 4.2

7 Replies

| Add a Reply
  • Not out of the box, but you could add the code to modify the toolbar.

    If your JS isn't great, let me know and I'll throw you a snippet when I get time.

    Another (possibly better) solution would be if MT's asset section supported adding assets from the web.

  • Well that was a lot easier than I thought, I love YUI :)

    Add this to your mt-static/plugins/yuieditor/config.js in the afterYUIInit function:

        YUIEditor.toolbar.addButtonToGroup({ type: 'push', label: 'Image Asset', value: 'insertasset' }, 'insertitem');
        YUIEditor.toolbar.on('insertassetClick', function() {
            //Get the selected element
            var _sel = YUIEditor._getSelectedElement();
            //If the selected element is an image, do the normal thing so they can manipulate the image
            if (_sel && _sel.tagName && (_sel.tagName.toLowerCase() == 'img')) {
                //Do the normal thing here..
            } else {
                //They don't have a selected image, open MT's default asset interface
                var div = DOM.getElement( "editor-content-enclosure" );
                app.openDialog( "__mode=list_assets&_type=asset&edit_field=" + div.getAttribute( "edit-field" )
                    + "&blog_id=" + div.getAttribute( "mt:blog-id" ) + "&dialog_view=1&filter=class&filter_val=image" );
                //This is important.. Return false here to not fire the rest of the listeners
                return false;
            }
        }, YUIEditor, true);
    
    

    //We need to add another button to access MT's file asset as well as the image asset
    YUIEditor.toolbar.addButtonToGroup({ type: 'push', label: 'File Asset', value: 'insertfile' }, 'insertitem');
    YUIEditor.toolbar.on('insertfileClick', function() {
    var div = DOM.getElement( "editor-content-enclosure" );
    app.openDialog( "__mode=list_assets&_type=asset&edit_field=" + div.getAttribute( "edit-field" )
    + "&blog_id=" + div.getAttribute( "mt:blog-id" ) + "&dialog_view=1" );
    }, YUIEditor, true);


    Whilst you are in there, set ConfigUseMTAssets to false (so that the default yui one is shown and we then add the MT ones with the above code).

    You will also need to make an icon for the button and something like this to the mt-static/plugins/yuieditor/assets/css/yui_editor.css

    .yui-skin-sam .yui-toolbar-container .yui-toolbar-insertasset span.yui-toolbar-icon,
    .yui-skin-sam .yui-toolbar-container .yui-button-insertasset-selected span.yui-toolbar-icon {
        background-image: url( ../assets/insert_file.gif );
        background-position: 3px 3px;
        left: 5px;
    }
    
    


    That should do it.

  • Very Cool! Thanks Richard! I would have asked you via your blog but the captcha wasn't working in the comments yesterday. I'm glad you're here to help out :-)

    I'll give it a try today and let you know how it goes!

    • Since I screwed up the DB there's going to be all sorts of weird things going on there!

      I'm moving to a new host and cos of the problems I had I'm starting all my templates from scratch (ish) so that it's less "cobbled together" and more planned from the start. Whilst I'm doing that, I really can't get the motivation to fix the problems on the old one, knowing it'll all change soon anyway!

  • Hi Richard,

    Most of the code works but when I click the icons to upload to the MT asset manager, the screen turns dark gray as if to open it up but nothing appears. Any ideas? I tried playing around with the javascript but couldn't get it to work.

    Any suggestions?

  • hmmm weird. What MT and YUI versions you using?

    Compare your config.js to mine:

    http://www.richardbenson.co.uk/mt/mt-static/plugins/YUIEditor/config.js


  • Okay thanks for that! I think there was a line break or something in there that messed things up for me. I'll test it out today and let you know how it goes :-)

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

694 2908

Last Topic: Blogspot to Movable Type by sdude on Feb 8, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 565

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012