Git Product home page Git Product logo

Comments (1)

lkwdwrd avatar lkwdwrd commented on June 17, 2024

Alright, had a chance to look through things. The register method changed quite a bit in 4.0.

Here it is in 3.9:

register: function( type, constructor ) {
    views[ type ] = constructor;
}

and here it is in 4.0:

register: function( type, constructor ) {
    var defaultConstructor = {
        type: type,
        View: {},
        toView: function( content ) {
            var match = wp.shortcode.next( this.type, content );

            if ( ! match ) {
                return;
            }

            return {
                index: match.index,
                content: match.content,
                options: {
                    shortcode: match.shortcode
                }
            };
        }
    };

    constructor = _.defaults( constructor, defaultConstructor );
    constructor.View = wp.mce.View.extend( constructor.View );

    views[ type ] = constructor;
}

The register method is being helpful and extending the wp.mce.Vew for us, that is already being done at line 239 of example-thing.js. The Backbone extend method expects an object, but we're passing it a constructor function. If you remove the extend call at line 239 and just pass the object as the view, it starts working fine.

View: {
    className: 'editor-thing',
    template:  media.template( 'editor-thing' ),
    initialize: function( options ) {
        this.shortcode = options.shortcode;
    },
    getHtml: function() {
        return this.template( _.defaults(
            this.shortcode.attrs.named,
            thing.defaults
        ) );
    }
},

This simple fix gets things going, but it looks like there was a lot of changes in the MCE views which renders some of the code in the example thing unnecessary. I'm still playing with it, may get to a pull request at some point.

Either way, thanks much for the example!

from example-thing.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.