diff --git a/css/sass/shortcode-ui-editor-styles.scss b/css/sass/shortcode-ui-editor-styles.scss index 6c602c9b..b20e13e0 100644 --- a/css/sass/shortcode-ui-editor-styles.scss +++ b/css/sass/shortcode-ui-editor-styles.scss @@ -23,3 +23,25 @@ body#wpview-iframe-sandbox { width: 100%; overflow: hidden; } + +.test-editable-blockquote { + + padding: 20px; + border: 1px solid #E1e1e1; + background: #f5f5f5; + + [contentEditable]:focus { + outline: none; + } + + blockquote { + font-size: 24px; + line-height: 1.5; + } + + p { + font-size: 16px; + line-height: 1.5; + font-style: italic; + } +} diff --git a/css/sass/shortcode-ui.scss b/css/sass/shortcode-ui.scss index 228107cf..72b77718 100644 --- a/css/sass/shortcode-ui.scss +++ b/css/sass/shortcode-ui.scss @@ -81,11 +81,11 @@ padding: 10px; border-top: 1px solid #ddd; } - + a.wp-color-result { border-bottom: 1px solid #ccc; } - + .media-toolbar { position: relative; height: auto; diff --git a/css/shortcode-ui-editor-styles.css b/css/shortcode-ui-editor-styles.css index 0a2e4c2d..6c42f54f 100644 --- a/css/shortcode-ui-editor-styles.css +++ b/css/shortcode-ui-editor-styles.css @@ -13,4 +13,18 @@ body#wpview-iframe-sandbox { width: 100%; overflow: hidden; } +.test-editable-blockquote { + padding: 20px; + border: 1px solid #E1e1e1; + background: #f5f5f5; } + .test-editable-blockquote [contentEditable]:focus { + outline: none; } + .test-editable-blockquote blockquote { + font-size: 24px; + line-height: 1.5; } + .test-editable-blockquote p { + font-size: 16px; + line-height: 1.5; + font-style: italic; } + /*# sourceMappingURL=shortcode-ui-editor-styles.css.map */ \ No newline at end of file diff --git a/css/shortcode-ui-editor-styles.css.map b/css/shortcode-ui-editor-styles.css.map index 8518dbc8..643e36e9 100644 --- a/css/shortcode-ui-editor-styles.css.map +++ b/css/shortcode-ui-editor-styles.css.map @@ -5,6 +5,6 @@ "../shortcode-ui-editor-styles.scss" ], "sourcesContent": [], - "mappings": "AAGA,AAAY,AAA0B;EACnC,AAAS;AAIZ,AAAa;EACX,AAAO;EACP,AAAa;AAGf,AAAa;EACX,AAAa;EACb,AAAO;EACP,AAAW;;AAIb,AAAI;EACH,AAAS;EACT,AAAO;EACP,AAAU", + "mappings": "AAGA,AAAY,AAA0B;EACnC,AAAS;AAIZ,AAAa;EACX,AAAO;EACP,AAAa;AAGf,AAAa;EACX,AAAa;EACb,AAAO;EACP,AAAW;;AAIb,AAAI;EACH,AAAS;EACT,AAAO;EACP,AAAU;;AAGX;EAEC,AAAS;EACT,AAAQ;EACR,AAAY;EAEb,AAA0B,AAAiB;IACzC,AAAS;EAGX,AAA0B;IACxB,AAAW;IACX,AAAa;EAGf,AAA0B;IACxB,AAAW;IACX,AAAa;IACb,AAAY", "names": [] } \ No newline at end of file diff --git a/inc/templates/edit-form.tpl.php b/inc/templates/edit-form.tpl.php index 83cf677a..fb43a380 100644 --- a/inc/templates/edit-form.tpl.php +++ b/inc/templates/edit-form.tpl.php @@ -135,3 +135,13 @@ <# } #> + + + + + diff --git a/js-tests/build/specs.js b/js-tests/build/specs.js index 11a40a67..a2d6539c 100644 --- a/js-tests/build/specs.js +++ b/js-tests/build/specs.js @@ -288,7 +288,7 @@ describe( "MCE View Constructor", function() { } ); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./../../../js/src/models/shortcode.js":10,"./../../../js/src/utils/shortcode-view-constructor.js":11,"./../../../js/src/utils/sui.js":12}],5:[function(require,module,exports){ +},{"./../../../js/src/models/shortcode.js":10,"./../../../js/src/utils/shortcode-view-constructor.js":12,"./../../../js/src/utils/sui.js":13}],5:[function(require,module,exports){ var Shortcodes = require('./../../../js/src/collections/shortcodes.js'); var sui = require('./../../../js/src/utils/sui.js'); @@ -305,7 +305,7 @@ describe( "SUI Util", function() { } ); -},{"./../../../js/src/collections/shortcodes.js":7,"./../../../js/src/utils/sui.js":12}],6:[function(require,module,exports){ +},{"./../../../js/src/collections/shortcodes.js":7,"./../../../js/src/utils/sui.js":13}],6:[function(require,module,exports){ (function (global){ var Backbone = (typeof window !== "undefined" ? window.Backbone : typeof global !== "undefined" ? global.Backbone : null); var ShortcodeAttribute = require('./../models/shortcode-attribute.js'); @@ -485,10 +485,26 @@ module.exports = Shortcode; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./../collections/shortcode-attributes.js":6,"./inner-content.js":8}],11:[function(require,module,exports){ +var getEditView = function ( id ) { + + var views = { + 'default': require('./../views/edit-shortcode-form.js'), + 'shortcake_dev': require('./../views/edit-shortcode-form-test.js'), + } + + return ( id in views ) ? views[ id ] : views['default']; + +} + +module.exports = getEditView; + +},{"./../views/edit-shortcode-form-test.js":17,"./../views/edit-shortcode-form.js":18}],12:[function(require,module,exports){ (function (global){ var sui = require('./sui.js'), wp = (typeof window !== "undefined" ? window.wp : typeof global !== "undefined" ? global.wp : null), - $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null); + $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null), + getEditView = require('./get-edit-view.js'); + // send_to_editor = require( 'sui-utils/sendtoeditor'); /** * Generic shortcode mce view constructor. @@ -498,7 +514,7 @@ var shortcodeViewConstructor = { initialize: function( options ) { this.shortcodeModel = this.getShortcodeModel( this.shortcode ); - this.fetch(); + this.renderPreview(); }, /** @@ -545,34 +561,20 @@ var shortcodeViewConstructor = { * * @return undefined */ - fetch : function() { - - var self = this; - - if ( ! this.fetching ) { - - this.fetching = true; + renderPreview : function() { - wp.ajax.post( 'do_shortcode', { - post_id: $( '#post_ID' ).val(), - shortcode: this.shortcodeModel.formatShortcode(), - nonce: shortcodeUIData.nonces.preview, - }).done( function( response ) { + var view; - if ( '' === response ) { - self.content = '' + self.shortcodeModel.formatShortcode() + ''; - } else { - self.content = response; - } + var shortcode = this.shortcodeModel; + view = getEditView( shortcode.get('shortcode_tag') ); + view = new view( { model: shortcode } ); - }).fail( function() { - self.content = '' + shortcodeUIData.strings.mce_view_error + ''; - } ).always( function() { - delete self.fetching; - self.render( null, true ); - } ); + this.content = view.render().$el; + this.render( null, true ); - } + shortcode.on('change', function() { + console.log( shortcode.formatShortcode() ); + } ); }, @@ -687,138 +689,710 @@ var shortcodeViewConstructor = { if ( switchEditors && switchEditors.pre_wpautop ) { content = switchEditors.pre_wpautop( content ); } - return content; + }, + +}; +module.exports = shortcodeViewConstructor; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./get-edit-view.js":11,"./sui.js":13}],13:[function(require,module,exports){ +var Shortcodes = require('./../collections/shortcodes.js'); + +window.Shortcode_UI = window.Shortcode_UI || { + shortcodes: new Shortcodes, + views: {}, + controllers: {}, +}; + +module.exports = window.Shortcode_UI; + +},{"./../collections/shortcodes.js":7}],14:[function(require,module,exports){ +var sui = require('./../utils/sui.js'); + +var editAttributeFieldAttachment = sui.views.editAttributeField.extend( { + + events: { + 'click .add' : '_openMediaFrame', + 'click .remove' : '_removeAttachment', + 'selectAttachment' : '_selectAttachment', }, - // Backwards compatability for Pre WP 4.2. - View: { + /** + * Update the field attachment. + * Re-renders UI. + * If ID is empty - does nothing. + * + * @param {int} id Attachment ID + */ + updateValue: function( id ) { - overlay: true, + if ( ! id ) { + return; + } - initialize: function( options ) { - this.shortcode = this.getShortcode( options ); - this.fetch(); - }, + this.setValue( id ); - getShortcode: function( options ) { + var self = this; - var shortcodeModel, shortcode; + if ( editAttributeFieldAttachment.getFromCache( id ) ) { + self._renderPreview( editAttributeFieldAttachment.getFromCache( id ) ); + return; - shortcodeModel = sui.shortcodes.findWhere( { shortcode_tag: options.shortcode.tag } ); + // Call the updateValue() function, to trigger any listeners + // hooked on it. + self.triggerCallbacks(); + } - if (!shortcodeModel) { - return; + this.$container.addClass( 'loading' ); + + wp.ajax.post( 'get-attachment', { + 'id': id + } ).done( function( attachment ) { + // Cache for later. + editAttributeFieldAttachment.setInCache( id, attachment ); + self._renderPreview( attachment ); + self.$container.removeClass( 'loading' ); + + // Call the updateValue() function, to trigger any listeners + // hooked on it. + self.triggerCallbacks(); + } ); + }, + + render: function() { + + // Set model default values. + for ( var arg in ShortcakeImageFieldData.defaultArgs ) { + if ( ! this.model.get( arg ) ) { + this.model.set( arg, ShortcakeImageFieldData.defaultArgs[ arg ] ); } + } - shortcode = shortcodeModel.clone(); + this.$el.html( this.template( this.model.toJSON() ) ); - shortcode.get('attrs').each( - function(attr) { + this.$container = this.$el.find( '.shortcake-attachment-preview' ); + var $addButton = this.$container.find( 'button.add' ); - if (attr.get('attr') in options.shortcode.attrs.named) { - attr.set('value', - options.shortcode.attrs.named[attr - .get('attr')]); - } + this.frame = wp.media( { + multiple: false, + title: this.model.get( 'frameTitle' ), + library: { + type: this.model.get( 'libraryType' ), + }, + } ); - }); + // Add initial Attachment if available. + this.updateValue( this.model.get( 'value' ) ); + + }, + + /** + * Renders attachment preview in field. + * @param {object} attachment model + * @return null + */ + _renderPreview: function( attachment ) { + + var $thumbnail = jQuery('
'); + + if ( 'image' !== attachment.type ) { + + jQuery( '