Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,40 @@ module.exports = function( grunt ) {

},

addtextdomain: {
options: {
textdomain: 'shortcode-ui', // Project text domain.
},
target: {
files: {
src: [ '*.php', '**/*.php', '!node_modules/**', '!php-tests/**', '!bin/**' ]
}
}
}, //addtextdomain

makepot: {
target: {
options: {
domainPath: '/languages',
mainFile: 'shortcode-ui.php',
potFilename: 'shortcode-ui.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
},
type: 'wp-plugin',
updateTimestamp: true
}
}
}, //makepot
} );

grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks("grunt-wp-i18n");

grunt.registerTask( 'default', ['sass' ] );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );

grunt.util.linefeed = '\n';

Expand Down
4 changes: 4 additions & 0 deletions css/sass/shortcode-ui.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
padding: 10px;
border-top: 1px solid #ddd;
}

a.wp-color-result {
border-bottom: 1px solid #ccc;
}
}

.edit-shortcode-form {
Expand Down
2 changes: 2 additions & 0 deletions css/shortcode-ui.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions css/shortcode-ui.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@
'type' => 'text',
'placeholder' => 'Test placeholder',
),
array(
'label' => 'Fieldmanager Textarea',
'attr' => 'fieldmanager_textarea',
'type' => 'Fieldmanager_TextArea',
),
array(
'label' => 'Fieldmanager Media',
'attr' => 'fieldmanager_media',
'type' => 'Fieldmanager_Media',
),

),
)
Expand Down
4 changes: 2 additions & 2 deletions inc/fields/class-field-attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function action_admin_enqueue_scripts() {
wp_localize_script( 'shortcake-field-attachment', 'ShorcakeImageFieldData', array(
'defaultArgs' => array(
'libraryType' => null, // array of mime types. eg image, image/jpg, application, application/pdf.
'addButton' => __( 'Select Attachment', 'shortcake' ),
'frameTitle' => __( 'Select Attachment', 'shortcake' ),
'addButton' => __( 'Select Attachment', 'shortcode-ui' ),
'frameTitle' => __( 'Select Attachment', 'shortcode-ui' ),
),
) );
}
Expand Down
99 changes: 99 additions & 0 deletions inc/fields/class-field-color.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

class Shortcake_Field_Color {

private static $instance = null;

// All registered post fields.
private $post_fields = array();

// Field Settings.
private $fields = array(
'color' => array(
'template' => 'fusion-shortcake-field-color',
'view' => 'editAttributeFieldColor',
),
);

public static function get_instance() {
if ( null == self::$instance ) {
self::$instance = new self;
self::$instance->setup_actions();
}
return self::$instance;
}

private function setup_actions() {

add_filter( 'shortcode_ui_fields', array( $this, 'filter_shortcode_ui_fields' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ), 100 );
add_action( 'shortcode_ui_loaded_editor', array( $this, 'load_template' ) );

}

private function color_attribute_present() {

foreach( Shortcode_UI::get_instance()->get_shortcodes() as $shortcode ) {
if ( empty( $shortcode['attrs'] ) ) {
continue;
}

foreach ( $shortcode['attrs'] as $attribute ) {
if ( empty( $attribute['type'] ) ) {
continue;
}

if ( $attribute['type'] == 'color' ) {
return true;
}
}
}

return false;

}

public function filter_shortcode_ui_fields( $fields ) {
return array_merge( $fields, $this->fields );
}

public function action_admin_enqueue_scripts() {

if ( ! $this->color_attribute_present() ) {
return;
}

$script = plugins_url( '/js/field-color.js', dirname( dirname( __FILE__ ) ) );

wp_enqueue_script( 'shortcake-field-color', $script, array( 'shortcode-ui' ) );

}

/**
* Output templates used by the color field.
*/
public function load_template() {

if ( ! $this->color_attribute_present() ) {
return;
}

wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style( 'wp-color-picker' );

?>

<script type="text/html" id="tmpl-fusion-shortcake-field-color">
<div class="field-block">
<label for="{{ data.attr }}">{{ data.label }}</label>
<input type="text" name="{{ data.attr }}" id="{{ data.attr }}" value="{{ data.value }}" placeholder="{{ data.placeholder }}" data-default-color="{{ data.value }}"/>
<# if ( typeof data.description == 'string' ) { #>
<p class="description">{{ data.description }}</p>
<# } #>
</div>
</script>

<?php
}

}
Loading