-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from xwp/feature/shortcake-integration
Add JS Widgets as Shortcodes (Post Elements) with Shortcode UI (via Shortcake)
- Loading branch information
Showing
24 changed files
with
658 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* global wp, JSON, Shortcode_UI */ | ||
/* eslint-disable strict */ | ||
/* eslint consistent-this: [ "error", "view" ] */ | ||
/* eslint-disable complexity */ | ||
|
||
Shortcode_UI.views.widgetFormField = (function( sui ) { | ||
'use strict'; | ||
|
||
/** | ||
* Widget form. | ||
* | ||
* @class | ||
*/ | ||
return sui.views.editAttributeField.extend( { | ||
|
||
events: {}, | ||
|
||
/** | ||
* Render. | ||
* | ||
* @return {sui.views.editAttributeField} View. | ||
*/ | ||
render: function() { | ||
var view = this, FormConstructor, instanceValue, form; | ||
|
||
if ( ! view.shortcode.get( 'widgetType' ) || ! wp.widgets.formConstructor[ view.shortcode.get( 'widgetType' ) ] ) { | ||
throw new Error( 'Unable to determine the widget type.' ); | ||
} | ||
|
||
view.$el.addClass( 'js-widget-form-shortcode-ui' ); | ||
instanceValue = new wp.customize.Value( view.getValue() ? JSON.parse( view.getValue() ) : {} ); | ||
FormConstructor = wp.widgets.formConstructor[ view.shortcode.get( 'widgetType' ) ]; | ||
form = new FormConstructor( { | ||
model: instanceValue, | ||
container: view.$el | ||
} ); | ||
instanceValue.bind( function( instanceData ) { | ||
view.setValue( JSON.stringify( instanceData ) ); | ||
} ); | ||
form.render(); | ||
|
||
view.triggerCallbacks(); | ||
return view; | ||
} | ||
} ); | ||
|
||
})( Shortcode_UI ); |
Oops, something went wrong.