Version Description
- Resolved bug in ditty_add_scripts function that was causing a javascript error
- Only possibly load cached ditty on live_updates
- Added option to disable fontawesome on front-end
Download this release
Release Info
Developer | metaphorcreations |
Plugin | Ditty News Ticker |
Version | 3.0.11 |
Comparing to | |
See all releases |
Code changes from version 3.0.10 to 3.0.11
- ditty-news-ticker.php +2 -2
- includes/admin/settings.php +16 -7
- includes/class-ditty-singles.php +16 -15
- includes/class-ditty.php +9 -3
- includes/helpers.php +40 -19
- includes/js/class-ditty-display-list.min.js +1 -862
- includes/js/ditty-admin.min.js +1 -888
- includes/js/ditty-editor.min.js +3 -5822
- includes/js/ditty.js +19 -12
- includes/js/ditty.min.js +1 -364
- readme.txt +7 -2
ditty-news-ticker.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Ditty (formerly Ditty News Ticker)
|
5 |
* Plugin URI: https://www.metaphorcreations.com/ditty
|
6 |
* Description: Formerly Ditty News Ticker. Ditty is a multi-functional data display plugin.
|
7 |
-
* Version: 3.0.
|
8 |
* Author: Metaphor Creations
|
9 |
* Author URI: https://www.metaphorcreations.com
|
10 |
* License: GPL-2.0+
|
@@ -20,7 +20,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
20 |
|
21 |
// Plugin version.
|
22 |
if ( ! defined( 'DITTY_VERSION' ) ) {
|
23 |
-
define( 'DITTY_VERSION', '3.0.
|
24 |
}
|
25 |
|
26 |
// Plugin Folder Path.
|
4 |
* Plugin Name: Ditty (formerly Ditty News Ticker)
|
5 |
* Plugin URI: https://www.metaphorcreations.com/ditty
|
6 |
* Description: Formerly Ditty News Ticker. Ditty is a multi-functional data display plugin.
|
7 |
+
* Version: 3.0.11
|
8 |
* Author: Metaphor Creations
|
9 |
* Author URI: https://www.metaphorcreations.com
|
10 |
* License: GPL-2.0+
|
20 |
|
21 |
// Plugin version.
|
22 |
if ( ! defined( 'DITTY_VERSION' ) ) {
|
23 |
+
define( 'DITTY_VERSION', '3.0.11' );
|
24 |
}
|
25 |
|
26 |
// Plugin Folder Path.
|
includes/admin/settings.php
CHANGED
@@ -232,14 +232,22 @@ function ditty_settings_display_templates() {
|
|
232 |
*/
|
233 |
function ditty_settings_advanced() {
|
234 |
$fields = array(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
'ditty_news_ticker' => array(
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
// 'ditty_layouts_sass' => array(
|
244 |
// 'type' => 'checkbox',
|
245 |
// 'id' => 'ditty_layouts_sass',
|
@@ -397,6 +405,7 @@ function ditty_settings_save( $data, $json_data ) {
|
|
397 |
'variation_defaults' => $sanitized_variation_defaults,
|
398 |
'global_ditty' => $sanitized_global_ditty,
|
399 |
'ditty_news_ticker' => isset( $data['ditty_news_ticker'] ) ? esc_attr( $data['ditty_news_ticker'] ) : false,
|
|
|
400 |
'notification_email' => ( isset( $data['notification_email'] ) && is_email( $data['notification_email'] ) ) ? $data['notification_email'] : false,
|
401 |
);
|
402 |
ditty_settings( $settings );
|
232 |
*/
|
233 |
function ditty_settings_advanced() {
|
234 |
$fields = array(
|
235 |
+
'disable_fontawesome' => array(
|
236 |
+
'type' => 'checkbox',
|
237 |
+
'id' => 'disable_fontawesome',
|
238 |
+
'name' => __( 'Font Awesome', 'ditty-news-ticker' ),
|
239 |
+
'label' => __( 'Disable Font Awesome from loading on the front-end', 'ditty-news-ticker' ),
|
240 |
+
'help' => __( 'This will disable the rendering of certain icons used in default Layouts and Layout tags.', 'ditty-news-ticker' ),
|
241 |
+
'std' => ditty_settings( 'disable_fontawesome' ),
|
242 |
+
),
|
243 |
'ditty_news_ticker' => array(
|
244 |
+
'type' => 'checkbox',
|
245 |
+
'id' => 'ditty_news_ticker',
|
246 |
+
'name' => __( 'Ditty News Ticker', 'ditty-news-ticker' ),
|
247 |
+
'label' => __( 'Enable Ditty News Ticker (Legacy code)', 'ditty-news-ticker' ),
|
248 |
+
'input_desc' => __( 'This will enable loading of all legacy scripts and post types. Only enable this option if you have active Ditty News Ticker posts displaying on your site. You must refresh your browser after saving before changes take place.', 'ditty-news-ticker' ),
|
249 |
+
'std' => ditty_settings( 'ditty_news_ticker' ),
|
250 |
+
),
|
251 |
// 'ditty_layouts_sass' => array(
|
252 |
// 'type' => 'checkbox',
|
253 |
// 'id' => 'ditty_layouts_sass',
|
405 |
'variation_defaults' => $sanitized_variation_defaults,
|
406 |
'global_ditty' => $sanitized_global_ditty,
|
407 |
'ditty_news_ticker' => isset( $data['ditty_news_ticker'] ) ? esc_attr( $data['ditty_news_ticker'] ) : false,
|
408 |
+
'disable_fontawesome' => isset( $data['disable_fontawesome'] ) ? esc_attr( $data['disable_fontawesome'] ) : false,
|
409 |
'notification_email' => ( isset( $data['notification_email'] ) && is_email( $data['notification_email'] ) ) ? $data['notification_email'] : false,
|
410 |
);
|
411 |
ditty_settings( $settings );
|
includes/class-ditty-singles.php
CHANGED
@@ -80,7 +80,7 @@ class Ditty_Singles {
|
|
80 |
* Add the editor item types panel
|
81 |
*
|
82 |
* @access public
|
83 |
-
* @since 3.0
|
84 |
*/
|
85 |
public function editor_settings_panel( $panels, $ditty_id ) {
|
86 |
if ( ! current_user_can( 'edit_dittys' ) ) {
|
@@ -184,7 +184,7 @@ class Ditty_Singles {
|
|
184 |
/**
|
185 |
* Add the edit page preview
|
186 |
* @access public
|
187 |
-
* @since 3.0
|
188 |
*/
|
189 |
public function edit_preview() {
|
190 |
global $post;
|
@@ -231,7 +231,7 @@ class Ditty_Singles {
|
|
231 |
'uniqid' => 'ditty-preview-' . $post->ID,
|
232 |
'class' => 'ditty-preview',
|
233 |
'show_editor' => 1,
|
234 |
-
'load_type' => '',
|
235 |
);
|
236 |
echo ditty_render( $atts );
|
237 |
?>
|
@@ -393,7 +393,7 @@ class Ditty_Singles {
|
|
393 |
* Return data for a Ditty to load via ajax
|
394 |
*
|
395 |
* @access public
|
396 |
-
* @since 3.0.
|
397 |
*/
|
398 |
public function init_ajax() {
|
399 |
check_ajax_referer( 'ditty', 'security' );
|
@@ -403,7 +403,7 @@ class Ditty_Singles {
|
|
403 |
$display_settings_ajax = isset( $_POST['display_settings'] ) ? esc_attr( $_POST['display_settings'] ) : false;
|
404 |
$layout_settings_ajax = isset( $_POST['layout_settings'] ) ? esc_attr( $_POST['layout_settings'] ) : false;
|
405 |
$editor_ajax = isset( $_POST['editor'] ) ? intval( $_POST['editor'] ) : false;
|
406 |
-
|
407 |
|
408 |
// Get the display attributes
|
409 |
if ( ! $display_ajax ) {
|
@@ -425,7 +425,7 @@ class Ditty_Singles {
|
|
425 |
$args['display'] = $display->get_display_id();
|
426 |
$args['showEditor'] = $editor_ajax;
|
427 |
|
428 |
-
$items = ditty_display_items( $id_ajax,
|
429 |
if ( ! is_array( $items ) ) {
|
430 |
$items = array();
|
431 |
}
|
@@ -458,7 +458,7 @@ class Ditty_Singles {
|
|
458 |
$display_settings = isset( $atts['data-display_settings'] ) ? $atts['data-display_settings'] : false;
|
459 |
$layout_settings = isset( $atts['data-layout_settings'] ) ? $atts['data-layout_settings'] : false;
|
460 |
$show_editor = isset( $atts['data-show_editor'] ) ? $atts['data-show_editor'] : false;
|
461 |
-
|
462 |
|
463 |
// Get the display attributes
|
464 |
if ( ! $display_id ) {
|
@@ -481,7 +481,7 @@ class Ditty_Singles {
|
|
481 |
$args['display'] = $display->get_display_id();
|
482 |
$args['showEditor'] = $show_editor;
|
483 |
|
484 |
-
$items = ditty_display_items( $ditty_id,
|
485 |
if ( ! is_array( $items ) ) {
|
486 |
$items = array();
|
487 |
}
|
@@ -499,7 +499,7 @@ class Ditty_Singles {
|
|
499 |
* Return live updates
|
500 |
*
|
501 |
* @access public
|
502 |
-
* @since 3.0
|
503 |
*/
|
504 |
public function live_updates_ajax() {
|
505 |
check_ajax_referer( 'ditty', 'security' );
|
@@ -509,8 +509,9 @@ class Ditty_Singles {
|
|
509 |
}
|
510 |
$updated_items = array();
|
511 |
if ( is_array( $live_ids ) && count( $live_ids ) > 0 ) {
|
512 |
-
foreach ( $live_ids as $ditty_id => $
|
513 |
-
$
|
|
|
514 |
}
|
515 |
}
|
516 |
$data = array(
|
@@ -542,13 +543,13 @@ class Ditty_Singles {
|
|
542 |
* Sanitize setting values before saving to the database
|
543 |
*
|
544 |
* @access public
|
545 |
-
* @since 3.0
|
546 |
*/
|
547 |
public function sanitize_settings( $settings ) {
|
548 |
$sanitized_settings = array();
|
549 |
-
$sanitized_settings['ajax_loading'] = isset( $settings['ajax_loading'] )
|
550 |
-
$sanitized_settings['live_updates'] = isset( $settings['live_updates'] )
|
551 |
-
$sanitized_settings['previewBg']
|
552 |
$sanitized_padding = array();
|
553 |
if ( isset( $settings['previewPadding'] ) && is_array( $settings['previewPadding'] ) && count( $settings['previewPadding'] ) > 0 ) {
|
554 |
foreach ( $settings['previewPadding'] as $key => $value ) {
|
80 |
* Add the editor item types panel
|
81 |
*
|
82 |
* @access public
|
83 |
+
* @since 3.0.11
|
84 |
*/
|
85 |
public function editor_settings_panel( $panels, $ditty_id ) {
|
86 |
if ( ! current_user_can( 'edit_dittys' ) ) {
|
184 |
/**
|
185 |
* Add the edit page preview
|
186 |
* @access public
|
187 |
+
* @since 3.0.11
|
188 |
*/
|
189 |
public function edit_preview() {
|
190 |
global $post;
|
231 |
'uniqid' => 'ditty-preview-' . $post->ID,
|
232 |
'class' => 'ditty-preview',
|
233 |
'show_editor' => 1,
|
234 |
+
//'load_type' => '',
|
235 |
);
|
236 |
echo ditty_render( $atts );
|
237 |
?>
|
393 |
* Return data for a Ditty to load via ajax
|
394 |
*
|
395 |
* @access public
|
396 |
+
* @since 3.0.11
|
397 |
*/
|
398 |
public function init_ajax() {
|
399 |
check_ajax_referer( 'ditty', 'security' );
|
403 |
$display_settings_ajax = isset( $_POST['display_settings'] ) ? esc_attr( $_POST['display_settings'] ) : false;
|
404 |
$layout_settings_ajax = isset( $_POST['layout_settings'] ) ? esc_attr( $_POST['layout_settings'] ) : false;
|
405 |
$editor_ajax = isset( $_POST['editor'] ) ? intval( $_POST['editor'] ) : false;
|
406 |
+
//$load_type = isset( $_POST['loud_type'] ) ? intval( $_POST['loud_type'] ) : '';
|
407 |
|
408 |
// Get the display attributes
|
409 |
if ( ! $display_ajax ) {
|
425 |
$args['display'] = $display->get_display_id();
|
426 |
$args['showEditor'] = $editor_ajax;
|
427 |
|
428 |
+
$items = ditty_display_items( $id_ajax, 'force', $layout_settings_ajax );
|
429 |
if ( ! is_array( $items ) ) {
|
430 |
$items = array();
|
431 |
}
|
458 |
$display_settings = isset( $atts['data-display_settings'] ) ? $atts['data-display_settings'] : false;
|
459 |
$layout_settings = isset( $atts['data-layout_settings'] ) ? $atts['data-layout_settings'] : false;
|
460 |
$show_editor = isset( $atts['data-show_editor'] ) ? $atts['data-show_editor'] : false;
|
461 |
+
//$load_type = isset( $atts['load_type'] ) ? $atts['load_type'] : '';
|
462 |
|
463 |
// Get the display attributes
|
464 |
if ( ! $display_id ) {
|
481 |
$args['display'] = $display->get_display_id();
|
482 |
$args['showEditor'] = $show_editor;
|
483 |
|
484 |
+
$items = ditty_display_items( $ditty_id, 'force', $layout_settings );
|
485 |
if ( ! is_array( $items ) ) {
|
486 |
$items = array();
|
487 |
}
|
499 |
* Return live updates
|
500 |
*
|
501 |
* @access public
|
502 |
+
* @since 3.0.11
|
503 |
*/
|
504 |
public function live_updates_ajax() {
|
505 |
check_ajax_referer( 'ditty', 'security' );
|
509 |
}
|
510 |
$updated_items = array();
|
511 |
if ( is_array( $live_ids ) && count( $live_ids ) > 0 ) {
|
512 |
+
foreach ( $live_ids as $ditty_id => $data ) {
|
513 |
+
$layout_settings = isset( $data['layout_settings'] ) ? $data['layout_settings'] : false;
|
514 |
+
$updated_items[$ditty_id] = ditty_display_items( $ditty_id, 'cache', $layout_settings );
|
515 |
}
|
516 |
}
|
517 |
$data = array(
|
543 |
* Sanitize setting values before saving to the database
|
544 |
*
|
545 |
* @access public
|
546 |
+
* @since 3.0.11
|
547 |
*/
|
548 |
public function sanitize_settings( $settings ) {
|
549 |
$sanitized_settings = array();
|
550 |
+
$sanitized_settings['ajax_loading'] = isset( $settings['ajax_loading'] ) ? esc_attr( $settings['ajax_loading'] ) : 'no';
|
551 |
+
$sanitized_settings['live_updates'] = isset( $settings['live_updates'] ) ? esc_attr( $settings['live_updates'] ) : 'no';
|
552 |
+
$sanitized_settings['previewBg'] = isset( $settings['previewBg'] ) ? sanitize_text_field( $settings['previewBg'] ) : false;
|
553 |
$sanitized_padding = array();
|
554 |
if ( isset( $settings['previewPadding'] ) && is_array( $settings['previewPadding'] ) && count( $settings['previewPadding'] ) > 0 ) {
|
555 |
foreach ( $settings['previewPadding'] as $key => $value ) {
|
includes/class-ditty.php
CHANGED
@@ -421,12 +421,15 @@ class Ditty {
|
|
421 |
/**
|
422 |
* Register the stylesheets.
|
423 |
*
|
424 |
-
* @since 3.0
|
425 |
*/
|
426 |
public function enqueue_styles() {
|
427 |
wp_enqueue_style( 'ditty', DITTY_URL . 'includes/css/ditty.css', array(), $this->version, 'all' );
|
428 |
-
|
429 |
-
|
|
|
|
|
|
|
430 |
if ( current_user_can( 'edit_dittys' ) || current_user_can( 'edit_ditty_layouts' ) ) {
|
431 |
wp_enqueue_style( 'wp-codemirror' );
|
432 |
wp_enqueue_style( 'protip', DITTY_URL . 'includes/libs/protip/protip.min.css', false, '1.4.21', false );
|
@@ -436,6 +439,9 @@ class Ditty {
|
|
436 |
}
|
437 |
if ( is_admin() ) {
|
438 |
wp_enqueue_style( 'ditty-admin', DITTY_URL . 'includes/css/ditty-admin.css', array(), $this->version, 'all' );
|
|
|
|
|
|
|
439 |
} else {
|
440 |
|
441 |
// Add scripts for the global Dittys
|
421 |
/**
|
422 |
* Register the stylesheets.
|
423 |
*
|
424 |
+
* @since 3.0.11
|
425 |
*/
|
426 |
public function enqueue_styles() {
|
427 |
wp_enqueue_style( 'ditty', DITTY_URL . 'includes/css/ditty.css', array(), $this->version, 'all' );
|
428 |
+
|
429 |
+
$disable_fontawesome = ditty_settings( 'disable_fontawesome' );
|
430 |
+
if ( ! $disable_fontawesome ) {
|
431 |
+
wp_enqueue_style( 'fontawesome', 'https://use.fontawesome.com/releases/v5.15.3/css/all.css', false, '5.15.3', false );
|
432 |
+
}
|
433 |
if ( current_user_can( 'edit_dittys' ) || current_user_can( 'edit_ditty_layouts' ) ) {
|
434 |
wp_enqueue_style( 'wp-codemirror' );
|
435 |
wp_enqueue_style( 'protip', DITTY_URL . 'includes/libs/protip/protip.min.css', false, '1.4.21', false );
|
439 |
}
|
440 |
if ( is_admin() ) {
|
441 |
wp_enqueue_style( 'ditty-admin', DITTY_URL . 'includes/css/ditty-admin.css', array(), $this->version, 'all' );
|
442 |
+
if ( $disable_fontawesome ) {
|
443 |
+
wp_enqueue_style( 'fontawesome', 'https://use.fontawesome.com/releases/v5.15.3/css/all.css', false, '5.15.3', false );
|
444 |
+
}
|
445 |
} else {
|
446 |
|
447 |
// Add scripts for the global Dittys
|
includes/helpers.php
CHANGED
@@ -3,19 +3,20 @@
|
|
3 |
/**
|
4 |
* Return the settings defaults
|
5 |
*
|
6 |
-
* @since 3.0
|
7 |
*/
|
8 |
function ditty_settings_defaults() {
|
9 |
$defaults = array(
|
10 |
-
'live_refresh'
|
11 |
-
'default_display'
|
12 |
-
'ditty_display_ui'
|
13 |
-
'ditty_layout_ui'
|
14 |
-
'ditty_layouts_sass'
|
15 |
-
'variation_defaults'
|
16 |
-
'global_ditty'
|
17 |
-
'ditty_news_ticker'
|
18 |
-
'
|
|
|
19 |
);
|
20 |
return apply_filters( 'ditty_settings_defaults', $defaults );
|
21 |
}
|
@@ -53,6 +54,28 @@ function ditty_settings( $key=false, $value='' ) {
|
|
53 |
}
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
/**
|
57 |
* Return an array of item types
|
58 |
*
|
@@ -911,11 +934,11 @@ function ditty_parse_custom_layouts( $layout_settings ) {
|
|
911 |
/**
|
912 |
* Return display items for a specific Ditty
|
913 |
*
|
914 |
-
* @since 3.0.
|
915 |
* @access public
|
916 |
* @var array $display_items Array of item objects
|
917 |
*/
|
918 |
-
function ditty_display_items( $ditty_id, $load_type =
|
919 |
$transient_name = "ditty_display_items_{$ditty_id}";
|
920 |
|
921 |
// Check for custom layouts
|
@@ -925,7 +948,7 @@ function ditty_display_items( $ditty_id, $load_type = false, $custom_layouts = f
|
|
925 |
$custom_layout_array = ditty_parse_custom_layouts( $custom_layouts );
|
926 |
}
|
927 |
|
928 |
-
//
|
929 |
$display_items = get_transient( $transient_name );
|
930 |
if ( ! $display_items || 'force' == $load_type ) {
|
931 |
$display_items = array();
|
@@ -960,7 +983,7 @@ function ditty_display_items( $ditty_id, $load_type = false, $custom_layouts = f
|
|
960 |
}
|
961 |
}
|
962 |
$display_items = apply_filters( 'ditty_display_items', $display_items, $ditty_id );
|
963 |
-
set_transient( $transient_name, $display_items, ( MINUTE_IN_SECONDS * ditty_settings( 'live_refresh' ) ) );
|
964 |
}
|
965 |
return $display_items;
|
966 |
}
|
@@ -1211,7 +1234,7 @@ function ditty_prepare_display_items( $meta ) {
|
|
1211 |
/**
|
1212 |
* Render the Ditty container
|
1213 |
*
|
1214 |
-
* @since 3.0.
|
1215 |
*/
|
1216 |
function ditty_render( $atts ) {
|
1217 |
global $ditty_singles;
|
@@ -1227,7 +1250,6 @@ function ditty_render( $atts ) {
|
|
1227 |
'uniqid' => '',
|
1228 |
'class' => '',
|
1229 |
'show_editor' => 0,
|
1230 |
-
'load_type' => '',
|
1231 |
);
|
1232 |
$args = shortcode_atts( $defaults, $atts );
|
1233 |
|
@@ -1265,7 +1287,6 @@ function ditty_render( $atts ) {
|
|
1265 |
'data-display_settings' => ( '' != $args['display_settings'] ) ? $args['display_settings'] : false,
|
1266 |
'data-layout_settings' => ( '' != $args['layout_settings'] ) ? $args['layout_settings'] : false,
|
1267 |
'data-show_editor' => ( 0 != intval( $args['show_editor'] ) ) ? '1' : false,
|
1268 |
-
'data-load_type' => ( '' != $args['load_type'] ) ? $args['load_type'] : false,
|
1269 |
'data-ajax_load' => $ajax_load,
|
1270 |
'data-live_updates' => $live_updates,
|
1271 |
);
|
@@ -1279,7 +1300,7 @@ function ditty_render( $atts ) {
|
|
1279 |
/**
|
1280 |
* Parse ditty script types and add to global
|
1281 |
*
|
1282 |
-
* @since 3.0
|
1283 |
*/
|
1284 |
function ditty_add_scripts( $ditty_id, $display = '' ) {
|
1285 |
|
@@ -1305,7 +1326,7 @@ function ditty_add_scripts( $ditty_id, $display = '' ) {
|
|
1305 |
}
|
1306 |
|
1307 |
// Store the display types
|
1308 |
-
if ( '' === $display ) {
|
1309 |
$display = get_post_meta( $ditty_id, '_ditty_display', true );
|
1310 |
}
|
1311 |
$display_obj = new Ditty_Display( $display );
|
3 |
/**
|
4 |
* Return the settings defaults
|
5 |
*
|
6 |
+
* @since 3.0.11
|
7 |
*/
|
8 |
function ditty_settings_defaults() {
|
9 |
$defaults = array(
|
10 |
+
'live_refresh' => 10,
|
11 |
+
'default_display' => false,
|
12 |
+
'ditty_display_ui' => 'enabled',
|
13 |
+
'ditty_layout_ui' => 'enabled',
|
14 |
+
'ditty_layouts_sass' => false,
|
15 |
+
'variation_defaults' => array(),
|
16 |
+
'global_ditty' => array(),
|
17 |
+
'ditty_news_ticker' => '',
|
18 |
+
'disable_fontawesome' => '',
|
19 |
+
'notification_email' => '',
|
20 |
);
|
21 |
return apply_filters( 'ditty_settings_defaults', $defaults );
|
22 |
}
|
54 |
}
|
55 |
}
|
56 |
|
57 |
+
/**
|
58 |
+
* Return a single Ditty setting
|
59 |
+
*
|
60 |
+
* @since 3.0
|
61 |
+
*/
|
62 |
+
function ditty_single_settings( $ditty_id, $key = false ) {
|
63 |
+
global $ditty_single_settings;
|
64 |
+
if ( ! isset( $ditty_single_settings[$ditty_id] ) ) {
|
65 |
+
$ditty_single_settings[$ditty_id] = get_post_meta( $ditty_id, '_ditty_settings', true );
|
66 |
+
}
|
67 |
+
if ( ! is_array( $ditty_single_settings[$ditty_id] ) ) {
|
68 |
+
$ditty_single_settings[$ditty_id] = array();
|
69 |
+
}
|
70 |
+
if ( $key ) {
|
71 |
+
if ( isset( $ditty_single_settings[$ditty_id][$key] ) ) {
|
72 |
+
return $ditty_single_settings[$ditty_id][$key];
|
73 |
+
}
|
74 |
+
} else {
|
75 |
+
return $ditty_single_settings[$ditty_id];
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
/**
|
80 |
* Return an array of item types
|
81 |
*
|
934 |
/**
|
935 |
* Return display items for a specific Ditty
|
936 |
*
|
937 |
+
* @since 3.0.11
|
938 |
* @access public
|
939 |
* @var array $display_items Array of item objects
|
940 |
*/
|
941 |
+
function ditty_display_items( $ditty_id, $load_type = 'cache', $custom_layouts = false ) {
|
942 |
$transient_name = "ditty_display_items_{$ditty_id}";
|
943 |
|
944 |
// Check for custom layouts
|
948 |
$custom_layout_array = ditty_parse_custom_layouts( $custom_layouts );
|
949 |
}
|
950 |
|
951 |
+
// Get the display items
|
952 |
$display_items = get_transient( $transient_name );
|
953 |
if ( ! $display_items || 'force' == $load_type ) {
|
954 |
$display_items = array();
|
983 |
}
|
984 |
}
|
985 |
$display_items = apply_filters( 'ditty_display_items', $display_items, $ditty_id );
|
986 |
+
set_transient( $transient_name, $display_items, ( MINUTE_IN_SECONDS * intval( ditty_settings( 'live_refresh' ) ) ) );
|
987 |
}
|
988 |
return $display_items;
|
989 |
}
|
1234 |
/**
|
1235 |
* Render the Ditty container
|
1236 |
*
|
1237 |
+
* @since 3.0.11
|
1238 |
*/
|
1239 |
function ditty_render( $atts ) {
|
1240 |
global $ditty_singles;
|
1250 |
'uniqid' => '',
|
1251 |
'class' => '',
|
1252 |
'show_editor' => 0,
|
|
|
1253 |
);
|
1254 |
$args = shortcode_atts( $defaults, $atts );
|
1255 |
|
1287 |
'data-display_settings' => ( '' != $args['display_settings'] ) ? $args['display_settings'] : false,
|
1288 |
'data-layout_settings' => ( '' != $args['layout_settings'] ) ? $args['layout_settings'] : false,
|
1289 |
'data-show_editor' => ( 0 != intval( $args['show_editor'] ) ) ? '1' : false,
|
|
|
1290 |
'data-ajax_load' => $ajax_load,
|
1291 |
'data-live_updates' => $live_updates,
|
1292 |
);
|
1300 |
/**
|
1301 |
* Parse ditty script types and add to global
|
1302 |
*
|
1303 |
+
* @since 3.0.11
|
1304 |
*/
|
1305 |
function ditty_add_scripts( $ditty_id, $display = '' ) {
|
1306 |
|
1326 |
}
|
1327 |
|
1328 |
// Store the display types
|
1329 |
+
if ( ! $display || '' === $display ) {
|
1330 |
$display = get_post_meta( $ditty_id, '_ditty_display', true );
|
1331 |
}
|
1332 |
$display_obj = new Ditty_Display( $display );
|
includes/js/class-ditty-display-list.min.js
CHANGED
@@ -1,862 +1 @@
|
|
1 |
-
/* global jQuery:true */
|
2 |
-
/* global dittyEditorInit:true */
|
3 |
-
/* global dittyLayoutCss:true */
|
4 |
-
/* global dittyUpdateItems:true */
|
5 |
-
/* //global console:true */
|
6 |
-
|
7 |
-
/**
|
8 |
-
* Ditty Slider class
|
9 |
-
*
|
10 |
-
* @since 3.0
|
11 |
-
* @return null
|
12 |
-
*/
|
13 |
-
|
14 |
-
(function ($) {
|
15 |
-
'use strict';
|
16 |
-
|
17 |
-
var defaults = {
|
18 |
-
id : 0,
|
19 |
-
title : '',
|
20 |
-
display : 0,
|
21 |
-
status : '',
|
22 |
-
spacing : 30,
|
23 |
-
paging : 0, // 0, 1
|
24 |
-
perPage : 0,
|
25 |
-
transition : 'fade', // fade, slideLeft, slideREight, slideDown, slideUp
|
26 |
-
transitionEase : 'easeInOutQuint',
|
27 |
-
transitionSpeed : 1.5, // 1 - 10
|
28 |
-
autoplay : 0, // 0, 1
|
29 |
-
autoplayPause : 0, // 0, 1
|
30 |
-
autoplaySpeed : 8, // 1 - 60
|
31 |
-
height : 0,
|
32 |
-
heightEase : 'easeInOutQuint',
|
33 |
-
heightSpeed : 1.5, // 1 - 10
|
34 |
-
arrows : 'none',
|
35 |
-
arrowsIconColor : '',
|
36 |
-
arrowsBgColor : '',
|
37 |
-
arrowsPosition : 'center',
|
38 |
-
arrowsPadding : {},
|
39 |
-
arrowsStatic : 0,
|
40 |
-
navPrev : '<i class="fas fa-angle-left"></i>',
|
41 |
-
navNext : '<i class="fas fa-angle-right"></i>',
|
42 |
-
bullets : 'none',
|
43 |
-
bulletsColor : '',
|
44 |
-
bulletsColorActive : '',
|
45 |
-
bulletsPosition : 'bottomCenter',
|
46 |
-
bulletsSpacing : 2,
|
47 |
-
bulletsPadding : {},
|
48 |
-
bullet : '',
|
49 |
-
maxWidth : '',
|
50 |
-
bgColor : '',
|
51 |
-
padding : {},
|
52 |
-
margin : {},
|
53 |
-
borderColor : {},
|
54 |
-
borderStyle : {},
|
55 |
-
borderWidth : {},
|
56 |
-
borderRadius : {},
|
57 |
-
contentsBgColor : '',
|
58 |
-
contentsPadding : {},
|
59 |
-
contentsBorderColor : {},
|
60 |
-
contentsBorderStyle : {},
|
61 |
-
contentsBorderWidth : {},
|
62 |
-
contentsBorderRadius : {},
|
63 |
-
pageBgColor : '',
|
64 |
-
pagePadding : {},
|
65 |
-
pageBorderColor : {},
|
66 |
-
pageBorderStyle : {},
|
67 |
-
pageBorderWidth : {},
|
68 |
-
pageBorderRadius : {},
|
69 |
-
itemTextColor : '',
|
70 |
-
itemBgColor : '',
|
71 |
-
itemBorderColor : {},
|
72 |
-
itemBorderStyle : {},
|
73 |
-
itemBorderWidth : {},
|
74 |
-
itemBorderRadius : {},
|
75 |
-
itemPadding : {},
|
76 |
-
page : 0,
|
77 |
-
shuffle : 0,
|
78 |
-
showEditor : 0,
|
79 |
-
// init : function () {},
|
80 |
-
items : [
|
81 |
-
// {
|
82 |
-
// id: null,
|
83 |
-
// uniq_id: null,
|
84 |
-
// parent_id: null,
|
85 |
-
// html: null,
|
86 |
-
// status: null,
|
87 |
-
// ...
|
88 |
-
]
|
89 |
-
};
|
90 |
-
|
91 |
-
var Ditty_List = function ( elmt, options ) {
|
92 |
-
|
93 |
-
this.displayType = 'list';
|
94 |
-
this.elmt = elmt;
|
95 |
-
this.$elmt = $( elmt );
|
96 |
-
this.settings = $.extend( {}, defaults, $.ditty_list.defaults, options );
|
97 |
-
this.total = this.settings.items.length;
|
98 |
-
this.totalPages = 1;
|
99 |
-
this.page = this.settings.page;
|
100 |
-
this.pages = [];
|
101 |
-
this.enabledItems = [];
|
102 |
-
this.visibleItems = [];
|
103 |
-
this.editItem = null;
|
104 |
-
|
105 |
-
if ( 1 === parseInt( this.settings.shuffle ) ) {
|
106 |
-
this.shuffle();
|
107 |
-
}
|
108 |
-
|
109 |
-
this._init();
|
110 |
-
};
|
111 |
-
|
112 |
-
Ditty_List.prototype = {
|
113 |
-
|
114 |
-
_init: function () {
|
115 |
-
|
116 |
-
// Remove the pre class
|
117 |
-
this.$elmt.removeClass( 'ditty--pre' );
|
118 |
-
|
119 |
-
// Add classes and data attributes
|
120 |
-
this.$elmt.addClass( 'ditty ditty-list' );
|
121 |
-
this.$elmt.attr( 'data-id', this.settings.id );
|
122 |
-
this.$elmt.attr( 'data-type', this.displayType );
|
123 |
-
this.$elmt.attr( 'data-display', this.settings.display );
|
124 |
-
|
125 |
-
// Calculate the number of pages
|
126 |
-
this._calculatePages();
|
127 |
-
|
128 |
-
// Initialize the slider
|
129 |
-
this._initSlider();
|
130 |
-
|
131 |
-
// Show the editor or start live updates
|
132 |
-
if ( this.settings.showEditor ) {
|
133 |
-
dittyEditorInit( this );
|
134 |
-
} else {
|
135 |
-
this.trigger( 'start_live_updates' );
|
136 |
-
}
|
137 |
-
},
|
138 |
-
|
139 |
-
/**
|
140 |
-
* Initialize the slider
|
141 |
-
*
|
142 |
-
* @since 3.0
|
143 |
-
* @return null
|
144 |
-
*/
|
145 |
-
_initSlider: function () {
|
146 |
-
|
147 |
-
// Modify any settings to fit a slider
|
148 |
-
var sliderSettings = [];
|
149 |
-
$.each( this.settings, function( key, value ) {
|
150 |
-
var sliderKey = key.replace( 'page', 'slide' );
|
151 |
-
sliderSettings[sliderKey] = value;
|
152 |
-
} );
|
153 |
-
sliderSettings.slides = this.pages;
|
154 |
-
|
155 |
-
// Create a new slider and bind actions
|
156 |
-
this.$elmt.ditty_slider( sliderSettings );
|
157 |
-
this.$elmt.on( 'ditty_slider_init', { self: this }, this._triggerInit );
|
158 |
-
this.$elmt.on( 'ditty_slider_update', { self: this }, this._triggerUpdate );
|
159 |
-
this.$elmt.on( 'ditty_slider_after_slide_update', { self: this }, this._triggerShowSlide );
|
160 |
-
},
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Destroy the slider
|
164 |
-
*
|
165 |
-
* @since 3.0
|
166 |
-
* @return null
|
167 |
-
*/
|
168 |
-
_destroySlider: function () {
|
169 |
-
if ( this.$elmt.ditty_slider ) {
|
170 |
-
this.$elmt.off( 'ditty_slider_init', { self: this }, this._triggerInit );
|
171 |
-
this.$elmt.off( 'ditty_slider_update', { self: this }, this._triggerUpdate );
|
172 |
-
this.$elmt.off( 'ditty_slider_after_slide_update', { self: this }, this._triggerShowSlide );
|
173 |
-
this.$elmt.ditty_slider( 'destroy' );
|
174 |
-
}
|
175 |
-
},
|
176 |
-
|
177 |
-
/**
|
178 |
-
* Update the slider
|
179 |
-
*
|
180 |
-
* @since 3.0
|
181 |
-
* @return null
|
182 |
-
*/
|
183 |
-
_updateSlider: function ( index ) {
|
184 |
-
var newIndex = index ? index : this.$elmt.ditty_slider( 'options', 'slide');
|
185 |
-
this.$elmt.ditty_slider( 'options', 'slides', this.settings.pages );
|
186 |
-
this.$elmt.ditty_slider( 'options', 'slide', -1 );
|
187 |
-
this.$elmt.ditty_slider( 'showSlide', newIndex );
|
188 |
-
},
|
189 |
-
|
190 |
-
/**
|
191 |
-
* Style individual items
|
192 |
-
*
|
193 |
-
* @since 3.0
|
194 |
-
* @return null
|
195 |
-
*/
|
196 |
-
_styleItem: function( $item ) {
|
197 |
-
$item.children( '.ditty-item__elements' ).css( {
|
198 |
-
color: this.settings.itemTextColor,
|
199 |
-
backgroundColor: this.settings.itemBgColor,
|
200 |
-
borderColor: this.settings.itemBorderColor,
|
201 |
-
borderStyle: this.settings.itemBorderStyle
|
202 |
-
} );
|
203 |
-
$item.children( '.ditty-item__elements' ).css( this.settings.itemPadding );
|
204 |
-
$item.children( '.ditty-item__elements' ).css( this.settings.itemBorderRadius );
|
205 |
-
$item.children( '.ditty-item__elements' ).css( this.settings.itemBorderWidth );
|
206 |
-
$item.css( {
|
207 |
-
paddingBottom: this.settings.spacing + 'px'
|
208 |
-
} );
|
209 |
-
},
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Create a page of items
|
213 |
-
*
|
214 |
-
* @since 3.0
|
215 |
-
* @return null
|
216 |
-
*/
|
217 |
-
_createPage: function( index ) {
|
218 |
-
var self = this,
|
219 |
-
$page = $( '<div class="ditty-list__page ditty-list__page--' + index + '"></div>' ),
|
220 |
-
items = this._getItemsByPageIndex( index );
|
221 |
-
|
222 |
-
$.each( items, function( index, value ) {
|
223 |
-
var $item = $( value.html );
|
224 |
-
self._styleItem( $item );
|
225 |
-
|
226 |
-
// Add the layout css to the DOM
|
227 |
-
if ( value.css ) {
|
228 |
-
dittyLayoutCss( value.css, value.layout_id );
|
229 |
-
}
|
230 |
-
$page.append( $item );
|
231 |
-
} );
|
232 |
-
|
233 |
-
// Remove the spacing from the last item
|
234 |
-
$page.children().last().css( { paddingBottom: 0 } );
|
235 |
-
|
236 |
-
var page = {
|
237 |
-
id : 'page' + parseInt( index + 1 ),
|
238 |
-
html : $page,
|
239 |
-
items : items
|
240 |
-
};
|
241 |
-
|
242 |
-
return page;
|
243 |
-
},
|
244 |
-
|
245 |
-
/**
|
246 |
-
* Calculate and create pages
|
247 |
-
*
|
248 |
-
* @since 3.0
|
249 |
-
* @return null
|
250 |
-
*/
|
251 |
-
_calculatePages: function () {
|
252 |
-
var self = this,
|
253 |
-
items = [];
|
254 |
-
$.each( this.settings.items, function( index, item ) {
|
255 |
-
if ( self._isItemEnabled( index ) ) {
|
256 |
-
items.push( item );
|
257 |
-
}
|
258 |
-
} );
|
259 |
-
this.enabledItems = items;
|
260 |
-
this.total = items.length;
|
261 |
-
|
262 |
-
if ( parseInt( this.settings.paging ) && parseInt( this.settings.perPage ) > 0 ) {
|
263 |
-
this.totalPages = Math.ceil( parseInt( this.total ) / parseInt( this.settings.perPage ) );
|
264 |
-
} else {
|
265 |
-
this.totalPages = 1;
|
266 |
-
}
|
267 |
-
|
268 |
-
this.pages = [];
|
269 |
-
for( var i = 0; i < this.totalPages; i++ ) {
|
270 |
-
this.pages.push( this._createPage( i ) );
|
271 |
-
}
|
272 |
-
},
|
273 |
-
|
274 |
-
/**
|
275 |
-
* Get a page index by item index
|
276 |
-
*
|
277 |
-
* @since 3.0
|
278 |
-
* @return null
|
279 |
-
*/
|
280 |
-
_getPageByItemIndex: function ( index ) {
|
281 |
-
var pageIndex = Math.ceil( ( parseInt( index ) + 1 ) / this.settings.perPage ) - 1;
|
282 |
-
return pageIndex;
|
283 |
-
},
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Get items by page index
|
287 |
-
*
|
288 |
-
* @since 3.0
|
289 |
-
* @return null
|
290 |
-
*/
|
291 |
-
_getItemsByPageIndex: function ( index ) {
|
292 |
-
var items = this.enabledItems;
|
293 |
-
|
294 |
-
// Pull the items for the current index
|
295 |
-
if ( parseInt( this.totalPages ) > 1 ) {
|
296 |
-
var start = parseInt( this.settings.perPage ) * index,
|
297 |
-
end = start + parseInt( this.settings.perPage );
|
298 |
-
items = this.enabledItems.slice( start, end );
|
299 |
-
}
|
300 |
-
return items;
|
301 |
-
},
|
302 |
-
|
303 |
-
/**
|
304 |
-
* Shuffle items items TODO
|
305 |
-
*
|
306 |
-
* @since 3.0
|
307 |
-
* @return null
|
308 |
-
*/
|
309 |
-
shuffle: function () {
|
310 |
-
var temp,
|
311 |
-
rand;
|
312 |
-
|
313 |
-
for ( var i = this.total - 1; i > 0; i-- ) {
|
314 |
-
rand = Math.floor( Math.random() * ( i + 1 ) );
|
315 |
-
temp = this.settings.items[i];
|
316 |
-
|
317 |
-
this.settings.items[i] = this.settings.items[rand];
|
318 |
-
this.settings.items[rand] = temp;
|
319 |
-
}
|
320 |
-
},
|
321 |
-
|
322 |
-
/**
|
323 |
-
* Check if a item is enabled
|
324 |
-
*
|
325 |
-
* @since 3.0
|
326 |
-
* @return null
|
327 |
-
*/
|
328 |
-
_isItemEnabled: function( index ) {
|
329 |
-
if ( undefined === this.settings.items[parseInt( index )] ) {
|
330 |
-
return false;
|
331 |
-
}
|
332 |
-
if ( undefined === this.settings.items[parseInt( index )].is_disabled ) {
|
333 |
-
return true;
|
334 |
-
} else {
|
335 |
-
if ( this.settings.items[parseInt( index )].is_disabled.length > 0 ) {
|
336 |
-
return false;
|
337 |
-
} else {
|
338 |
-
return true;
|
339 |
-
}
|
340 |
-
}
|
341 |
-
},
|
342 |
-
|
343 |
-
/**
|
344 |
-
* Get the disabled status of all items
|
345 |
-
*
|
346 |
-
* @since 3.0
|
347 |
-
* @return null
|
348 |
-
*/
|
349 |
-
_disabledItemsStatus: function () {
|
350 |
-
var self = this,
|
351 |
-
statuses = {};
|
352 |
-
$.each( this.settings.items, function( i, item ) {
|
353 |
-
if ( self._isItemEnabled( i ) ) {
|
354 |
-
statuses[item.id] = 'enabled';
|
355 |
-
} else {
|
356 |
-
statuses[item.id] = 'disabled';
|
357 |
-
}
|
358 |
-
} );
|
359 |
-
return statuses;
|
360 |
-
},
|
361 |
-
|
362 |
-
/**
|
363 |
-
* Add a disabled type to a item
|
364 |
-
*
|
365 |
-
* @since 3.0
|
366 |
-
* @return null
|
367 |
-
*/
|
368 |
-
addItemDisabled: function ( id, slug ) {
|
369 |
-
var self = this;
|
370 |
-
$.each( this.settings.items, function( i, item ) {
|
371 |
-
if ( String( item.id ) === String( id ) ) {
|
372 |
-
if ( ! $.isArray( self.settings.items[i].is_disabled ) ) {
|
373 |
-
self.settings.items[i].is_disabled = [];
|
374 |
-
}
|
375 |
-
self.settings.items[i].is_disabled.push( slug );
|
376 |
-
}
|
377 |
-
} );
|
378 |
-
this.updateItems( this.settings.items );
|
379 |
-
this.trigger( 'disabled_items_update' );
|
380 |
-
},
|
381 |
-
|
382 |
-
/**
|
383 |
-
* Remove a disabled type from a item
|
384 |
-
*
|
385 |
-
* @since 3.0
|
386 |
-
* @return null
|
387 |
-
*/
|
388 |
-
removeItemDisabled: function ( id, slug ) {
|
389 |
-
var self = this;
|
390 |
-
$.each( this.settings.items, function( i, item ) {
|
391 |
-
if ( String( item.id ) === String( id ) ) {
|
392 |
-
if ( $.isArray( self.settings.items[i].is_disabled ) && self.settings.items[i].is_disabled.length ) {
|
393 |
-
self.settings.items[i].is_disabled = $.grep( self.settings.items[i].is_disabled, function( value ) {
|
394 |
-
return value !== slug;
|
395 |
-
} );
|
396 |
-
}
|
397 |
-
}
|
398 |
-
} );
|
399 |
-
this.updateItems( this.settings.items );
|
400 |
-
this.trigger( 'disabled_items_update' );
|
401 |
-
},
|
402 |
-
|
403 |
-
/**
|
404 |
-
* Show a specific item by index or id
|
405 |
-
*
|
406 |
-
* @since 3.0
|
407 |
-
* @return null
|
408 |
-
*/
|
409 |
-
showItem: function ( id ) {
|
410 |
-
var itemIndexes = [];
|
411 |
-
$.each( this.settings.items, function( i, item ) {
|
412 |
-
if ( String( item.id ) === String( id ) ) {
|
413 |
-
itemIndexes.push( i );
|
414 |
-
}
|
415 |
-
} );
|
416 |
-
if ( 0 !== itemIndexes.length ) {
|
417 |
-
var page = this._getPageByItemIndex( parseInt( itemIndexes[0] ) );
|
418 |
-
this.$elmt.ditty_slider( 'showSlide', page );
|
419 |
-
}
|
420 |
-
},
|
421 |
-
|
422 |
-
/**
|
423 |
-
* Add a new item
|
424 |
-
*
|
425 |
-
* @since 3.0
|
426 |
-
* @return null
|
427 |
-
*/
|
428 |
-
addItem: function ( item, index, type ) {
|
429 |
-
var newItems = this.settings.items.slice(),
|
430 |
-
indexExists = true;
|
431 |
-
|
432 |
-
if ( index >= this.total || index < 0 ) {
|
433 |
-
indexExists = false;
|
434 |
-
}
|
435 |
-
|
436 |
-
// Replace a item
|
437 |
-
if ( 'replace' === type && indexExists ) {
|
438 |
-
newItems.splice( index, 1, item );
|
439 |
-
|
440 |
-
// Add a item
|
441 |
-
} else {
|
442 |
-
if ( null === index || '' === index ) {
|
443 |
-
newItems.splice( parseInt( this.item ) + 1, 0, item );
|
444 |
-
} else {
|
445 |
-
if ( index >= this.total ) {
|
446 |
-
newItems.push( item );
|
447 |
-
} else if ( index < 0 ) {
|
448 |
-
newItems.splice( 0, 0, item );
|
449 |
-
} else {
|
450 |
-
newItems.splice( index, 0, item );
|
451 |
-
}
|
452 |
-
}
|
453 |
-
}
|
454 |
-
this.updateItems( newItems );
|
455 |
-
},
|
456 |
-
|
457 |
-
/**
|
458 |
-
* Delete a item by index
|
459 |
-
*
|
460 |
-
* @since 3.0
|
461 |
-
* @return null
|
462 |
-
*/
|
463 |
-
deleteItem: function ( id ) {
|
464 |
-
var updatedItems = [];
|
465 |
-
$.each( this.settings.items, function( index, item ) {
|
466 |
-
if ( String( item.id ) !== String( id ) ) {
|
467 |
-
updatedItems.push( item );
|
468 |
-
}
|
469 |
-
} );
|
470 |
-
this.updateItems( updatedItems );
|
471 |
-
},
|
472 |
-
|
473 |
-
/**
|
474 |
-
* Update the current items
|
475 |
-
*
|
476 |
-
* @since 3.0
|
477 |
-
* @return null
|
478 |
-
*/
|
479 |
-
updateItems: function ( newItems, itemId, type, forceSwapAll ) {
|
480 |
-
if ( undefined === newItems ) {
|
481 |
-
return false;
|
482 |
-
}
|
483 |
-
|
484 |
-
var self = this,
|
485 |
-
currentIndex = this.$elmt.ditty_slider( 'options', 'slide' ),
|
486 |
-
forceSwaps = [];
|
487 |
-
|
488 |
-
// Update a single item id
|
489 |
-
if ( itemId ) {
|
490 |
-
var tempCurrentItems = this.settings.items.slice(),
|
491 |
-
tempNewItems = [],
|
492 |
-
tempSwapped = false;
|
493 |
-
|
494 |
-
$.each( tempCurrentItems, function( index, item ) {
|
495 |
-
if ( String( item.id ) === String( itemId ) ) {
|
496 |
-
|
497 |
-
// Add after the id
|
498 |
-
if ( 'after' === type ) {
|
499 |
-
tempNewItems.push( item );
|
500 |
-
$.each( newItems, function( index, newItem ) {
|
501 |
-
tempNewItems.push( newItem );
|
502 |
-
} );
|
503 |
-
tempSwapped = true;
|
504 |
-
|
505 |
-
// Add before the id
|
506 |
-
} else if ( 'before' === type ) {
|
507 |
-
$.each( newItems, function( index, newItem ) {
|
508 |
-
tempNewItems.push( newItem );
|
509 |
-
} );
|
510 |
-
tempNewItems.push( item );
|
511 |
-
tempSwapped = true;
|
512 |
-
|
513 |
-
// Else swap the ID
|
514 |
-
} else {
|
515 |
-
if ( ! tempSwapped ) {
|
516 |
-
$.each( newItems, function( index, newItem ) {
|
517 |
-
tempNewItems.push( newItem );
|
518 |
-
forceSwaps.push( String( newItem.uniq_id ) );
|
519 |
-
} );
|
520 |
-
tempSwapped = true;
|
521 |
-
}
|
522 |
-
}
|
523 |
-
} else {
|
524 |
-
tempNewItems.push( item );
|
525 |
-
}
|
526 |
-
} );
|
527 |
-
if ( ! tempSwapped ) {
|
528 |
-
$.each( this.settings.items, function( index, item ) {
|
529 |
-
tempNewItems.push( item );
|
530 |
-
} );
|
531 |
-
tempSwapped = true;
|
532 |
-
}
|
533 |
-
newItems = tempNewItems;
|
534 |
-
}
|
535 |
-
this.settings.items = newItems;
|
536 |
-
this.total = newItems.length;
|
537 |
-
this._calculatePages();
|
538 |
-
this.$elmt.ditty_slider( 'options', 'slides', this.pages );
|
539 |
-
|
540 |
-
var $currentPage = this.$elmt.ditty_slider( 'options', 'currentSlide' ),
|
541 |
-
currentItems = $currentPage.children( '.ditty-item' ),
|
542 |
-
newIndex = this.$elmt.ditty_slider( 'options', 'slide' ),
|
543 |
-
itemSwaps = [];
|
544 |
-
|
545 |
-
if ( currentIndex !== newIndex ) {
|
546 |
-
return false;
|
547 |
-
}
|
548 |
-
|
549 |
-
var newPageItems,
|
550 |
-
newPageItemsCount = 0,
|
551 |
-
$lastCurrentItem = null,
|
552 |
-
lastCurrentItemPadding = -1,
|
553 |
-
currentItemsUpdated = [];
|
554 |
-
|
555 |
-
if ( this.pages[newIndex] ) {
|
556 |
-
newPageItems = this.pages[newIndex].items;
|
557 |
-
newPageItemsCount = newPageItems.length;
|
558 |
-
|
559 |
-
// Add new page items
|
560 |
-
$.each( newPageItems, function( index, newItem ) {
|
561 |
-
var $newItem = $( newItem.html );
|
562 |
-
|
563 |
-
// Add the css and style the items
|
564 |
-
if ( newItem.css ) {
|
565 |
-
dittyLayoutCss( newItem.css, newItem.layout_id );
|
566 |
-
}
|
567 |
-
self._styleItem( $newItem );
|
568 |
-
if ( index === newPageItemsCount - 1 ) {
|
569 |
-
$newItem.css( { paddingBottom: 0 } );
|
570 |
-
}
|
571 |
-
|
572 |
-
// Swap existing items
|
573 |
-
if ( currentItems[index] ) {
|
574 |
-
var $currentItem = $( currentItems[index] );
|
575 |
-
$lastCurrentItem = $currentItem;
|
576 |
-
|
577 |
-
currentItemsUpdated.push( index );
|
578 |
-
if ( forceSwapAll || ( String( $currentItem.data( 'item_uniq_id' ) ) !== String( newItem.uniq_id ) ) || forceSwaps.includes( String( newItem.uniq_id ) ) ) {
|
579 |
-
itemSwaps.push( {
|
580 |
-
currentItem: $currentItem,
|
581 |
-
newItem: $newItem
|
582 |
-
} );
|
583 |
-
}
|
584 |
-
|
585 |
-
// Add new items
|
586 |
-
} else {
|
587 |
-
var $tempItem = $( '<div class="ditty-temp-item"></div>' );
|
588 |
-
$currentPage.append( $tempItem );
|
589 |
-
itemSwaps.push( {
|
590 |
-
currentItem: $tempItem,
|
591 |
-
newItem: $newItem
|
592 |
-
} );
|
593 |
-
|
594 |
-
lastCurrentItemPadding = parseInt( self.settings.spacing );
|
595 |
-
}
|
596 |
-
} );
|
597 |
-
}
|
598 |
-
|
599 |
-
// Remove old page items
|
600 |
-
$.each( currentItems, function( index ) {
|
601 |
-
if ( ! currentItemsUpdated.includes( index ) ) {
|
602 |
-
var $currentItem = $( currentItems[index] ),
|
603 |
-
$tempItem = $( '<div class="ditty-temp-item"></div>' );
|
604 |
-
itemSwaps.push( {
|
605 |
-
currentItem: $currentItem,
|
606 |
-
newItem: $tempItem
|
607 |
-
} );
|
608 |
-
|
609 |
-
lastCurrentItemPadding = 0;
|
610 |
-
}
|
611 |
-
} );
|
612 |
-
|
613 |
-
// Add padding to the last current item
|
614 |
-
if ( null !== $lastCurrentItem && lastCurrentItemPadding >= 0 ) {
|
615 |
-
$lastCurrentItem.css( {
|
616 |
-
paddingBottom: lastCurrentItemPadding + 'px'
|
617 |
-
} );
|
618 |
-
}
|
619 |
-
|
620 |
-
dittyUpdateItems( itemSwaps );
|
621 |
-
this.trigger( 'update' );
|
622 |
-
},
|
623 |
-
|
624 |
-
/**
|
625 |
-
* Return the currently visible items
|
626 |
-
*
|
627 |
-
* @since 3.0
|
628 |
-
* @return null
|
629 |
-
*/
|
630 |
-
getActiveItems: function () {
|
631 |
-
return this._getItemsByPageIndex( this.page );
|
632 |
-
},
|
633 |
-
|
634 |
-
/**
|
635 |
-
* Trigger the init
|
636 |
-
*
|
637 |
-
* @since 3.0
|
638 |
-
* @return null
|
639 |
-
*/
|
640 |
-
_triggerInit: function ( e ) {
|
641 |
-
var self = e.data.self;
|
642 |
-
self.trigger( 'init' );
|
643 |
-
},
|
644 |
-
|
645 |
-
/**
|
646 |
-
* Trigger an update
|
647 |
-
*
|
648 |
-
* @since 3.0
|
649 |
-
* @return null
|
650 |
-
*/
|
651 |
-
_triggerUpdate: function ( e ) {
|
652 |
-
var self = e.data.self;
|
653 |
-
self.trigger( 'update' );
|
654 |
-
},
|
655 |
-
|
656 |
-
/**
|
657 |
-
* Trigger a slide update
|
658 |
-
*
|
659 |
-
* @since 3.0
|
660 |
-
* @return null
|
661 |
-
*/
|
662 |
-
_triggerShowSlide: function ( e, slide ) {
|
663 |
-
var self = e.data.self;
|
664 |
-
self.page = slide;
|
665 |
-
self.trigger( 'active_items_update' );
|
666 |
-
},
|
667 |
-
|
668 |
-
/**
|
669 |
-
* Trigger events
|
670 |
-
*
|
671 |
-
* @since 3.0
|
672 |
-
* @return null
|
673 |
-
*/
|
674 |
-
trigger: function ( fn ) {
|
675 |
-
var params = [];
|
676 |
-
|
677 |
-
switch( fn ) {
|
678 |
-
case 'active_items_update':
|
679 |
-
params = [this, this.getActiveItems()];
|
680 |
-
break;
|
681 |
-
case 'disabled_items_update':
|
682 |
-
params = [this._disabledItemsStatus()];
|
683 |
-
break;
|
684 |
-
case 'start_live_updates':
|
685 |
-
params = [this.settings.id];
|
686 |
-
break;
|
687 |
-
default:
|
688 |
-
params = [
|
689 |
-
this.settings,
|
690 |
-
this.$elmt
|
691 |
-
];
|
692 |
-
break;
|
693 |
-
}
|
694 |
-
|
695 |
-
this.$elmt.trigger( 'ditty_' + fn, params );
|
696 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
697 |
-
this.settings[fn].apply( this.$elmt, params );
|
698 |
-
}
|
699 |
-
//params.unshift( this );
|
700 |
-
$( 'body' ).trigger( 'ditty_' + fn, params );
|
701 |
-
},
|
702 |
-
|
703 |
-
/**
|
704 |
-
* Return data for the object
|
705 |
-
*
|
706 |
-
* @since 3.0
|
707 |
-
* @return null
|
708 |
-
*/
|
709 |
-
_getOption: function( key ) {
|
710 |
-
switch( key ) {
|
711 |
-
case 'ditty':
|
712 |
-
return this;
|
713 |
-
case 'type':
|
714 |
-
return this.displayType;
|
715 |
-
case 'display':
|
716 |
-
return this.settings.display;
|
717 |
-
case 'items':
|
718 |
-
return this.settings.items;
|
719 |
-
default:
|
720 |
-
return this.settings[key];
|
721 |
-
}
|
722 |
-
},
|
723 |
-
|
724 |
-
/**
|
725 |
-
* Set data for the object
|
726 |
-
*
|
727 |
-
* @since 3.0
|
728 |
-
* @return null
|
729 |
-
*/
|
730 |
-
_setOption: function( key, value ) {
|
731 |
-
|
732 |
-
if ( undefined === value ) {
|
733 |
-
return false;
|
734 |
-
}
|
735 |
-
|
736 |
-
var sliderKey = key,
|
737 |
-
sliderValue = value,
|
738 |
-
updateSlider = true;
|
739 |
-
|
740 |
-
var self = this;
|
741 |
-
|
742 |
-
switch( key ) {
|
743 |
-
case 'items':
|
744 |
-
updateSlider = false;
|
745 |
-
this.updateItems( value );
|
746 |
-
break;
|
747 |
-
case 'perPage':
|
748 |
-
case 'paging':
|
749 |
-
updateSlider = false;
|
750 |
-
this.settings[key] = value;
|
751 |
-
this.updateItems( this.settings.items );
|
752 |
-
break;
|
753 |
-
case 'spacing':
|
754 |
-
this.settings[key] = value;
|
755 |
-
this.$elmt.find( '.ditty-item' ).each( function() {
|
756 |
-
$( this ).css( { paddingBottom: self.settings.spacing + 'px' } );
|
757 |
-
});
|
758 |
-
this.$elmt.find( '.ditty-list__page' ).each( function() {
|
759 |
-
$( this ).children( '.ditty-item:last-child' ).css( { paddingBottom: 0 } );
|
760 |
-
});
|
761 |
-
break;
|
762 |
-
case 'itemTextColor':
|
763 |
-
case 'itemBgColor':
|
764 |
-
case 'itemBorderColor':
|
765 |
-
case 'itemBorderStyle':
|
766 |
-
case 'itemBorderWidth':
|
767 |
-
case 'itemBorderRadius':
|
768 |
-
case 'itemPadding':
|
769 |
-
this.settings[key] = value;
|
770 |
-
this.$elmt.find( '.ditty-item' ).each( function() {
|
771 |
-
self._styleItem( $( this ) );
|
772 |
-
} );
|
773 |
-
break;
|
774 |
-
default:
|
775 |
-
this.settings[key] = value;
|
776 |
-
break;
|
777 |
-
}
|
778 |
-
|
779 |
-
// Convert page to slide
|
780 |
-
if ( updateSlider ) {
|
781 |
-
sliderKey = sliderKey.replace( 'page', 'slide' );
|
782 |
-
this.$elmt.ditty_slider( 'options', sliderKey, sliderValue );
|
783 |
-
}
|
784 |
-
},
|
785 |
-
|
786 |
-
/**
|
787 |
-
* Get or set ditty options
|
788 |
-
*
|
789 |
-
* @since 3.0
|
790 |
-
* @return null
|
791 |
-
*/
|
792 |
-
options: function ( key, value ) {
|
793 |
-
var self = this;
|
794 |
-
if ( typeof key === 'object' ) {
|
795 |
-
$.each( key, function( k, v ) {
|
796 |
-
self._setOption( k, v );
|
797 |
-
});
|
798 |
-
} else if ( typeof key === 'string' ) {
|
799 |
-
if ( value === undefined ) {
|
800 |
-
return self._getOption( key );
|
801 |
-
}
|
802 |
-
self._setOption( key, value );
|
803 |
-
} else {
|
804 |
-
return self.settings;
|
805 |
-
}
|
806 |
-
},
|
807 |
-
|
808 |
-
/**
|
809 |
-
* Destroy this object
|
810 |
-
*
|
811 |
-
* @since 3.0
|
812 |
-
* @return null
|
813 |
-
*/
|
814 |
-
destroy: function () {
|
815 |
-
this._destroySlider();
|
816 |
-
this.$elmt.removeClass( 'ditty ditty-list' );
|
817 |
-
this.$elmt.removeAttr( 'data-id' );
|
818 |
-
this.$elmt.removeAttr( 'data-type' );
|
819 |
-
this.$elmt.removeAttr( 'data-display' );
|
820 |
-
this.$elmt.removeAttr( 'style' );
|
821 |
-
this.$elmt.empty();
|
822 |
-
this.elmt._ditty_list = null;
|
823 |
-
}
|
824 |
-
};
|
825 |
-
|
826 |
-
$.fn.ditty_list = function( options ) {
|
827 |
-
var args = arguments,
|
828 |
-
error = false,
|
829 |
-
returns;
|
830 |
-
|
831 |
-
if ( options === undefined || typeof options === 'object' ) {
|
832 |
-
return this.each( function () {
|
833 |
-
if ( ! this._ditty_list ) {
|
834 |
-
this._ditty_list = new Ditty_List( this, options );
|
835 |
-
}
|
836 |
-
});
|
837 |
-
} else if ( typeof options === 'string' ) {
|
838 |
-
this.each( function () {
|
839 |
-
var instance = this._ditty_list;
|
840 |
-
|
841 |
-
if ( ! instance ) {
|
842 |
-
throw new Error( 'No Ditty_List applied to this element.' );
|
843 |
-
}
|
844 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
845 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
846 |
-
} else {
|
847 |
-
error = true;
|
848 |
-
}
|
849 |
-
} );
|
850 |
-
|
851 |
-
if ( error ) {
|
852 |
-
throw new Error( 'No method "' + options + '" in Ditty_List.' );
|
853 |
-
}
|
854 |
-
|
855 |
-
return returns !== undefined ? returns : this;
|
856 |
-
}
|
857 |
-
};
|
858 |
-
|
859 |
-
$.ditty_list = {};
|
860 |
-
$.ditty_list.defaults = defaults;
|
861 |
-
|
862 |
-
} )( jQuery );
|
1 |
+
!function($){"use strict";var t={id:0,title:"",display:0,status:"",spacing:30,paging:0,perPage:0,transition:"fade",transitionEase:"easeInOutQuint",transitionSpeed:1.5,autoplay:0,autoplayPause:0,autoplaySpeed:8,height:0,heightEase:"easeInOutQuint",heightSpeed:1.5,arrows:"none",arrowsIconColor:"",arrowsBgColor:"",arrowsPosition:"center",arrowsPadding:{},arrowsStatic:0,navPrev:'<i class="fas fa-angle-left"></i>',navNext:'<i class="fas fa-angle-right"></i>',bullets:"none",bulletsColor:"",bulletsColorActive:"",bulletsPosition:"bottomCenter",bulletsSpacing:2,bulletsPadding:{},bullet:"",maxWidth:"",bgColor:"",padding:{},margin:{},borderColor:{},borderStyle:{},borderWidth:{},borderRadius:{},contentsBgColor:"",contentsPadding:{},contentsBorderColor:{},contentsBorderStyle:{},contentsBorderWidth:{},contentsBorderRadius:{},pageBgColor:"",pagePadding:{},pageBorderColor:{},pageBorderStyle:{},pageBorderWidth:{},pageBorderRadius:{},itemTextColor:"",itemBgColor:"",itemBorderColor:{},itemBorderStyle:{},itemBorderWidth:{},itemBorderRadius:{},itemPadding:{},page:0,shuffle:0,showEditor:0,items:[]},i=function(i,e){this.displayType="list",this.elmt=i,this.$elmt=$(i),this.settings=$.extend({},t,$.ditty_list.defaults,e),this.total=this.settings.items.length,this.totalPages=1,this.page=this.settings.page,this.pages=[],this.enabledItems=[],this.visibleItems=[],this.editItem=null,1===parseInt(this.settings.shuffle)&&this.shuffle(),this._init()};i.prototype={_init:function(){this.$elmt.removeClass("ditty--pre"),this.$elmt.addClass("ditty ditty-list"),this.$elmt.attr("data-id",this.settings.id),this.$elmt.attr("data-type",this.displayType),this.$elmt.attr("data-display",this.settings.display),this._calculatePages(),this._initSlider(),this.settings.showEditor?dittyEditorInit(this):this.trigger("start_live_updates")},_initSlider:function(){var t=[];$.each(this.settings,(function(i,e){var s=i.replace("page","slide");t[s]=e})),t.slides=this.pages,this.$elmt.ditty_slider(t),this.$elmt.on("ditty_slider_init",{self:this},this._triggerInit),this.$elmt.on("ditty_slider_update",{self:this},this._triggerUpdate),this.$elmt.on("ditty_slider_after_slide_update",{self:this},this._triggerShowSlide)},_destroySlider:function(){this.$elmt.ditty_slider&&(this.$elmt.off("ditty_slider_init",{self:this},this._triggerInit),this.$elmt.off("ditty_slider_update",{self:this},this._triggerUpdate),this.$elmt.off("ditty_slider_after_slide_update",{self:this},this._triggerShowSlide),this.$elmt.ditty_slider("destroy"))},_updateSlider:function(t){var i=t||this.$elmt.ditty_slider("options","slide");this.$elmt.ditty_slider("options","slides",this.settings.pages),this.$elmt.ditty_slider("options","slide",-1),this.$elmt.ditty_slider("showSlide",i)},_styleItem:function(t){t.children(".ditty-item__elements").css({color:this.settings.itemTextColor,backgroundColor:this.settings.itemBgColor,borderColor:this.settings.itemBorderColor,borderStyle:this.settings.itemBorderStyle}),t.children(".ditty-item__elements").css(this.settings.itemPadding),t.children(".ditty-item__elements").css(this.settings.itemBorderRadius),t.children(".ditty-item__elements").css(this.settings.itemBorderWidth),t.css({paddingBottom:this.settings.spacing+"px"})},_createPage:function(t){var i=this,e=$('<div class="ditty-list__page ditty-list__page--'+t+'"></div>'),s=this._getItemsByPageIndex(t);return $.each(s,(function(t,s){var n=$(s.html);i._styleItem(n),s.css&&dittyLayoutCss(s.css,s.layout_id),e.append(n)})),e.children().last().css({paddingBottom:0}),{id:"page"+parseInt(t+1),html:e,items:s}},_calculatePages:function(){var t=this,i=[];$.each(this.settings.items,(function(e,s){t._isItemEnabled(e)&&i.push(s)})),this.enabledItems=i,this.total=i.length,parseInt(this.settings.paging)&&parseInt(this.settings.perPage)>0?this.totalPages=Math.ceil(parseInt(this.total)/parseInt(this.settings.perPage)):this.totalPages=1,this.pages=[];for(var e=0;e<this.totalPages;e++)this.pages.push(this._createPage(e))},_getPageByItemIndex:function(t){return Math.ceil((parseInt(t)+1)/this.settings.perPage)-1},_getItemsByPageIndex:function(t){var i=this.enabledItems;if(parseInt(this.totalPages)>1){var e=parseInt(this.settings.perPage)*t,s=e+parseInt(this.settings.perPage);i=this.enabledItems.slice(e,s)}return i},shuffle:function(){for(var t,i,e=this.total-1;e>0;e--)i=Math.floor(Math.random()*(e+1)),t=this.settings.items[e],this.settings.items[e]=this.settings.items[i],this.settings.items[i]=t},_isItemEnabled:function(t){return void 0!==this.settings.items[parseInt(t)]&&(void 0===this.settings.items[parseInt(t)].is_disabled||!(this.settings.items[parseInt(t)].is_disabled.length>0))},_disabledItemsStatus:function(){var t=this,i={};return $.each(this.settings.items,(function(e,s){t._isItemEnabled(e)?i[s.id]="enabled":i[s.id]="disabled"})),i},addItemDisabled:function(t,i){var e=this;$.each(this.settings.items,(function(s,n){String(n.id)===String(t)&&($.isArray(e.settings.items[s].is_disabled)||(e.settings.items[s].is_disabled=[]),e.settings.items[s].is_disabled.push(i))})),this.updateItems(this.settings.items),this.trigger("disabled_items_update")},removeItemDisabled:function(t,i){var e=this;$.each(this.settings.items,(function(s,n){String(n.id)===String(t)&&$.isArray(e.settings.items[s].is_disabled)&&e.settings.items[s].is_disabled.length&&(e.settings.items[s].is_disabled=$.grep(e.settings.items[s].is_disabled,(function(t){return t!==i})))})),this.updateItems(this.settings.items),this.trigger("disabled_items_update")},showItem:function(t){var i=[];if($.each(this.settings.items,(function(e,s){String(s.id)===String(t)&&i.push(e)})),0!==i.length){var e=this._getPageByItemIndex(parseInt(i[0]));this.$elmt.ditty_slider("showSlide",e)}},addItem:function(t,i,e){var s=this.settings.items.slice(),n=!0;(i>=this.total||i<0)&&(n=!1),"replace"===e&&n?s.splice(i,1,t):null===i||""===i?s.splice(parseInt(this.item)+1,0,t):i>=this.total?s.push(t):i<0?s.splice(0,0,t):s.splice(i,0,t),this.updateItems(s)},deleteItem:function(t){var i=[];$.each(this.settings.items,(function(e,s){String(s.id)!==String(t)&&i.push(s)})),this.updateItems(i)},updateItems:function(t,i,e,s){if(void 0===t)return!1;var n=this,a=this.$elmt.ditty_slider("options","slide"),r=[];if(i){var d=this.settings.items.slice(),l=[],h=!1;$.each(d,(function(s,n){String(n.id)===String(i)?"after"===e?(l.push(n),$.each(t,(function(t,i){l.push(i)})),h=!0):"before"===e?($.each(t,(function(t,i){l.push(i)})),l.push(n),h=!0):h||($.each(t,(function(t,i){l.push(i),r.push(String(i.uniq_id))})),h=!0):l.push(n)})),h||($.each(this.settings.items,(function(t,i){l.push(i)})),h=!0),t=l}this.settings.items=t,this.total=t.length,this._calculatePages(),this.$elmt.ditty_slider("options","slides",this.pages);var o=this.$elmt.ditty_slider("options","currentSlide"),g=o.children(".ditty-item"),m=this.$elmt.ditty_slider("options","slide"),c=[];if(a!==m)return!1;var p,u=0,_=null,f=-1,y=[];this.pages[m]&&(p=this.pages[m].items,u=p.length,$.each(p,(function(t,i){var e=$(i.html);if(i.css&&dittyLayoutCss(i.css,i.layout_id),n._styleItem(e),t===u-1&&e.css({paddingBottom:0}),g[t]){var a=$(g[t]);_=a,y.push(t),(s||String(a.data("item_uniq_id"))!==String(i.uniq_id)||r.includes(String(i.uniq_id)))&&c.push({currentItem:a,newItem:e})}else{var d=$('<div class="ditty-temp-item"></div>');o.append(d),c.push({currentItem:d,newItem:e}),f=parseInt(n.settings.spacing)}}))),$.each(g,(function(t){if(!y.includes(t)){var i=$(g[t]),e=$('<div class="ditty-temp-item"></div>');c.push({currentItem:i,newItem:e}),f=0}})),null!==_&&f>=0&&_.css({paddingBottom:f+"px"}),dittyUpdateItems(c),this.trigger("update")},getActiveItems:function(){return this._getItemsByPageIndex(this.page)},_triggerInit:function(t){t.data.self.trigger("init")},_triggerUpdate:function(t){t.data.self.trigger("update")},_triggerShowSlide:function(t,i){var e=t.data.self;e.page=i,e.trigger("active_items_update")},trigger:function(t){var i=[];switch(t){case"active_items_update":i=[this,this.getActiveItems()];break;case"disabled_items_update":i=[this._disabledItemsStatus()];break;case"start_live_updates":i=[this.settings.id];break;default:i=[this.settings,this.$elmt]}this.$elmt.trigger("ditty_"+t,i),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,i),$("body").trigger("ditty_"+t,i)},_getOption:function(t){switch(t){case"ditty":return this;case"type":return this.displayType;case"display":return this.settings.display;case"items":return this.settings.items;default:return this.settings[t]}},_setOption:function(t,i){if(void 0===i)return!1;var e=t,s=i,n=!0,a=this;switch(t){case"items":n=!1,this.updateItems(i);break;case"perPage":case"paging":n=!1,this.settings[t]=i,this.updateItems(this.settings.items);break;case"spacing":this.settings[t]=i,this.$elmt.find(".ditty-item").each((function(){$(this).css({paddingBottom:a.settings.spacing+"px"})})),this.$elmt.find(".ditty-list__page").each((function(){$(this).children(".ditty-item:last-child").css({paddingBottom:0})}));break;case"itemTextColor":case"itemBgColor":case"itemBorderColor":case"itemBorderStyle":case"itemBorderWidth":case"itemBorderRadius":case"itemPadding":this.settings[t]=i,this.$elmt.find(".ditty-item").each((function(){a._styleItem($(this))}));break;default:this.settings[t]=i}n&&(e=e.replace("page","slide"),this.$elmt.ditty_slider("options",e,s))},options:function(t,i){var e=this;if("object"==typeof t)$.each(t,(function(t,i){e._setOption(t,i)}));else{if("string"!=typeof t)return e.settings;if(void 0===i)return e._getOption(t);e._setOption(t,i)}},destroy:function(){this._destroySlider(),this.$elmt.removeClass("ditty ditty-list"),this.$elmt.removeAttr("data-id"),this.$elmt.removeAttr("data-type"),this.$elmt.removeAttr("data-display"),this.$elmt.removeAttr("style"),this.$elmt.empty(),this.elmt._ditty_list=null}},$.fn.ditty_list=function(t){var e,s=arguments,n=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_list||(this._ditty_list=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_list;if(!i)throw new Error("No Ditty_List applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):n=!0})),n)throw new Error('No method "'+t+'" in Ditty_List.');return void 0!==e?e:this}},$.ditty_list={},$.ditty_list.defaults=t}(jQuery);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/js/ditty-admin.min.js
CHANGED
@@ -1,888 +1 @@
|
|
1 |
-
/* global jQuery:true */
|
2 |
-
/* global dittyAdminVars:true */
|
3 |
-
/* global console:true */
|
4 |
-
|
5 |
-
// @codekit-append 'admin/class-ditty-settings.js';
|
6 |
-
// @codekit-append 'admin/class-ditty-extension.js';
|
7 |
-
// @codekit-append 'admin/ditty-extensions.js';
|
8 |
-
// @codekit-append 'admin/ditty-displays.js';
|
9 |
-
|
10 |
-
jQuery( document ).ready( function( $ ) {
|
11 |
-
|
12 |
-
// Setup strict mode
|
13 |
-
(function() {
|
14 |
-
|
15 |
-
"use strict";
|
16 |
-
|
17 |
-
$( '#poststuff' ).trigger( 'ditty_init_fields' );
|
18 |
-
$( '#ditty-settings' ).ditty_settings();
|
19 |
-
|
20 |
-
}() );
|
21 |
-
|
22 |
-
} );
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Ditty Settings
|
26 |
-
*
|
27 |
-
* @since 3.0
|
28 |
-
* @return null
|
29 |
-
*/
|
30 |
-
|
31 |
-
(function ($) {
|
32 |
-
'use strict';
|
33 |
-
|
34 |
-
var defaults = {
|
35 |
-
};
|
36 |
-
|
37 |
-
var Ditty_Settings = function ( elmt, options ) {
|
38 |
-
|
39 |
-
this.elmt = elmt;
|
40 |
-
this.settings = $.extend( {}, defaults, $.ditty_settings.defaults, options );
|
41 |
-
this.$elmt = $( elmt );
|
42 |
-
this.$form = this.$elmt.find( '.ditty-settings__form' );
|
43 |
-
this.$panels = this.$elmt.find( '.ditty-settings__panels' );
|
44 |
-
this.saveBtns = this.$elmt.find( '.ditty-settings__save' );
|
45 |
-
this.tabs = this.$elmt.find( '.ditty-settings__tab' );
|
46 |
-
this.$notice_update = this.$elmt.find( '.ditty-notification--updated' );
|
47 |
-
this.$notice_error = this.$elmt.find( '.ditty-notification--error' );
|
48 |
-
this.$notice_warning = this.$elmt.find( '.ditty-notification--warning' );
|
49 |
-
this.initData = null;
|
50 |
-
this._init();
|
51 |
-
};
|
52 |
-
|
53 |
-
|
54 |
-
Ditty_Settings.prototype = {
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Initialize the data list
|
58 |
-
*
|
59 |
-
* @since 3.0
|
60 |
-
* @return null
|
61 |
-
*/
|
62 |
-
_init: function () {
|
63 |
-
|
64 |
-
// Initialize the slider
|
65 |
-
this._initSlider();
|
66 |
-
|
67 |
-
// Add listeners
|
68 |
-
$( 'body' ).on( 'ditty_field_clone_update', { self: this }, this._enableSettingsUpdates );
|
69 |
-
this.saveBtns.on( 'click', { self: this }, this._submitForm );
|
70 |
-
this.tabs.on( 'click', { self: this }, this._tabClick );
|
71 |
-
this.$panels.on( 'ditty_slider_init', { self: this }, this._sliderInit );
|
72 |
-
this.$panels.on( 'ditty_slider_before_slide_update', { self: this }, this._beforeSlideUpdate );
|
73 |
-
this.$form.on( 'keyup change', 'input[type="text"], input[type="number"], textarea, select', { self: this }, this._checkUpdates );
|
74 |
-
this.$form.on( 'click', 'input[type="radio"], input[type="checkbox"]', { self: this }, this._checkUpdates );
|
75 |
-
this.$form.on( 'ditty_input_wysiwyg_update', '.ditty-input--wysiwyg', { self: this }, this._checkUpdates );
|
76 |
-
this.$form.on( 'click', '.ditty-default-layout-install', { self: this }, this._installLayout );
|
77 |
-
this.$form.on( 'click', '.ditty-default-display-install', { self: this }, this._installDisplay );
|
78 |
-
},
|
79 |
-
|
80 |
-
/**
|
81 |
-
* Initialize the extensions
|
82 |
-
*
|
83 |
-
* @since 3.0
|
84 |
-
* @return null
|
85 |
-
*/
|
86 |
-
_initSlider: function () {
|
87 |
-
var initPanel = this.$panels.data( 'init_panel' );
|
88 |
-
this.$panels.ditty_slider( {
|
89 |
-
transition : 'fade',
|
90 |
-
transitionSpeed : 0.75,
|
91 |
-
heightSpeed : 0.75,
|
92 |
-
touchSwipe : false,
|
93 |
-
slidesEl : '.ditty-settings__panel',
|
94 |
-
slideId : ( '' !== initPanel ) ? initPanel : false
|
95 |
-
} );
|
96 |
-
},
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Slider init
|
100 |
-
*
|
101 |
-
* @since 3.0
|
102 |
-
* @return null
|
103 |
-
*/
|
104 |
-
_sliderInit: function( e ) {
|
105 |
-
var self = e.data.self;
|
106 |
-
self.initData = self.$form.serialize();
|
107 |
-
},
|
108 |
-
|
109 |
-
/**
|
110 |
-
* Before slide update
|
111 |
-
*
|
112 |
-
* @since 3.0
|
113 |
-
* @return null
|
114 |
-
*/
|
115 |
-
_beforeSlideUpdate: function( e, index, slide ) {
|
116 |
-
var self = e.data.self;
|
117 |
-
self._initFields( slide.$elmt );
|
118 |
-
self.$elmt.find( '.ditty-settings__tab' ).removeClass( 'active' );
|
119 |
-
self.$elmt.find( '.ditty-settings__tab[data-panel="' + slide.id + '"]' ).addClass( 'active' );
|
120 |
-
},
|
121 |
-
|
122 |
-
/**
|
123 |
-
* Preview button add updates class
|
124 |
-
*
|
125 |
-
* @since 3.0
|
126 |
-
* @return null
|
127 |
-
*/
|
128 |
-
_enableSettingsUpdates: function( e ) {
|
129 |
-
var self = ( e ) ? e.data.self : this;
|
130 |
-
self.saveBtns.addClass( 'has-updates' );
|
131 |
-
//self.notice_warning.slideDown();
|
132 |
-
},
|
133 |
-
|
134 |
-
/**
|
135 |
-
* Preview button remove updates class
|
136 |
-
*
|
137 |
-
* @since 3.0
|
138 |
-
* @return null
|
139 |
-
*/
|
140 |
-
_disableSettingsUpdates: function() {
|
141 |
-
this.saveBtns.removeClass( 'has-updates' );
|
142 |
-
},
|
143 |
-
|
144 |
-
/**
|
145 |
-
* Check for updates
|
146 |
-
*
|
147 |
-
* @since 3.0
|
148 |
-
* @return null
|
149 |
-
*/
|
150 |
-
_checkUpdates: function( e ) {
|
151 |
-
var self = e ? e.data.self : this;
|
152 |
-
var currentData = self.$form.serialize();
|
153 |
-
if ( currentData !== self.initData ) {
|
154 |
-
self._enableSettingsUpdates();
|
155 |
-
} else {
|
156 |
-
self._disableSettingsUpdates();
|
157 |
-
}
|
158 |
-
},
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Initialize dynamic fields
|
162 |
-
*
|
163 |
-
* @since 3.0
|
164 |
-
* @return null
|
165 |
-
*/
|
166 |
-
_initFields: function ( $fields ) {
|
167 |
-
$fields.find( '.ditty-data-list' ).ditty_ui_data_list();
|
168 |
-
$fields.trigger( 'ditty_init_fields' );
|
169 |
-
$.protip( {
|
170 |
-
defaults: {
|
171 |
-
position: 'top',
|
172 |
-
size: 'small',
|
173 |
-
scheme: 'black',
|
174 |
-
classes: 'ditty-protip'
|
175 |
-
}
|
176 |
-
} );
|
177 |
-
},
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Show or hide post types
|
181 |
-
*
|
182 |
-
* @since 3.0
|
183 |
-
* @return null
|
184 |
-
*/
|
185 |
-
_togglePostTypes: function () {
|
186 |
-
if ( $( 'input[name="ditty_layout_ui"]' ).length ) {
|
187 |
-
var layoutUiVal = $( 'input[name="ditty_layout_ui"]:checked' ).val(),
|
188 |
-
$layoutMenu = $( '#adminmenu .wp-submenu > li > a[href="edit.php?post_type=ditty_layout"]' );
|
189 |
-
if ( 'disabled' === layoutUiVal ) {
|
190 |
-
$layoutMenu.hide();
|
191 |
-
} else {
|
192 |
-
$layoutMenu.css( 'display', 'block' );
|
193 |
-
}
|
194 |
-
}
|
195 |
-
if ( $( 'input[name="ditty_display_ui"]' ).length ) {
|
196 |
-
var displayUiVal = $( 'input[name="ditty_display_ui"]:checked' ).val(),
|
197 |
-
$displayMenu = $( '#adminmenu .wp-submenu > li > a[href="edit.php?post_type=ditty_display"]' );
|
198 |
-
if ( 'disabled' === displayUiVal ) {
|
199 |
-
$displayMenu.hide();
|
200 |
-
} else {
|
201 |
-
$displayMenu.css( 'display', 'block' );
|
202 |
-
}
|
203 |
-
}
|
204 |
-
},
|
205 |
-
|
206 |
-
/**
|
207 |
-
* Listen for a tab click
|
208 |
-
*
|
209 |
-
* @since 3.0
|
210 |
-
* @return null
|
211 |
-
*/
|
212 |
-
_tabClick: function( e ) {
|
213 |
-
e.preventDefault();
|
214 |
-
var self = e.data.self,
|
215 |
-
$tab = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
216 |
-
slideId = $tab.data( 'panel' ),
|
217 |
-
$currentTab = self.$elmt.find( '.ditty-settings__tab.active' );
|
218 |
-
|
219 |
-
if ( $currentTab === $tab ) {
|
220 |
-
return false;
|
221 |
-
}
|
222 |
-
|
223 |
-
self.$elmt.find( '.ditty-extension__tab' ).removeClass( 'active' );
|
224 |
-
$tab.addClass( 'active' );
|
225 |
-
|
226 |
-
self.$panels.ditty_slider( 'showSlideById', slideId );
|
227 |
-
},
|
228 |
-
|
229 |
-
/**
|
230 |
-
* Update inputs after save and sanitize
|
231 |
-
*
|
232 |
-
* @since 3.0
|
233 |
-
* @return null
|
234 |
-
*/
|
235 |
-
_upateInputs: function( updates ) {
|
236 |
-
$.each( updates, function( inputName, updatedValue ) {
|
237 |
-
if ( $( 'input[name="' + inputName + '"]' ).length ) {
|
238 |
-
$( 'input[name="' + inputName + '"]' ).val( updatedValue );
|
239 |
-
}
|
240 |
-
} );
|
241 |
-
},
|
242 |
-
|
243 |
-
/**
|
244 |
-
* Submit updates
|
245 |
-
*
|
246 |
-
* @since 3.0
|
247 |
-
* @return null
|
248 |
-
*/
|
249 |
-
_submitForm: function( e ) {
|
250 |
-
e.preventDefault();
|
251 |
-
var self = e.data.self;
|
252 |
-
|
253 |
-
if ( self.$elmt.hasClass( 'updating' ) ) {
|
254 |
-
return false;
|
255 |
-
}
|
256 |
-
|
257 |
-
self.$elmt.trigger( 'ditty_pre_save_fields' );
|
258 |
-
self.$elmt.addClass( 'updating' );
|
259 |
-
self.saveBtns.text( dittyAdminVars.adminStrings.settingsSaving );
|
260 |
-
|
261 |
-
self.$form.ajaxSubmit( {
|
262 |
-
url : dittyAdminVars.ajaxurl,
|
263 |
-
type : 'post',
|
264 |
-
dataType : 'json',
|
265 |
-
data : {
|
266 |
-
action : 'ditty_settings_save',
|
267 |
-
security : dittyAdminVars.security
|
268 |
-
},
|
269 |
-
success: function( data ) {
|
270 |
-
if ( data.input_updates ) {
|
271 |
-
self._upateInputs( data.input_updates );
|
272 |
-
}
|
273 |
-
self.initData = self.$form.serialize();
|
274 |
-
self.saveBtns.text( dittyAdminVars.adminStrings.settings_updated );
|
275 |
-
setTimeout( function() {
|
276 |
-
self.saveBtns.text( dittyAdminVars.adminStrings.settings_save );
|
277 |
-
}, 2000 );
|
278 |
-
self.$elmt.removeClass( 'updating' );
|
279 |
-
self._disableSettingsUpdates();
|
280 |
-
|
281 |
-
//self.$notice_update.slideDown();
|
282 |
-
|
283 |
-
// Check the post types display
|
284 |
-
self._togglePostTypes();
|
285 |
-
}
|
286 |
-
} );
|
287 |
-
},
|
288 |
-
|
289 |
-
/**
|
290 |
-
* Install a layout
|
291 |
-
*
|
292 |
-
* @since 3.0
|
293 |
-
* @return null
|
294 |
-
*/
|
295 |
-
_installLayout: function( e ) {
|
296 |
-
e.preventDefault();
|
297 |
-
var self = e.data.self,
|
298 |
-
$button = $( e.target ).is( 'button' ) ? $( e.target ) : $( e.target ).parents( 'button' ),
|
299 |
-
$icon = $button.find( 'i' ),
|
300 |
-
iconClass = $icon.attr( 'class' );
|
301 |
-
|
302 |
-
if ( $button.hasClass( 'updating' ) ) {
|
303 |
-
return false;
|
304 |
-
}
|
305 |
-
$button.addClass( 'updating' );
|
306 |
-
$icon.attr( 'class', dittyAdminVars.updateIcon );
|
307 |
-
|
308 |
-
var data = {
|
309 |
-
action : 'ditty_install_layout',
|
310 |
-
layout_template : $button.data( 'layout_template' ),
|
311 |
-
layout_version : $button.data( 'layout_version' ),
|
312 |
-
security : dittyAdminVars.security
|
313 |
-
};
|
314 |
-
$.post( dittyAdminVars.ajaxurl, data, function( response ) {
|
315 |
-
$icon.attr( 'class', iconClass );
|
316 |
-
self.$elmt.removeClass( 'updating' );
|
317 |
-
if ( response ) {
|
318 |
-
$button.replaceWith( response.button );
|
319 |
-
}
|
320 |
-
} );
|
321 |
-
},
|
322 |
-
|
323 |
-
/**
|
324 |
-
* Install a display
|
325 |
-
*
|
326 |
-
* @since 3.0
|
327 |
-
* @return null
|
328 |
-
*/
|
329 |
-
_installDisplay: function( e ) {
|
330 |
-
e.preventDefault();
|
331 |
-
var self = e.data.self,
|
332 |
-
$button = $( e.target ).is( 'button' ) ? $( e.target ) : $( e.target ).parents( 'button' ),
|
333 |
-
$icon = $button.find( 'i' ),
|
334 |
-
iconClass = $icon.attr( 'class' );
|
335 |
-
|
336 |
-
if ( $button.hasClass( 'updating' ) ) {
|
337 |
-
return false;
|
338 |
-
}
|
339 |
-
$button.addClass( 'updating' );
|
340 |
-
$icon.attr( 'class', dittyAdminVars.updateIcon );
|
341 |
-
|
342 |
-
var data = {
|
343 |
-
action : 'ditty_install_display',
|
344 |
-
display_type : $button.data( 'display_type' ),
|
345 |
-
display_template : $button.data( 'display_template' ),
|
346 |
-
display_version : $button.data( 'display_version' ),
|
347 |
-
security : dittyAdminVars.security
|
348 |
-
};
|
349 |
-
$.post( dittyAdminVars.ajaxurl, data, function( response ) {
|
350 |
-
$icon.attr( 'class', iconClass );
|
351 |
-
self.$elmt.removeClass( 'updating' );
|
352 |
-
if ( response ) {
|
353 |
-
$button.replaceWith( response.button );
|
354 |
-
}
|
355 |
-
} );
|
356 |
-
},
|
357 |
-
|
358 |
-
/**
|
359 |
-
* Return a specific setting
|
360 |
-
*
|
361 |
-
* @since 3.0
|
362 |
-
* @return null
|
363 |
-
*/
|
364 |
-
_options: function ( key ) {
|
365 |
-
return this.settings[key];
|
366 |
-
},
|
367 |
-
|
368 |
-
/**
|
369 |
-
* Setup triggers
|
370 |
-
*
|
371 |
-
* @since 3.0
|
372 |
-
* @return null
|
373 |
-
*/
|
374 |
-
trigger: function ( fn, customParams ) {
|
375 |
-
var params = [this.settings];
|
376 |
-
if ( customParams ) {
|
377 |
-
params = customParams;
|
378 |
-
}
|
379 |
-
|
380 |
-
this.$elmt.trigger( 'ditty_settings_' + fn, params );
|
381 |
-
|
382 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
383 |
-
this.settings[fn].apply( this.$elmt, params );
|
384 |
-
}
|
385 |
-
},
|
386 |
-
|
387 |
-
/**
|
388 |
-
* Allow settings to be modified
|
389 |
-
*
|
390 |
-
* @since 3.0
|
391 |
-
* @return null
|
392 |
-
*/
|
393 |
-
options: function ( key, value ) {
|
394 |
-
|
395 |
-
if ( typeof key === 'object' ) {
|
396 |
-
this.settings = $.extend( {}, defaults, $.ditty_settings.defaults, key );
|
397 |
-
} else if ( typeof key === 'string' ) {
|
398 |
-
if ( value === undefined ) {
|
399 |
-
return this.settings[key];
|
400 |
-
}
|
401 |
-
this.settings[key] = value;
|
402 |
-
} else {
|
403 |
-
return this.settings;
|
404 |
-
}
|
405 |
-
|
406 |
-
this.trigger( 'options_update' );
|
407 |
-
},
|
408 |
-
|
409 |
-
/**
|
410 |
-
* Destroy the editor
|
411 |
-
*
|
412 |
-
* @since 3.0
|
413 |
-
* @return null
|
414 |
-
*/
|
415 |
-
destroy: function () {
|
416 |
-
|
417 |
-
// Remove listeners
|
418 |
-
$( 'body' ).off( 'ditty_field_clone_update', { self: this }, this._enableSettingsUpdates );
|
419 |
-
this.saveBtns.off( 'click', { self: this }, this._submitForm );
|
420 |
-
this.tabs.off( 'click', { self: this }, this._tabClick );
|
421 |
-
this.$panels.off( 'ditty_slider_init', { self: this }, this._sliderInit );
|
422 |
-
this.$panels.off( 'ditty_slider_before_slide_update', { self: this }, this._beforeSlideUpdate );
|
423 |
-
this.$form.off( 'keyup change', 'input[type="text"], input[type="number"], textarea, select', { self: this }, this._checkUpdates );
|
424 |
-
this.$form.off( 'click', 'input[type="radio"], input[type="checkbox"]', { self: this }, this._checkUpdates );
|
425 |
-
this.$form.off( 'ditty_input_wysiwyg_update', '.ditty-input--wysiwyg', { self: this }, this._checkUpdates );
|
426 |
-
this.$form.off( 'click', '.ditty-default-layout-install', { self: this }, this._installLayout );
|
427 |
-
this.$form.off( 'click', '.ditty-default-display-install', { self: this }, this._installDisplay );
|
428 |
-
|
429 |
-
this.$panels.ditty_slider( 'destroy' );
|
430 |
-
this.elmt._ditty_settings = null;
|
431 |
-
}
|
432 |
-
};
|
433 |
-
|
434 |
-
/**
|
435 |
-
* Create the data list
|
436 |
-
*
|
437 |
-
* @since 3.0
|
438 |
-
* @return null
|
439 |
-
*/
|
440 |
-
$.fn.ditty_settings = function( options ) {
|
441 |
-
var args = arguments,
|
442 |
-
error = false,
|
443 |
-
returns;
|
444 |
-
|
445 |
-
if ( options === undefined || typeof options === 'object' ) {
|
446 |
-
return this.each( function () {
|
447 |
-
if ( ! this._ditty_settings ) {
|
448 |
-
this._ditty_settings = new Ditty_Settings( this, options );
|
449 |
-
}
|
450 |
-
});
|
451 |
-
} else if ( typeof options === 'string' ) {
|
452 |
-
this.each( function () {
|
453 |
-
var instance = this._ditty_settings;
|
454 |
-
|
455 |
-
if ( ! instance ) {
|
456 |
-
throw new Error( 'No Ditty_Settings applied to this element.' );
|
457 |
-
}
|
458 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
459 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
460 |
-
} else {
|
461 |
-
error = true;
|
462 |
-
}
|
463 |
-
} );
|
464 |
-
|
465 |
-
if ( error ) {
|
466 |
-
throw new Error( 'No method "' + options + '" in Ditty_Settings.' );
|
467 |
-
}
|
468 |
-
|
469 |
-
return returns !== undefined ? returns : this;
|
470 |
-
}
|
471 |
-
};
|
472 |
-
|
473 |
-
$.ditty_settings = {};
|
474 |
-
$.ditty_settings.defaults = defaults;
|
475 |
-
|
476 |
-
} )( jQuery );
|
477 |
-
|
478 |
-
|
479 |
-
/**
|
480 |
-
* Ditty Extension class
|
481 |
-
*
|
482 |
-
* @since 3.0
|
483 |
-
* @return null
|
484 |
-
*/
|
485 |
-
|
486 |
-
(function ($) {
|
487 |
-
'use strict';
|
488 |
-
|
489 |
-
var defaults = {
|
490 |
-
};
|
491 |
-
|
492 |
-
var Ditty_Extension = function ( elmt, options ) {
|
493 |
-
|
494 |
-
this.elmt = elmt;
|
495 |
-
this.settings = $.extend( {}, defaults, $.ditty_extension.defaults, options );
|
496 |
-
this.$elmt = $( elmt );
|
497 |
-
this.$panels = $( elmt ).find( '.ditty-extension__panels' );
|
498 |
-
this.initPanel = this.$panels.data( 'init_panel' );
|
499 |
-
|
500 |
-
this._init();
|
501 |
-
};
|
502 |
-
|
503 |
-
Ditty_Extension.prototype = {
|
504 |
-
|
505 |
-
_init: function () {
|
506 |
-
|
507 |
-
// Add listeners
|
508 |
-
this.$elmt.on( 'click', '.ditty-extension__tab', { self: this }, this._tabClick );
|
509 |
-
this.$elmt.on( 'click', 'button[name="submit"]', { self: this }, this._updatePanel );
|
510 |
-
this.$elmt.on( 'click', '.ditty-extension__license__submit', { self: this, action: 'ditty_extension_license_activate' }, this._licenseUpdate );
|
511 |
-
this.$elmt.on( 'click', '.ditty-extension__license__refresh', { self: this, action: 'ditty_extension_license_refresh' }, this._licenseUpdate );
|
512 |
-
this.$elmt.on( 'click', '.ditty-extension__license__deactivate', { self: this, action: 'ditty_extension_license_deactivate' }, this._licenseUpdate );
|
513 |
-
this.$panels.on( 'ditty_slider_before_slide_update', { self: this }, this._beforePanelUpdate );
|
514 |
-
this._initSlider();
|
515 |
-
},
|
516 |
-
|
517 |
-
/**
|
518 |
-
* Initialize the slider
|
519 |
-
*
|
520 |
-
* @since 3.0
|
521 |
-
* @return null
|
522 |
-
*/
|
523 |
-
_initSlider: function () {
|
524 |
-
var args = {
|
525 |
-
transition : 'fade',
|
526 |
-
transitionSpeed : 0.75,
|
527 |
-
heightSpeed : 0.75,
|
528 |
-
touchSwipe : false,
|
529 |
-
slidesEl : '.ditty-extension__panel',
|
530 |
-
slideId : ( '' !== this.initPanel ) ? this.initPanel : false
|
531 |
-
};
|
532 |
-
this.$panels.ditty_slider( args );
|
533 |
-
},
|
534 |
-
|
535 |
-
/**
|
536 |
-
* Initialize the slider
|
537 |
-
*
|
538 |
-
* @since 3.0
|
539 |
-
* @return null
|
540 |
-
*/
|
541 |
-
_beforePanelUpdate: function ( e, index, slide ) {
|
542 |
-
var self = e.data.self;
|
543 |
-
self.$elmt.find( '.ditty-extension__tab' ).removeClass( 'active' );
|
544 |
-
self.$elmt.find( '.ditty-extension__tab[data-slide_id="' + slide.id + '"]' ).addClass( 'active' );
|
545 |
-
},
|
546 |
-
|
547 |
-
/**
|
548 |
-
* Tab click
|
549 |
-
*
|
550 |
-
* @since 3.0
|
551 |
-
* @return null
|
552 |
-
*/
|
553 |
-
_tabClick: function ( e ) {
|
554 |
-
e.preventDefault();
|
555 |
-
var self = e.data.self;
|
556 |
-
var $tab = $( this ),
|
557 |
-
slideId = $tab.data( 'slide_id' ),
|
558 |
-
transition = 'slideLeft',
|
559 |
-
$currentTab = self.$elmt.find( '.ditty-extension__tab.active' );
|
560 |
-
|
561 |
-
if ( $currentTab === $tab ) {
|
562 |
-
return false;
|
563 |
-
}
|
564 |
-
|
565 |
-
if ( $tab.index() < $currentTab.index() ) {
|
566 |
-
transition = 'slideRight';
|
567 |
-
}
|
568 |
-
|
569 |
-
//self.$elmt.find( '.ditty-extension__tab' ).removeClass( 'active' );
|
570 |
-
//$tab.addClass( 'active' );
|
571 |
-
|
572 |
-
self.$panels.ditty_slider( 'options', 'transition', transition );
|
573 |
-
self.$panels.ditty_slider( 'showSlideById', slideId );
|
574 |
-
},
|
575 |
-
|
576 |
-
/**
|
577 |
-
* Panel update listener
|
578 |
-
*
|
579 |
-
* @since 3.0
|
580 |
-
* @return null
|
581 |
-
*/
|
582 |
-
_updatePanel: function ( e ) {
|
583 |
-
e.preventDefault();
|
584 |
-
var self = e.data.self;
|
585 |
-
|
586 |
-
var $button = $( this ),
|
587 |
-
$panel = $button.parents( '.ditty-extension__panel' ),
|
588 |
-
$form = $button.parents( '.ditty-extension__form' ),
|
589 |
-
$icon = $button.find( 'i' ),
|
590 |
-
iconClass = $icon.attr( 'class' ),
|
591 |
-
extension = self.$elmt.data( 'extension' ),
|
592 |
-
panel = $panel.data( 'slide_id' );
|
593 |
-
|
594 |
-
if ( self.$elmt.hasClass( 'updating' ) ) {
|
595 |
-
return false;
|
596 |
-
}
|
597 |
-
|
598 |
-
self.$elmt.addClass( 'updating' );
|
599 |
-
$icon.attr( 'class', dittyAdminVars.updateIcon );
|
600 |
-
|
601 |
-
$form.ajaxSubmit( {
|
602 |
-
url : dittyAdminVars.ajaxurl,
|
603 |
-
type : 'post',
|
604 |
-
dataType : 'json',
|
605 |
-
data : {
|
606 |
-
action : 'ditty_extension_panel_update',
|
607 |
-
extension : extension,
|
608 |
-
panel : panel,
|
609 |
-
security : dittyAdminVars.security
|
610 |
-
},
|
611 |
-
success: function( response ) {
|
612 |
-
$icon.attr( 'class', iconClass );
|
613 |
-
self.$elmt.removeClass( 'updating' );
|
614 |
-
$( '#ditty-extensions' ).trigger( 'ditty_extension_panel_updated', [ response, self.$elmt, $panel ] );
|
615 |
-
}
|
616 |
-
} );
|
617 |
-
},
|
618 |
-
|
619 |
-
/**
|
620 |
-
* Update a license
|
621 |
-
*
|
622 |
-
* @since 3.0
|
623 |
-
* @return null
|
624 |
-
*/
|
625 |
-
_licenseUpdate: function ( e ) {
|
626 |
-
e.preventDefault();
|
627 |
-
var self = e.data.self,
|
628 |
-
action = e.data.action;
|
629 |
-
|
630 |
-
var $button = $( this ),
|
631 |
-
$message = self.$elmt.find( '.ditty-extension__license__message' ),
|
632 |
-
$input = $button.siblings( '.ditty-extension__license__input' ),
|
633 |
-
license = $input.val(),
|
634 |
-
extension = $button.data( 'extension' ),
|
635 |
-
extensionId = $button.data( 'extension_id' ),
|
636 |
-
extensionName = $button.data( 'extension_name' ),
|
637 |
-
$icon = $button.children( 'i' );
|
638 |
-
|
639 |
-
if ( self.$elmt.hasClass( 'updating' ) ) {
|
640 |
-
return false;
|
641 |
-
}
|
642 |
-
|
643 |
-
self.$elmt.addClass( 'updating' );
|
644 |
-
$icon.attr( 'class', dittyAdminVars.updateIcon );
|
645 |
-
|
646 |
-
// Load the new display data
|
647 |
-
var data = {
|
648 |
-
action : action,
|
649 |
-
license : license,
|
650 |
-
extension : extension,
|
651 |
-
extension_id : extensionId,
|
652 |
-
extension_name : extensionName,
|
653 |
-
security : dittyAdminVars.security
|
654 |
-
};
|
655 |
-
$.post( dittyAdminVars.ajaxurl, data, function( response ) {
|
656 |
-
if ( response ) {
|
657 |
-
self.$elmt.attr( 'data-license_status', response.status );
|
658 |
-
$message.text( response.message );
|
659 |
-
}
|
660 |
-
if ( response.license_key ) {
|
661 |
-
if ( 'DELETE' === response.license_key ) {
|
662 |
-
$input.val( '' );
|
663 |
-
} else {
|
664 |
-
$input.val( response.license_key );
|
665 |
-
}
|
666 |
-
}
|
667 |
-
$icon.attr( 'class', $icon.data( 'class' ) );
|
668 |
-
self.$elmt.removeClass( 'updating' );
|
669 |
-
}, 'json' );
|
670 |
-
},
|
671 |
-
|
672 |
-
/**
|
673 |
-
* Return data for the object
|
674 |
-
*
|
675 |
-
* @since 3.0
|
676 |
-
* @return null
|
677 |
-
*/
|
678 |
-
_getOption: function( key ) {
|
679 |
-
switch( key ) {
|
680 |
-
default:
|
681 |
-
return this.settings[key];
|
682 |
-
}
|
683 |
-
},
|
684 |
-
|
685 |
-
/**
|
686 |
-
* Set data for the object
|
687 |
-
*
|
688 |
-
* @since 3.0
|
689 |
-
* @return null
|
690 |
-
*/
|
691 |
-
_setOption: function( key, value ) {
|
692 |
-
if ( undefined === value ) {
|
693 |
-
return false;
|
694 |
-
}
|
695 |
-
|
696 |
-
this.settings[key] = value;
|
697 |
-
},
|
698 |
-
|
699 |
-
/**
|
700 |
-
* Get or set ditty options
|
701 |
-
*
|
702 |
-
* @since 3.0
|
703 |
-
* @return null
|
704 |
-
*/
|
705 |
-
options: function ( key, value ) {
|
706 |
-
var self = this;
|
707 |
-
if ( typeof key === 'object' ) {
|
708 |
-
$.each( key, function( k, v ) {
|
709 |
-
self._setOption( k, v );
|
710 |
-
});
|
711 |
-
} else if ( typeof key === 'string' ) {
|
712 |
-
if ( value === undefined ) {
|
713 |
-
return self._getOption( key );
|
714 |
-
}
|
715 |
-
self._setOption( key, value );
|
716 |
-
} else {
|
717 |
-
return self.settings;
|
718 |
-
}
|
719 |
-
},
|
720 |
-
|
721 |
-
/**
|
722 |
-
* Destroy this object
|
723 |
-
*
|
724 |
-
* @since 3.0
|
725 |
-
* @return null
|
726 |
-
*/
|
727 |
-
destroy: function () {
|
728 |
-
// Remove listeners
|
729 |
-
this.$elmt.off( 'click', '.ditty-extension__tab', { self: this }, this._tabClick );
|
730 |
-
this.$elmt.off( 'click', 'button[name="submit"]', { self: this }, this._updatePanel );
|
731 |
-
this.$elmt.off( 'click', '.ditty-extension__license__submit, .ditty-extension__license__refresh', { self: this, action: 'ditty_extension_license_activate' }, this._licenseUpdate );
|
732 |
-
this.$elmt.off( 'click', '.ditty-extension__license__deactivate', { self: this, action: 'ditty_extension_license_deactivate' }, this._licenseUpdate );
|
733 |
-
this.$panels.off( 'ditty_slider_after_slide_update', { self: this }, this._afterPanelUpdate );
|
734 |
-
|
735 |
-
this.$panels.ditty_slider( 'destroy' );
|
736 |
-
this.elmt._ditty_extension = null;
|
737 |
-
}
|
738 |
-
};
|
739 |
-
|
740 |
-
$.fn.ditty_extension = function( options ) {
|
741 |
-
var args = arguments,
|
742 |
-
error = false,
|
743 |
-
returns;
|
744 |
-
|
745 |
-
if ( options === undefined || typeof options === 'object' ) {
|
746 |
-
return this.each( function () {
|
747 |
-
if ( ! this._ditty_extension ) {
|
748 |
-
this._ditty_extension = new Ditty_Extension( this, options );
|
749 |
-
}
|
750 |
-
});
|
751 |
-
} else if ( typeof options === 'string' ) {
|
752 |
-
this.each( function () {
|
753 |
-
var instance = this._ditty_extension;
|
754 |
-
|
755 |
-
if ( ! instance ) {
|
756 |
-
throw new Error( 'No Ditty_Extension applied to this element.' );
|
757 |
-
}
|
758 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
759 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
760 |
-
} else {
|
761 |
-
error = true;
|
762 |
-
}
|
763 |
-
} );
|
764 |
-
|
765 |
-
if ( error ) {
|
766 |
-
throw new Error( 'No method "' + options + '" in Ditty_Extension.' );
|
767 |
-
}
|
768 |
-
|
769 |
-
return returns !== undefined ? returns : this;
|
770 |
-
}
|
771 |
-
};
|
772 |
-
|
773 |
-
$.ditty_extension = {};
|
774 |
-
$.ditty_extension.defaults = defaults;
|
775 |
-
|
776 |
-
} )( jQuery );
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
jQuery( document ).ready( function( $ ) {
|
781 |
-
// Setup strict mode
|
782 |
-
(function() {
|
783 |
-
|
784 |
-
"use strict";
|
785 |
-
|
786 |
-
// Setup protip
|
787 |
-
$.protip( {
|
788 |
-
defaults: {
|
789 |
-
position: 'top',
|
790 |
-
size: 'small',
|
791 |
-
scheme: 'black',
|
792 |
-
classes: 'ditty-protip'
|
793 |
-
}
|
794 |
-
} );
|
795 |
-
|
796 |
-
/**
|
797 |
-
* Listen for an accordion toggle click
|
798 |
-
*
|
799 |
-
* @since 3.0
|
800 |
-
* @return null
|
801 |
-
*/
|
802 |
-
// $( '#ditty-extensions' ).on( 'click', '.ditty-accordion__toggle', function( e ) {
|
803 |
-
// e.preventDefault();
|
804 |
-
// var $accordion = $( this ).parent(),
|
805 |
-
// $content = $( this ).next();
|
806 |
-
//
|
807 |
-
// if ( $accordion.hasClass( 'active' ) ) {
|
808 |
-
// $accordion.removeClass( 'active' );
|
809 |
-
// $content.stop().slideUp( { duration: 750, easing: "easeInOutQuint" } );
|
810 |
-
// } else {
|
811 |
-
// $accordion.addClass( 'active' );
|
812 |
-
// $content.stop().slideDown( { duration: 750, easing: "easeInOutQuint" }, function() {
|
813 |
-
// $content.css( 'height', 'auto' );
|
814 |
-
// } );
|
815 |
-
// }
|
816 |
-
// } );
|
817 |
-
//
|
818 |
-
/**
|
819 |
-
* Initialize the extensions
|
820 |
-
*
|
821 |
-
* @since 3.0
|
822 |
-
* @return null
|
823 |
-
*/
|
824 |
-
function ditty_extensions_init() {
|
825 |
-
$( '#ditty-extensions' ).find( '.ditty-extension' ).each( function( index ) {
|
826 |
-
|
827 |
-
var $extension = $( this ),
|
828 |
-
$panels = $extension.find( '.ditty-extension__panels' );
|
829 |
-
|
830 |
-
if ( $panels.length ) {
|
831 |
-
$extension.ditty_extension();
|
832 |
-
}
|
833 |
-
|
834 |
-
$( '#ditty-extensions' ).trigger( 'ditty_init_fields' );
|
835 |
-
|
836 |
-
setTimeout( function() {
|
837 |
-
$extension.addClass( 'ditty-extension--init' );
|
838 |
-
}, index * 250 );
|
839 |
-
|
840 |
-
} );
|
841 |
-
}
|
842 |
-
ditty_extensions_init();
|
843 |
-
|
844 |
-
}() );
|
845 |
-
|
846 |
-
} );
|
847 |
-
|
848 |
-
|
849 |
-
jQuery( document ).ready( function( $ ) {
|
850 |
-
// Setup strict mode
|
851 |
-
(function() {
|
852 |
-
|
853 |
-
"use strict";
|
854 |
-
|
855 |
-
var isDisplayPost = ( $( 'input[name="post_type"]' ).length && 'ditty_display' == $( 'input[name="post_type"]' ).val() ),
|
856 |
-
ajaxSubmitComplete = false;
|
857 |
-
|
858 |
-
$( 'form#post' ).on( 'submit', function( e ) {
|
859 |
-
if ( isDisplayPost && ! ajaxSubmitComplete ) {
|
860 |
-
e.preventDefault();
|
861 |
-
|
862 |
-
var $button = $( '#publishing-action' ).children( 'input[type="submit"]' ),
|
863 |
-
$spinner = $( '#publishing-action' ).children( '.spinner' );
|
864 |
-
|
865 |
-
$button.attr( 'disabled', 'disabled' );
|
866 |
-
$spinner.css( 'visibility', 'visible' );
|
867 |
-
|
868 |
-
var data = {
|
869 |
-
action : 'ditty_admin_display_update',
|
870 |
-
display_id : $( 'input[name="post_ID"]' ).val(),
|
871 |
-
security : dittyAdminVars.security
|
872 |
-
};
|
873 |
-
$( '#ditty-display-settings' ).ajaxSubmit( {
|
874 |
-
url : dittyAdminVars.ajaxurl,
|
875 |
-
type : 'post',
|
876 |
-
dataType : 'json',
|
877 |
-
data : data,
|
878 |
-
success: function( response ) {
|
879 |
-
ajaxSubmitComplete = true;
|
880 |
-
$( 'form#post' ).submit();
|
881 |
-
}
|
882 |
-
} );
|
883 |
-
}
|
884 |
-
} );
|
885 |
-
|
886 |
-
}() );
|
887 |
-
|
888 |
-
} );
|
1 |
+
jQuery(document).ready((function($){!function(){"use strict";$("#poststuff").trigger("ditty_init_fields"),$("#ditty-settings").ditty_settings()}()})),function($){"use strict";var t={},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_settings.defaults,e),this.$elmt=$(i),this.$form=this.$elmt.find(".ditty-settings__form"),this.$panels=this.$elmt.find(".ditty-settings__panels"),this.saveBtns=this.$elmt.find(".ditty-settings__save"),this.tabs=this.$elmt.find(".ditty-settings__tab"),this.$notice_update=this.$elmt.find(".ditty-notification--updated"),this.$notice_error=this.$elmt.find(".ditty-notification--error"),this.$notice_warning=this.$elmt.find(".ditty-notification--warning"),this.initData=null,this._init()};i.prototype={_init:function(){this._initSlider(),$("body").on("ditty_field_clone_update",{self:this},this._enableSettingsUpdates),this.saveBtns.on("click",{self:this},this._submitForm),this.tabs.on("click",{self:this},this._tabClick),this.$panels.on("ditty_slider_init",{self:this},this._sliderInit),this.$panels.on("ditty_slider_before_slide_update",{self:this},this._beforeSlideUpdate),this.$form.on("keyup change",'input[type="text"], input[type="number"], textarea, select',{self:this},this._checkUpdates),this.$form.on("click",'input[type="radio"], input[type="checkbox"]',{self:this},this._checkUpdates),this.$form.on("ditty_input_wysiwyg_update",".ditty-input--wysiwyg",{self:this},this._checkUpdates),this.$form.on("click",".ditty-default-layout-install",{self:this},this._installLayout),this.$form.on("click",".ditty-default-display-install",{self:this},this._installDisplay)},_initSlider:function(){var t=this.$panels.data("init_panel");this.$panels.ditty_slider({transition:"fade",transitionSpeed:.75,heightSpeed:.75,touchSwipe:!1,slidesEl:".ditty-settings__panel",slideId:""!==t&&t})},_sliderInit:function(t){var i=t.data.self;i.initData=i.$form.serialize()},_beforeSlideUpdate:function(t,i,e){var s=t.data.self;s._initFields(e.$elmt),s.$elmt.find(".ditty-settings__tab").removeClass("active"),s.$elmt.find('.ditty-settings__tab[data-panel="'+e.id+'"]').addClass("active")},_enableSettingsUpdates:function(t){(t?t.data.self:this).saveBtns.addClass("has-updates")},_disableSettingsUpdates:function(){this.saveBtns.removeClass("has-updates")},_checkUpdates:function(t){var i=t?t.data.self:this;i.$form.serialize()!==i.initData?i._enableSettingsUpdates():i._disableSettingsUpdates()},_initFields:function(t){t.find(".ditty-data-list").ditty_ui_data_list(),t.trigger("ditty_init_fields"),$.protip({defaults:{position:"top",size:"small",scheme:"black",classes:"ditty-protip"}})},_togglePostTypes:function(){if($('input[name="ditty_layout_ui"]').length){var t=$('input[name="ditty_layout_ui"]:checked').val(),i=$('#adminmenu .wp-submenu > li > a[href="edit.php?post_type=ditty_layout"]');"disabled"===t?i.hide():i.css("display","block")}if($('input[name="ditty_display_ui"]').length){var e=$('input[name="ditty_display_ui"]:checked').val(),s=$('#adminmenu .wp-submenu > li > a[href="edit.php?post_type=ditty_display"]');"disabled"===e?s.hide():s.css("display","block")}},_tabClick:function(t){t.preventDefault();var i=t.data.self,e=$(t.target).is("a")?$(t.target):$(t.target).parent("a"),s=e.data("panel");if(i.$elmt.find(".ditty-settings__tab.active")===e)return!1;i.$elmt.find(".ditty-extension__tab").removeClass("active"),e.addClass("active"),i.$panels.ditty_slider("showSlideById",s)},_upateInputs:function(t){$.each(t,(function(t,i){$('input[name="'+t+'"]').length&&$('input[name="'+t+'"]').val(i)}))},_submitForm:function(t){t.preventDefault();var i=t.data.self;if(i.$elmt.hasClass("updating"))return!1;i.$elmt.trigger("ditty_pre_save_fields"),i.$elmt.addClass("updating"),i.saveBtns.text(dittyAdminVars.adminStrings.settingsSaving),i.$form.ajaxSubmit({url:dittyAdminVars.ajaxurl,type:"post",dataType:"json",data:{action:"ditty_settings_save",security:dittyAdminVars.security},success:function(t){t.input_updates&&i._upateInputs(t.input_updates),i.initData=i.$form.serialize(),i.saveBtns.text(dittyAdminVars.adminStrings.settings_updated),setTimeout((function(){i.saveBtns.text(dittyAdminVars.adminStrings.settings_save)}),2e3),i.$elmt.removeClass("updating"),i._disableSettingsUpdates(),i._togglePostTypes()}})},_installLayout:function(t){t.preventDefault();var i=t.data.self,e=$(t.target).is("button")?$(t.target):$(t.target).parents("button"),s=e.find("i"),n=s.attr("class");if(e.hasClass("updating"))return!1;e.addClass("updating"),s.attr("class",dittyAdminVars.updateIcon);var a={action:"ditty_install_layout",layout_template:e.data("layout_template"),layout_version:e.data("layout_version"),security:dittyAdminVars.security};$.post(dittyAdminVars.ajaxurl,a,(function(t){s.attr("class",n),i.$elmt.removeClass("updating"),t&&e.replaceWith(t.button)}))},_installDisplay:function(t){t.preventDefault();var i=t.data.self,e=$(t.target).is("button")?$(t.target):$(t.target).parents("button"),s=e.find("i"),n=s.attr("class");if(e.hasClass("updating"))return!1;e.addClass("updating"),s.attr("class",dittyAdminVars.updateIcon);var a={action:"ditty_install_display",display_type:e.data("display_type"),display_template:e.data("display_template"),display_version:e.data("display_version"),security:dittyAdminVars.security};$.post(dittyAdminVars.ajaxurl,a,(function(t){s.attr("class",n),i.$elmt.removeClass("updating"),t&&e.replaceWith(t.button)}))},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_settings_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_settings.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){$("body").off("ditty_field_clone_update",{self:this},this._enableSettingsUpdates),this.saveBtns.off("click",{self:this},this._submitForm),this.tabs.off("click",{self:this},this._tabClick),this.$panels.off("ditty_slider_init",{self:this},this._sliderInit),this.$panels.off("ditty_slider_before_slide_update",{self:this},this._beforeSlideUpdate),this.$form.off("keyup change",'input[type="text"], input[type="number"], textarea, select',{self:this},this._checkUpdates),this.$form.off("click",'input[type="radio"], input[type="checkbox"]',{self:this},this._checkUpdates),this.$form.off("ditty_input_wysiwyg_update",".ditty-input--wysiwyg",{self:this},this._checkUpdates),this.$form.off("click",".ditty-default-layout-install",{self:this},this._installLayout),this.$form.off("click",".ditty-default-display-install",{self:this},this._installDisplay),this.$panels.ditty_slider("destroy"),this.elmt._ditty_settings=null}},$.fn.ditty_settings=function(t){var e,s=arguments,n=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_settings||(this._ditty_settings=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_settings;if(!i)throw new Error("No Ditty_Settings applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):n=!0})),n)throw new Error('No method "'+t+'" in Ditty_Settings.');return void 0!==e?e:this}},$.ditty_settings={},$.ditty_settings.defaults=t}(jQuery),function($){"use strict";var t={},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_extension.defaults,e),this.$elmt=$(i),this.$panels=$(i).find(".ditty-extension__panels"),this.initPanel=this.$panels.data("init_panel"),this._init()};i.prototype={_init:function(){this.$elmt.on("click",".ditty-extension__tab",{self:this},this._tabClick),this.$elmt.on("click",'button[name="submit"]',{self:this},this._updatePanel),this.$elmt.on("click",".ditty-extension__license__submit",{self:this,action:"ditty_extension_license_activate"},this._licenseUpdate),this.$elmt.on("click",".ditty-extension__license__refresh",{self:this,action:"ditty_extension_license_refresh"},this._licenseUpdate),this.$elmt.on("click",".ditty-extension__license__deactivate",{self:this,action:"ditty_extension_license_deactivate"},this._licenseUpdate),this.$panels.on("ditty_slider_before_slide_update",{self:this},this._beforePanelUpdate),this._initSlider()},_initSlider:function(){var t={transition:"fade",transitionSpeed:.75,heightSpeed:.75,touchSwipe:!1,slidesEl:".ditty-extension__panel",slideId:""!==this.initPanel&&this.initPanel};this.$panels.ditty_slider(t)},_beforePanelUpdate:function(t,i,e){var s=t.data.self;s.$elmt.find(".ditty-extension__tab").removeClass("active"),s.$elmt.find('.ditty-extension__tab[data-slide_id="'+e.id+'"]').addClass("active")},_tabClick:function(t){t.preventDefault();var i=t.data.self,e=$(this),s=e.data("slide_id"),n="slideLeft",a=i.$elmt.find(".ditty-extension__tab.active");if(a===e)return!1;e.index()<a.index()&&(n="slideRight"),i.$panels.ditty_slider("options","transition",n),i.$panels.ditty_slider("showSlideById",s)},_updatePanel:function(t){t.preventDefault();var i=t.data.self,e=$(this),s=e.parents(".ditty-extension__panel"),n=e.parents(".ditty-extension__form"),a=e.find("i"),d=a.attr("class"),l=i.$elmt.data("extension"),o=s.data("slide_id");if(i.$elmt.hasClass("updating"))return!1;i.$elmt.addClass("updating"),a.attr("class",dittyAdminVars.updateIcon),n.ajaxSubmit({url:dittyAdminVars.ajaxurl,type:"post",dataType:"json",data:{action:"ditty_extension_panel_update",extension:l,panel:o,security:dittyAdminVars.security},success:function(t){a.attr("class",d),i.$elmt.removeClass("updating"),$("#ditty-extensions").trigger("ditty_extension_panel_updated",[t,i.$elmt,s])}})},_licenseUpdate:function(t){t.preventDefault();var i=t.data.self,e=t.data.action,s=$(this),n=i.$elmt.find(".ditty-extension__license__message"),a=s.siblings(".ditty-extension__license__input"),d=a.val(),l=s.data("extension"),o=s.data("extension_id"),r=s.data("extension_name"),_=s.children("i");if(i.$elmt.hasClass("updating"))return!1;i.$elmt.addClass("updating"),_.attr("class",dittyAdminVars.updateIcon);var p={action:e,license:d,extension:l,extension_id:o,extension_name:r,security:dittyAdminVars.security};$.post(dittyAdminVars.ajaxurl,p,(function(t){t&&(i.$elmt.attr("data-license_status",t.status),n.text(t.message)),t.license_key&&("DELETE"===t.license_key?a.val(""):a.val(t.license_key)),_.attr("class",_.data("class")),i.$elmt.removeClass("updating")}),"json")},_getOption:function(t){return this.settings[t]},_setOption:function(t,i){if(void 0===i)return!1;this.settings[t]=i},options:function(t,i){var e=this;if("object"==typeof t)$.each(t,(function(t,i){e._setOption(t,i)}));else{if("string"!=typeof t)return e.settings;if(void 0===i)return e._getOption(t);e._setOption(t,i)}},destroy:function(){this.$elmt.off("click",".ditty-extension__tab",{self:this},this._tabClick),this.$elmt.off("click",'button[name="submit"]',{self:this},this._updatePanel),this.$elmt.off("click",".ditty-extension__license__submit, .ditty-extension__license__refresh",{self:this,action:"ditty_extension_license_activate"},this._licenseUpdate),this.$elmt.off("click",".ditty-extension__license__deactivate",{self:this,action:"ditty_extension_license_deactivate"},this._licenseUpdate),this.$panels.off("ditty_slider_after_slide_update",{self:this},this._afterPanelUpdate),this.$panels.ditty_slider("destroy"),this.elmt._ditty_extension=null}},$.fn.ditty_extension=function(t){var e,s=arguments,n=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_extension||(this._ditty_extension=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_extension;if(!i)throw new Error("No Ditty_Extension applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):n=!0})),n)throw new Error('No method "'+t+'" in Ditty_Extension.');return void 0!==e?e:this}},$.ditty_extension={},$.ditty_extension.defaults=t}(jQuery),jQuery(document).ready((function($){!function(){"use strict";$.protip({defaults:{position:"top",size:"small",scheme:"black",classes:"ditty-protip"}}),$("#ditty-extensions").find(".ditty-extension").each((function(t){var i=$(this);i.find(".ditty-extension__panels").length&&i.ditty_extension(),$("#ditty-extensions").trigger("ditty_init_fields"),setTimeout((function(){i.addClass("ditty-extension--init")}),250*t)}))}()})),jQuery(document).ready((function($){!function(){"use strict";var t=$('input[name="post_type"]').length&&"ditty_display"==$('input[name="post_type"]').val(),i=!1;$("form#post").on("submit",(function(e){if(t&&!i){e.preventDefault();var s=$("#publishing-action").children('input[type="submit"]'),n=$("#publishing-action").children(".spinner");s.attr("disabled","disabled"),n.css("visibility","visible");var a={action:"ditty_admin_display_update",display_id:$('input[name="post_ID"]').val(),security:dittyAdminVars.security};$("#ditty-display-settings").ajaxSubmit({url:dittyAdminVars.ajaxurl,type:"post",dataType:"json",data:a,success:function(t){i=!0,$("form#post").submit()}})}}))}()}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/js/ditty-editor.min.js
CHANGED
@@ -1,5822 +1,3 @@
|
|
1 |
-
/* global dittyVars:true */
|
2 |
-
/* global jQuery:true */
|
3 |
-
// @codekit-append 'partials/class-ditty-ui-data-list.js';
|
4 |
-
// @codekit-append 'editor/helpers.js';
|
5 |
-
// @codekit-append 'editor/class-ditty-editor.js';
|
6 |
-
// @codekit-append 'editor/class-ditty-settings-panel.js';
|
7 |
-
// @codekit-append 'editor/class-ditty-items-panel.js';
|
8 |
-
// @codekit-append 'editor/class-ditty-item-types-panel.js';
|
9 |
-
// @codekit-append 'editor/class-ditty-item-editor-panel.js';
|
10 |
-
// @codekit-append 'editor/class-ditty-displays-panel.js';
|
11 |
-
// @codekit-append 'editor/class-ditty-display-editor-panel.js';
|
12 |
-
// @codekit-append 'editor/class-ditty-layout-variations-panel.js';
|
13 |
-
// @codekit-append 'editor/class-ditty-layouts-panel.js';
|
14 |
-
// @codekit-append 'editor/class-ditty-layout-html-editor-panel.js';
|
15 |
-
// @codekit-append 'editor/class-ditty-layout-css-editor-panel.js';
|
16 |
-
// @codekit-append 'editor/ditty-list-display-editor.js';
|
17 |
-
// @codekit-append 'editor/ditty-ticker-display-editor.js';
|
18 |
-
|
19 |
-
jQuery( document ).ready( function( $ ) {
|
20 |
-
|
21 |
-
// Setup strict mode
|
22 |
-
(function() {
|
23 |
-
|
24 |
-
"use strict";
|
25 |
-
|
26 |
-
/**
|
27 |
-
* Close down editor display panels appropriately
|
28 |
-
*
|
29 |
-
* @since 3.0
|
30 |
-
* @return null
|
31 |
-
*/
|
32 |
-
$( 'body' ).on( 'ditty_editor_before_panel_update', function( event, slideId, $slide, prevSlideId, $prevSlide, editor ) {
|
33 |
-
|
34 |
-
// Disable any delayed Ditty updates
|
35 |
-
editor.delayedSubmitDisable();
|
36 |
-
|
37 |
-
// Setup protip
|
38 |
-
$.protip({
|
39 |
-
defaults: {
|
40 |
-
position: 'top',
|
41 |
-
size: 'small',
|
42 |
-
scheme: 'black',
|
43 |
-
classes: 'ditty-protip'
|
44 |
-
}
|
45 |
-
} );
|
46 |
-
|
47 |
-
switch( slideId ) {
|
48 |
-
case 'settings':
|
49 |
-
if ( ! $slide.hasClass( 'init' ) ) {
|
50 |
-
$slide.ditty_settings_panel( { editor: editor } );
|
51 |
-
}
|
52 |
-
break;
|
53 |
-
case 'items':
|
54 |
-
if ( $slide.hasClass( 'init' ) ) {
|
55 |
-
$slide.ditty_items_panel( 'panelVisible' );
|
56 |
-
} else {
|
57 |
-
$slide.ditty_items_panel( { editor: editor } );
|
58 |
-
}
|
59 |
-
break;
|
60 |
-
case 'displays':
|
61 |
-
$slide.find( '.ditty-data-list__item' ).removeClass( 'editing' );
|
62 |
-
if ( $slide.hasClass( 'init' ) ) {
|
63 |
-
$slide.ditty_displays_panel( 'panelVisible' );
|
64 |
-
} else {
|
65 |
-
$slide.ditty_displays_panel( {
|
66 |
-
editor: editor
|
67 |
-
} );
|
68 |
-
}
|
69 |
-
break;
|
70 |
-
case 'item_types':
|
71 |
-
$slide.find( '.ditty-data-list__item' ).removeClass( 'editing' );
|
72 |
-
if ( $slide.hasClass( 'init' ) ) {
|
73 |
-
$slide.ditty_item_types_panel( 'panelVisible' );
|
74 |
-
} else {
|
75 |
-
$slide.ditty_item_types_panel( {
|
76 |
-
editor: editor
|
77 |
-
} );
|
78 |
-
}
|
79 |
-
break;
|
80 |
-
case 'item_editor':
|
81 |
-
$slide.ditty_item_editor_panel( { editor : editor } );
|
82 |
-
break;
|
83 |
-
case 'display_editor':
|
84 |
-
$slide.ditty_display_editor_panel( { editor: editor } );
|
85 |
-
break;
|
86 |
-
case 'layouts':
|
87 |
-
if ( ! ( 'layoutHtmlEditor' === prevSlideId || 'layoutCssEditor' === prevSlideId ) ) {
|
88 |
-
$slide.ditty_layouts_panel( { editor : editor } );
|
89 |
-
}
|
90 |
-
break;
|
91 |
-
case 'layout_variations':
|
92 |
-
if ( $slide.hasClass( 'init' ) ) {
|
93 |
-
$slide.ditty_layout_variations_panel( 'panelVisible' );
|
94 |
-
} else {
|
95 |
-
$slide.ditty_layout_variations_panel( { editor : editor } );
|
96 |
-
}
|
97 |
-
break;
|
98 |
-
case 'layout_html_editor':
|
99 |
-
$slide.ditty_layout_html_editor_panel( {
|
100 |
-
editor : editor,
|
101 |
-
prevPanel : prevSlideId
|
102 |
-
} );
|
103 |
-
break;
|
104 |
-
case 'layout_css_editor':
|
105 |
-
$slide.ditty_layout_css_editor_panel( {
|
106 |
-
editor : editor,
|
107 |
-
prevPanel : prevSlideId
|
108 |
-
} );
|
109 |
-
break;
|
110 |
-
default:
|
111 |
-
break;
|
112 |
-
}
|
113 |
-
} );
|
114 |
-
|
115 |
-
/**
|
116 |
-
* Setup the editor display panel when ready
|
117 |
-
*
|
118 |
-
* @since 3.0
|
119 |
-
* @return null
|
120 |
-
*/
|
121 |
-
$( 'body' ).on( 'ditty_editor_panel_removed', function( event, slideId, $slide ) {
|
122 |
-
switch( slideId ) {
|
123 |
-
case 'item_editor':
|
124 |
-
if ( $slide.ditty_item_editor_panel ) {
|
125 |
-
$slide.ditty_item_editor_panel( 'destroy' );
|
126 |
-
}
|
127 |
-
break;
|
128 |
-
case 'display_editor':
|
129 |
-
if ( $slide.ditty_display_editor_panel ) {
|
130 |
-
$slide.ditty_display_editor_panel( 'destroy' );
|
131 |
-
}
|
132 |
-
break;
|
133 |
-
case 'layouts':
|
134 |
-
if ( $slide.ditty_layouts_panel ) {
|
135 |
-
$slide.ditty_layouts_panel( 'destroy' );
|
136 |
-
}
|
137 |
-
break;
|
138 |
-
case 'layout_variations':
|
139 |
-
if ( $slide.ditty_layout_variations_panel ) {
|
140 |
-
$slide.ditty_layout_variations_panel( 'destroy' );
|
141 |
-
}
|
142 |
-
break;
|
143 |
-
case 'layouts':
|
144 |
-
if ( $slide.ditty_layouts_panel ) {
|
145 |
-
$slide.ditty_layouts_panel( 'destroy' );
|
146 |
-
}
|
147 |
-
break;
|
148 |
-
case 'layout_html_editor':
|
149 |
-
if ( $slide.ditty_layout_html_editor_panel ) {
|
150 |
-
$slide.ditty_layout_html_editor_panel( 'destroy' );
|
151 |
-
}
|
152 |
-
break;
|
153 |
-
case 'layout_css_editor':
|
154 |
-
if ( $slide.ditty_layout_css_editor_panel ) {
|
155 |
-
$slide.ditty_layout_css_editor_panel( 'destroy' );
|
156 |
-
}
|
157 |
-
break;
|
158 |
-
default:
|
159 |
-
break;
|
160 |
-
}
|
161 |
-
} );
|
162 |
-
|
163 |
-
}() );
|
164 |
-
|
165 |
-
} );
|
166 |
-
|
167 |
-
|
168 |
-
/**
|
169 |
-
* Initialize an editor
|
170 |
-
*
|
171 |
-
* @since 3.0
|
172 |
-
* @return null
|
173 |
-
*/
|
174 |
-
function dittyEditorInit( ditty ) {
|
175 |
-
if ( ! ditty ) {
|
176 |
-
return false;
|
177 |
-
}
|
178 |
-
var status = ditty.options( 'status' ),
|
179 |
-
panel = 'auto-draft' === status ? 'settings' : false;
|
180 |
-
|
181 |
-
jQuery( '#ditty-editor__settings' ).ditty_editor( {
|
182 |
-
ditty: ditty,
|
183 |
-
panel: panel
|
184 |
-
} );
|
185 |
-
}
|
186 |
-
dittyEditorInit();
|
187 |
-
|
188 |
-
/**
|
189 |
-
* UI - Data List
|
190 |
-
*
|
191 |
-
* @since 3.0
|
192 |
-
* @return null
|
193 |
-
*/
|
194 |
-
|
195 |
-
(function ($) {
|
196 |
-
'use strict';
|
197 |
-
|
198 |
-
var defaults = {
|
199 |
-
listType : 'toggle',
|
200 |
-
showAll : true,
|
201 |
-
activeFilter : '*',
|
202 |
-
filter : '.ditty-data-list__filter',
|
203 |
-
filterSelector : 'filter',
|
204 |
-
item : '.ditty-data-list__item',
|
205 |
-
itemSelector : 'filter'
|
206 |
-
};
|
207 |
-
|
208 |
-
var Ditty_UI_Data_List = function ( elmt, options ) {
|
209 |
-
|
210 |
-
this.elmt = elmt;
|
211 |
-
this.settings = $.extend( {}, defaults, $.ditty_ui_data_list.defaults, options );
|
212 |
-
this.$elmt = $( elmt );
|
213 |
-
this.filters = [];
|
214 |
-
|
215 |
-
this._init();
|
216 |
-
};
|
217 |
-
|
218 |
-
|
219 |
-
Ditty_UI_Data_List.prototype = {
|
220 |
-
|
221 |
-
/**
|
222 |
-
* Initialize the data list
|
223 |
-
*
|
224 |
-
* @since 3.0
|
225 |
-
* @return null
|
226 |
-
*/
|
227 |
-
_init: function () {
|
228 |
-
|
229 |
-
var self = this;
|
230 |
-
|
231 |
-
this.$elmt.on( 'click', this.settings.filter, { self: this }, this._filterClick );
|
232 |
-
this.$elmt.find( this.settings.filter + '.active' ).each( function() {
|
233 |
-
self._filterList( $( this ).data( self.settings.filterSelector ) );
|
234 |
-
});
|
235 |
-
|
236 |
-
if ( '*' !== this.settings.activeFilter ) {
|
237 |
-
this._filterList( this.settings.activeFilter );
|
238 |
-
}
|
239 |
-
|
240 |
-
// Trigger the init
|
241 |
-
setTimeout( function () {
|
242 |
-
self.trigger( 'init' );
|
243 |
-
}, 1 );
|
244 |
-
},
|
245 |
-
|
246 |
-
|
247 |
-
/**
|
248 |
-
* Select the filter and update the list
|
249 |
-
*
|
250 |
-
* @since 3.0
|
251 |
-
* @return null
|
252 |
-
*/
|
253 |
-
_filterList: function( filter ) {
|
254 |
-
|
255 |
-
var self = this,
|
256 |
-
filters = this.filters;
|
257 |
-
|
258 |
-
if ( 'toggle' === this.settings.listType ) {
|
259 |
-
|
260 |
-
if ( this.filters.includes( filter ) ) {
|
261 |
-
if ( this.settings.showAll ) {
|
262 |
-
this.filters = [];
|
263 |
-
this.$elmt.find( this.settings.filter ).removeClass( 'active' );
|
264 |
-
this.$elmt.find( this.settings.item ).show();
|
265 |
-
}
|
266 |
-
} else {
|
267 |
-
this.filters = [ filter ];
|
268 |
-
this.$elmt.find( this.settings.filter ).removeClass( 'active' );
|
269 |
-
this.$elmt.find( this.settings.filter + '[data-' + this.settings.filterSelector + '="' + filter + '"]' ).addClass( 'active' );
|
270 |
-
this.$elmt.find( this.settings.item ).hide();
|
271 |
-
this.$elmt.find( this.settings.item + '[data-' + this.settings.itemSelector + '="' + filter + '"]' ).show();
|
272 |
-
}
|
273 |
-
} else if ( 'filter' === this.settings.listType ) {
|
274 |
-
|
275 |
-
this.$elmt.find( this.settings.item ).hide();
|
276 |
-
|
277 |
-
if ( this.filters.includes( filter ) ) {
|
278 |
-
this.$elmt.find( this.settings.filter + '[data-' + this.settings.filterSelector + '="' + filter + '"]' ).removeClass( 'active' );
|
279 |
-
for( var i = 0; i < this.filters.length; i++ ) {
|
280 |
-
if ( self.filters[i] === filter ) {
|
281 |
-
self.filters.splice( i, 1 );
|
282 |
-
}
|
283 |
-
}
|
284 |
-
} else {
|
285 |
-
this.$elmt.find( this.settings.filter + '[data-' + this.settings.filterSelector + '="' + filter + '"]' ).addClass( 'active' );
|
286 |
-
this.filters.push( filter );
|
287 |
-
}
|
288 |
-
|
289 |
-
// Show the filtered items
|
290 |
-
$.each( this.filters, function( index, value ) {
|
291 |
-
self.$elmt.find( this.settings.item + '[data-' + this.settings.itemSelector + '="' + value + '"]' ).show();
|
292 |
-
});
|
293 |
-
|
294 |
-
// Show all if no filters
|
295 |
-
if( 0 === this.filters.length ) {
|
296 |
-
self.$elmt.find( this.settings.item ).show();
|
297 |
-
}
|
298 |
-
}
|
299 |
-
|
300 |
-
if ( filters !== this.filters ) {
|
301 |
-
self.trigger( 'update' );
|
302 |
-
}
|
303 |
-
},
|
304 |
-
|
305 |
-
|
306 |
-
/**
|
307 |
-
* Filter click listener
|
308 |
-
*
|
309 |
-
* @since 3.0
|
310 |
-
* @return null
|
311 |
-
*/
|
312 |
-
_filterClick: function( e ) {
|
313 |
-
e.preventDefault();
|
314 |
-
|
315 |
-
var self = e.data.self,
|
316 |
-
$link = $( e.target );
|
317 |
-
|
318 |
-
if ( ! $link.is( 'a' ) ) {
|
319 |
-
$link = $link.parents( 'a' );
|
320 |
-
}
|
321 |
-
|
322 |
-
self._filterList( $link.data( self.settings.filterSelector ) );
|
323 |
-
},
|
324 |
-
|
325 |
-
|
326 |
-
/**
|
327 |
-
* Return a specific setting
|
328 |
-
*
|
329 |
-
* @since 3.0
|
330 |
-
* @return null
|
331 |
-
*/
|
332 |
-
_options: function ( key ) {
|
333 |
-
return this.settings[key];
|
334 |
-
},
|
335 |
-
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Setup triggers
|
339 |
-
*
|
340 |
-
* @since 3.0
|
341 |
-
* @return null
|
342 |
-
*/
|
343 |
-
trigger: function ( fn, customParams ) {
|
344 |
-
var params = [ this.settings, this.filters ];
|
345 |
-
|
346 |
-
if ( customParams ) {
|
347 |
-
params = customParams;
|
348 |
-
}
|
349 |
-
|
350 |
-
this.$elmt.trigger( 'ditty_ui_data_list_' + fn, params );
|
351 |
-
|
352 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
353 |
-
this.settings[fn].apply( this.$elmt, params );
|
354 |
-
}
|
355 |
-
},
|
356 |
-
|
357 |
-
|
358 |
-
/**
|
359 |
-
* Allow settings to be modified
|
360 |
-
*
|
361 |
-
* @since 3.0
|
362 |
-
* @return null
|
363 |
-
*/
|
364 |
-
options: function ( key, value ) {
|
365 |
-
|
366 |
-
if ( typeof key === 'object' ) {
|
367 |
-
this.settings = $.extend( {}, defaults, $.ditty_ui_data_list.defaults, key );
|
368 |
-
} else if ( typeof key === 'string' ) {
|
369 |
-
if ( value === undefined ) {
|
370 |
-
return this.settings[key];
|
371 |
-
}
|
372 |
-
this.settings[key] = value;
|
373 |
-
} else {
|
374 |
-
return this.settings;
|
375 |
-
}
|
376 |
-
|
377 |
-
this.trigger( 'options_update' );
|
378 |
-
},
|
379 |
-
|
380 |
-
|
381 |
-
/**
|
382 |
-
* Destroy the editor
|
383 |
-
*
|
384 |
-
* @since 3.0
|
385 |
-
* @return null
|
386 |
-
*/
|
387 |
-
destroy: function () {
|
388 |
-
|
389 |
-
this.$elmt.off( 'click', this.settings.filter, { self: this }, this._filterClick );
|
390 |
-
|
391 |
-
// Trigger a reset notice
|
392 |
-
this.trigger( 'destroy' );
|
393 |
-
this.elmt._ditty_ui_data_list = null;
|
394 |
-
}
|
395 |
-
};
|
396 |
-
|
397 |
-
|
398 |
-
/**
|
399 |
-
* Create the data list
|
400 |
-
*
|
401 |
-
* @since 3.0
|
402 |
-
* @return null
|
403 |
-
*/
|
404 |
-
$.fn.ditty_ui_data_list = function( options ) {
|
405 |
-
var args = arguments,
|
406 |
-
error = false,
|
407 |
-
returns;
|
408 |
-
|
409 |
-
if ( options === undefined || typeof options === 'object' ) {
|
410 |
-
return this.each( function () {
|
411 |
-
if ( ! this._ditty_ui_data_list ) {
|
412 |
-
this._ditty_ui_data_list = new Ditty_UI_Data_List( this, options );
|
413 |
-
}
|
414 |
-
});
|
415 |
-
} else if ( typeof options === 'string' ) {
|
416 |
-
this.each( function () {
|
417 |
-
var instance = this._ditty_ui_data_list;
|
418 |
-
|
419 |
-
if ( ! instance ) {
|
420 |
-
throw new Error( 'No Ditty_UI_Data_List applied to this element.' );
|
421 |
-
}
|
422 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
423 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
424 |
-
} else {
|
425 |
-
error = true;
|
426 |
-
}
|
427 |
-
} );
|
428 |
-
|
429 |
-
if ( error ) {
|
430 |
-
throw new Error( 'No method "' + options + '" in Ditty_UI_Data_List.' );
|
431 |
-
}
|
432 |
-
|
433 |
-
return returns !== undefined ? returns : this;
|
434 |
-
}
|
435 |
-
};
|
436 |
-
|
437 |
-
$.ditty_ui_data_list = {};
|
438 |
-
$.ditty_ui_data_list.defaults = defaults;
|
439 |
-
|
440 |
-
} )( jQuery );
|
441 |
-
|
442 |
-
|
443 |
-
/**
|
444 |
-
* Reorder a set of items by id
|
445 |
-
*
|
446 |
-
* @since 3.0
|
447 |
-
* @return null
|
448 |
-
*/
|
449 |
-
function dittyGetItemsById( items, id ) {
|
450 |
-
var idItems = [];
|
451 |
-
jQuery.each( items, function( i, item ) {
|
452 |
-
if ( String( item.id ) === String( id ) ) {
|
453 |
-
idItems.push( item );
|
454 |
-
}
|
455 |
-
} );
|
456 |
-
return idItems;
|
457 |
-
}
|
458 |
-
|
459 |
-
/**
|
460 |
-
* Reorder a set of items
|
461 |
-
*
|
462 |
-
* @since 3.0
|
463 |
-
* @return null
|
464 |
-
*/
|
465 |
-
function dittyItemsReorder( items, ids ) {
|
466 |
-
var orderedItems = [];
|
467 |
-
jQuery.each( ids, function( index, id ) {
|
468 |
-
orderedItems = jQuery.merge( orderedItems, dittyGetItemsById( items, id ) );
|
469 |
-
} );
|
470 |
-
return orderedItems;
|
471 |
-
}
|
472 |
-
|
473 |
-
/**
|
474 |
-
* Ditty editor ajax request
|
475 |
-
* @since 3.0
|
476 |
-
* @return null
|
477 |
-
*/
|
478 |
-
// function ditty_editor_ajax( data, elmt ) {
|
479 |
-
// var defaults = {
|
480 |
-
// action : 'ditty_editor_ajax',
|
481 |
-
// draft_values : elmt.settings.editor.getDraftValues(),
|
482 |
-
// security : dittyVars.security
|
483 |
-
// };
|
484 |
-
// var ajax_data = jQuery.extend( {}, defaults, data );
|
485 |
-
// jQuery.post( dittyVars.ajaxurl, ajax_data, function( response ) {
|
486 |
-
// if ( response.draft_values ) {
|
487 |
-
// elmt.settings.editor.updateDraftValues( false, response.draft_values );
|
488 |
-
// }
|
489 |
-
// if ( response.hook ) {
|
490 |
-
// elmt.$elmt.trigger( response.hook, [response] );
|
491 |
-
// }
|
492 |
-
// }, 'json' );
|
493 |
-
// }
|
494 |
-
|
495 |
-
/**
|
496 |
-
* Update draft data
|
497 |
-
* @since 3.0
|
498 |
-
* @return null
|
499 |
-
*/
|
500 |
-
function dittyDraftUpdate( elmt, type, key, value ) {
|
501 |
-
var draftValues = elmt.settings.editor.getDraftValues( type );
|
502 |
-
if ( ! draftValues ) {
|
503 |
-
draftValues = {};
|
504 |
-
}
|
505 |
-
if ( key ) {
|
506 |
-
draftValues[key] = value;
|
507 |
-
} else {
|
508 |
-
draftValues = value;
|
509 |
-
}
|
510 |
-
return elmt.settings.editor.updateDraftValues( type, draftValues );
|
511 |
-
}
|
512 |
-
|
513 |
-
/**
|
514 |
-
* Get draft data
|
515 |
-
* @since 3.0
|
516 |
-
* @return null
|
517 |
-
*/
|
518 |
-
function dittyDraftGet( elmt, type, key ) {
|
519 |
-
var draftValues = elmt.settings.editor.getDraftValues( type );
|
520 |
-
if ( ! draftValues ) {
|
521 |
-
return false;
|
522 |
-
}
|
523 |
-
if ( key && draftValues[key] ) {
|
524 |
-
return draftValues[key];
|
525 |
-
} else {
|
526 |
-
return draftValues;
|
527 |
-
}
|
528 |
-
}
|
529 |
-
|
530 |
-
/**
|
531 |
-
* Set a ditty element to delete
|
532 |
-
*
|
533 |
-
* @since 3.0
|
534 |
-
* @return null
|
535 |
-
*/
|
536 |
-
function dittyDraftDelete( type, elmt, el_id ) {
|
537 |
-
var draftValues = elmt.settings.editor.getDraftValues( type ),
|
538 |
-
updatedDraftValues = {};
|
539 |
-
|
540 |
-
jQuery.each( draftValues, function( id, values ) {
|
541 |
-
if ( String( el_id ) !== String( id ) ) {
|
542 |
-
updatedDraftValues[id] = values;
|
543 |
-
}
|
544 |
-
} );
|
545 |
-
if ( 'new-' !== String( el_id ).substring( 0, 4 ) ) {
|
546 |
-
updatedDraftValues[el_id] = 'DELETE';
|
547 |
-
}
|
548 |
-
return elmt.settings.editor.updateDraftValues( type, updatedDraftValues );
|
549 |
-
}
|
550 |
-
function dittyDraftItemDelete( elmt, itemId ) {
|
551 |
-
return dittyDraftDelete( 'items', elmt, itemId );
|
552 |
-
}
|
553 |
-
function dittyDraftLayoutDelete( elmt, layoutId ) {
|
554 |
-
return dittyDraftDelete( 'layouts', elmt, layoutId );
|
555 |
-
}
|
556 |
-
function dittyDraftDisplayDelete( elmt, displayId ) {
|
557 |
-
return dittyDraftDelete( 'displays', elmt, displayId );
|
558 |
-
}
|
559 |
-
|
560 |
-
/**
|
561 |
-
* Update item draft data
|
562 |
-
*
|
563 |
-
* @since 3.0
|
564 |
-
* @return null
|
565 |
-
*/
|
566 |
-
function dittyDraftItemUpdateData( elmt, itemId, key, value ) {
|
567 |
-
var itemDraftValues = elmt.settings.editor.getDraftValues( 'items' );
|
568 |
-
if ( ! itemDraftValues ) {
|
569 |
-
itemDraftValues = {};
|
570 |
-
}
|
571 |
-
if ( ! itemDraftValues[itemId] ) {
|
572 |
-
itemDraftValues[itemId] = {};
|
573 |
-
}
|
574 |
-
if ( ! itemDraftValues[itemId].data ) {
|
575 |
-
itemDraftValues[itemId].data = {};
|
576 |
-
}
|
577 |
-
if ( key ) {
|
578 |
-
itemDraftValues[itemId].data[key] = value;
|
579 |
-
} else {
|
580 |
-
itemDraftValues[itemId].data = value;
|
581 |
-
}
|
582 |
-
return elmt.settings.editor.updateDraftValues( 'items', itemDraftValues );
|
583 |
-
}
|
584 |
-
|
585 |
-
/**
|
586 |
-
* Get item draft data
|
587 |
-
*
|
588 |
-
* @since 3.0
|
589 |
-
* @return null
|
590 |
-
*/
|
591 |
-
function dittyDraftItemGetData( elmt, itemId, key ) {
|
592 |
-
var itemDraftValues = elmt.settings.editor.getDraftValues( 'items' );
|
593 |
-
if ( ! itemDraftValues[itemId] ) {
|
594 |
-
return false;
|
595 |
-
}
|
596 |
-
if ( ! itemDraftValues[itemId].data ) {
|
597 |
-
return false;
|
598 |
-
}
|
599 |
-
if ( key ) {
|
600 |
-
if ( itemDraftValues[itemId].data[key] ) {
|
601 |
-
return itemDraftValues[itemId].data[key];
|
602 |
-
}
|
603 |
-
} else {
|
604 |
-
return itemDraftValues[itemId].data;
|
605 |
-
}
|
606 |
-
}
|
607 |
-
|
608 |
-
/**
|
609 |
-
* Update item draft meta
|
610 |
-
*
|
611 |
-
* @since 3.0
|
612 |
-
* @return null
|
613 |
-
*/
|
614 |
-
function dittyDraftItemUpdateMeta( elmt, itemId, key, value ) {
|
615 |
-
var itemDraftValues = elmt.settings.editor.getDraftValues( 'items' );
|
616 |
-
if ( ! itemDraftValues ) {
|
617 |
-
itemDraftValues = {};
|
618 |
-
}
|
619 |
-
if ( ! itemDraftValues[itemId] ) {
|
620 |
-
itemDraftValues[itemId] = {};
|
621 |
-
}
|
622 |
-
if ( ! itemDraftValues[itemId].meta ) {
|
623 |
-
itemDraftValues[itemId].meta = {};
|
624 |
-
}
|
625 |
-
if ( key ) {
|
626 |
-
itemDraftValues[itemId].meta[key] = value;
|
627 |
-
} else {
|
628 |
-
itemDraftValues[itemId].meta = value;
|
629 |
-
}
|
630 |
-
return elmt.settings.editor.updateDraftValues( 'items', itemDraftValues );
|
631 |
-
}
|
632 |
-
|
633 |
-
/**
|
634 |
-
* Get item draft meta
|
635 |
-
*
|
636 |
-
* @since 3.0
|
637 |
-
* @return null
|
638 |
-
*/
|
639 |
-
function dittyDraftItemGetMeta( elmt, itemId, key ) {
|
640 |
-
var itemDraftValues = elmt.settings.editor.getDraftValues( 'items' );
|
641 |
-
if ( ! itemDraftValues[itemId] ) {
|
642 |
-
return false;
|
643 |
-
}
|
644 |
-
if ( ! itemDraftValues[itemId].meta ) {
|
645 |
-
return false;
|
646 |
-
}
|
647 |
-
if ( key ) {
|
648 |
-
if ( itemDraftValues[itemId].meta[key] ) {
|
649 |
-
return itemDraftValues[itemId].meta[key];
|
650 |
-
}
|
651 |
-
} else {
|
652 |
-
return itemDraftValues[itemId].meta;
|
653 |
-
}
|
654 |
-
}
|
655 |
-
|
656 |
-
/**
|
657 |
-
* Update layout draft meta
|
658 |
-
*
|
659 |
-
* @since 3.0
|
660 |
-
* @return null
|
661 |
-
*/
|
662 |
-
function dittyDraftLayoutUpdate( elmt, layoutId, key, value ) {
|
663 |
-
var layoutDraftValues = elmt.settings.editor.getDraftValues( 'layouts' );
|
664 |
-
if ( ! layoutDraftValues ) {
|
665 |
-
layoutDraftValues = {};
|
666 |
-
}
|
667 |
-
if ( ! layoutDraftValues[layoutId] ) {
|
668 |
-
layoutDraftValues[layoutId] = {};
|
669 |
-
}
|
670 |
-
if ( key ) {
|
671 |
-
layoutDraftValues[layoutId][key] = value;
|
672 |
-
} else {
|
673 |
-
layoutDraftValues[layoutId] = value;
|
674 |
-
}
|
675 |
-
return elmt.settings.editor.updateDraftValues( 'layouts', layoutDraftValues );
|
676 |
-
}
|
677 |
-
|
678 |
-
/**
|
679 |
-
* Get layout draft meta
|
680 |
-
*
|
681 |
-
* @since 3.0
|
682 |
-
* @return null
|
683 |
-
*/
|
684 |
-
function dittyDraftLayoutGet( elmt, layoutId, key ) {
|
685 |
-
var layoutDraftValues = elmt.settings.editor.getDraftValues( 'layouts' );
|
686 |
-
if ( ! layoutDraftValues[layoutId] ) {
|
687 |
-
return false;
|
688 |
-
}
|
689 |
-
if ( key ) {
|
690 |
-
if ( layoutDraftValues[layoutId][key] ) {
|
691 |
-
return layoutDraftValues[layoutId][key];
|
692 |
-
}
|
693 |
-
} else {
|
694 |
-
return layoutDraftValues[layoutId];
|
695 |
-
}
|
696 |
-
}
|
697 |
-
|
698 |
-
/**
|
699 |
-
* Update display draft meta
|
700 |
-
*
|
701 |
-
* @since 3.0
|
702 |
-
* @return null
|
703 |
-
*/
|
704 |
-
function dittyDraftDisplayUpdate( elmt, displayId, key, value ) {
|
705 |
-
var displayDraftValues = elmt.settings.editor.getDraftValues( 'displays' );
|
706 |
-
if ( ! displayDraftValues ) {
|
707 |
-
displayDraftValues = {};
|
708 |
-
}
|
709 |
-
if ( ! displayDraftValues[displayId] ) {
|
710 |
-
displayDraftValues[displayId] = {};
|
711 |
-
}
|
712 |
-
if ( key ) {
|
713 |
-
displayDraftValues[displayId][key] = value;
|
714 |
-
} else {
|
715 |
-
displayDraftValues[displayId] = value;
|
716 |
-
}
|
717 |
-
return elmt.settings.editor.updateDraftValues( 'displays', displayDraftValues );
|
718 |
-
}
|
719 |
-
|
720 |
-
/**
|
721 |
-
* Get layout draft meta
|
722 |
-
*
|
723 |
-
* @since 3.0
|
724 |
-
* @return null
|
725 |
-
*/
|
726 |
-
function dittyDraftDisplayGet( elmt, displayId, key ) {
|
727 |
-
var displayDraftValues = elmt.settings.editor.getDraftValues( 'layouts' );
|
728 |
-
if ( ! displayDraftValues[displayId] ) {
|
729 |
-
return false;
|
730 |
-
}
|
731 |
-
if ( key ) {
|
732 |
-
if ( displayDraftValues[displayId][key] ) {
|
733 |
-
return displayDraftValues[displayId][key];
|
734 |
-
}
|
735 |
-
} else {
|
736 |
-
return displayDraftValues[displayId];
|
737 |
-
}
|
738 |
-
}
|
739 |
-
|
740 |
-
/* global tinymce:true */
|
741 |
-
|
742 |
-
/**
|
743 |
-
* Ditty Editor
|
744 |
-
*
|
745 |
-
* @since 3.0
|
746 |
-
* @return null
|
747 |
-
*/
|
748 |
-
|
749 |
-
(function ($) {
|
750 |
-
'use strict';
|
751 |
-
|
752 |
-
var defaults = {
|
753 |
-
screen : 'admin',
|
754 |
-
ditty : null,
|
755 |
-
panel : ''
|
756 |
-
};
|
757 |
-
|
758 |
-
var Ditty_Editor = function( elmt, options ) {
|
759 |
-
|
760 |
-
this.elmt = elmt;
|
761 |
-
this.settings = $.extend( {}, defaults, $.ditty_editor.defaults, options );
|
762 |
-
this.$elmt = $( elmt );
|
763 |
-
this.ditty = this.settings.ditty;
|
764 |
-
this.dittyId = this.settings.ditty.options( 'id' );
|
765 |
-
this.dittyType = this.settings.ditty.options( 'type' );
|
766 |
-
this.displayId = 0;
|
767 |
-
this.panelsLoaded = 0;
|
768 |
-
this.unsavedUpdates = {};
|
769 |
-
this.draftValues = {};
|
770 |
-
|
771 |
-
this.$overlay = null;
|
772 |
-
this.$contents = null;
|
773 |
-
this.$header = null;
|
774 |
-
this.$update = null;
|
775 |
-
this.$updateCount = null;
|
776 |
-
this.$updateLabel = null;
|
777 |
-
this.$tabs = null;
|
778 |
-
this.$panels = null;
|
779 |
-
this.currentTab = 0;
|
780 |
-
this.currentPanel = this.settings.panel;
|
781 |
-
this.delayedSubmit = false;
|
782 |
-
this.tabs = [];
|
783 |
-
this.panels = [];
|
784 |
-
this.activeItems = [];
|
785 |
-
|
786 |
-
this._init();
|
787 |
-
};
|
788 |
-
|
789 |
-
|
790 |
-
Ditty_Editor.prototype = {
|
791 |
-
|
792 |
-
/**
|
793 |
-
* Initialize the editor
|
794 |
-
*
|
795 |
-
* @since 3.0
|
796 |
-
* @return null
|
797 |
-
*/
|
798 |
-
_init: function () {
|
799 |
-
var self = this,
|
800 |
-
$contents,
|
801 |
-
$header,
|
802 |
-
$updateCount,
|
803 |
-
$updateLabel,
|
804 |
-
$update,
|
805 |
-
$tabs,
|
806 |
-
$panels;
|
807 |
-
|
808 |
-
// Create the editor contents
|
809 |
-
$contents = $( '<div class="ditty-editor__contents"></div>' );
|
810 |
-
this.$contents = $contents;
|
811 |
-
|
812 |
-
// Create the editor header
|
813 |
-
$header = $( '<div class="ditty-editor__header"></div>' );
|
814 |
-
this.$header = $header;
|
815 |
-
|
816 |
-
// Create the editor update button count
|
817 |
-
$updateCount = $( '<span class="ditty-editor__update__count"></span>' );
|
818 |
-
this.$updateCount = $updateCount;
|
819 |
-
|
820 |
-
// Create the editor update button label
|
821 |
-
$updateLabel = $( '<span class="ditty-editor__update__label">Save Ditty</span>' );
|
822 |
-
this.$updateLabel = $updateLabel;
|
823 |
-
|
824 |
-
// Create the editor update button
|
825 |
-
$update = $( '<button type="submit" class="ditty-editor__update ditty-button ditty-button--primary"></button>' );
|
826 |
-
this.$update = $update;
|
827 |
-
|
828 |
-
// Create the editor tabs
|
829 |
-
$tabs = $( '<div class="ditty-editor__tabs"></div>' );
|
830 |
-
this.$tabs = $tabs;
|
831 |
-
|
832 |
-
// Create the editor panels
|
833 |
-
$panels = $( '<div class="ditty-editor__panels"></div>' );
|
834 |
-
this.$panels = $panels;
|
835 |
-
|
836 |
-
// Add the new elements
|
837 |
-
$update.prepend( $updateCount, $updateLabel );
|
838 |
-
$header.append( $update );
|
839 |
-
$contents.append( $header, $tabs, $panels );
|
840 |
-
this.$elmt.append( $contents );
|
841 |
-
|
842 |
-
this.$overlay = $( '<div class="ditty-updating-overlay ditty-admin-item__overlay"><div class="ditty-updating-overlay__inner"><i class="fas fa-sync-alt fa-spin"></i></div></div>' );
|
843 |
-
this.$elmt.append( this.$overlay );
|
844 |
-
|
845 |
-
// Setup action listeners
|
846 |
-
$( document ).on( 'postbox-moved', { self: this }, this._postboxMoved );
|
847 |
-
$( document ).on( 'postboxes-columnchange', { self: this }, this._postboxMoved );
|
848 |
-
$( window ).on( 'beforeunload', { self: this }, this._beforeunload );
|
849 |
-
this.ditty.$elmt.on( 'ditty_active_items_update', { self: this }, this._dittyItemsUpdated );
|
850 |
-
this.ditty.$elmt.on( 'ditty_disabled_items_update', { self: this }, this._disabledItemsUpdate );
|
851 |
-
this.$tabs.on( 'click', '.ditty-editor__tab', { self: this }, this._showPanel );
|
852 |
-
this.$update.on( 'click', { self: this }, this._saveClick );
|
853 |
-
this.$panels.on( 'ditty_slider_init', { self: this }, this._editorLoaded );
|
854 |
-
this.$panels.on( 'ditty_slider_before_slide_update', { self: this }, this._beforeSlideUpdate );
|
855 |
-
this.$panels.on( 'ditty_slider_after_slide_update', { self: this }, this._afterSlideUpdate );
|
856 |
-
this.$panels.on( 'ditty_slider_slide_removed', { self: this }, this._slideRemoved );
|
857 |
-
|
858 |
-
// Load the editor contents
|
859 |
-
this._loadContents();
|
860 |
-
|
861 |
-
// Stop live updates
|
862 |
-
this.trigger( 'stop_live_updates' );
|
863 |
-
|
864 |
-
// Trigger the init
|
865 |
-
setTimeout( function() {
|
866 |
-
self.trigger( 'init' );
|
867 |
-
}, 1 );
|
868 |
-
},
|
869 |
-
|
870 |
-
|
871 |
-
/**
|
872 |
-
* Select the filter and update the list
|
873 |
-
*
|
874 |
-
* @since 3.0
|
875 |
-
* @return null
|
876 |
-
*/
|
877 |
-
_loadContents: function() {
|
878 |
-
|
879 |
-
var self = this;
|
880 |
-
|
881 |
-
var data = {
|
882 |
-
action : 'ditty_editor_load_contents',
|
883 |
-
ditty_id : this.dittyId,
|
884 |
-
security : dittyVars.security
|
885 |
-
};
|
886 |
-
|
887 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
888 |
-
self._initTabs( response.tabs );
|
889 |
-
self._initPanels( response.panels );
|
890 |
-
self._initSlider();
|
891 |
-
}, 'json' );
|
892 |
-
|
893 |
-
},
|
894 |
-
|
895 |
-
/**
|
896 |
-
* Initialize the editor
|
897 |
-
*
|
898 |
-
* @since 3.0
|
899 |
-
* @return null
|
900 |
-
*/
|
901 |
-
_editorLoaded: function ( e ) {
|
902 |
-
var self = e.data.self;
|
903 |
-
$( 'body' ).trigger( 'ditty_editor_loaded', [ self ] );
|
904 |
-
},
|
905 |
-
|
906 |
-
/**
|
907 |
-
* Get the editor update count
|
908 |
-
*
|
909 |
-
* @since 3.0
|
910 |
-
* @return null
|
911 |
-
*/
|
912 |
-
_setUpdateCount: function() {
|
913 |
-
// var total = 0;
|
914 |
-
// $.each( this.unsavedUpdates, function( type, data ) {
|
915 |
-
// total += data.length;
|
916 |
-
// } );
|
917 |
-
//
|
918 |
-
// if ( total > 0 ) {
|
919 |
-
// this.$updateCount.text( total );
|
920 |
-
// } else {
|
921 |
-
// this.$updateCount.text( '' );
|
922 |
-
// }
|
923 |
-
},
|
924 |
-
|
925 |
-
/**
|
926 |
-
* Initialize the slider
|
927 |
-
*
|
928 |
-
* @since 3.0
|
929 |
-
* @return null
|
930 |
-
*/
|
931 |
-
_initSlider: function () {
|
932 |
-
var slideId = this.tabs[0].id;
|
933 |
-
if ( this.currentPanel && '' !== this.currentPanel ) {
|
934 |
-
slideId = this.currentPanel;
|
935 |
-
}
|
936 |
-
|
937 |
-
// Create a new slider and bind actions
|
938 |
-
this.$panels.ditty_slider( {
|
939 |
-
transition : 'fade',
|
940 |
-
transitionSpeed : 0.75,
|
941 |
-
heightSpeed : 0.75,
|
942 |
-
touchSwipe : false,
|
943 |
-
slides : this.panels,
|
944 |
-
slideId : slideId
|
945 |
-
} );
|
946 |
-
},
|
947 |
-
|
948 |
-
/**
|
949 |
-
* Before slide update
|
950 |
-
*
|
951 |
-
* @since 3.0
|
952 |
-
* @return null
|
953 |
-
*/
|
954 |
-
_beforeSlideUpdate: function ( e, index, slide, prevIndex, prevSlide ) {
|
955 |
-
var self = e.data.self;
|
956 |
-
self.updateStart();
|
957 |
-
self._updateTab( slide.id );
|
958 |
-
$( 'body' ).trigger( 'ditty_editor_before_panel_update', [ slide.id, slide.$elmt, prevSlide.id, prevSlide.$elmt, self ] );
|
959 |
-
},
|
960 |
-
|
961 |
-
/**
|
962 |
-
* After slide update
|
963 |
-
*
|
964 |
-
* @since 3.0
|
965 |
-
* @return null
|
966 |
-
*/
|
967 |
-
_afterSlideUpdate: function ( e, index, slide, prevIndex, prevSlide ) {
|
968 |
-
var self = e.data.self;
|
969 |
-
self.updateStop();
|
970 |
-
$( 'body' ).trigger( 'ditty_editor_after_panel_update', [ slide.id, slide.$elmt, prevSlide.id, prevSlide.$elmt, self ] );
|
971 |
-
},
|
972 |
-
|
973 |
-
/**
|
974 |
-
* Slide removed notice
|
975 |
-
*
|
976 |
-
* @since 3.0
|
977 |
-
* @return null
|
978 |
-
*/
|
979 |
-
_slideRemoved: function ( e, slide ) {
|
980 |
-
var self = e.data.self;
|
981 |
-
$( 'body' ).trigger( 'ditty_editor_panel_removed', [ slide.id, slide.$elmt, self ] );
|
982 |
-
},
|
983 |
-
|
984 |
-
/**
|
985 |
-
* Show a specific panel
|
986 |
-
*
|
987 |
-
* @since 3.0
|
988 |
-
* @return null
|
989 |
-
*/
|
990 |
-
_showPanel: function ( e ) {
|
991 |
-
e.preventDefault();
|
992 |
-
var self = e.data.self,
|
993 |
-
$tab = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
994 |
-
panelId = $tab.data( 'panel' ),
|
995 |
-
index = parseInt( $tab.data( 'index' ) );
|
996 |
-
|
997 |
-
if ( panelId === self.currentTab ) {
|
998 |
-
return false;
|
999 |
-
}
|
1000 |
-
|
1001 |
-
var transition = index > self.currentTab ? 'slideLeft' : 'slideRight';
|
1002 |
-
self.$panels.ditty_slider( 'options', 'transition', transition );
|
1003 |
-
self.$panels.ditty_slider( 'showSlideById', panelId );
|
1004 |
-
self.currentTab = index;
|
1005 |
-
self.$elmt.trigger( 'ditty_editor_add_drafts' );
|
1006 |
-
},
|
1007 |
-
|
1008 |
-
/**
|
1009 |
-
* Update the active tab
|
1010 |
-
*
|
1011 |
-
* @since 3.0
|
1012 |
-
* @return null
|
1013 |
-
*/
|
1014 |
-
_updateTab: function ( id ) {
|
1015 |
-
var $tab = $( '.ditty-editor__tab[data-panel="' + id + '"]' );
|
1016 |
-
if ( undefined !== $tab[0] ) {
|
1017 |
-
$( '.ditty-editor__tab' ).removeClass( 'active' );
|
1018 |
-
$tab.addClass( 'active' );
|
1019 |
-
this.currentTab = parseInt( $tab.data( 'index' ) );
|
1020 |
-
}
|
1021 |
-
},
|
1022 |
-
|
1023 |
-
/**
|
1024 |
-
* Initialize the editor tabs
|
1025 |
-
*
|
1026 |
-
* @since 3.0
|
1027 |
-
* @return null
|
1028 |
-
*/
|
1029 |
-
_initTabs: function ( tabs ) {
|
1030 |
-
var self = this,
|
1031 |
-
index = 0;
|
1032 |
-
$.each( tabs, function( key, value ) {
|
1033 |
-
var $tab = $( '<a href="#" class="ditty-editor__tab ditty-editor__tab--' + key + '" data-panel="' + key + '" data-index="' + index + '"><i class="' + value.icon + '"></i><span>' + value.label + '</span></a>' );
|
1034 |
-
self.$tabs.append( $tab );
|
1035 |
-
self.tabs.push( {
|
1036 |
-
id: key,
|
1037 |
-
tab: $tab
|
1038 |
-
} );
|
1039 |
-
index++;
|
1040 |
-
} );
|
1041 |
-
},
|
1042 |
-
|
1043 |
-
/**
|
1044 |
-
* Initialize the editor panels
|
1045 |
-
*
|
1046 |
-
* @since 3.0
|
1047 |
-
* @return null
|
1048 |
-
*/
|
1049 |
-
_initPanels: function ( panels ) {
|
1050 |
-
var self = this;
|
1051 |
-
$.each( panels, function( key, value ) {
|
1052 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--' + key + '">' + value + '</div>';
|
1053 |
-
self.panels.push( {
|
1054 |
-
id : key,
|
1055 |
-
html : html,
|
1056 |
-
cache : true
|
1057 |
-
} );
|
1058 |
-
} );
|
1059 |
-
},
|
1060 |
-
|
1061 |
-
/**
|
1062 |
-
* Initialize dynamic fields
|
1063 |
-
*
|
1064 |
-
* @since 3.0
|
1065 |
-
* @return null
|
1066 |
-
*/
|
1067 |
-
_initFields: function ( $fields ) {
|
1068 |
-
$fields.find( '.ditty-data-list' ).ditty_ui_data_list();
|
1069 |
-
$fields.trigger( 'ditty_init_fields' );
|
1070 |
-
$.protip({
|
1071 |
-
defaults: {
|
1072 |
-
position: 'top',
|
1073 |
-
size: 'small',
|
1074 |
-
scheme: 'black',
|
1075 |
-
classes: 'ditty-protip'
|
1076 |
-
}
|
1077 |
-
});
|
1078 |
-
},
|
1079 |
-
|
1080 |
-
/**
|
1081 |
-
* Save the Ditty via ajax
|
1082 |
-
*
|
1083 |
-
* @since 3.0
|
1084 |
-
* @return null
|
1085 |
-
*/
|
1086 |
-
saveDitty: function( args ) {
|
1087 |
-
var self = this,
|
1088 |
-
dittyId = self.dittyId;
|
1089 |
-
|
1090 |
-
self.$updateLabel.text( 'Updating...' );
|
1091 |
-
self.updateStart(); // Stop the update overlay
|
1092 |
-
|
1093 |
-
var data = {
|
1094 |
-
action : 'ditty_editor_save',
|
1095 |
-
ditty_id : dittyId,
|
1096 |
-
draft_values : self.draftValues,
|
1097 |
-
return_items : 1,
|
1098 |
-
security : dittyVars.security
|
1099 |
-
};
|
1100 |
-
data = $.extend( {}, data, args );
|
1101 |
-
|
1102 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
1103 |
-
$( 'body' ).trigger( 'ditty_editor_save_ditty_response', [response] );
|
1104 |
-
|
1105 |
-
// Update the items
|
1106 |
-
if ( response.display_items ) {
|
1107 |
-
self.ditty.options( 'items', response.display_items );
|
1108 |
-
}
|
1109 |
-
self.draftValues = {};
|
1110 |
-
self.unsavedUpdates = {};
|
1111 |
-
self._setUpdateCount();
|
1112 |
-
self.$elmt.removeClass( 'ditty-editor--updates-exist' );
|
1113 |
-
|
1114 |
-
self.$updateLabel.text( 'Ditty Saved!' );
|
1115 |
-
setTimeout(function() {
|
1116 |
-
self.$updateLabel.text( 'Save Ditty' );
|
1117 |
-
}, 2000 );
|
1118 |
-
self.updateStop(); // Stop the update overlay
|
1119 |
-
|
1120 |
-
if ( response.new_ditty_url ) {
|
1121 |
-
window.history.pushState( null, '', '/wp-admin/post.php?post=' + dittyId + '&action=edit' );
|
1122 |
-
}
|
1123 |
-
} );
|
1124 |
-
},
|
1125 |
-
_saveClick: function( e ) {
|
1126 |
-
e.preventDefault();
|
1127 |
-
var self = e.data.self;
|
1128 |
-
self.$elmt.trigger( 'ditty_editor_save_drafts' );
|
1129 |
-
if ( ! self.delayedSubmit ) {
|
1130 |
-
self.saveDitty();
|
1131 |
-
}
|
1132 |
-
},
|
1133 |
-
|
1134 |
-
/**
|
1135 |
-
* Close
|
1136 |
-
*
|
1137 |
-
* @since 3.0
|
1138 |
-
* @return null
|
1139 |
-
*/
|
1140 |
-
/*
|
1141 |
-
_close: function() {
|
1142 |
-
//this.trigger( 'close' );
|
1143 |
-
},
|
1144 |
-
*/
|
1145 |
-
|
1146 |
-
/**
|
1147 |
-
* Cancel click
|
1148 |
-
*
|
1149 |
-
* @since 3.0
|
1150 |
-
* @return null
|
1151 |
-
*/
|
1152 |
-
/*
|
1153 |
-
_cancel_click: function( e ) {
|
1154 |
-
e.preventDefault();
|
1155 |
-
var self = e.data.self;
|
1156 |
-
self._close();
|
1157 |
-
},
|
1158 |
-
*/
|
1159 |
-
|
1160 |
-
/**
|
1161 |
-
* Listen for updated items
|
1162 |
-
*
|
1163 |
-
* @since 3.0
|
1164 |
-
* @return null
|
1165 |
-
*/
|
1166 |
-
_dittyItemsUpdated: function( e, ditty, items ) {
|
1167 |
-
var self = e.data.self;
|
1168 |
-
self.activeItems = items;
|
1169 |
-
self.trigger( 'active_items_update' );
|
1170 |
-
},
|
1171 |
-
|
1172 |
-
/**
|
1173 |
-
* Listen for updated disabled items
|
1174 |
-
*
|
1175 |
-
* @since 3.0
|
1176 |
-
* @return null
|
1177 |
-
*/
|
1178 |
-
_disabledItemsUpdate: function( e, items ) {
|
1179 |
-
var self = e.data.self;
|
1180 |
-
$.each( items, function( id, status ) {
|
1181 |
-
if ( 'disabled' === status ) {
|
1182 |
-
self.$elmt.find( '#ditty-editor-item--' + id ).addClass( 'ditty-editor-item--disabled' );
|
1183 |
-
} else {
|
1184 |
-
self.$elmt.find( '#ditty-editor-item--' + id ).removeClass( 'ditty-editor-item--disabled' );
|
1185 |
-
}
|
1186 |
-
} );
|
1187 |
-
},
|
1188 |
-
|
1189 |
-
/**
|
1190 |
-
* Postbox moved listener
|
1191 |
-
*
|
1192 |
-
* @since 3.0
|
1193 |
-
* @return null
|
1194 |
-
*/
|
1195 |
-
_postboxMoved: function ( e, item ) {
|
1196 |
-
if ( ! window.tinymce ) {
|
1197 |
-
return false;
|
1198 |
-
}
|
1199 |
-
|
1200 |
-
$( item ).find( '.wp-editor-area' ).each( function() {
|
1201 |
-
var id = $( this ).attr( 'id' );
|
1202 |
-
tinymce.execCommand( 'mceRemoveEditor', true, id );
|
1203 |
-
tinymce.execCommand( 'mceAddEditor', true, id );
|
1204 |
-
} );
|
1205 |
-
},
|
1206 |
-
|
1207 |
-
/**
|
1208 |
-
* Warn users before leaving
|
1209 |
-
*
|
1210 |
-
* @since 3.0
|
1211 |
-
* @return null
|
1212 |
-
*/
|
1213 |
-
_beforeunload: function ( e ) {
|
1214 |
-
var self = e.data.self;
|
1215 |
-
if ( Object.keys( self.unsavedUpdates ).length > 0 ) {
|
1216 |
-
return true;
|
1217 |
-
} else {
|
1218 |
-
return undefined;
|
1219 |
-
}
|
1220 |
-
},
|
1221 |
-
|
1222 |
-
/**
|
1223 |
-
* Window resize listener
|
1224 |
-
*
|
1225 |
-
* @since 3.0
|
1226 |
-
* @return null
|
1227 |
-
*/
|
1228 |
-
_windowResize: function( e ) {
|
1229 |
-
e.preventDefault();
|
1230 |
-
//var self = e.data.self;
|
1231 |
-
//self._set_editor_padding();
|
1232 |
-
},
|
1233 |
-
|
1234 |
-
/**
|
1235 |
-
* Return a specific setting
|
1236 |
-
*
|
1237 |
-
* @since 3.0
|
1238 |
-
* @return null
|
1239 |
-
*/
|
1240 |
-
_options: function ( key ) {
|
1241 |
-
return this.settings[key];
|
1242 |
-
},
|
1243 |
-
|
1244 |
-
/**
|
1245 |
-
* Check if an update exists
|
1246 |
-
*
|
1247 |
-
* @since 3.0
|
1248 |
-
* @return null
|
1249 |
-
*/
|
1250 |
-
panelExists: function ( id ) {
|
1251 |
-
var panels = this.$panels.ditty_slider( 'options', 'slides' ),
|
1252 |
-
exists = false;
|
1253 |
-
|
1254 |
-
$.each( panels, function( index, panel ) {
|
1255 |
-
if ( String( panel.id ) === String( id ) ) {
|
1256 |
-
exists = true;
|
1257 |
-
return;
|
1258 |
-
}
|
1259 |
-
} );
|
1260 |
-
return exists;
|
1261 |
-
},
|
1262 |
-
|
1263 |
-
/**
|
1264 |
-
* Check if an update exists
|
1265 |
-
*
|
1266 |
-
* @since 3.0
|
1267 |
-
* @return null
|
1268 |
-
*/
|
1269 |
-
showPanel: function ( id, html ) {
|
1270 |
-
if ( html ) {
|
1271 |
-
this.$panels.ditty_slider( 'addSlideById', id, html );
|
1272 |
-
}
|
1273 |
-
this.$panels.ditty_slider( 'showSlideById', id, true );
|
1274 |
-
},
|
1275 |
-
|
1276 |
-
/**
|
1277 |
-
* Check if an update exists
|
1278 |
-
*
|
1279 |
-
* @since 3.0
|
1280 |
-
* @return null
|
1281 |
-
*/
|
1282 |
-
updateExists: function ( type, id ) {
|
1283 |
-
if ( undefined === this.unsavedUpdates[type] ) {
|
1284 |
-
this.unsavedUpdates[type] = [];
|
1285 |
-
}
|
1286 |
-
if ( -1 !== $.inArray( id, this.unsavedUpdates[type] ) ) {
|
1287 |
-
return true;
|
1288 |
-
}
|
1289 |
-
},
|
1290 |
-
|
1291 |
-
/**
|
1292 |
-
* Let the user know there are unsaved updates
|
1293 |
-
*
|
1294 |
-
* @since 3.0
|
1295 |
-
* @return null
|
1296 |
-
*/
|
1297 |
-
addUpdate: function ( type, id ) {
|
1298 |
-
var updated = false;
|
1299 |
-
if ( undefined === this.unsavedUpdates[type] ) {
|
1300 |
-
this.unsavedUpdates[type] = [];
|
1301 |
-
}
|
1302 |
-
if ( -1 === $.inArray( id, this.unsavedUpdates[type] ) ) {
|
1303 |
-
updated = true;
|
1304 |
-
this.unsavedUpdates[type].push( id );
|
1305 |
-
}
|
1306 |
-
this._setUpdateCount();
|
1307 |
-
this.$elmt.addClass( 'ditty-editor--updates-exist' );
|
1308 |
-
//this.$updateLabel.text( 'Unsaved Updates' );
|
1309 |
-
|
1310 |
-
return updated;
|
1311 |
-
},
|
1312 |
-
|
1313 |
-
/**
|
1314 |
-
* Remove an update notification
|
1315 |
-
*
|
1316 |
-
* @since 3.0
|
1317 |
-
* @return null
|
1318 |
-
*/
|
1319 |
-
removeUpdate: function ( type, id ) {
|
1320 |
-
if ( undefined === this.unsavedUpdates[type] ) {
|
1321 |
-
return false;
|
1322 |
-
}
|
1323 |
-
if ( -1 === $.inArray( id, this.unsavedUpdates[type] ) ) {
|
1324 |
-
return false;
|
1325 |
-
}
|
1326 |
-
var removed = false,
|
1327 |
-
updatedType = [];
|
1328 |
-
|
1329 |
-
$.each( this.unsavedUpdates[type], function( index, type_id ) {
|
1330 |
-
if ( String( id ) === String( type_id ) ) {
|
1331 |
-
removed = true;
|
1332 |
-
} else {
|
1333 |
-
updatedType.push( type_id );
|
1334 |
-
}
|
1335 |
-
} );
|
1336 |
-
this.unsavedUpdates[type] = updatedType;
|
1337 |
-
this._setUpdateCount();
|
1338 |
-
if ( '' === this.$updateCount.text() ) {
|
1339 |
-
this.$elmt.removeClass( 'ditty-editor--updates-exist' );
|
1340 |
-
}
|
1341 |
-
return removed;
|
1342 |
-
},
|
1343 |
-
|
1344 |
-
/**
|
1345 |
-
* Show the update overlay
|
1346 |
-
*
|
1347 |
-
* @since 3.0
|
1348 |
-
* @return null
|
1349 |
-
*/
|
1350 |
-
updateStart: function () {
|
1351 |
-
this.$overlay.fadeIn();
|
1352 |
-
},
|
1353 |
-
|
1354 |
-
/**
|
1355 |
-
* Hide the update overlay
|
1356 |
-
*
|
1357 |
-
* @since 3.0
|
1358 |
-
* @return null
|
1359 |
-
*/
|
1360 |
-
updateStop: function () {
|
1361 |
-
this.$overlay.fadeOut();
|
1362 |
-
},
|
1363 |
-
|
1364 |
-
/**
|
1365 |
-
* Initialize dynamic fields
|
1366 |
-
*
|
1367 |
-
* @since 3.0
|
1368 |
-
* @return null
|
1369 |
-
*/
|
1370 |
-
initFields: function ( $fields ) {
|
1371 |
-
this._initFields( $fields );
|
1372 |
-
},
|
1373 |
-
|
1374 |
-
/**
|
1375 |
-
* Add draft values
|
1376 |
-
*
|
1377 |
-
* @since 3.0
|
1378 |
-
* @return null
|
1379 |
-
*/
|
1380 |
-
updateDraftValues: function ( key, value ) {
|
1381 |
-
this.$elmt.addClass( 'ditty-editor--updates-exist' );
|
1382 |
-
if ( key ) {
|
1383 |
-
this.draftValues[key] = value;
|
1384 |
-
if ( 'development' === dittyVars.mode && window.console ) {
|
1385 |
-
console.log( 'draftValues:', this.draftValues );
|
1386 |
-
}
|
1387 |
-
return this.draftValues[key];
|
1388 |
-
} else {
|
1389 |
-
this.draftValues = value;
|
1390 |
-
if ( 'development' === dittyVars.mode && window.console ) {
|
1391 |
-
console.log( 'draftValues:', this.draftValues );
|
1392 |
-
}
|
1393 |
-
return this.draftValues;
|
1394 |
-
}
|
1395 |
-
|
1396 |
-
},
|
1397 |
-
|
1398 |
-
/**
|
1399 |
-
* Get draft values
|
1400 |
-
*
|
1401 |
-
* @since 3.0
|
1402 |
-
* @return null
|
1403 |
-
*/
|
1404 |
-
getDraftValues: function ( key ) {
|
1405 |
-
if ( key ) {
|
1406 |
-
if ( this.draftValues[key] ) {
|
1407 |
-
return this.draftValues[key];
|
1408 |
-
} else {
|
1409 |
-
return false;
|
1410 |
-
}
|
1411 |
-
} else {
|
1412 |
-
return this.draftValues;
|
1413 |
-
}
|
1414 |
-
},
|
1415 |
-
|
1416 |
-
/**
|
1417 |
-
* Enable/disable delayed submit
|
1418 |
-
*
|
1419 |
-
* @since 3.0
|
1420 |
-
* @return null
|
1421 |
-
*/
|
1422 |
-
delayedSubmitEnable: function () {
|
1423 |
-
this.delayedSubmit = true;
|
1424 |
-
},
|
1425 |
-
delayedSubmitDisable: function () {
|
1426 |
-
this.delayedSubmit = false;
|
1427 |
-
},
|
1428 |
-
|
1429 |
-
/**
|
1430 |
-
* Setup triggers
|
1431 |
-
*
|
1432 |
-
* @since 3.0
|
1433 |
-
* @return null
|
1434 |
-
*/
|
1435 |
-
trigger: function ( fn, customParams ) {
|
1436 |
-
var params = [];
|
1437 |
-
|
1438 |
-
switch( fn ) {
|
1439 |
-
case 'active_items_update':
|
1440 |
-
params = [this.ditty, this.activeItems];
|
1441 |
-
break;
|
1442 |
-
case 'stop_live_updates':
|
1443 |
-
params = [this.dittyId];
|
1444 |
-
break;
|
1445 |
-
default:
|
1446 |
-
params = [this.settings];
|
1447 |
-
break;
|
1448 |
-
}
|
1449 |
-
|
1450 |
-
if ( customParams ) {
|
1451 |
-
params = customParams;
|
1452 |
-
}
|
1453 |
-
|
1454 |
-
this.$elmt.trigger( 'ditty_editor_' + fn, params );
|
1455 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
1456 |
-
this.settings[fn].apply( this.$elmt, params );
|
1457 |
-
}
|
1458 |
-
$( 'body' ).trigger( 'ditty_' + fn, params );
|
1459 |
-
},
|
1460 |
-
|
1461 |
-
/**
|
1462 |
-
* Allow settings to be modified
|
1463 |
-
*
|
1464 |
-
* @since 3.0
|
1465 |
-
* @return null
|
1466 |
-
*/
|
1467 |
-
/*
|
1468 |
-
options: function ( key, value ) {
|
1469 |
-
|
1470 |
-
if ( typeof key === 'object' ) {
|
1471 |
-
this.settings = $.extend( {}, defaults, $.ditty_editor.defaults, key );
|
1472 |
-
} else if ( typeof key === 'string' ) {
|
1473 |
-
if ( value === undefined ) {
|
1474 |
-
return this.settings[key];
|
1475 |
-
}
|
1476 |
-
this.settings[key] = value;
|
1477 |
-
} else {
|
1478 |
-
return this.settings;
|
1479 |
-
}
|
1480 |
-
|
1481 |
-
this.trigger( 'options_update' );
|
1482 |
-
},
|
1483 |
-
*/
|
1484 |
-
|
1485 |
-
/**
|
1486 |
-
* Return option data for the object
|
1487 |
-
*
|
1488 |
-
* @since 3.0
|
1489 |
-
* @return value
|
1490 |
-
*/
|
1491 |
-
_getPanelOption: function( key ) {
|
1492 |
-
switch( key ) {
|
1493 |
-
case 'elmnt':
|
1494 |
-
return this.$panels;
|
1495 |
-
default:
|
1496 |
-
return this.settings[key];
|
1497 |
-
}
|
1498 |
-
},
|
1499 |
-
|
1500 |
-
/**
|
1501 |
-
* Set options data for the object
|
1502 |
-
*
|
1503 |
-
* @since 3.0
|
1504 |
-
* @return null
|
1505 |
-
*/
|
1506 |
-
_setPanelOption: function( key, value ) {
|
1507 |
-
if ( undefined === value ) {
|
1508 |
-
return false;
|
1509 |
-
}
|
1510 |
-
this.$panels.ditty_slider( 'options', key, value );
|
1511 |
-
this.trigger( 'update' );
|
1512 |
-
},
|
1513 |
-
|
1514 |
-
/**
|
1515 |
-
* Hook to get or set editor options
|
1516 |
-
*
|
1517 |
-
* @since 3.0
|
1518 |
-
* @return null
|
1519 |
-
*/
|
1520 |
-
panelOptions: function ( key, value ) {
|
1521 |
-
var self = this;
|
1522 |
-
if ( typeof key === 'object' ) {
|
1523 |
-
$.each( key, function( k, v ) {
|
1524 |
-
self._setPanelOption( k, v );
|
1525 |
-
} );
|
1526 |
-
} else if ( typeof key === 'string' ) {
|
1527 |
-
if ( value === undefined ) {
|
1528 |
-
return self._getPanelOption( key );
|
1529 |
-
}
|
1530 |
-
self._setPanelOption( key, value );
|
1531 |
-
} else {
|
1532 |
-
return self.$panels.ditty_slider( 'options' );
|
1533 |
-
}
|
1534 |
-
},
|
1535 |
-
|
1536 |
-
/**
|
1537 |
-
* Return option data for the object
|
1538 |
-
*
|
1539 |
-
* @since 3.0
|
1540 |
-
* @return value
|
1541 |
-
*/
|
1542 |
-
_getOption: function( key ) {
|
1543 |
-
switch( key ) {
|
1544 |
-
case 'elmnt':
|
1545 |
-
return this;
|
1546 |
-
default:
|
1547 |
-
return this.settings[key];
|
1548 |
-
}
|
1549 |
-
},
|
1550 |
-
|
1551 |
-
/**
|
1552 |
-
* Set options data for the object
|
1553 |
-
*
|
1554 |
-
* @since 3.0
|
1555 |
-
* @return null
|
1556 |
-
*/
|
1557 |
-
_setOption: function( key, value ) {
|
1558 |
-
if ( undefined === value ) {
|
1559 |
-
return false;
|
1560 |
-
}
|
1561 |
-
this.settings[key] = value;
|
1562 |
-
this.trigger( 'update' );
|
1563 |
-
},
|
1564 |
-
|
1565 |
-
/**
|
1566 |
-
* Hook to get or set editor options
|
1567 |
-
*
|
1568 |
-
* @since 3.0
|
1569 |
-
* @return null
|
1570 |
-
*/
|
1571 |
-
options: function ( key, value ) {
|
1572 |
-
var self = this;
|
1573 |
-
if ( typeof key === 'object' ) {
|
1574 |
-
$.each( key, function( k, v ) {
|
1575 |
-
self._setOption( k, v );
|
1576 |
-
} );
|
1577 |
-
} else if ( typeof key === 'string' ) {
|
1578 |
-
if ( value === undefined ) {
|
1579 |
-
return self._getOption( key );
|
1580 |
-
}
|
1581 |
-
self._setOption( key, value );
|
1582 |
-
} else {
|
1583 |
-
return self.settings;
|
1584 |
-
}
|
1585 |
-
},
|
1586 |
-
|
1587 |
-
/**
|
1588 |
-
* Destroy the editor
|
1589 |
-
*
|
1590 |
-
* @since 3.0
|
1591 |
-
* @return null
|
1592 |
-
*/
|
1593 |
-
destroy: function () {
|
1594 |
-
if ( this.$panels.ditty_slider ) {
|
1595 |
-
this.$panels.ditty_slider( 'destroy' );
|
1596 |
-
}
|
1597 |
-
|
1598 |
-
$( document ).off( 'postbox-moved', { self: this }, this._postboxMoved );
|
1599 |
-
$( document ).off( 'postboxes-columnchange', { self: this }, this._postboxMoved );
|
1600 |
-
$( window ).off( 'beforeunload', { self: this }, this._beforeunload );
|
1601 |
-
this.ditty.$elmt.off( 'ditty_active_items_update', { self: this }, this._dittyItemsUpdated );
|
1602 |
-
this.ditty.$elmt.off( 'ditty_disabled_items_update', { self: this }, this._disabledItemsUpdate );
|
1603 |
-
this.$tabs.off( 'click', 'ditty-editor__tab', { self: this }, this._showPanel );
|
1604 |
-
this.$update.off( 'click', { self: this }, this._saveClick );
|
1605 |
-
this.$panels.off( 'ditty_slider_init', { self: this }, this._editorLoaded );
|
1606 |
-
this.$panels.off( 'ditty_slider_before_slide_update', { self: this }, this._beforeSlideUpdate );
|
1607 |
-
this.$panels.off( 'ditty_slider_after_slide_update', { self: this }, this._afterSlideUpdate );
|
1608 |
-
this.$panels.off( 'ditty_slider_slide_removed', { self: this }, this._slideRemoved );
|
1609 |
-
|
1610 |
-
this.trigger( 'destroy' );
|
1611 |
-
this.elmt._ditty_editor = null;
|
1612 |
-
}
|
1613 |
-
};
|
1614 |
-
|
1615 |
-
/**
|
1616 |
-
* Create the data list
|
1617 |
-
*
|
1618 |
-
* @since 3.0
|
1619 |
-
* @return null
|
1620 |
-
*/
|
1621 |
-
$.fn.ditty_editor = function( options ) {
|
1622 |
-
var args = arguments,
|
1623 |
-
error = false,
|
1624 |
-
returns;
|
1625 |
-
|
1626 |
-
if ( options === undefined || typeof options === 'object' ) {
|
1627 |
-
return this.each( function () {
|
1628 |
-
if ( ! this._ditty_editor ) {
|
1629 |
-
this._ditty_editor = new Ditty_Editor( this, options );
|
1630 |
-
}
|
1631 |
-
});
|
1632 |
-
} else if ( typeof options === 'string' ) {
|
1633 |
-
this.each( function () {
|
1634 |
-
var instance = this._ditty_editor;
|
1635 |
-
|
1636 |
-
if ( ! instance ) {
|
1637 |
-
throw new Error( 'No Ditty_Editor applied to this element.' );
|
1638 |
-
}
|
1639 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
1640 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
1641 |
-
} else {
|
1642 |
-
error = true;
|
1643 |
-
}
|
1644 |
-
} );
|
1645 |
-
|
1646 |
-
if ( error ) {
|
1647 |
-
throw new Error( 'No method "' + options + '" in Ditty_Editor.' );
|
1648 |
-
}
|
1649 |
-
|
1650 |
-
return returns !== undefined ? returns : this;
|
1651 |
-
}
|
1652 |
-
};
|
1653 |
-
|
1654 |
-
$.ditty_editor = {};
|
1655 |
-
$.ditty_editor.defaults = defaults;
|
1656 |
-
|
1657 |
-
} )( jQuery );
|
1658 |
-
|
1659 |
-
|
1660 |
-
/**
|
1661 |
-
* Ditty Editor Settings Panel
|
1662 |
-
*
|
1663 |
-
* @since 3.0
|
1664 |
-
* @return null
|
1665 |
-
*/
|
1666 |
-
|
1667 |
-
(function ($) {
|
1668 |
-
'use strict';
|
1669 |
-
|
1670 |
-
var defaults = {
|
1671 |
-
editor: null
|
1672 |
-
};
|
1673 |
-
|
1674 |
-
var Ditty_Settings_Panel = function ( elmt, options ) {
|
1675 |
-
this.elmt = elmt;
|
1676 |
-
this.settings = $.extend( {}, defaults, $.ditty_settings_panel.defaults, options );
|
1677 |
-
this.$elmt = $( elmt );
|
1678 |
-
this.$form = this.$elmt.find( '.ditty-editor-options' );
|
1679 |
-
this.$title = this.$elmt.find( 'input[name="title]' );
|
1680 |
-
this.$previewBg = this.$elmt.find( 'input[name="previewBg"]' );
|
1681 |
-
this.$previewPaddingTop = this.$elmt.find( 'input[name="previewPadding[paddingTop]"]' );
|
1682 |
-
this.$previewPaddingBottom = this.$elmt.find( 'input[name="previewPadding[paddingBottom]"]' );
|
1683 |
-
this.$previewPaddingLeft = this.$elmt.find( 'input[name="previewPadding[paddingLeft]"]' );
|
1684 |
-
this.$previewPaddingRight = this.$elmt.find( 'input[name="previewPadding[paddingRight]"]' );
|
1685 |
-
this.$postTitle = $( '.ditty-post__title' );
|
1686 |
-
this.$editorPreview = $( '#ditty-editor__preview' );
|
1687 |
-
this.dittyId = this.$form.data( 'ditty_id' );
|
1688 |
-
this.initData = null;
|
1689 |
-
this.afterUpdateAction = '';
|
1690 |
-
|
1691 |
-
this._init();
|
1692 |
-
};
|
1693 |
-
|
1694 |
-
|
1695 |
-
Ditty_Settings_Panel.prototype = {
|
1696 |
-
|
1697 |
-
/**
|
1698 |
-
* Initialize the panel
|
1699 |
-
*
|
1700 |
-
* @since 3.0
|
1701 |
-
* @return null
|
1702 |
-
*/
|
1703 |
-
_init: function () {
|
1704 |
-
|
1705 |
-
// Save the initial data
|
1706 |
-
this.initData = this.$form.serialize();
|
1707 |
-
|
1708 |
-
// Initialize dynamic fields
|
1709 |
-
this.settings.editor.initFields( this.$elmt );
|
1710 |
-
|
1711 |
-
// Add actions
|
1712 |
-
this.settings.editor.$elmt.on( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
1713 |
-
this.settings.editor.$elmt.on( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
1714 |
-
this.$form.on( 'submit', { self: this }, this._submitForm );
|
1715 |
-
this.$form.on( 'keyup change', 'input[type="text"], input[type="number"], textarea, select', { self: this }, this._checkUpdates );
|
1716 |
-
this.$form.on( 'click', 'input[type="radio"], input[type="checkbox"]', { self: this }, this._checkUpdates );
|
1717 |
-
this.$form.on( 'ditty_input_wysiwyg_update', '.ditty-input--wysiwyg', { self: this }, this._checkUpdates );
|
1718 |
-
this.$form.on( 'keyup change', 'input[name="title"]', { self: this }, this._titleChange );
|
1719 |
-
this.$form.on( 'keyup change', '.ditty-field--preview_settings *', { self: this }, this._previewBgChange );
|
1720 |
-
|
1721 |
-
this.$elmt.addClass( 'init' );
|
1722 |
-
},
|
1723 |
-
|
1724 |
-
/**
|
1725 |
-
* Check for updates
|
1726 |
-
*
|
1727 |
-
* @since 3.0
|
1728 |
-
* @return null
|
1729 |
-
*/
|
1730 |
-
_checkUpdates: function( e ) {
|
1731 |
-
var self = e ? e.data.self : this;
|
1732 |
-
var currentData = self.$form.serialize();
|
1733 |
-
if ( currentData !== self.initData ) {
|
1734 |
-
self.settings.editor.addUpdate( 'settings', self.itemId );
|
1735 |
-
self.settings.editor.delayedSubmitEnable(); // Enable the delayed submit since we have changes
|
1736 |
-
} else {
|
1737 |
-
self.settings.editor.removeUpdate( 'settings', self.itemId );
|
1738 |
-
}
|
1739 |
-
},
|
1740 |
-
|
1741 |
-
/**
|
1742 |
-
* Listen for title changes
|
1743 |
-
*
|
1744 |
-
* @since 3.0
|
1745 |
-
* @return null
|
1746 |
-
*/
|
1747 |
-
_titleChange: function( e ) {
|
1748 |
-
var self = e ? e.data.self : this;
|
1749 |
-
var title = $( e.target ).val();
|
1750 |
-
self.$postTitle.text( title );
|
1751 |
-
},
|
1752 |
-
|
1753 |
-
/**
|
1754 |
-
* Listen for the preview background change
|
1755 |
-
*
|
1756 |
-
* @since 3.0
|
1757 |
-
* @return null
|
1758 |
-
*/
|
1759 |
-
_previewBgChange: function( e ) {
|
1760 |
-
var self = e ? e.data.self : this;
|
1761 |
-
var preview_css = {
|
1762 |
-
backgroundColor : self.$previewBg.val(),
|
1763 |
-
paddingTop : self.$previewPaddingTop.val(),
|
1764 |
-
paddingBottom : self.$previewPaddingBottom.val(),
|
1765 |
-
paddingLeft : self.$previewPaddingLeft.val(),
|
1766 |
-
paddingRight : self.$previewPaddingRight.val()
|
1767 |
-
};
|
1768 |
-
self.$editorPreview.css( preview_css );
|
1769 |
-
},
|
1770 |
-
|
1771 |
-
/**
|
1772 |
-
* Editor updated listener
|
1773 |
-
*
|
1774 |
-
* @since 3.0
|
1775 |
-
* @return null
|
1776 |
-
*/
|
1777 |
-
_addDrafts: function( e ) {
|
1778 |
-
var self = e.data.self,
|
1779 |
-
currentData = self.$form.serialize();
|
1780 |
-
|
1781 |
-
if ( currentData !== self.initData ) {
|
1782 |
-
self.$form.trigger( 'submit' );
|
1783 |
-
}
|
1784 |
-
},
|
1785 |
-
|
1786 |
-
/**
|
1787 |
-
* Editor updated listener
|
1788 |
-
*
|
1789 |
-
* @since 3.0
|
1790 |
-
* @return null
|
1791 |
-
*/
|
1792 |
-
_saveDrafts: function( e ) {
|
1793 |
-
var self = e.data.self,
|
1794 |
-
currentData = self.$form.serialize();
|
1795 |
-
|
1796 |
-
if ( currentData !== self.initData ) {
|
1797 |
-
self.afterUpdateAction = 'save';
|
1798 |
-
self.$form.trigger( 'submit' );
|
1799 |
-
}
|
1800 |
-
},
|
1801 |
-
|
1802 |
-
/**
|
1803 |
-
* Submit updates
|
1804 |
-
*
|
1805 |
-
* @since 3.0
|
1806 |
-
* @return null
|
1807 |
-
*/
|
1808 |
-
_submitForm: function( e ) {
|
1809 |
-
e.preventDefault();
|
1810 |
-
var self = e.data.self,
|
1811 |
-
dittyId = self.dittyId;
|
1812 |
-
|
1813 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
1814 |
-
|
1815 |
-
var data = {
|
1816 |
-
action : 'ditty_editor_settings_update',
|
1817 |
-
ditty_id : dittyId,
|
1818 |
-
draft_values : self.settings.editor.getDraftValues(),
|
1819 |
-
security : dittyVars.security
|
1820 |
-
};
|
1821 |
-
self.$form.ajaxSubmit( {
|
1822 |
-
url : dittyVars.ajaxurl,
|
1823 |
-
type : 'post',
|
1824 |
-
dataType : 'json',
|
1825 |
-
data : data,
|
1826 |
-
success : function( response ) {
|
1827 |
-
self.initData = self.$form.serialize();
|
1828 |
-
dittyDraftUpdate( self, 'settings', false, response );
|
1829 |
-
self.settings.editor.delayedSubmitDisable(); // Remove the delayed submit since we just submitted
|
1830 |
-
if ( 'save' === self.afterUpdateAction ) { // Update the ticker
|
1831 |
-
self.settings.editor.saveDitty( { return_items: 0 } );
|
1832 |
-
}
|
1833 |
-
self.afterUpdateAction = '';
|
1834 |
-
}
|
1835 |
-
} );
|
1836 |
-
},
|
1837 |
-
|
1838 |
-
/**
|
1839 |
-
* Return a specific setting
|
1840 |
-
*
|
1841 |
-
* @since 3.0
|
1842 |
-
* @return null
|
1843 |
-
*/
|
1844 |
-
_options: function ( key ) {
|
1845 |
-
return this.settings[key];
|
1846 |
-
},
|
1847 |
-
|
1848 |
-
/**
|
1849 |
-
* Setup triggers
|
1850 |
-
*
|
1851 |
-
* @since 3.0
|
1852 |
-
* @return null
|
1853 |
-
*/
|
1854 |
-
trigger: function ( fn, customParams ) {
|
1855 |
-
var params = [this.settings];
|
1856 |
-
|
1857 |
-
if ( customParams ) {
|
1858 |
-
params = customParams;
|
1859 |
-
}
|
1860 |
-
|
1861 |
-
this.$elmt.trigger( 'ditty_settings_panel_' + fn, params );
|
1862 |
-
|
1863 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
1864 |
-
this.settings[fn].apply( this.$elmt, params );
|
1865 |
-
}
|
1866 |
-
},
|
1867 |
-
|
1868 |
-
/**
|
1869 |
-
* Allow settings to be modified
|
1870 |
-
*
|
1871 |
-
* @since 3.0
|
1872 |
-
* @return null
|
1873 |
-
*/
|
1874 |
-
options: function ( key, value ) {
|
1875 |
-
|
1876 |
-
if ( typeof key === 'object' ) {
|
1877 |
-
this.settings = $.extend( {}, defaults, $.ditty_settings_panel.defaults, key );
|
1878 |
-
} else if ( typeof key === 'string' ) {
|
1879 |
-
if ( value === undefined ) {
|
1880 |
-
return this.settings[key];
|
1881 |
-
}
|
1882 |
-
this.settings[key] = value;
|
1883 |
-
} else {
|
1884 |
-
return this.settings;
|
1885 |
-
}
|
1886 |
-
|
1887 |
-
this.trigger( 'options_update' );
|
1888 |
-
},
|
1889 |
-
|
1890 |
-
/**
|
1891 |
-
* Destroy the editor
|
1892 |
-
*
|
1893 |
-
* @since 3.0
|
1894 |
-
* @return null
|
1895 |
-
*/
|
1896 |
-
destroy: function () {
|
1897 |
-
|
1898 |
-
// Remove the init class
|
1899 |
-
this.$elmt.removeClass( 'init' );
|
1900 |
-
|
1901 |
-
// Remove actions
|
1902 |
-
this.settings.editor.$elmt.off( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
1903 |
-
this.settings.editor.$elmt.off( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
1904 |
-
this.$form.off( 'submit', { self: this }, this._submitForm );
|
1905 |
-
this.$form.off( 'keyup change', 'input[type="text"], input[type="number"], textarea, select', { self: this }, this._checkUpdates );
|
1906 |
-
this.$form.off( 'keyup change', 'input[name="previewBg"]', { self: this }, this._previewBg_cahnge );
|
1907 |
-
this.$form.off( 'keyup change', 'input[name="title"]', { self: this }, this._titleChange );
|
1908 |
-
this.$form.off( 'click', 'input[type="radio"], input[type="checkbox"]', { self: this }, this._checkUpdates );
|
1909 |
-
this.$form.off( 'ditty_input_wysiwyg_update', '.ditty-input--wysiwyg', { self: this }, this._checkUpdates );
|
1910 |
-
|
1911 |
-
this.trigger( 'destroy' );
|
1912 |
-
this.elmt._ditty_settings_panel = null;
|
1913 |
-
}
|
1914 |
-
};
|
1915 |
-
|
1916 |
-
/**
|
1917 |
-
* Create the data list
|
1918 |
-
*
|
1919 |
-
* @since 3.0
|
1920 |
-
* @return null
|
1921 |
-
*/
|
1922 |
-
$.fn.ditty_settings_panel = function( options ) {
|
1923 |
-
var args = arguments,
|
1924 |
-
error = false,
|
1925 |
-
returns;
|
1926 |
-
|
1927 |
-
if ( options === undefined || typeof options === 'object' ) {
|
1928 |
-
return this.each( function () {
|
1929 |
-
if ( ! this._ditty_settings_panel ) {
|
1930 |
-
this._ditty_settings_panel = new Ditty_Settings_Panel( this, options );
|
1931 |
-
}
|
1932 |
-
});
|
1933 |
-
} else if ( typeof options === 'string' ) {
|
1934 |
-
this.each( function () {
|
1935 |
-
var instance = this._ditty_settings_panel;
|
1936 |
-
|
1937 |
-
if ( ! instance ) {
|
1938 |
-
throw new Error( 'No Ditty_Settings_Panel applied to this element.' );
|
1939 |
-
}
|
1940 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
1941 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
1942 |
-
} else {
|
1943 |
-
error = true;
|
1944 |
-
}
|
1945 |
-
} );
|
1946 |
-
|
1947 |
-
if ( error ) {
|
1948 |
-
throw new Error( 'No method "' + options + '" in Ditty_Settings_Panel.' );
|
1949 |
-
}
|
1950 |
-
|
1951 |
-
return returns !== undefined ? returns : this;
|
1952 |
-
}
|
1953 |
-
};
|
1954 |
-
|
1955 |
-
$.ditty_settings_panel = {};
|
1956 |
-
$.ditty_settings_panel.defaults = defaults;
|
1957 |
-
|
1958 |
-
} )( jQuery );
|
1959 |
-
|
1960 |
-
|
1961 |
-
/**
|
1962 |
-
* Ditty Editor Items Panel
|
1963 |
-
*
|
1964 |
-
* @since 3.0
|
1965 |
-
* @return null
|
1966 |
-
*/
|
1967 |
-
|
1968 |
-
(function ($) {
|
1969 |
-
'use strict';
|
1970 |
-
|
1971 |
-
var defaults = {
|
1972 |
-
editor: null
|
1973 |
-
};
|
1974 |
-
|
1975 |
-
var Ditty_Items_Panel = function ( elmt, options ) {
|
1976 |
-
this.elmt = elmt;
|
1977 |
-
this.settings = $.extend( {}, defaults, $.ditty_items_panel.defaults, options );
|
1978 |
-
this.$elmt = $( elmt );
|
1979 |
-
this.$add = $( elmt ).find( '.ditty-editor-options__add' );
|
1980 |
-
this.$contents = $( elmt ).find( '.ditty-editor__panel__contents' );
|
1981 |
-
this.$list = $( elmt ).find( '.ditty-data-list' );
|
1982 |
-
this.$listItems = $( elmt ).find( '.ditty-data-list__items' );
|
1983 |
-
this.isEmptyTicker = false;
|
1984 |
-
|
1985 |
-
this._init();
|
1986 |
-
};
|
1987 |
-
|
1988 |
-
|
1989 |
-
Ditty_Items_Panel.prototype = {
|
1990 |
-
|
1991 |
-
/**
|
1992 |
-
* Initialize the panel
|
1993 |
-
*
|
1994 |
-
* @since 3.0
|
1995 |
-
* @return null
|
1996 |
-
*/
|
1997 |
-
_init: function () {
|
1998 |
-
this.$elmt.addClass( 'init' );
|
1999 |
-
|
2000 |
-
// Add actions
|
2001 |
-
this.settings.editor.$elmt.on( 'ditty_editor_aactive_items_update', { self: this }, this._dittyActiveItemsUpdated );
|
2002 |
-
this.$add.on( 'click', { self: this }, this._add_item );
|
2003 |
-
this.$elmt.on( 'click', '.ditty-data-list__item', { self: this }, this._showItem );
|
2004 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__icon', { self: this }, this._editType );
|
2005 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__edit', { self: this }, this._editItem );
|
2006 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__layout', { self: this }, this._editLayoutVariations );
|
2007 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__clone', { self: this }, this._cloneItem );
|
2008 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__delete', { self: this }, this._deleteItem );
|
2009 |
-
this.$list.on( 'click', '.ditty-editor-item > a', { self: this }, this._actionClick );
|
2010 |
-
$( 'body' ).on( 'ditty_editor_save_ditty_response', { self: this }, this._dittyEditorSaveResponse );
|
2011 |
-
|
2012 |
-
// Make sure there is at least one item
|
2013 |
-
if ( 1 > this.$elmt.find( '.ditty-data-list__item' ).length ) {
|
2014 |
-
this.isEmptyTicker = true;
|
2015 |
-
this.$add.trigger( 'click' );
|
2016 |
-
}
|
2017 |
-
|
2018 |
-
// Initialize list sorting
|
2019 |
-
this._initializeSorting();
|
2020 |
-
|
2021 |
-
// Highlight the current items
|
2022 |
-
this._highlightListItems( this.settings.editor.activeItems );
|
2023 |
-
},
|
2024 |
-
|
2025 |
-
/**
|
2026 |
-
* Update new layout ids on save
|
2027 |
-
*
|
2028 |
-
* @since 3.0
|
2029 |
-
* @return null
|
2030 |
-
*/
|
2031 |
-
dittyUpdateSavedDraftLayouts: function( draftId, newID ) {
|
2032 |
-
$.each( $( '.ditty-editor-item' ), function() {
|
2033 |
-
var layoutValue = $( this ).data( 'layout_value' );
|
2034 |
-
$.each( layoutValue, function( type, id ) {
|
2035 |
-
if ( String( id ) === String( draftId ) ) {
|
2036 |
-
layoutValue[type] = String( newID );
|
2037 |
-
}
|
2038 |
-
} );
|
2039 |
-
$( this ).attr( 'data-layout_value', layoutValue ).data( 'layout_value', layoutValue );
|
2040 |
-
} );
|
2041 |
-
},
|
2042 |
-
|
2043 |
-
/**
|
2044 |
-
* Update new item ids on save
|
2045 |
-
*
|
2046 |
-
* @since 3.0
|
2047 |
-
* @return null
|
2048 |
-
*/
|
2049 |
-
_dittyEditorSaveResponse: function( e, response ) {
|
2050 |
-
var self = e.data.self;
|
2051 |
-
if ( response.ditty_new_item_ids ) {
|
2052 |
-
$.each( response.ditty_new_item_ids, function( draftId, newId ) {
|
2053 |
-
var $editorItem = $( '#ditty-editor-item--' + draftId );
|
2054 |
-
if ( $editorItem.length ) {
|
2055 |
-
$editorItem.attr( 'id', 'ditty-editor-item--' + newId );
|
2056 |
-
$editorItem.attr( 'data-item_id', newId ).data( 'item_id', newId );
|
2057 |
-
}
|
2058 |
-
} );
|
2059 |
-
}
|
2060 |
-
if ( response.ditty_new_layout_ids ) {
|
2061 |
-
$.each( response.ditty_new_layout_ids, function( draftId, newID ) {
|
2062 |
-
self.dittyUpdateSavedDraftLayouts( draftId, newID );
|
2063 |
-
} );
|
2064 |
-
}
|
2065 |
-
},
|
2066 |
-
|
2067 |
-
/**
|
2068 |
-
* Highlight a list item
|
2069 |
-
*
|
2070 |
-
* @since 3.0
|
2071 |
-
* @return null
|
2072 |
-
*/
|
2073 |
-
_highlightListItem: function( item ) {
|
2074 |
-
var itemId = item.id + '';
|
2075 |
-
itemId = itemId.split( '_' );
|
2076 |
-
this.$elmt.find( '#ditty-editor-item--' + itemId[0] ).addClass( 'active' );
|
2077 |
-
},
|
2078 |
-
|
2079 |
-
/**
|
2080 |
-
* Loop through the active items and highlight
|
2081 |
-
*
|
2082 |
-
* @since 3.0
|
2083 |
-
* @return null
|
2084 |
-
*/
|
2085 |
-
_highlightListItems: function( items ) {
|
2086 |
-
this.$elmt.find( '.ditty-data-list__item' ).removeClass( 'active' );
|
2087 |
-
var self = this;
|
2088 |
-
if ( Array.isArray( items ) ) {
|
2089 |
-
$.each( items, function( i, item ) {
|
2090 |
-
self._highlightListItem( item );
|
2091 |
-
});
|
2092 |
-
} else {
|
2093 |
-
self._highlightListItem( items );
|
2094 |
-
}
|
2095 |
-
},
|
2096 |
-
|
2097 |
-
/**
|
2098 |
-
* Update the highlighted items when active
|
2099 |
-
*
|
2100 |
-
* @since 3.0
|
2101 |
-
* @return null
|
2102 |
-
*/
|
2103 |
-
_dittyActiveItemsUpdated: function( e, ditty, items ) {
|
2104 |
-
var self = e.data.self;
|
2105 |
-
self._highlightListItems( items );
|
2106 |
-
},
|
2107 |
-
|
2108 |
-
/**
|
2109 |
-
* Initialize item sorting
|
2110 |
-
*
|
2111 |
-
* @since 3.0
|
2112 |
-
* @return null
|
2113 |
-
*/
|
2114 |
-
_initializeSorting: function() {
|
2115 |
-
var self = this;
|
2116 |
-
this.$listItems.sortable( {
|
2117 |
-
handle: '.ditty-data-list__item__move',
|
2118 |
-
items: '.ditty-data-list__item',
|
2119 |
-
axis: 'y',
|
2120 |
-
start: function( event, ui ) {
|
2121 |
-
var $item = $( ui.item );
|
2122 |
-
$item.addClass( 'ditty-data-list__item--moving' );
|
2123 |
-
},
|
2124 |
-
stop: function( event, ui ) {
|
2125 |
-
var $item = $( ui.item );
|
2126 |
-
$item.removeClass( 'ditty-data-list__item--moving' );
|
2127 |
-
self.settings.editor.addUpdate( 'item_order', self.settings.editor.dittyId ); // Add to the update queue
|
2128 |
-
},
|
2129 |
-
update: function() {
|
2130 |
-
self._updateItemIndexes( 'updateDitty' );
|
2131 |
-
}
|
2132 |
-
} );
|
2133 |
-
},
|
2134 |
-
|
2135 |
-
/**
|
2136 |
-
* Show a specific item
|
2137 |
-
*
|
2138 |
-
* @since 3.0
|
2139 |
-
* @return null
|
2140 |
-
*/
|
2141 |
-
_showItem: function( e ) {
|
2142 |
-
e.preventDefault();
|
2143 |
-
var self = e.data.self;
|
2144 |
-
if ( ! $( e.target ).is( 'a' ) && ! $( e.target ).parent().is( 'a' ) ) {
|
2145 |
-
var $item = $( e.target ).is( '.ditty-data-list__item' ) ? $( e.target ) : $( e.target ).parents( '.ditty-data-list__item' ),
|
2146 |
-
itemId = $item.data( 'item_id' );
|
2147 |
-
|
2148 |
-
// Update the display element
|
2149 |
-
self.settings.editor.ditty.showItem( itemId );
|
2150 |
-
}
|
2151 |
-
},
|
2152 |
-
|
2153 |
-
/**
|
2154 |
-
* Trigger an actions when a button is clicked
|
2155 |
-
*
|
2156 |
-
* @since 3.0
|
2157 |
-
* @return null
|
2158 |
-
*/
|
2159 |
-
_actionClick: function( e ) {
|
2160 |
-
e.preventDefault();
|
2161 |
-
var self = e.data.self,
|
2162 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
2163 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
2164 |
-
dittyId = $item.data( 'ditty_id' ),
|
2165 |
-
itemId = $item.data( 'item_id' );
|
2166 |
-
|
2167 |
-
dittyVars.editor.currentItem = $item; // Set the current item
|
2168 |
-
|
2169 |
-
$( 'body' ).trigger( 'ditty_editor_item_action_click', [$button, $item, itemId, dittyId, self.settings.editor] );
|
2170 |
-
},
|
2171 |
-
|
2172 |
-
/**
|
2173 |
-
* Edit a item type
|
2174 |
-
*
|
2175 |
-
* @since 3.0
|
2176 |
-
* @return null
|
2177 |
-
*/
|
2178 |
-
_editType: function( e ) {
|
2179 |
-
e.preventDefault();
|
2180 |
-
var self = e.data.self;
|
2181 |
-
|
2182 |
-
var $button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
2183 |
-
$item = $button.parents( '.ditty-data-list__item' );
|
2184 |
-
|
2185 |
-
$item.trigger( 'click' );
|
2186 |
-
$item.addClass( 'editing' );
|
2187 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
2188 |
-
self.settings.editor.panelOptions( 'transition', 'slideRight' );
|
2189 |
-
self.settings.editor.showPanel( 'item_types' );
|
2190 |
-
},
|
2191 |
-
|
2192 |
-
/**
|
2193 |
-
* Edit a item
|
2194 |
-
*
|
2195 |
-
* @since 3.0
|
2196 |
-
* @return null
|
2197 |
-
*/
|
2198 |
-
_editItem: function( e ) {
|
2199 |
-
e.preventDefault();
|
2200 |
-
var self = e.data.self;
|
2201 |
-
|
2202 |
-
var $button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
2203 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
2204 |
-
itemId = $item.data( 'item_id' );
|
2205 |
-
|
2206 |
-
$item.trigger( 'click' );
|
2207 |
-
$item.addClass( 'editing' );
|
2208 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
2209 |
-
|
2210 |
-
// var data = {
|
2211 |
-
// hook : 'ditty_editorItem_fields',
|
2212 |
-
// itemId : itemId,
|
2213 |
-
// };
|
2214 |
-
// ditty_editor_ajax( data, self );
|
2215 |
-
|
2216 |
-
// Load the item fields
|
2217 |
-
var data = {
|
2218 |
-
action : 'ditty_editor_item_fields',
|
2219 |
-
item_id : itemId,
|
2220 |
-
draft_values : self.settings.editor.getDraftValues(),
|
2221 |
-
security : dittyVars.security
|
2222 |
-
};
|
2223 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
2224 |
-
if ( response ) {
|
2225 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--item_editor">' + response + '</div>';
|
2226 |
-
self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
2227 |
-
self.settings.editor.showPanel( 'item_editor', html );
|
2228 |
-
}
|
2229 |
-
} );
|
2230 |
-
},
|
2231 |
-
|
2232 |
-
// _ditty_editorItem_fields: function( e, data ) {
|
2233 |
-
// var self = e.data.self;
|
2234 |
-
// if ( data.html ) {
|
2235 |
-
// var html = '<div class="ditty-editor__panel ditty-editor__panel--item_editor">' + data.html + '</div>';
|
2236 |
-
// self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
2237 |
-
// self.settings.editor.showPanel( 'item_editor', html );
|
2238 |
-
// }
|
2239 |
-
// },
|
2240 |
-
|
2241 |
-
/**
|
2242 |
-
* Edit a item layout variation
|
2243 |
-
*
|
2244 |
-
* @since 3.0
|
2245 |
-
* @return null
|
2246 |
-
*/
|
2247 |
-
_editLayoutVariations: function( e ) {
|
2248 |
-
e.preventDefault();
|
2249 |
-
var self = e.data.self;
|
2250 |
-
|
2251 |
-
var $button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
2252 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
2253 |
-
itemType = $item.data( 'item_type' ),
|
2254 |
-
layoutValue = $item.data( 'layout_value' ),
|
2255 |
-
itemLabel = $item.find( '.ditty-data-list__item__label' ).html();
|
2256 |
-
|
2257 |
-
$item.trigger( 'click' );
|
2258 |
-
$item.addClass( 'editing' );
|
2259 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
2260 |
-
|
2261 |
-
// Load the item fields
|
2262 |
-
var data = {
|
2263 |
-
action : 'ditty_editor_layout_variations',
|
2264 |
-
ditty_id : self.settings.editor.dittyId,
|
2265 |
-
item_type : itemType,
|
2266 |
-
item_label : itemLabel,
|
2267 |
-
layout_value : layoutValue,
|
2268 |
-
draft_values : self.settings.editor.getDraftValues(),
|
2269 |
-
security : dittyVars.security
|
2270 |
-
};
|
2271 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
2272 |
-
if ( response ) {
|
2273 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--layout-variations">' + response + '</div>';
|
2274 |
-
self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
2275 |
-
self.settings.editor.showPanel( 'layout_variations', html );
|
2276 |
-
}
|
2277 |
-
} );
|
2278 |
-
},
|
2279 |
-
|
2280 |
-
/**
|
2281 |
-
* Add a new item
|
2282 |
-
*
|
2283 |
-
* @since 3.0
|
2284 |
-
* @return null
|
2285 |
-
*/
|
2286 |
-
_add_item: function( e ) {
|
2287 |
-
e.preventDefault();
|
2288 |
-
var self = e.data.self,
|
2289 |
-
dittyId = self.settings.editor.dittyId;
|
2290 |
-
|
2291 |
-
//self.settings.editor.updateStart(); // Start the update overlay
|
2292 |
-
|
2293 |
-
// Load the new display fields
|
2294 |
-
var data = {
|
2295 |
-
action : 'ditty_editor_item_add',
|
2296 |
-
ditty_id : dittyId,
|
2297 |
-
draft_values : self.settings.editor.getDraftValues(),
|
2298 |
-
security : dittyVars.security
|
2299 |
-
};
|
2300 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
2301 |
-
if ( response.display_items ) {
|
2302 |
-
if ( self.isEmptyTicker ) {
|
2303 |
-
var placeholderItems = self.settings.editor.ditty.options( 'items' );
|
2304 |
-
$.each( placeholderItems, function( index, data ) {
|
2305 |
-
self.settings.editor.ditty.deleteItem( data.id );
|
2306 |
-
} );
|
2307 |
-
self.isEmptyTicker = false;
|
2308 |
-
}
|
2309 |
-
$.each( response.display_items, function( key, value ) {
|
2310 |
-
self.settings.editor.ditty.addItem( value, 0 );
|
2311 |
-
} );
|
2312 |
-
}
|
2313 |
-
if ( response.editor_item ) {
|
2314 |
-
var $new = $( response.editor_item );
|
2315 |
-
$new.hide();
|
2316 |
-
self.$listItems.prepend( $new );
|
2317 |
-
$new.slideDown();
|
2318 |
-
self._updateItemIndexes();
|
2319 |
-
//self.settings.editor.addUpdate( 'item_add', value.id ); // Add to the update queue
|
2320 |
-
}
|
2321 |
-
if ( response.draft_id && response.draft_data ) {
|
2322 |
-
dittyDraftItemUpdateData( self, response.draft_id, null, response.draft_data );
|
2323 |
-
}
|
2324 |
-
if ( response.draft_id && response.draft_meta ) {
|
2325 |
-
dittyDraftItemUpdateMeta( self, response.draft_id, null, response.draft_meta );
|
2326 |
-
}
|
2327 |
-
//.settings.editor.updateStop(); // Stop the update overlay
|
2328 |
-
}, 'json' );
|
2329 |
-
},
|
2330 |
-
|
2331 |
-
/**
|
2332 |
-
* Clone a item
|
2333 |
-
*
|
2334 |
-
* @since 3.0
|
2335 |
-
* @return null
|
2336 |
-
*/
|
2337 |
-
_cloneItem: function( e ) {
|
2338 |
-
e.preventDefault();
|
2339 |
-
var self = e.data.self,
|
2340 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
2341 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
2342 |
-
itemId = $item.data( 'item_id' );
|
2343 |
-
|
2344 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
2345 |
-
|
2346 |
-
// Load the new display fields
|
2347 |
-
var data = {
|
2348 |
-
action : 'ditty_editor_item_clone',
|
2349 |
-
item_id : itemId,
|
2350 |
-
draft_values : self.settings.editor.getDraftValues(),
|
2351 |
-
security : dittyVars.security
|
2352 |
-
};
|
2353 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
2354 |
-
if ( response.display_items && response.display_items.length ) {
|
2355 |
-
self.settings.editor.ditty.updateItems( response.display_items, itemId, 'after' );
|
2356 |
-
}
|
2357 |
-
if ( response.editor_item ) {
|
2358 |
-
var $new = $( response.editor_item );
|
2359 |
-
$new.hide();
|
2360 |
-
$item.after( $new );
|
2361 |
-
$new.slideDown();
|
2362 |
-
self._updateItemIndexes();
|
2363 |
-
}
|
2364 |
-
if ( response.draft_id && response.draft_data ) {
|
2365 |
-
dittyDraftItemUpdateData( self, response.draft_id, null, response.draft_data );
|
2366 |
-
}
|
2367 |
-
if ( response.draft_id && response.draft_meta ) {
|
2368 |
-
dittyDraftItemUpdateMeta( self, response.draft_id, null, response.draft_meta );
|
2369 |
-
}
|
2370 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
2371 |
-
}, 'json' );
|
2372 |
-
},
|
2373 |
-
|
2374 |
-
/**
|
2375 |
-
* Delete a item
|
2376 |
-
*
|
2377 |
-
* @since 3.0
|
2378 |
-
* @return null
|
2379 |
-
*/
|
2380 |
-
_deleteItem: function( e ) {
|
2381 |
-
e.preventDefault();
|
2382 |
-
var self = e.data.self,
|
2383 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
2384 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
2385 |
-
itemId = $item.data( 'item_id' );
|
2386 |
-
|
2387 |
-
if ( 1 >= self.$elmt.find( '.ditty-data-list__item' ).length ) {
|
2388 |
-
self.$add.trigger( 'click' );
|
2389 |
-
}
|
2390 |
-
|
2391 |
-
// Remove the item from the editor and ditty
|
2392 |
-
$item.slideUp( function() {
|
2393 |
-
$( this ).remove();
|
2394 |
-
} );
|
2395 |
-
self.settings.editor.ditty.deleteItem( itemId );
|
2396 |
-
dittyDraftItemDelete( self, itemId ); // Remove the draft data
|
2397 |
-
},
|
2398 |
-
|
2399 |
-
/**
|
2400 |
-
* Update the item order
|
2401 |
-
*
|
2402 |
-
* @since 3.0
|
2403 |
-
* @return null
|
2404 |
-
*/
|
2405 |
-
_updateItemIndexes: function( action ) {
|
2406 |
-
var self = this,
|
2407 |
-
itemIds = [];
|
2408 |
-
|
2409 |
-
this.$elmt.find( '.ditty-data-list__item' ).each( function( index ) {
|
2410 |
-
var itemId = $( this ).data( 'item_id' );
|
2411 |
-
itemIds.push( itemId );
|
2412 |
-
dittyDraftItemUpdateData( self, itemId, 'item_index', index );
|
2413 |
-
} );
|
2414 |
-
|
2415 |
-
if ( 'updateDitty' === action ) {
|
2416 |
-
// Update the ditty with the new order
|
2417 |
-
var reorderedItems = dittyItemsReorder( self.settings.editor.ditty.options( 'items' ), itemIds );
|
2418 |
-
self.settings.editor.ditty.options( 'items', reorderedItems );
|
2419 |
-
}
|
2420 |
-
},
|
2421 |
-
|
2422 |
-
/**
|
2423 |
-
* Do actions when panel is visible
|
2424 |
-
*
|
2425 |
-
* @since 3.0
|
2426 |
-
* @return null
|
2427 |
-
*/
|
2428 |
-
panelVisible: function () {
|
2429 |
-
this.$elmt.find( '.ditty-data-list__item' ).removeClass( 'editing' );
|
2430 |
-
},
|
2431 |
-
|
2432 |
-
/**
|
2433 |
-
* Return a specific setting
|
2434 |
-
*
|
2435 |
-
* @since 3.0
|
2436 |
-
* @return null
|
2437 |
-
*/
|
2438 |
-
_options: function ( key ) {
|
2439 |
-
return this.settings[key];
|
2440 |
-
},
|
2441 |
-
|
2442 |
-
/**
|
2443 |
-
* Setup triggers
|
2444 |
-
*
|
2445 |
-
* @since 3.0
|
2446 |
-
* @return null
|
2447 |
-
*/
|
2448 |
-
trigger: function ( fn, customParams ) {
|
2449 |
-
var params = [this.settings];
|
2450 |
-
|
2451 |
-
if ( customParams ) {
|
2452 |
-
params = customParams;
|
2453 |
-
}
|
2454 |
-
|
2455 |
-
this.$elmt.trigger( 'ditty_items_panel_' + fn, params );
|
2456 |
-
|
2457 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
2458 |
-
this.settings[fn].apply( this.$elmt, params );
|
2459 |
-
}
|
2460 |
-
},
|
2461 |
-
|
2462 |
-
/**
|
2463 |
-
* Allow settings to be modified
|
2464 |
-
*
|
2465 |
-
* @since 3.0
|
2466 |
-
* @return null
|
2467 |
-
*/
|
2468 |
-
options: function ( key, value ) {
|
2469 |
-
|
2470 |
-
if ( typeof key === 'object' ) {
|
2471 |
-
this.settings = $.extend( {}, defaults, $.ditty_items_panel.defaults, key );
|
2472 |
-
} else if ( typeof key === 'string' ) {
|
2473 |
-
if ( value === undefined ) {
|
2474 |
-
return this.settings[key];
|
2475 |
-
}
|
2476 |
-
this.settings[key] = value;
|
2477 |
-
} else {
|
2478 |
-
return this.settings;
|
2479 |
-
}
|
2480 |
-
|
2481 |
-
this.trigger( 'options_update' );
|
2482 |
-
},
|
2483 |
-
|
2484 |
-
/**
|
2485 |
-
* Destroy the editor
|
2486 |
-
*
|
2487 |
-
* @since 3.0
|
2488 |
-
* @return null
|
2489 |
-
*/
|
2490 |
-
destroy: function () {
|
2491 |
-
|
2492 |
-
// Remove the init class
|
2493 |
-
this.$elmt.removeClass( 'init' );
|
2494 |
-
|
2495 |
-
// Remove actions
|
2496 |
-
this.settings.editor.$elmt.off( 'ditty_editor_active_items_update', { self: this }, this._dittyActiveItemsUpdated );
|
2497 |
-
this.$add.off( 'click', { self: this }, this._add_item );
|
2498 |
-
this.$elmt.off( 'click', '.ditty-data-list__item', { self: this }, this._showItem );
|
2499 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__icon', { self: this }, this._editType );
|
2500 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__edit', { self: this }, this._editItem );
|
2501 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__layout', { self: this }, this._editLayoutVariations );
|
2502 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__clone', { self: this }, this._cloneItem );
|
2503 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__delete', { self: this }, this._deleteItem );
|
2504 |
-
this.$list.off( 'click', '.ditty-editor-item > a', { self: this }, this._actionClick );
|
2505 |
-
$( 'body' ).off( 'ditty_editor_save_ditty_response', { self: this }, this._dittyEditorSaveResponse );
|
2506 |
-
|
2507 |
-
this.trigger( 'destroy' );
|
2508 |
-
this.elmt._ditty_items_panel = null;
|
2509 |
-
}
|
2510 |
-
};
|
2511 |
-
|
2512 |
-
/**
|
2513 |
-
* Create the data list
|
2514 |
-
*
|
2515 |
-
* @since 3.0
|
2516 |
-
* @return null
|
2517 |
-
*/
|
2518 |
-
$.fn.ditty_items_panel = function( options ) {
|
2519 |
-
var args = arguments,
|
2520 |
-
error = false,
|
2521 |
-
returns;
|
2522 |
-
|
2523 |
-
if ( options === undefined || typeof options === 'object' ) {
|
2524 |
-
return this.each( function () {
|
2525 |
-
if ( ! this._ditty_items_panel ) {
|
2526 |
-
this._ditty_items_panel = new Ditty_Items_Panel( this, options );
|
2527 |
-
}
|
2528 |
-
});
|
2529 |
-
} else if ( typeof options === 'string' ) {
|
2530 |
-
this.each( function () {
|
2531 |
-
var instance = this._ditty_items_panel;
|
2532 |
-
|
2533 |
-
if ( ! instance ) {
|
2534 |
-
throw new Error( 'No Ditty_Items_Panel applied to this element.' );
|
2535 |
-
}
|
2536 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
2537 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
2538 |
-
} else {
|
2539 |
-
error = true;
|
2540 |
-
}
|
2541 |
-
} );
|
2542 |
-
|
2543 |
-
if ( error ) {
|
2544 |
-
throw new Error( 'No method "' + options + '" in Ditty_Items_Panel.' );
|
2545 |
-
}
|
2546 |
-
|
2547 |
-
return returns !== undefined ? returns : this;
|
2548 |
-
}
|
2549 |
-
};
|
2550 |
-
|
2551 |
-
$.ditty_items_panel = {};
|
2552 |
-
$.ditty_items_panel.defaults = defaults;
|
2553 |
-
|
2554 |
-
} )( jQuery );
|
2555 |
-
|
2556 |
-
|
2557 |
-
/**
|
2558 |
-
* Ditty Editor
|
2559 |
-
*
|
2560 |
-
* @since 3.0
|
2561 |
-
* @return null
|
2562 |
-
*/
|
2563 |
-
|
2564 |
-
(function ($) {
|
2565 |
-
'use strict';
|
2566 |
-
|
2567 |
-
var defaults = {
|
2568 |
-
editor: null
|
2569 |
-
};
|
2570 |
-
|
2571 |
-
var Ditty_Item_Types_Panel = function ( elmt, options ) {
|
2572 |
-
|
2573 |
-
this.elmt = elmt;
|
2574 |
-
this.settings = $.extend( {}, defaults, $.ditty_item_types_panel.defaults, options );
|
2575 |
-
this.$elmt = $( elmt );
|
2576 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
2577 |
-
this.$editorItem = this.settings.editor.$panels.find( '.ditty-editor__panel--items' ).find( '.ditty-data-list__item.editing' );
|
2578 |
-
this.editorDittyId = this.$editorItem.data( 'ditty_id' );
|
2579 |
-
this.editorItemId = this.$editorItem.data( 'item_id' );
|
2580 |
-
this.currentType = null;
|
2581 |
-
|
2582 |
-
this._init();
|
2583 |
-
};
|
2584 |
-
|
2585 |
-
|
2586 |
-
Ditty_Item_Types_Panel.prototype = {
|
2587 |
-
|
2588 |
-
/**
|
2589 |
-
* Initialize the data list
|
2590 |
-
*
|
2591 |
-
* @since 3.0
|
2592 |
-
* @return null
|
2593 |
-
*/
|
2594 |
-
_init: function () {
|
2595 |
-
this.$elmt.addClass( 'init' );
|
2596 |
-
|
2597 |
-
// Initialize dynamic fields
|
2598 |
-
this.settings.editor.initFields( this.$elmt );
|
2599 |
-
|
2600 |
-
// Add actions
|
2601 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
2602 |
-
this.$elmt.on( 'click', '.ditty-editor-item-type', { self: this }, this._typeClick );
|
2603 |
-
|
2604 |
-
this.panelVisible();
|
2605 |
-
},
|
2606 |
-
|
2607 |
-
/**
|
2608 |
-
* Return to the item list
|
2609 |
-
*
|
2610 |
-
* @since 3.0
|
2611 |
-
* @return null
|
2612 |
-
*/
|
2613 |
-
_showItemsList: function() {
|
2614 |
-
this.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
2615 |
-
this.settings.editor.showPanel( 'items' );
|
2616 |
-
},
|
2617 |
-
|
2618 |
-
/**
|
2619 |
-
* Cancel click
|
2620 |
-
*
|
2621 |
-
* @since 3.0
|
2622 |
-
* @return null
|
2623 |
-
*/
|
2624 |
-
_backClick: function( e ) {
|
2625 |
-
e.preventDefault();
|
2626 |
-
var self = e.data.self;
|
2627 |
-
self._showItemsList();
|
2628 |
-
},
|
2629 |
-
|
2630 |
-
/**
|
2631 |
-
* Select a new type
|
2632 |
-
*
|
2633 |
-
* @since 3.0
|
2634 |
-
* @return null
|
2635 |
-
*/
|
2636 |
-
_typeClick: function( e ) {
|
2637 |
-
e.preventDefault();
|
2638 |
-
|
2639 |
-
var self = e.data.self,
|
2640 |
-
$item = $( e.target ).is( '.ditty-editor-item-type' ) ? $( e.target ) : $( e.target ).parents( '.ditty-editor-item-type' ),
|
2641 |
-
itemType = $item.data( 'item_type' );
|
2642 |
-
|
2643 |
-
if ( itemType === self.currentType ) {
|
2644 |
-
self._showItemsList(); // Show the display list
|
2645 |
-
} else {
|
2646 |
-
|
2647 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
2648 |
-
//dittyDraftItemUpdateData( self, self.editorItemId, 'item_type', itemType );
|
2649 |
-
|
2650 |
-
var data = {
|
2651 |
-
action : 'ditty_editor_item_type_update',
|
2652 |
-
item_id : self.editorItemId,
|
2653 |
-
item_type : itemType,
|
2654 |
-
draft_values : self.settings.editor.getDraftValues(),
|
2655 |
-
security : dittyVars.security
|
2656 |
-
};
|
2657 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
2658 |
-
if ( response.display_items ) {
|
2659 |
-
self.settings.editor.ditty.updateItems( response.display_items, self.editorItemId );
|
2660 |
-
}
|
2661 |
-
if ( response.editor_item ) {
|
2662 |
-
var $editorItem = $( response.editor_item );
|
2663 |
-
self.$editorItem.after( $editorItem );
|
2664 |
-
self.$editorItem.remove();
|
2665 |
-
self.$editorItem = $editorItem;
|
2666 |
-
}
|
2667 |
-
if ( response.draft_id && response.draft_data ) {
|
2668 |
-
dittyDraftItemUpdateData( self, response.draft_id, null, response.draft_data );
|
2669 |
-
}
|
2670 |
-
self._showItemsList(); // Show the display list
|
2671 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
2672 |
-
}, 'json' );
|
2673 |
-
}
|
2674 |
-
},
|
2675 |
-
|
2676 |
-
/**
|
2677 |
-
* Do actions when panel is visible
|
2678 |
-
*
|
2679 |
-
* @since 3.0
|
2680 |
-
* @return null
|
2681 |
-
*/
|
2682 |
-
panelVisible: function () {
|
2683 |
-
this.$editorItem = this.settings.editor.$panels.find( '.ditty-editor__panel--items' ).find( '.ditty-data-list__item.editing' );
|
2684 |
-
this.editorDittyId = this.$editorItem.data( 'ditty_id' );
|
2685 |
-
this.editorItemId = this.$editorItem.data( 'item_id' );
|
2686 |
-
this.currentType = this.$editorItem.data( 'item_type' );
|
2687 |
-
|
2688 |
-
this.$elmt.find( '.ditty-editor-item-type' ).removeClass( 'active' );
|
2689 |
-
this.$elmt.find( '.ditty-editor-item-type[data-itemType="' + this.currentType + '"]' ).addClass( 'active' );
|
2690 |
-
},
|
2691 |
-
|
2692 |
-
/**
|
2693 |
-
* Do actions when panel is hidden
|
2694 |
-
*
|
2695 |
-
* @since 3.0
|
2696 |
-
* @return null
|
2697 |
-
*/
|
2698 |
-
panelHidden: function () {
|
2699 |
-
var $editorItemIcon = this.$editorItem.find( '.ditty-data-list__item__icon' ).children( 'i' );
|
2700 |
-
$editorItemIcon.attr( 'class', $editorItemIcon.data( 'class' ) );
|
2701 |
-
},
|
2702 |
-
|
2703 |
-
/**
|
2704 |
-
* Return a specific setting
|
2705 |
-
*
|
2706 |
-
* @since 3.0
|
2707 |
-
* @return null
|
2708 |
-
*/
|
2709 |
-
_options: function ( key ) {
|
2710 |
-
return this.settings[key];
|
2711 |
-
},
|
2712 |
-
|
2713 |
-
/**
|
2714 |
-
* Setup triggers
|
2715 |
-
*
|
2716 |
-
* @since 3.0
|
2717 |
-
* @return null
|
2718 |
-
*/
|
2719 |
-
trigger: function ( fn, customParams ) {
|
2720 |
-
var params = [this.settings];
|
2721 |
-
if ( customParams ) {
|
2722 |
-
params = customParams;
|
2723 |
-
}
|
2724 |
-
|
2725 |
-
this.$elmt.trigger( 'ditty_item_types_panel_' + fn, params );
|
2726 |
-
|
2727 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
2728 |
-
this.settings[fn].apply( this.$elmt, params );
|
2729 |
-
}
|
2730 |
-
},
|
2731 |
-
|
2732 |
-
/**
|
2733 |
-
* Allow settings to be modified
|
2734 |
-
*
|
2735 |
-
* @since 3.0
|
2736 |
-
* @return null
|
2737 |
-
*/
|
2738 |
-
options: function ( key, value ) {
|
2739 |
-
|
2740 |
-
if ( typeof key === 'object' ) {
|
2741 |
-
this.settings = $.extend( {}, defaults, $.ditty_item_types_panel.defaults, key );
|
2742 |
-
} else if ( typeof key === 'string' ) {
|
2743 |
-
if ( value === undefined ) {
|
2744 |
-
return this.settings[key];
|
2745 |
-
}
|
2746 |
-
this.settings[key] = value;
|
2747 |
-
} else {
|
2748 |
-
return this.settings;
|
2749 |
-
}
|
2750 |
-
|
2751 |
-
this.trigger( 'options_update' );
|
2752 |
-
},
|
2753 |
-
|
2754 |
-
/**
|
2755 |
-
* Destroy the editor
|
2756 |
-
*
|
2757 |
-
* @since 3.0
|
2758 |
-
* @return null
|
2759 |
-
*/
|
2760 |
-
destroy: function () {
|
2761 |
-
|
2762 |
-
// Remove the init class
|
2763 |
-
this.$elmt.removeClass( 'init' );
|
2764 |
-
|
2765 |
-
// Remove actions
|
2766 |
-
this.$back.off( 'click', { self: this }, this._backClick );
|
2767 |
-
this.$elmt.off( 'click', '.ditty-editor-item-type', { self: this }, this._typeClick );
|
2768 |
-
|
2769 |
-
this.trigger( 'destroy' );
|
2770 |
-
this.elmt._ditty_item_types_panel = null;
|
2771 |
-
}
|
2772 |
-
};
|
2773 |
-
|
2774 |
-
/**
|
2775 |
-
* Create the data list
|
2776 |
-
*
|
2777 |
-
* @since 3.0
|
2778 |
-
* @return null
|
2779 |
-
*/
|
2780 |
-
$.fn.ditty_item_types_panel = function( options ) {
|
2781 |
-
var args = arguments,
|
2782 |
-
error = false,
|
2783 |
-
returns;
|
2784 |
-
|
2785 |
-
if ( options === undefined || typeof options === 'object' ) {
|
2786 |
-
return this.each( function () {
|
2787 |
-
if ( ! this._ditty_item_types_panel ) {
|
2788 |
-
this._ditty_item_types_panel = new Ditty_Item_Types_Panel( this, options );
|
2789 |
-
}
|
2790 |
-
});
|
2791 |
-
} else if ( typeof options === 'string' ) {
|
2792 |
-
this.each( function () {
|
2793 |
-
var instance = this._ditty_item_types_panel;
|
2794 |
-
|
2795 |
-
if ( ! instance ) {
|
2796 |
-
throw new Error( 'No Ditty_Item_Types_Panel applied to this element.' );
|
2797 |
-
}
|
2798 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
2799 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
2800 |
-
} else {
|
2801 |
-
error = true;
|
2802 |
-
}
|
2803 |
-
} );
|
2804 |
-
|
2805 |
-
if ( error ) {
|
2806 |
-
throw new Error( 'No method "' + options + '" in Ditty_Item_Types_Panel.' );
|
2807 |
-
}
|
2808 |
-
|
2809 |
-
return returns !== undefined ? returns : this;
|
2810 |
-
}
|
2811 |
-
};
|
2812 |
-
|
2813 |
-
$.ditty_item_types_panel = {};
|
2814 |
-
$.ditty_item_types_panel.defaults = defaults;
|
2815 |
-
|
2816 |
-
} )( jQuery );
|
2817 |
-
|
2818 |
-
|
2819 |
-
/**
|
2820 |
-
* Ditty Editor
|
2821 |
-
*
|
2822 |
-
* @since 3.0
|
2823 |
-
* @return null
|
2824 |
-
*/
|
2825 |
-
|
2826 |
-
(function ($) {
|
2827 |
-
'use strict';
|
2828 |
-
|
2829 |
-
var defaults = {
|
2830 |
-
editor: null
|
2831 |
-
};
|
2832 |
-
|
2833 |
-
var Ditty_Item_Editor_Panel = function ( elmt, options ) {
|
2834 |
-
|
2835 |
-
this.elmt = elmt;
|
2836 |
-
this.settings = $.extend( {}, defaults, $.ditty_item_editor_panel.defaults, options );
|
2837 |
-
this.$elmt = $( elmt );
|
2838 |
-
this.$form = this.$elmt.find( '.ditty-editor-options' );
|
2839 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
2840 |
-
this.$preview = this.$elmt.find( '.ditty-editor-options__preview' );
|
2841 |
-
this.$title = this.$elmt.find( '.ditty-editor-options__title' );
|
2842 |
-
this.itemId = this.$form.data( 'item_id' );
|
2843 |
-
this.itemType = this.$form.data( 'item_type' );
|
2844 |
-
this.dittyId = this.$form.data( 'ditty_id' );
|
2845 |
-
this.$editorItem = this.settings.editor.$panels.find( '.ditty-editor__panel--items' ).find( '.ditty-data-list__item.editing' );
|
2846 |
-
this.$editorItemTitle = this.$editorItem.find( '.ditty-data-list__item__label' );
|
2847 |
-
this.initData = null;
|
2848 |
-
this.afterUpdateAction = '';
|
2849 |
-
|
2850 |
-
this._init();
|
2851 |
-
};
|
2852 |
-
|
2853 |
-
|
2854 |
-
Ditty_Item_Editor_Panel.prototype = {
|
2855 |
-
|
2856 |
-
/**
|
2857 |
-
* Initialize the data list
|
2858 |
-
*
|
2859 |
-
* @since 3.0
|
2860 |
-
* @return null
|
2861 |
-
*/
|
2862 |
-
_init: function () {
|
2863 |
-
|
2864 |
-
// Save the initial data
|
2865 |
-
this.initData = this.$form.serialize();
|
2866 |
-
|
2867 |
-
// Initialize dynamic fields
|
2868 |
-
this.settings.editor.initFields( this.$elmt );
|
2869 |
-
|
2870 |
-
// Add actions
|
2871 |
-
this.settings.editor.$elmt.on( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
2872 |
-
this.settings.editor.$elmt.on( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
2873 |
-
this.$form.on( 'submit', { self: this }, this._submitForm );
|
2874 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
2875 |
-
this.$preview.on( 'click', { self: this }, this._previewClick );
|
2876 |
-
this.$form.on( 'keyup change', 'input[type="text"], input[type="number"], textarea, select', { self: this }, this._checkUpdates );
|
2877 |
-
this.$form.on( 'click', 'input[type="radio"], input[type="checkbox"]', { self: this }, this._checkUpdates );
|
2878 |
-
this.$form.on( 'ditty_input_wysiwyg_update', '.ditty-input--wysiwyg', { self: this }, this._checkUpdates );
|
2879 |
-
this.$form.on( 'ditty_field_update', '.ditty-field__input', { self: this }, this._checkUpdates );
|
2880 |
-
},
|
2881 |
-
|
2882 |
-
/**
|
2883 |
-
* Return to the item list
|
2884 |
-
*
|
2885 |
-
* @since 3.0
|
2886 |
-
* @return null
|
2887 |
-
*/
|
2888 |
-
_showItemList: function() {
|
2889 |
-
this.settings.editor.$panels.ditty_slider( 'options', 'transition', 'slideRight' );
|
2890 |
-
this.settings.editor.$panels.ditty_slider( 'showSlideById', 'items' );
|
2891 |
-
},
|
2892 |
-
|
2893 |
-
/**
|
2894 |
-
* Preview button add updates class
|
2895 |
-
*
|
2896 |
-
* @since 3.0
|
2897 |
-
* @return null
|
2898 |
-
*/
|
2899 |
-
_enablePreviewButton: function() {
|
2900 |
-
this.$preview.addClass( 'ditty-has-updates' );
|
2901 |
-
},
|
2902 |
-
|
2903 |
-
/**
|
2904 |
-
* Preview button remove updates class
|
2905 |
-
*
|
2906 |
-
* @since 3.0
|
2907 |
-
* @return null
|
2908 |
-
*/
|
2909 |
-
_disablePreviewButton: function() {
|
2910 |
-
this.$preview.removeClass( 'ditty-has-updates' );
|
2911 |
-
this.$preview.children( 'i' ).attr( 'class', this.$preview.children( 'i' ).data( 'class' ) );
|
2912 |
-
},
|
2913 |
-
|
2914 |
-
/**
|
2915 |
-
* Check for updates
|
2916 |
-
*
|
2917 |
-
* @since 3.0
|
2918 |
-
* @return null
|
2919 |
-
*/
|
2920 |
-
_checkUpdates: function( e ) {
|
2921 |
-
var self = e ? e.data.self : this;
|
2922 |
-
var currentData = self.$form.serialize();
|
2923 |
-
if ( currentData !== self.initData ) {
|
2924 |
-
self._enablePreviewButton();
|
2925 |
-
self.settings.editor.addUpdate( 'item_settings', self.itemId );
|
2926 |
-
self.settings.editor.delayedSubmitEnable(); // Enable the delayed submit since we have changes
|
2927 |
-
} else {
|
2928 |
-
self._disablePreviewButton();
|
2929 |
-
self.settings.editor.removeUpdate( 'item_settings', self.itemId );
|
2930 |
-
}
|
2931 |
-
},
|
2932 |
-
|
2933 |
-
/**
|
2934 |
-
* Editor tabs listener
|
2935 |
-
*
|
2936 |
-
* @since 3.0
|
2937 |
-
* @return null
|
2938 |
-
*/
|
2939 |
-
_addDrafts: function( e ) {
|
2940 |
-
var self = e.data.self,
|
2941 |
-
currentData = self.$form.serialize();
|
2942 |
-
|
2943 |
-
if ( currentData !== self.initData ) {
|
2944 |
-
self.$form.trigger( 'submit' );
|
2945 |
-
}
|
2946 |
-
},
|
2947 |
-
|
2948 |
-
/**
|
2949 |
-
* Editor updated listener
|
2950 |
-
*
|
2951 |
-
* @since 3.0
|
2952 |
-
* @return null
|
2953 |
-
*/
|
2954 |
-
_saveDrafts: function( e ) {
|
2955 |
-
var self = e.data.self,
|
2956 |
-
currentData = self.$form.serialize();
|
2957 |
-
|
2958 |
-
if ( currentData !== self.initData ) {
|
2959 |
-
self.afterUpdateAction = 'save';
|
2960 |
-
self.$form.trigger( 'submit' );
|
2961 |
-
}
|
2962 |
-
},
|
2963 |
-
|
2964 |
-
/**
|
2965 |
-
* Back click
|
2966 |
-
*
|
2967 |
-
* @since 3.0
|
2968 |
-
* @return null
|
2969 |
-
*/
|
2970 |
-
_backClick: function( e ) {
|
2971 |
-
e.preventDefault();
|
2972 |
-
var self = e.data.self,
|
2973 |
-
currentData = self.$form.serialize();
|
2974 |
-
|
2975 |
-
if ( currentData === self.initData ) {
|
2976 |
-
self._showItemList();
|
2977 |
-
} else {
|
2978 |
-
self.afterUpdateAction = 'return';
|
2979 |
-
self.$form.trigger( 'submit' );
|
2980 |
-
}
|
2981 |
-
},
|
2982 |
-
|
2983 |
-
/**
|
2984 |
-
* Preview any changes
|
2985 |
-
*
|
2986 |
-
* @since 3.0
|
2987 |
-
* @return null
|
2988 |
-
*/
|
2989 |
-
_previewClick: function( e ) {
|
2990 |
-
e.preventDefault();
|
2991 |
-
var self = e.data.self,
|
2992 |
-
currentData = self.$form.serialize();
|
2993 |
-
|
2994 |
-
if ( currentData !== self.initData ) {
|
2995 |
-
self.$preview.children( 'i' ).attr( 'class', dittyVars.updateIcon );
|
2996 |
-
self.$form.trigger( 'submit' );
|
2997 |
-
}
|
2998 |
-
},
|
2999 |
-
|
3000 |
-
/**
|
3001 |
-
* Submit updates
|
3002 |
-
*
|
3003 |
-
* @since 3.0
|
3004 |
-
* @return null
|
3005 |
-
*/
|
3006 |
-
_submitForm: function( e ) {
|
3007 |
-
e.preventDefault();
|
3008 |
-
var self = e.data.self,
|
3009 |
-
itemId = self.itemId;
|
3010 |
-
|
3011 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
3012 |
-
|
3013 |
-
var data = {
|
3014 |
-
action : 'ditty_editor_item_update',
|
3015 |
-
item_id : itemId,
|
3016 |
-
draft_values : self.settings.editor.getDraftValues(),
|
3017 |
-
security : dittyVars.security
|
3018 |
-
};
|
3019 |
-
self.$form.ajaxSubmit( {
|
3020 |
-
url : dittyVars.ajaxurl,
|
3021 |
-
type : 'post',
|
3022 |
-
dataType : 'json',
|
3023 |
-
data : data,
|
3024 |
-
error : function() {
|
3025 |
-
},
|
3026 |
-
success : function( response ) {
|
3027 |
-
if ( response.value_updates ) {
|
3028 |
-
self._updateValues( response.value_updates );
|
3029 |
-
}
|
3030 |
-
self.initData = self.$form.serialize();
|
3031 |
-
self._disablePreviewButton();
|
3032 |
-
|
3033 |
-
if ( response.display_items ) {
|
3034 |
-
self.settings.editor.ditty.updateItems( response.display_items, itemId );
|
3035 |
-
}
|
3036 |
-
if ( response.editor_item ) {
|
3037 |
-
var $item = $( response.editor_item ),
|
3038 |
-
itemTitle = $item.children( '.ditty-data-list__item__label' ).text();
|
3039 |
-
|
3040 |
-
// Set the new titles
|
3041 |
-
self.$title.html( itemTitle );
|
3042 |
-
self.$editorItemTitle.html( itemTitle );
|
3043 |
-
}
|
3044 |
-
if ( response.draft_id && response.draft_data ) {
|
3045 |
-
dittyDraftItemUpdateData( self, response.draft_id, null, response.draft_data );
|
3046 |
-
}
|
3047 |
-
if ( response.draft_id && response.draft_meta ) {
|
3048 |
-
dittyDraftItemUpdateMeta( self, response.draft_id, null, response.draft_meta );
|
3049 |
-
}
|
3050 |
-
|
3051 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
3052 |
-
self.settings.editor.delayedSubmitDisable(); // Remove the delayed submit since we just submitted
|
3053 |
-
|
3054 |
-
// Show the items list
|
3055 |
-
if ( 'return' === self.afterUpdateAction ) {
|
3056 |
-
self._showItemList();
|
3057 |
-
}
|
3058 |
-
// Update the Ditty
|
3059 |
-
if ( 'save' === self.afterUpdateAction ) {
|
3060 |
-
self.settings.editor.saveDitty( { return_items: 0 } );
|
3061 |
-
}
|
3062 |
-
self.afterUpdateAction = '';
|
3063 |
-
}
|
3064 |
-
} );
|
3065 |
-
},
|
3066 |
-
|
3067 |
-
/**
|
3068 |
-
* Update field values
|
3069 |
-
*
|
3070 |
-
* @since 3.0
|
3071 |
-
* @return null
|
3072 |
-
*/
|
3073 |
-
_updateValues: function ( data ) {
|
3074 |
-
var self = this;
|
3075 |
-
$.each( data, function( key, value ) {
|
3076 |
-
var $element = self.$form.find( '[name="' + key + '"]' );
|
3077 |
-
if ( $element.length ) {
|
3078 |
-
$element.val( value );
|
3079 |
-
}
|
3080 |
-
} );
|
3081 |
-
},
|
3082 |
-
|
3083 |
-
/**
|
3084 |
-
* Return a specific setting
|
3085 |
-
*
|
3086 |
-
* @since 3.0
|
3087 |
-
* @return null
|
3088 |
-
*/
|
3089 |
-
_options: function ( key ) {
|
3090 |
-
return this.settings[key];
|
3091 |
-
},
|
3092 |
-
|
3093 |
-
/**
|
3094 |
-
* Setup triggers
|
3095 |
-
*
|
3096 |
-
* @since 3.0
|
3097 |
-
* @return null
|
3098 |
-
*/
|
3099 |
-
trigger: function ( fn, customParams ) {
|
3100 |
-
var params = [this.settings];
|
3101 |
-
|
3102 |
-
if ( customParams ) {
|
3103 |
-
params = customParams;
|
3104 |
-
}
|
3105 |
-
|
3106 |
-
this.$elmt.trigger( 'ditty_item_editor_panel_' + fn, params );
|
3107 |
-
|
3108 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
3109 |
-
this.settings[fn].apply( this.$elmt, params );
|
3110 |
-
}
|
3111 |
-
},
|
3112 |
-
|
3113 |
-
/**
|
3114 |
-
* Allow settings to be modified
|
3115 |
-
*
|
3116 |
-
* @since 3.0
|
3117 |
-
* @return null
|
3118 |
-
*/
|
3119 |
-
options: function ( key, value ) {
|
3120 |
-
|
3121 |
-
if ( typeof key === 'object' ) {
|
3122 |
-
this.settings = $.extend( {}, defaults, $.ditty_item_editor_panel.defaults, key );
|
3123 |
-
} else if ( typeof key === 'string' ) {
|
3124 |
-
if ( value === undefined ) {
|
3125 |
-
return this.settings[key];
|
3126 |
-
}
|
3127 |
-
this.settings[key] = value;
|
3128 |
-
} else {
|
3129 |
-
return this.settings;
|
3130 |
-
}
|
3131 |
-
|
3132 |
-
this.trigger( 'options_update' );
|
3133 |
-
},
|
3134 |
-
|
3135 |
-
/**
|
3136 |
-
* Destroy the editor
|
3137 |
-
*
|
3138 |
-
* @since 3.0
|
3139 |
-
* @return null
|
3140 |
-
*/
|
3141 |
-
destroy: function () {
|
3142 |
-
|
3143 |
-
// Remove listeners
|
3144 |
-
this.settings.editor.$elmt.off( 'ditty_editor_add_drafts', { self: this }, this._saveDrafts );
|
3145 |
-
this.settings.editor.$elmt.off( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
3146 |
-
this.$form.off( 'submit', { self: this }, this._submitForm );
|
3147 |
-
this.$back.off( 'click', { self: this }, this._backClick );
|
3148 |
-
this.$preview.off( 'click', { self: this }, this._previewClick );
|
3149 |
-
this.$form.off( 'keyup change', 'input[type="text"], input[type="number"], textarea, select', { self: this }, this._checkUpdates );
|
3150 |
-
this.$form.off( 'click', 'input[type="radio"], input[type="checkbox"]', { self: this }, this._checkUpdates );
|
3151 |
-
this.$form.off( 'ditty_input_wysiwyg_update', '.ditty-input--wysiwyg', { self: this }, this._checkUpdates );
|
3152 |
-
this.$form.off( 'ditty_field_update', '.ditty-field__input', { self: this }, this._checkUpdates );
|
3153 |
-
|
3154 |
-
this.elmt._ditty_item_editor_panel = null;
|
3155 |
-
}
|
3156 |
-
};
|
3157 |
-
|
3158 |
-
/**
|
3159 |
-
* Create the data list
|
3160 |
-
*
|
3161 |
-
* @since 3.0
|
3162 |
-
* @return null
|
3163 |
-
*/
|
3164 |
-
$.fn.ditty_item_editor_panel = function( options ) {
|
3165 |
-
var args = arguments,
|
3166 |
-
error = false,
|
3167 |
-
returns;
|
3168 |
-
|
3169 |
-
if ( options === undefined || typeof options === 'object' ) {
|
3170 |
-
return this.each( function () {
|
3171 |
-
if ( ! this._ditty_item_editor_panel ) {
|
3172 |
-
this._ditty_item_editor_panel = new Ditty_Item_Editor_Panel( this, options );
|
3173 |
-
}
|
3174 |
-
});
|
3175 |
-
} else if ( typeof options === 'string' ) {
|
3176 |
-
this.each( function () {
|
3177 |
-
var instance = this._ditty_item_editor_panel;
|
3178 |
-
|
3179 |
-
if ( ! instance ) {
|
3180 |
-
throw new Error( 'No Ditty_Item_Editor_Panel applied to this element.' );
|
3181 |
-
}
|
3182 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
3183 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
3184 |
-
} else {
|
3185 |
-
error = true;
|
3186 |
-
}
|
3187 |
-
} );
|
3188 |
-
|
3189 |
-
if ( error ) {
|
3190 |
-
throw new Error( 'No method "' + options + '" in Ditty_Item_Editor_Panel.' );
|
3191 |
-
}
|
3192 |
-
|
3193 |
-
return returns !== undefined ? returns : this;
|
3194 |
-
}
|
3195 |
-
};
|
3196 |
-
|
3197 |
-
$.ditty_item_editor_panel = {};
|
3198 |
-
$.ditty_item_editor_panel.defaults = defaults;
|
3199 |
-
|
3200 |
-
} )( jQuery );
|
3201 |
-
|
3202 |
-
|
3203 |
-
/**
|
3204 |
-
* Ditty Displays Panel
|
3205 |
-
*
|
3206 |
-
* @since 3.0
|
3207 |
-
* @return null
|
3208 |
-
*/
|
3209 |
-
( function ( $ ) {
|
3210 |
-
'use strict';
|
3211 |
-
|
3212 |
-
var defaults = {
|
3213 |
-
editor: null
|
3214 |
-
};
|
3215 |
-
|
3216 |
-
var Ditty_Displays_Panel = function ( elmt, options ) {
|
3217 |
-
this.elmt = elmt;
|
3218 |
-
this.settings = $.extend( {}, defaults, $.ditty_displays_panel.defaults, options );
|
3219 |
-
this.$elmt = $( elmt );
|
3220 |
-
this.$list = $( elmt ).find( '.ditty-data-list__items' );
|
3221 |
-
this.$contents = $( elmt ).find( '.ditty-editor__panel__contents' );
|
3222 |
-
this.initDisplay = null;
|
3223 |
-
|
3224 |
-
this._init();
|
3225 |
-
};
|
3226 |
-
|
3227 |
-
|
3228 |
-
Ditty_Displays_Panel.prototype = {
|
3229 |
-
|
3230 |
-
/**
|
3231 |
-
* Initialize the panel
|
3232 |
-
*
|
3233 |
-
* @since 3.0
|
3234 |
-
* @return null
|
3235 |
-
*/
|
3236 |
-
_init: function () {
|
3237 |
-
this.$elmt.addClass( 'init' );
|
3238 |
-
|
3239 |
-
// Setup the display list
|
3240 |
-
this.$elmt.ditty_ui_data_list( {
|
3241 |
-
filter : '.ditty-display-panel__filter',
|
3242 |
-
item : '.ditty-editor-display',
|
3243 |
-
itemSelector : 'display_type'
|
3244 |
-
} );
|
3245 |
-
|
3246 |
-
// Activate the current layout
|
3247 |
-
this.initDisplay = this.$list.data( 'active' );
|
3248 |
-
this._activateDisplay( this.$list.find( '#ditty-editor-display--' + this.initDisplay ) );
|
3249 |
-
|
3250 |
-
// Add listeners
|
3251 |
-
this.$elmt.on( 'click', '.ditty-data-list__item', { self: this }, this._selectDisplay );
|
3252 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__edit', { self: this }, this._editDisplay );
|
3253 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__clone', { self: this }, this._cloneDisplay );
|
3254 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__delete', { self: this }, this._deleteDisplay );
|
3255 |
-
this.settings.editor.$elmt.on( 'ditty_editor_saveDrafts', { self: this }, this._saveDrafts );
|
3256 |
-
},
|
3257 |
-
|
3258 |
-
/**
|
3259 |
-
* Editor updated listener
|
3260 |
-
*
|
3261 |
-
* @since 3.0
|
3262 |
-
* @return null
|
3263 |
-
*/
|
3264 |
-
_saveDrafts: function( e ) {
|
3265 |
-
var self = e.data.self;
|
3266 |
-
self.initDisplay = self.$list.find( '.ditty-editor-display.active' ).data( 'display_id' );
|
3267 |
-
},
|
3268 |
-
|
3269 |
-
/**
|
3270 |
-
* Activate a display
|
3271 |
-
*
|
3272 |
-
* @since 3.0
|
3273 |
-
* @return null
|
3274 |
-
*/
|
3275 |
-
_activateDisplay: function ( $display ) {
|
3276 |
-
this.$list.find( '.ditty-editor-display' ).removeClass( 'active' );
|
3277 |
-
$display.addClass( 'active' );
|
3278 |
-
},
|
3279 |
-
|
3280 |
-
/**
|
3281 |
-
* Load a new display
|
3282 |
-
*
|
3283 |
-
* @since 3.0
|
3284 |
-
* @return null
|
3285 |
-
*/
|
3286 |
-
_initDitty: function( displayType, displayId, values ) {
|
3287 |
-
|
3288 |
-
var $elmnt = this.settings.editor.ditty.$elmt;
|
3289 |
-
|
3290 |
-
values.display = displayId;
|
3291 |
-
values.id = this.settings.editor.ditty.options( 'id' );
|
3292 |
-
values.items = this.settings.editor.ditty.options( 'items' );
|
3293 |
-
values.height = this.settings.editor.ditty.options( 'height' );
|
3294 |
-
|
3295 |
-
this.settings.editor.ditty.destroy();
|
3296 |
-
|
3297 |
-
// Setup the new ticker and overwrite ditty
|
3298 |
-
$elmnt['ditty_' + displayType]( values );
|
3299 |
-
this.settings.editor.ditty = $elmnt['ditty_' + displayType]( 'options', 'ditty' );
|
3300 |
-
},
|
3301 |
-
|
3302 |
-
/**
|
3303 |
-
* Load a new display
|
3304 |
-
*
|
3305 |
-
* @since 3.0
|
3306 |
-
* @return null
|
3307 |
-
*/
|
3308 |
-
_selectDisplay: function( e ) {
|
3309 |
-
e.preventDefault();
|
3310 |
-
var self = e.data.self;
|
3311 |
-
if ( $( e.target ).parent().is( 'a' ) ) {
|
3312 |
-
return false;
|
3313 |
-
}
|
3314 |
-
|
3315 |
-
var $display = $( e.target ).is( '.ditty-data-list__item' ) ? $( e.target ) : $( e.target ).parents( '.ditty-data-list__item' ),
|
3316 |
-
displayId = $display.data( 'display_id' ),
|
3317 |
-
displayType = $display.data( 'display_type' );
|
3318 |
-
|
3319 |
-
if ( $display.hasClass( 'active' ) ) {
|
3320 |
-
return false;
|
3321 |
-
}
|
3322 |
-
|
3323 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
3324 |
-
dittyDraftUpdate( self, 'post_meta', '_ditty_display', displayId );
|
3325 |
-
self._activateDisplay( $display );
|
3326 |
-
|
3327 |
-
// Load the new display data
|
3328 |
-
var data = {
|
3329 |
-
action : 'ditty_editor_select_display',
|
3330 |
-
display_id : displayId,
|
3331 |
-
draft_values : self.settings.editor.getDraftValues(),
|
3332 |
-
security : dittyVars.security
|
3333 |
-
};
|
3334 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
3335 |
-
if ( ! response ) {
|
3336 |
-
return false;
|
3337 |
-
}
|
3338 |
-
self._initDitty( displayType, displayId, response ); // Initialize a new ditty
|
3339 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
3340 |
-
}, 'json' );
|
3341 |
-
},
|
3342 |
-
|
3343 |
-
/**
|
3344 |
-
* Clone a display
|
3345 |
-
*
|
3346 |
-
* @since 3.0
|
3347 |
-
* @return null
|
3348 |
-
*/
|
3349 |
-
_cloneDisplay: function( e ) {
|
3350 |
-
e.preventDefault();
|
3351 |
-
var self = e.data.self,
|
3352 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
3353 |
-
$display = $button.parents( '.ditty-data-list__item' ),
|
3354 |
-
displayId = $display.data( 'display_id' );
|
3355 |
-
|
3356 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
3357 |
-
|
3358 |
-
// Load the new display fields
|
3359 |
-
var data = {
|
3360 |
-
action : 'ditty_editor_display_clone',
|
3361 |
-
display_id : displayId,
|
3362 |
-
draft_values : self.settings.editor.getDraftValues(),
|
3363 |
-
security : dittyVars.security
|
3364 |
-
};
|
3365 |
-
|
3366 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
3367 |
-
if ( response.editor_display ) {
|
3368 |
-
var $clone = $( response.editor_display );
|
3369 |
-
$clone.hide();
|
3370 |
-
$display.after( $clone );
|
3371 |
-
$clone.slideDown();
|
3372 |
-
}
|
3373 |
-
if ( response.draft_id && response.draft_data ) {
|
3374 |
-
dittyDraftDisplayUpdate( self, response.draft_id, null, response.draft_data );
|
3375 |
-
}
|
3376 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
3377 |
-
}, 'json' );
|
3378 |
-
},
|
3379 |
-
|
3380 |
-
/**
|
3381 |
-
* Delete a display
|
3382 |
-
*
|
3383 |
-
* @since 3.0
|
3384 |
-
* @return null
|
3385 |
-
*/
|
3386 |
-
_deleteDisplay: function( e ) {
|
3387 |
-
e.preventDefault();
|
3388 |
-
|
3389 |
-
var self = e.data.self,
|
3390 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
3391 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
3392 |
-
$nextItem = null,
|
3393 |
-
displayId = $item.data( 'display_id' );
|
3394 |
-
|
3395 |
-
// Find the display to load if this one is active
|
3396 |
-
if ( $item.hasClass( 'active' ) ) {
|
3397 |
-
if ( $item.prev().length ) {
|
3398 |
-
$nextItem = $item.prev();
|
3399 |
-
} else if ( $item.next().length ) {
|
3400 |
-
$nextItem = $item.next();
|
3401 |
-
}
|
3402 |
-
}
|
3403 |
-
|
3404 |
-
$item.slideUp( function() {
|
3405 |
-
$( this ).remove();
|
3406 |
-
} );
|
3407 |
-
dittyDraftDisplayDelete( self, displayId );
|
3408 |
-
|
3409 |
-
// Possibly select another display
|
3410 |
-
if ( null !== $nextItem ) {
|
3411 |
-
$nextItem.trigger( 'click' );
|
3412 |
-
}
|
3413 |
-
},
|
3414 |
-
|
3415 |
-
/**
|
3416 |
-
* Edit a display
|
3417 |
-
*
|
3418 |
-
* @since 3.0
|
3419 |
-
* @return null
|
3420 |
-
*/
|
3421 |
-
_editDisplay: function( e ) {
|
3422 |
-
e.preventDefault();
|
3423 |
-
var self = e.data.self;
|
3424 |
-
self.$displayEdit = $( this ).parents( '.ditty-data-list__item' );
|
3425 |
-
|
3426 |
-
var $button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
3427 |
-
$display = $button.parents( '.ditty-data-list__item' ),
|
3428 |
-
displayId = $display.data( 'display_id' );
|
3429 |
-
|
3430 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
3431 |
-
$display.addClass( 'editing' );
|
3432 |
-
|
3433 |
-
// Load the new display fields
|
3434 |
-
var data = {
|
3435 |
-
action : 'ditty_editor_display_fields',
|
3436 |
-
display_id : displayId,
|
3437 |
-
draft_values : self.settings.editor.getDraftValues(),
|
3438 |
-
security : dittyVars.security
|
3439 |
-
};
|
3440 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
3441 |
-
if ( response ) {
|
3442 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--displayEditor">' + response + '</div>';
|
3443 |
-
self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
3444 |
-
self.settings.editor.showPanel( 'display_editor', html );
|
3445 |
-
}
|
3446 |
-
} );
|
3447 |
-
},
|
3448 |
-
|
3449 |
-
/**
|
3450 |
-
* Do actions when panel is visible
|
3451 |
-
*
|
3452 |
-
* @since 3.0
|
3453 |
-
* @return null
|
3454 |
-
*/
|
3455 |
-
panelVisible: function () {
|
3456 |
-
this.$elmt.find( '.ditty-data-list__item' ).removeClass( 'editing' );
|
3457 |
-
},
|
3458 |
-
|
3459 |
-
/**
|
3460 |
-
* Setup triggers
|
3461 |
-
*
|
3462 |
-
* @since 3.0
|
3463 |
-
* @return null
|
3464 |
-
*/
|
3465 |
-
trigger: function ( fn, customParams ) {
|
3466 |
-
var params = [this.settings];
|
3467 |
-
if ( customParams ) {
|
3468 |
-
params = customParams;
|
3469 |
-
}
|
3470 |
-
|
3471 |
-
this.$elmt.trigger( 'ditty_displays_panel_' + fn, params );
|
3472 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
3473 |
-
this.settings[fn].apply( this.$elmt, params );
|
3474 |
-
}
|
3475 |
-
},
|
3476 |
-
|
3477 |
-
/**
|
3478 |
-
* Allow settings to be modified
|
3479 |
-
*
|
3480 |
-
* @since 3.0
|
3481 |
-
* @return null
|
3482 |
-
*/
|
3483 |
-
options: function ( key, value ) {
|
3484 |
-
if ( typeof key === 'object' ) {
|
3485 |
-
this.settings = $.extend( {}, defaults, $.ditty_displays_panel.defaults, key );
|
3486 |
-
} else if ( typeof key === 'string' ) {
|
3487 |
-
if ( value === undefined ) {
|
3488 |
-
return this.settings[key];
|
3489 |
-
}
|
3490 |
-
this.settings[key] = value;
|
3491 |
-
} else {
|
3492 |
-
return this.settings;
|
3493 |
-
}
|
3494 |
-
|
3495 |
-
this.trigger( 'options_update' );
|
3496 |
-
},
|
3497 |
-
|
3498 |
-
/**
|
3499 |
-
* Destroy the panel
|
3500 |
-
*
|
3501 |
-
* @since 3.0
|
3502 |
-
* @return null
|
3503 |
-
*/
|
3504 |
-
destroy: function () {
|
3505 |
-
|
3506 |
-
// Remove the init class
|
3507 |
-
this.$elmt.removeClass( 'init' );
|
3508 |
-
|
3509 |
-
// Destroy the display list
|
3510 |
-
this.$elmt.ditty_ui_data_list( 'destroy' );
|
3511 |
-
|
3512 |
-
// Remove listeners
|
3513 |
-
this.$elmt.off( 'click', '.ditty-data-list__item', { self: this }, this._selectDisplay );
|
3514 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__edit', { self: this }, this._editDisplay );
|
3515 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__clone', { self: this }, this._cloneDisplay );
|
3516 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__delete', { self: this }, this._deleteDisplay );
|
3517 |
-
this.settings.editor.$elmt.off( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
3518 |
-
|
3519 |
-
this.trigger( 'destroy' );
|
3520 |
-
this.elmt._ditty_displays_panel = null;
|
3521 |
-
}
|
3522 |
-
};
|
3523 |
-
|
3524 |
-
/**
|
3525 |
-
* Create the data list
|
3526 |
-
*
|
3527 |
-
* @since 3.0
|
3528 |
-
* @return null
|
3529 |
-
*/
|
3530 |
-
$.fn.ditty_displays_panel = function( options ) {
|
3531 |
-
var args = arguments,
|
3532 |
-
error = false,
|
3533 |
-
returns;
|
3534 |
-
|
3535 |
-
if ( options === undefined || typeof options === 'object' ) {
|
3536 |
-
return this.each( function () {
|
3537 |
-
if ( ! this._ditty_displays_panel ) {
|
3538 |
-
this._ditty_displays_panel = new Ditty_Displays_Panel( this, options );
|
3539 |
-
}
|
3540 |
-
});
|
3541 |
-
} else if ( typeof options === 'string' ) {
|
3542 |
-
this.each( function () {
|
3543 |
-
var instance = this._ditty_displays_panel;
|
3544 |
-
|
3545 |
-
if ( ! instance ) {
|
3546 |
-
throw new Error( 'No Ditty_Displays_Panel applied to this element.' );
|
3547 |
-
}
|
3548 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
3549 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
3550 |
-
} else {
|
3551 |
-
error = true;
|
3552 |
-
}
|
3553 |
-
} );
|
3554 |
-
|
3555 |
-
if ( error ) {
|
3556 |
-
throw new Error( 'No method "' + options + '" in Ditty_Displays_Panel.' );
|
3557 |
-
}
|
3558 |
-
|
3559 |
-
return returns !== undefined ? returns : this;
|
3560 |
-
}
|
3561 |
-
};
|
3562 |
-
|
3563 |
-
$.ditty_displays_panel = {};
|
3564 |
-
$.ditty_displays_panel.defaults = defaults;
|
3565 |
-
|
3566 |
-
} )( jQuery );
|
3567 |
-
|
3568 |
-
|
3569 |
-
/**
|
3570 |
-
* Ditty Display Editor Panel
|
3571 |
-
*
|
3572 |
-
* @since 3.0
|
3573 |
-
* @return null
|
3574 |
-
*/
|
3575 |
-
|
3576 |
-
(function ($) {
|
3577 |
-
'use strict';
|
3578 |
-
|
3579 |
-
var defaults = {
|
3580 |
-
editor: null
|
3581 |
-
};
|
3582 |
-
|
3583 |
-
var Ditty_Display_Editor_Panel = function ( elmt, options ) {
|
3584 |
-
|
3585 |
-
this.elmt = elmt;
|
3586 |
-
this.settings = $.extend( {}, defaults, $.ditty_display_editor_panel.defaults, options );
|
3587 |
-
this.$elmt = $( elmt );
|
3588 |
-
this.$form = this.$elmt.find( '.ditty-editor-options' );
|
3589 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
3590 |
-
this.$optionsTitle = this.$elmt.find( '.ditty-editor-options__title' );
|
3591 |
-
this.$importExportField = this.$elmt.find( '.ditty-editor__import-export__field' );
|
3592 |
-
this.$importExportUpdate = this.$elmt.find( '.ditty-editor__import-export__update' );
|
3593 |
-
this.displayTitle = null;
|
3594 |
-
this.displayId = this.settings.editor.ditty.options( 'display' );
|
3595 |
-
this.displayType = this.settings.editor.ditty.options( 'type' );
|
3596 |
-
this.$editorDisplay = this.settings.editor.$panels.find( '.ditty-editor__panel--displays' ).find( '.ditty-data-list__item.editing' );
|
3597 |
-
this.$editorDisplayTitle = this.$editorDisplay.find( '.ditty-data-list__item__label' );
|
3598 |
-
this.displayOptions = null;
|
3599 |
-
this.initData = null;
|
3600 |
-
this.afterUpdateAction = '';
|
3601 |
-
|
3602 |
-
this._init();
|
3603 |
-
};
|
3604 |
-
|
3605 |
-
|
3606 |
-
Ditty_Display_Editor_Panel.prototype = {
|
3607 |
-
|
3608 |
-
/**
|
3609 |
-
* Initialize the data list
|
3610 |
-
*
|
3611 |
-
* @since 3.0
|
3612 |
-
* @return null
|
3613 |
-
*/
|
3614 |
-
_init: function () {
|
3615 |
-
|
3616 |
-
var self = this,
|
3617 |
-
displayOptions;
|
3618 |
-
|
3619 |
-
// Save the initial data
|
3620 |
-
this.initData = this.$form.serialize();
|
3621 |
-
|
3622 |
-
// Initialize dynamic fields
|
3623 |
-
this.settings.editor.initFields( this.$elmt );
|
3624 |
-
|
3625 |
-
// Store the current ditty options
|
3626 |
-
displayOptions = this.settings.editor.ditty.$elmt['ditty_' + this.displayType]( 'options' );
|
3627 |
-
this.displayOptions = $.extend( {}, displayOptions );
|
3628 |
-
|
3629 |
-
this.displayTitle = this.$optionsTitle.val();
|
3630 |
-
|
3631 |
-
// Add actions
|
3632 |
-
this.$importExportUpdate.on( 'click', { self: this }, this._importUpdate );
|
3633 |
-
this.settings.editor.$elmt.on( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
3634 |
-
this.settings.editor.$elmt.on( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
3635 |
-
this.$form.on( 'submit', { self: this }, this._submitForm );
|
3636 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
3637 |
-
this.$elmt.on( 'change', 'input[type="text"], input[type="number"]', { self: this }, this._textfieldListeners );
|
3638 |
-
this.$form.on( 'click', 'input[type="radio"]', { self: this }, this._radioListeners );
|
3639 |
-
this.$form.on( 'click', 'input[type="checkbox"]', { self: this }, this._checkboxListeners );
|
3640 |
-
this.$form.on( 'change', 'select', { self: this }, this._selectListeners );
|
3641 |
-
this.$form.on( 'ditty_field_clone_update', { self: this }, this._cloneListeners );
|
3642 |
-
|
3643 |
-
// Trigger the init
|
3644 |
-
setTimeout( function() {
|
3645 |
-
self.trigger( 'init', [self] );
|
3646 |
-
}, 1 );
|
3647 |
-
},
|
3648 |
-
|
3649 |
-
/**
|
3650 |
-
* Return to the displays list
|
3651 |
-
*
|
3652 |
-
* @since 3.0
|
3653 |
-
* @return null
|
3654 |
-
*/
|
3655 |
-
_showDisplayList: function() {
|
3656 |
-
this.settings.editor.$panels.ditty_slider( 'options', 'transition', 'slideRight' );
|
3657 |
-
this.settings.editor.$panels.ditty_slider( 'showSlideById', 'displays' );
|
3658 |
-
},
|
3659 |
-
|
3660 |
-
/**
|
3661 |
-
* Check for updates
|
3662 |
-
*
|
3663 |
-
* @since 3.0
|
3664 |
-
* @return null
|
3665 |
-
*/
|
3666 |
-
_checkUpdates: function() {
|
3667 |
-
var currentData = this.$form.serialize();
|
3668 |
-
if ( currentData !== this.initData ) {
|
3669 |
-
this.settings.editor.addUpdate( 'displaySettings', this.displayId );
|
3670 |
-
this.settings.editor.delayedSubmitEnable(); // Enable the delayed submit since we have changes
|
3671 |
-
} else {
|
3672 |
-
this.settings.editor.removeUpdate( 'displaySettings', this.displayId );
|
3673 |
-
}
|
3674 |
-
},
|
3675 |
-
|
3676 |
-
/**
|
3677 |
-
* Editor tabs listener
|
3678 |
-
*
|
3679 |
-
* @since 3.0
|
3680 |
-
* @return null
|
3681 |
-
*/
|
3682 |
-
_addDrafts: function( e ) {
|
3683 |
-
var self = e.data.self,
|
3684 |
-
currentData = self.$form.serialize();
|
3685 |
-
|
3686 |
-
if ( currentData !== self.initData ) {
|
3687 |
-
self.$form.trigger( 'submit' );
|
3688 |
-
}
|
3689 |
-
},
|
3690 |
-
|
3691 |
-
/**
|
3692 |
-
* Editor updated listener
|
3693 |
-
*
|
3694 |
-
* @since 3.0
|
3695 |
-
* @return null
|
3696 |
-
*/
|
3697 |
-
_saveDrafts: function( e ) {
|
3698 |
-
var self = e.data.self,
|
3699 |
-
currentData = self.$form.serialize();
|
3700 |
-
|
3701 |
-
if ( currentData !== self.initData ) {
|
3702 |
-
self.afterUpdateAction = 'save';
|
3703 |
-
self.$form.trigger( 'submit' );
|
3704 |
-
}
|
3705 |
-
},
|
3706 |
-
|
3707 |
-
/**
|
3708 |
-
* Back click
|
3709 |
-
*
|
3710 |
-
* @since 3.0
|
3711 |
-
* @return null
|
3712 |
-
*/
|
3713 |
-
_backClick: function( e ) {
|
3714 |
-
e.preventDefault();
|
3715 |
-
var self = e.data.self,
|
3716 |
-
currentData = self.$form.serialize();
|
3717 |
-
|
3718 |
-
if ( currentData === self.initData ) {
|
3719 |
-
self._showDisplayList();
|
3720 |
-
} else {
|
3721 |
-
self.afterUpdateAction = 'return';
|
3722 |
-
self.$form.trigger( 'submit' );
|
3723 |
-
}
|
3724 |
-
},
|
3725 |
-
|
3726 |
-
/**
|
3727 |
-
* Cancel click
|
3728 |
-
*
|
3729 |
-
* @since 3.0
|
3730 |
-
* @return null
|
3731 |
-
*/
|
3732 |
-
_submitForm: function( e ) {
|
3733 |
-
e.preventDefault();
|
3734 |
-
var self = e.data.self;
|
3735 |
-
|
3736 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
3737 |
-
|
3738 |
-
var data = {
|
3739 |
-
action : 'ditty_editor_display_update',
|
3740 |
-
display_id : self.displayId,
|
3741 |
-
draft_values : self.settings.editor.getDraftValues(),
|
3742 |
-
security : dittyVars.security
|
3743 |
-
};
|
3744 |
-
self.$form.ajaxSubmit( {
|
3745 |
-
url : dittyVars.ajaxurl,
|
3746 |
-
type : 'post',
|
3747 |
-
dataType : 'json',
|
3748 |
-
data : data,
|
3749 |
-
success: function( response ) {
|
3750 |
-
self.initData = self.$form.serialize();
|
3751 |
-
|
3752 |
-
if ( response.draft_id && response.draft_label ) {
|
3753 |
-
self.displayTitle = response.draft_label;
|
3754 |
-
self.$editorDisplayTitle.text( response.draft_label );
|
3755 |
-
dittyDraftDisplayUpdate( self, response.draft_id, 'label', response.draft_label );
|
3756 |
-
}
|
3757 |
-
if ( response.draft_id && response.draft_settings ) {
|
3758 |
-
self.displayOptions = response.draft_settings;
|
3759 |
-
dittyDraftDisplayUpdate( self, response.draft_id, 'settings', response.draft_settings );
|
3760 |
-
}
|
3761 |
-
if ( response.draft_settings_json && self.$importExportField.length ) {
|
3762 |
-
self.$importExportField.val( response.draft_settings_json );
|
3763 |
-
}
|
3764 |
-
|
3765 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
3766 |
-
self.settings.editor.delayedSubmitDisable(); // Remove the delayed submit since we just submitted
|
3767 |
-
|
3768 |
-
// Show the display list
|
3769 |
-
if ( 'return' === self.afterUpdateAction ) {
|
3770 |
-
self._showDisplayList();
|
3771 |
-
}
|
3772 |
-
// Update the ticker
|
3773 |
-
if ( 'save' === self.afterUpdateAction ) {
|
3774 |
-
self.settings.editor.saveDitty();
|
3775 |
-
}
|
3776 |
-
self.afterUpdateAction = '';
|
3777 |
-
}
|
3778 |
-
} );
|
3779 |
-
},
|
3780 |
-
|
3781 |
-
/**
|
3782 |
-
* Update the imported values
|
3783 |
-
*
|
3784 |
-
* @since 3.0
|
3785 |
-
* @return null
|
3786 |
-
*/
|
3787 |
-
_importUpdate: function( e ) {
|
3788 |
-
e.preventDefault();
|
3789 |
-
|
3790 |
-
// var self = e.data.self,
|
3791 |
-
// values = self.$importExportField.val();
|
3792 |
-
},
|
3793 |
-
|
3794 |
-
/**
|
3795 |
-
* Listen for clone changes
|
3796 |
-
*
|
3797 |
-
* @since 3.0
|
3798 |
-
* @return null
|
3799 |
-
*/
|
3800 |
-
_cloneListeners: function( e, fieldData, cloneName ) {
|
3801 |
-
var self = e.data.self,
|
3802 |
-
$target = $( e.target );
|
3803 |
-
|
3804 |
-
self.settings.editor.ditty.options( cloneName, fieldData );
|
3805 |
-
},
|
3806 |
-
|
3807 |
-
/**
|
3808 |
-
* Listen for textfield changes
|
3809 |
-
*
|
3810 |
-
* @since 3.0
|
3811 |
-
* @return null
|
3812 |
-
*/
|
3813 |
-
_textfieldListeners: function( e ) {
|
3814 |
-
var self = e.data.self,
|
3815 |
-
$target = $( e.target ),
|
3816 |
-
name = $target.attr( 'name' ),
|
3817 |
-
$fieldset = $target.parents( '.ditty-input--spacing__group, .ditty-input--radius__group' );
|
3818 |
-
|
3819 |
-
if ( $fieldset.length ) {
|
3820 |
-
var fieldsetName = '',
|
3821 |
-
fieldsetValue = {};
|
3822 |
-
$fieldset.find( 'input').each( function() {
|
3823 |
-
name = $( this ).attr( 'name' );
|
3824 |
-
fieldsetName = name.split( '[' );
|
3825 |
-
fieldsetName = fieldsetName[0];
|
3826 |
-
var matches = name.match(/\[(.*)\]/);
|
3827 |
-
fieldsetValue[matches[1]] = $( this ).val();
|
3828 |
-
} );
|
3829 |
-
self.settings.editor.ditty.options( fieldsetName, fieldsetValue );
|
3830 |
-
} else {
|
3831 |
-
self.settings.editor.ditty.options( name, $target.val() );
|
3832 |
-
}
|
3833 |
-
self._checkUpdates();
|
3834 |
-
},
|
3835 |
-
|
3836 |
-
/**
|
3837 |
-
* Listen for radio button changes
|
3838 |
-
*
|
3839 |
-
* @since 3.0
|
3840 |
-
* @return null
|
3841 |
-
*/
|
3842 |
-
_radioListeners: function( e ) {
|
3843 |
-
var self = e.data.self,
|
3844 |
-
$target = $( e.target ),
|
3845 |
-
value = $target.val(),
|
3846 |
-
name = $target.attr( 'name' );
|
3847 |
-
|
3848 |
-
self.settings.editor.ditty.options( name, value );
|
3849 |
-
self._checkUpdates();
|
3850 |
-
},
|
3851 |
-
|
3852 |
-
/**
|
3853 |
-
* Listen for checkbox changes
|
3854 |
-
*
|
3855 |
-
* @since 3.0
|
3856 |
-
* @return null
|
3857 |
-
*/
|
3858 |
-
_checkboxListeners: function( e ) {
|
3859 |
-
var self = e.data.self,
|
3860 |
-
$target = $( e.target ),
|
3861 |
-
value = $target.is( ':checked' ) ? $( this ).val() : false,
|
3862 |
-
name = $target.attr( 'name' );
|
3863 |
-
|
3864 |
-
self.settings.editor.ditty.options( name, value );
|
3865 |
-
self._checkUpdates();
|
3866 |
-
},
|
3867 |
-
|
3868 |
-
/**
|
3869 |
-
* Listen for select changes
|
3870 |
-
*
|
3871 |
-
* @since 3.0
|
3872 |
-
* @return null
|
3873 |
-
*/
|
3874 |
-
_selectListeners: function( e ) {
|
3875 |
-
var self = e.data.self,
|
3876 |
-
$target = $( e.target ),
|
3877 |
-
value = $target.val(),
|
3878 |
-
name = $target.attr( 'name' );
|
3879 |
-
|
3880 |
-
self.settings.editor.ditty.options( name, value );
|
3881 |
-
self._checkUpdates();
|
3882 |
-
},
|
3883 |
-
|
3884 |
-
/**
|
3885 |
-
* Return a specific setting
|
3886 |
-
*
|
3887 |
-
* @since 3.0
|
3888 |
-
* @return null
|
3889 |
-
*/
|
3890 |
-
_options: function ( key ) {
|
3891 |
-
return this.settings[key];
|
3892 |
-
},
|
3893 |
-
|
3894 |
-
/**
|
3895 |
-
* Setup triggers
|
3896 |
-
*
|
3897 |
-
* @since 3.0
|
3898 |
-
* @return null
|
3899 |
-
*/
|
3900 |
-
trigger: function ( fn, customParams ) {
|
3901 |
-
var params = [this.settings];
|
3902 |
-
|
3903 |
-
if ( customParams ) {
|
3904 |
-
params = customParams;
|
3905 |
-
}
|
3906 |
-
|
3907 |
-
this.$elmt.trigger( 'ditty_display_editor_panel_' + fn, params );
|
3908 |
-
|
3909 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
3910 |
-
this.settings[fn].apply( this.$elmt, params );
|
3911 |
-
}
|
3912 |
-
},
|
3913 |
-
|
3914 |
-
|
3915 |
-
/**
|
3916 |
-
* Allow settings to be modified
|
3917 |
-
*
|
3918 |
-
* @since 3.0
|
3919 |
-
* @return null
|
3920 |
-
*/
|
3921 |
-
options: function ( key, value ) {
|
3922 |
-
|
3923 |
-
if ( typeof key === 'object' ) {
|
3924 |
-
this.settings = $.extend( {}, defaults, $.ditty_display_editor_panel.defaults, key );
|
3925 |
-
} else if ( typeof key === 'string' ) {
|
3926 |
-
if ( value === undefined ) {
|
3927 |
-
return this.settings[key];
|
3928 |
-
}
|
3929 |
-
this.settings[key] = value;
|
3930 |
-
} else {
|
3931 |
-
return this.settings;
|
3932 |
-
}
|
3933 |
-
|
3934 |
-
this.trigger( 'options_update' );
|
3935 |
-
},
|
3936 |
-
|
3937 |
-
|
3938 |
-
/**
|
3939 |
-
* Destroy the editor
|
3940 |
-
*
|
3941 |
-
* @since 3.0
|
3942 |
-
* @return null
|
3943 |
-
*/
|
3944 |
-
destroy: function () {
|
3945 |
-
|
3946 |
-
this.trigger( 'destroy', [this] );
|
3947 |
-
|
3948 |
-
// Remove actions
|
3949 |
-
this.$importExportUpdate.off( 'click', { this: this }, this._importUpdate );
|
3950 |
-
this.settings.editor.$elmt.off( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
3951 |
-
this.settings.editor.$elmt.off( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
3952 |
-
this.$form.off( 'submit', { this: this }, this._submitForm );
|
3953 |
-
this.$back.off( 'click', { this: this }, this._cancel_click );
|
3954 |
-
this.$elmt.off( 'change', 'input[type="text"], input[type="number"]', { self: this }, this._textfieldListeners );
|
3955 |
-
this.$form.off( 'click', 'input[type="radio"]', { self: this }, this._radioListeners );
|
3956 |
-
this.$form.off( 'click', 'input[type="checkbox"]', { self: this }, this._checkboxListeners );
|
3957 |
-
this.$form.off( 'change', 'select', { self: this }, this._selectListeners );
|
3958 |
-
this.$form.off( 'ditty_field_clone_update', { self: this }, this._cloneListeners );
|
3959 |
-
|
3960 |
-
this.elmt._ditty_display_editor_panel = null;
|
3961 |
-
}
|
3962 |
-
};
|
3963 |
-
|
3964 |
-
|
3965 |
-
/**
|
3966 |
-
* Create the data list
|
3967 |
-
*
|
3968 |
-
* @since 3.0
|
3969 |
-
* @return null
|
3970 |
-
*/
|
3971 |
-
$.fn.ditty_display_editor_panel = function( options ) {
|
3972 |
-
var args = arguments,
|
3973 |
-
error = false,
|
3974 |
-
returns;
|
3975 |
-
|
3976 |
-
if ( options === undefined || typeof options === 'object' ) {
|
3977 |
-
return this.each( function () {
|
3978 |
-
if ( ! this._ditty_display_editor_panel ) {
|
3979 |
-
this._ditty_display_editor_panel = new Ditty_Display_Editor_Panel( this, options );
|
3980 |
-
}
|
3981 |
-
});
|
3982 |
-
} else if ( typeof options === 'string' ) {
|
3983 |
-
this.each( function () {
|
3984 |
-
var instance = this._ditty_display_editor_panel;
|
3985 |
-
|
3986 |
-
if ( ! instance ) {
|
3987 |
-
throw new Error( 'No Ditty_Display_Editor_Panel applied to this element.' );
|
3988 |
-
}
|
3989 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
3990 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
3991 |
-
} else {
|
3992 |
-
error = true;
|
3993 |
-
}
|
3994 |
-
} );
|
3995 |
-
|
3996 |
-
if ( error ) {
|
3997 |
-
throw new Error( 'No method "' + options + '" in Ditty_Display_Editor_Panel.' );
|
3998 |
-
}
|
3999 |
-
|
4000 |
-
return returns !== undefined ? returns : this;
|
4001 |
-
}
|
4002 |
-
};
|
4003 |
-
|
4004 |
-
$.ditty_display_editor_panel = {};
|
4005 |
-
$.ditty_display_editor_panel.defaults = defaults;
|
4006 |
-
|
4007 |
-
} )( jQuery );
|
4008 |
-
|
4009 |
-
|
4010 |
-
/**
|
4011 |
-
* Ditty Layout Variations Panel
|
4012 |
-
*
|
4013 |
-
* @since 3.0
|
4014 |
-
* @return null
|
4015 |
-
*/
|
4016 |
-
( function ( $ ) {
|
4017 |
-
'use strict';
|
4018 |
-
|
4019 |
-
var defaults = {
|
4020 |
-
editor: null
|
4021 |
-
};
|
4022 |
-
|
4023 |
-
var Ditty_Layout_Variations_Panel = function ( elmt, options ) {
|
4024 |
-
this.elmt = elmt;
|
4025 |
-
this.settings = $.extend( {}, defaults, $.ditty_layout_variations_panel.defaults, options );
|
4026 |
-
this.$elmt = $( elmt );
|
4027 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
4028 |
-
this.$list = $( elmt ).find( '.ditty-data-list__items' );
|
4029 |
-
this.$editorItem = dittyVars.editor.currentItem;
|
4030 |
-
this.editorItemLabel = this.$editorItem.find( '.ditty-data-list__item__label' ).text();
|
4031 |
-
this.editorDittyId = this.$editorItem.data( 'ditty_id' );
|
4032 |
-
this.editorItemId = this.$editorItem.data( 'item_id' );
|
4033 |
-
this.editorItemType = this.$editorItem.data( 'item_type' );
|
4034 |
-
|
4035 |
-
this._init();
|
4036 |
-
};
|
4037 |
-
|
4038 |
-
|
4039 |
-
Ditty_Layout_Variations_Panel.prototype = {
|
4040 |
-
|
4041 |
-
/**
|
4042 |
-
* Initialize the panel
|
4043 |
-
*
|
4044 |
-
* @since 3.0
|
4045 |
-
* @return null
|
4046 |
-
*/
|
4047 |
-
_init: function () {
|
4048 |
-
this.$elmt.addClass( 'init' );
|
4049 |
-
|
4050 |
-
// Add actions
|
4051 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
4052 |
-
this.$elmt.on( 'click', '.ditty-layout-variation__change', { self: this }, this._changeTemplate );
|
4053 |
-
this.$elmt.on( 'click', '.ditty-layout-variation__edit_html', { self: this, editType: 'html' }, this._editLayout );
|
4054 |
-
this.$elmt.on( 'click', '.ditty-layout-variation__edit_css', { self: this, editType: 'css' }, this._editLayout );
|
4055 |
-
$( 'body' ).on( 'ditty_editor_save_ditty_response', { self: this }, this._dittyEditorSaveResponse );
|
4056 |
-
},
|
4057 |
-
|
4058 |
-
/**
|
4059 |
-
* Return to the item list
|
4060 |
-
*
|
4061 |
-
* @since 3.0
|
4062 |
-
* @return null
|
4063 |
-
*/
|
4064 |
-
_showItemList: function() {
|
4065 |
-
this.settings.editor.$panels.ditty_slider( 'options', 'transition', 'slideRight' );
|
4066 |
-
this.settings.editor.$panels.ditty_slider( 'showSlideById', 'items' );
|
4067 |
-
},
|
4068 |
-
|
4069 |
-
/**
|
4070 |
-
* Cancel click
|
4071 |
-
*
|
4072 |
-
* @since 3.0
|
4073 |
-
* @return null
|
4074 |
-
*/
|
4075 |
-
_backClick: function( e ) {
|
4076 |
-
e.preventDefault();
|
4077 |
-
var self = e.data.self;
|
4078 |
-
self._showItemList();
|
4079 |
-
},
|
4080 |
-
|
4081 |
-
/**
|
4082 |
-
* Update new item ids on save
|
4083 |
-
*
|
4084 |
-
* @since 3.0
|
4085 |
-
* @return null
|
4086 |
-
*/
|
4087 |
-
_dittyEditorSaveResponse: function( e, response ) {
|
4088 |
-
var self = e.data.self;
|
4089 |
-
if ( response.ditty_new_layout_ids ) {
|
4090 |
-
$.each( response.ditty_new_layout_ids, function( draftId, newId ) {
|
4091 |
-
var $variationItem = $( '.ditty-layout-variation[data-layout_id="' + draftId + '"]' );
|
4092 |
-
if ( $variationItem.length ) {
|
4093 |
-
$variationItem.attr( 'data-layout_id', newId ).data( 'layout_id', newId );
|
4094 |
-
}
|
4095 |
-
} );
|
4096 |
-
}
|
4097 |
-
},
|
4098 |
-
|
4099 |
-
/**
|
4100 |
-
* Load a new layout
|
4101 |
-
*
|
4102 |
-
* @since 3.0
|
4103 |
-
* @return null
|
4104 |
-
*/
|
4105 |
-
_changeTemplate: function( e ) {
|
4106 |
-
e.preventDefault();
|
4107 |
-
var self = e.data.self;
|
4108 |
-
|
4109 |
-
var $button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
4110 |
-
$layoutVariation = $button.parents( '.ditty-data-list__item' ),
|
4111 |
-
layoutId = $layoutVariation.data( 'layout_id' ),
|
4112 |
-
variationId = $layoutVariation.data( 'layout_variation_id' ),
|
4113 |
-
variationLabel = $layoutVariation.data( 'layout_variation_label' );
|
4114 |
-
|
4115 |
-
dittyVars.editor.currentLayoutVariation = $layoutVariation; // Set the current layout variation
|
4116 |
-
|
4117 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4118 |
-
$layoutVariation.addClass( 'editing' );
|
4119 |
-
|
4120 |
-
// Load the item fields
|
4121 |
-
var data = {
|
4122 |
-
action : 'ditty_editor_layouts',
|
4123 |
-
ditty_id : self.editorDittyId,
|
4124 |
-
item_type : self.editorItemType,
|
4125 |
-
variation_id : variationId,
|
4126 |
-
variation_label : variationLabel,
|
4127 |
-
layout_id : layoutId,
|
4128 |
-
draft_values : self.settings.editor.getDraftValues(),
|
4129 |
-
security : dittyVars.security
|
4130 |
-
};
|
4131 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
4132 |
-
if ( response ) {
|
4133 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--layouts">' + response + '</div>';
|
4134 |
-
self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
4135 |
-
self.settings.editor.showPanel( 'layouts', html );
|
4136 |
-
}
|
4137 |
-
} );
|
4138 |
-
},
|
4139 |
-
|
4140 |
-
/**
|
4141 |
-
* Edit the html or css of a layout
|
4142 |
-
*
|
4143 |
-
* @since 3.0
|
4144 |
-
* @return null
|
4145 |
-
*/
|
4146 |
-
_editLayout: function( e ) {
|
4147 |
-
e.preventDefault();
|
4148 |
-
var self = e.data.self,
|
4149 |
-
editType = e.data.editType,
|
4150 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
4151 |
-
$layoutVariation = $button.parents( '.ditty-data-list__item' ),
|
4152 |
-
layoutId = $layoutVariation.data( 'layout_id' ),
|
4153 |
-
itemType = $layoutVariation.data( 'item_type' );
|
4154 |
-
|
4155 |
-
dittyVars.editor.currentLayoutVariation = $layoutVariation; // Set the current layout variation
|
4156 |
-
|
4157 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4158 |
-
self.$list.find( '.ditty-data-list__item' ).removeClass( 'editing' );
|
4159 |
-
$layoutVariation.addClass( 'editing' );
|
4160 |
-
|
4161 |
-
var itemIds = [],
|
4162 |
-
items = self.settings.editor.ditty.options( 'items' );
|
4163 |
-
|
4164 |
-
$.each( items, function( index, item ) {
|
4165 |
-
itemIds.push( item.uniqId );
|
4166 |
-
} );
|
4167 |
-
|
4168 |
-
// Load the new display fields
|
4169 |
-
var data = {
|
4170 |
-
action : 'ditty_editor_layout_fields',
|
4171 |
-
layout_id : layoutId,
|
4172 |
-
item_type : itemType,
|
4173 |
-
ditty_id : self.editorDittyId,
|
4174 |
-
item_id : self.editorItemId,
|
4175 |
-
item_ids : itemIds,
|
4176 |
-
edit_type : editType,
|
4177 |
-
draft_values : self.settings.editor.getDraftValues(),
|
4178 |
-
security : dittyVars.security
|
4179 |
-
};
|
4180 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
4181 |
-
if ( response ) {
|
4182 |
-
var slideId = 'layout_' + editType + '_editor',
|
4183 |
-
html = '<div class="ditty-editor__panel ditty-editor__panel--' + slideId + '">' + response.form + '</div>';
|
4184 |
-
|
4185 |
-
self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
4186 |
-
self.settings.editor.showPanel( slideId, html );
|
4187 |
-
}
|
4188 |
-
}, 'json' );
|
4189 |
-
},
|
4190 |
-
|
4191 |
-
/**
|
4192 |
-
* Do actions when panel is visible
|
4193 |
-
*
|
4194 |
-
* @since 3.0
|
4195 |
-
* @return null
|
4196 |
-
*/
|
4197 |
-
panelVisible: function () {
|
4198 |
-
this.$list.find( '.ditty-layout-variation' ).removeClass( 'editing' );
|
4199 |
-
},
|
4200 |
-
|
4201 |
-
/**
|
4202 |
-
* Setup triggers
|
4203 |
-
*
|
4204 |
-
* @since 3.0
|
4205 |
-
* @return null
|
4206 |
-
*/
|
4207 |
-
trigger: function ( fn, customParams ) {
|
4208 |
-
var params = [this.settings];
|
4209 |
-
if ( customParams ) {
|
4210 |
-
params = customParams;
|
4211 |
-
}
|
4212 |
-
|
4213 |
-
this.$elmt.trigger( 'ditty_layout_variations_panel_' + fn, params );
|
4214 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
4215 |
-
this.settings[fn].apply( this.$elmt, params );
|
4216 |
-
}
|
4217 |
-
},
|
4218 |
-
|
4219 |
-
/**
|
4220 |
-
* Allow settings to be modified
|
4221 |
-
*
|
4222 |
-
* @since 3.0
|
4223 |
-
* @return null
|
4224 |
-
*/
|
4225 |
-
options: function ( key, value ) {
|
4226 |
-
if ( typeof key === 'object' ) {
|
4227 |
-
this.settings = $.extend( {}, defaults, $.ditty_layout_variations_panel.defaults, key );
|
4228 |
-
} else if ( typeof key === 'string' ) {
|
4229 |
-
if ( value === undefined ) {
|
4230 |
-
return this.settings[key];
|
4231 |
-
}
|
4232 |
-
this.settings[key] = value;
|
4233 |
-
} else {
|
4234 |
-
return this.settings;
|
4235 |
-
}
|
4236 |
-
|
4237 |
-
this.trigger( 'options_update' );
|
4238 |
-
},
|
4239 |
-
|
4240 |
-
/**
|
4241 |
-
* Destroy the editor
|
4242 |
-
*
|
4243 |
-
* @since 3.0
|
4244 |
-
* @return null
|
4245 |
-
*/
|
4246 |
-
destroy: function () {
|
4247 |
-
this.$elmt.removeClass( 'init' );
|
4248 |
-
this.$back.off( 'click', { self: this }, this._backClick );
|
4249 |
-
this.$elmt.off( 'click', '.ditty-layout-variation__change', { self: this }, this._changeTemplate );
|
4250 |
-
this.$elmt.off( 'click', '.ditty-layout-variation__edit_html', { self: this, editType: 'html' }, this._editLayout );
|
4251 |
-
this.$elmt.off( 'click', '.ditty-layout-variation__edit_css', { self: this, editType: 'css' }, this._editLayout );
|
4252 |
-
$( 'body' ).off( 'ditty_editor_save_ditty_response', { self: this }, this._dittyEditorSaveResponse );
|
4253 |
-
|
4254 |
-
this.elmt._ditty_layout_variations_panel = null;
|
4255 |
-
}
|
4256 |
-
};
|
4257 |
-
|
4258 |
-
/**
|
4259 |
-
* Create the data list
|
4260 |
-
*
|
4261 |
-
* @since 3.0
|
4262 |
-
* @return null
|
4263 |
-
*/
|
4264 |
-
$.fn.ditty_layout_variations_panel = function( options ) {
|
4265 |
-
var args = arguments,
|
4266 |
-
error = false,
|
4267 |
-
returns;
|
4268 |
-
|
4269 |
-
if ( options === undefined || typeof options === 'object' ) {
|
4270 |
-
return this.each( function () {
|
4271 |
-
if ( ! this._ditty_layout_variations_panel ) {
|
4272 |
-
this._ditty_layout_variations_panel = new Ditty_Layout_Variations_Panel( this, options );
|
4273 |
-
}
|
4274 |
-
});
|
4275 |
-
} else if ( typeof options === 'string' ) {
|
4276 |
-
this.each( function () {
|
4277 |
-
var instance = this._ditty_layout_variations_panel;
|
4278 |
-
|
4279 |
-
if ( ! instance ) {
|
4280 |
-
throw new Error( 'No Ditty_Layout_Variations_Panel applied to this element.' );
|
4281 |
-
}
|
4282 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
4283 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
4284 |
-
} else {
|
4285 |
-
error = true;
|
4286 |
-
}
|
4287 |
-
} );
|
4288 |
-
|
4289 |
-
if ( error ) {
|
4290 |
-
throw new Error( 'No method "' + options + '" in Ditty_Layout_Variations_Panel.' );
|
4291 |
-
}
|
4292 |
-
|
4293 |
-
return returns !== undefined ? returns : this;
|
4294 |
-
}
|
4295 |
-
};
|
4296 |
-
|
4297 |
-
$.ditty_layout_variations_panel = {};
|
4298 |
-
$.ditty_layout_variations_panel.defaults = defaults;
|
4299 |
-
|
4300 |
-
} )( jQuery );
|
4301 |
-
|
4302 |
-
/**
|
4303 |
-
* Ditty Layouts Panel
|
4304 |
-
*
|
4305 |
-
* @since 3.0
|
4306 |
-
* @return null
|
4307 |
-
*/
|
4308 |
-
( function ( $ ) {
|
4309 |
-
'use strict';
|
4310 |
-
|
4311 |
-
var defaults = {
|
4312 |
-
editor: null
|
4313 |
-
};
|
4314 |
-
|
4315 |
-
var Ditty_Layouts_Panel = function ( elmt, options ) {
|
4316 |
-
this.elmt = elmt;
|
4317 |
-
this.settings = $.extend( {}, defaults, $.ditty_layouts_panel.defaults, options );
|
4318 |
-
this.$elmt = $( elmt );
|
4319 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
4320 |
-
this.$list = $( elmt ).find( '.ditty-data-list__items' );
|
4321 |
-
this.$editorItem = dittyVars.editor.currentItem;
|
4322 |
-
this.editorDittyId = this.$editorItem.data( 'ditty_id' );
|
4323 |
-
this.editorItemId = this.$editorItem.data( 'item_id' );
|
4324 |
-
this.editorItemtype = this.$editorItem.data( 'item_type' );
|
4325 |
-
this.$editorVariation = dittyVars.editor.currentLayoutVariation;
|
4326 |
-
this.editorVariationId = this.$editorVariation.data( 'layout_variation_id' );
|
4327 |
-
this.editorLayoutId = this.$editorVariation.data( 'layout_id' );
|
4328 |
-
this._init();
|
4329 |
-
};
|
4330 |
-
|
4331 |
-
|
4332 |
-
Ditty_Layouts_Panel.prototype = {
|
4333 |
-
|
4334 |
-
/**
|
4335 |
-
* Initialize the panel
|
4336 |
-
*
|
4337 |
-
* @since 3.0
|
4338 |
-
* @return null
|
4339 |
-
*/
|
4340 |
-
_init: function () {
|
4341 |
-
this.$elmt.addClass( 'init' );
|
4342 |
-
|
4343 |
-
// Add actions
|
4344 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
4345 |
-
this.$elmt.on( 'click', '.ditty-data-list__item', { self: this }, this._selectLayout );
|
4346 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__edit_html', { self: this, editType: 'html' }, this._editLayout );
|
4347 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__edit_css', { self: this, editType: 'css' }, this._editLayout );
|
4348 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__clone', { self: this }, this._cloneLayout );
|
4349 |
-
this.$elmt.on( 'click', '.ditty-data-list__item__delete', { self: this }, this._deleteLayout );
|
4350 |
-
this.$list.on( 'click', '.ditty-editor-layout > a', { self: this }, this._actionClick );
|
4351 |
-
$( 'body' ).on( 'ditty_editor_save_ditty_response', { self: this }, this._dittyEditorSaveResponse );
|
4352 |
-
|
4353 |
-
// Activate the current layout
|
4354 |
-
this._activateLayout( this.$list.find( '#ditty-editor-layout--' + this.editorLayoutId ) );
|
4355 |
-
},
|
4356 |
-
|
4357 |
-
/**
|
4358 |
-
* Activate a layout
|
4359 |
-
*
|
4360 |
-
* @since 3.0
|
4361 |
-
* @return null
|
4362 |
-
*/
|
4363 |
-
_activateLayout: function ( $layout ) {
|
4364 |
-
this.$list.find( '.ditty-editor-layout' ).removeClass( 'active' );
|
4365 |
-
$layout.addClass( 'active' );
|
4366 |
-
},
|
4367 |
-
|
4368 |
-
/**
|
4369 |
-
* Return to the item list
|
4370 |
-
*
|
4371 |
-
* @since 3.0
|
4372 |
-
* @return null
|
4373 |
-
*/
|
4374 |
-
_showVariationsList: function() {
|
4375 |
-
this.settings.editor.$panels.ditty_slider( 'options', 'transition', 'slideRight' );
|
4376 |
-
this.settings.editor.$panels.ditty_slider( 'showSlideById', 'layout_variations' );
|
4377 |
-
},
|
4378 |
-
|
4379 |
-
/**
|
4380 |
-
* Cancel click
|
4381 |
-
*
|
4382 |
-
* @since 3.0
|
4383 |
-
* @return null
|
4384 |
-
*/
|
4385 |
-
_backClick: function( e ) {
|
4386 |
-
e.preventDefault();
|
4387 |
-
var self = e.data.self;
|
4388 |
-
self._showVariationsList();
|
4389 |
-
},
|
4390 |
-
|
4391 |
-
/**
|
4392 |
-
* Update new item ids on save
|
4393 |
-
*
|
4394 |
-
* @since 3.0
|
4395 |
-
* @return null
|
4396 |
-
*/
|
4397 |
-
_dittyEditorSaveResponse: function( e, response ) {
|
4398 |
-
var self = e.data.self;
|
4399 |
-
if ( response.ditty_new_layout_ids ) {
|
4400 |
-
$.each( response.ditty_new_layout_ids, function( draftId, newId ) {
|
4401 |
-
var $editorItem = $( '#ditty-editor-layout--' + draftId );
|
4402 |
-
if ( $editorItem.length ) {
|
4403 |
-
$editorItem.attr( 'id', 'ditty-editor-layout--' + newId );
|
4404 |
-
$editorItem.attr( 'data-layout_id', newId ).data( 'layout_id', newId );
|
4405 |
-
}
|
4406 |
-
} );
|
4407 |
-
}
|
4408 |
-
},
|
4409 |
-
|
4410 |
-
/**
|
4411 |
-
* Update new layout ids on save
|
4412 |
-
*
|
4413 |
-
* @since 3.0
|
4414 |
-
* @return null
|
4415 |
-
*/
|
4416 |
-
// dittyUpdatedDraftLayouts: function( variationType, layoutId ) {
|
4417 |
-
// var self = this;
|
4418 |
-
//
|
4419 |
-
// $.each( $( '.ditty-editor-item' ), function() {
|
4420 |
-
// var itemID = $( this ).data( 'item_id' ),
|
4421 |
-
// itemType = $( this ).data( 'item_type' ),
|
4422 |
-
// layoutValue = $( this ).data( 'layout_value' );
|
4423 |
-
// $.each( layoutValue, function( type, id ) {
|
4424 |
-
// if ( String( itemType ) === String( self.editorItemtype ) && String( type ) === String( variationType ) ) {
|
4425 |
-
// layoutValue[type] = String( layoutId );
|
4426 |
-
// dittyDraftItemUpdateData( self, itemID, 'layout_value', layoutValue );
|
4427 |
-
// }
|
4428 |
-
// } );
|
4429 |
-
// } );
|
4430 |
-
// },
|
4431 |
-
|
4432 |
-
/**
|
4433 |
-
* Load a new layout
|
4434 |
-
*
|
4435 |
-
* @since 3.0
|
4436 |
-
* @return null
|
4437 |
-
*/
|
4438 |
-
_selectLayout: function( e ) {
|
4439 |
-
e.preventDefault();
|
4440 |
-
var self = e.data.self;
|
4441 |
-
if ( $( e.target ).parent().is( 'a' ) ) {
|
4442 |
-
return false;
|
4443 |
-
}
|
4444 |
-
|
4445 |
-
var $layout = $( e.target ).is( '.ditty-data-list__item' ) ? $( e.target ) : $( e.target ).parents( '.ditty-data-list__item' ),
|
4446 |
-
layoutId = $layout.data( 'layout_id' ),
|
4447 |
-
layoutVersion = $layout.data( 'layout_version' ),
|
4448 |
-
layoutValue = self.$editorItem.data( 'layout_value' );
|
4449 |
-
|
4450 |
-
if ( $layout.hasClass( 'active' ) ) {
|
4451 |
-
return false;
|
4452 |
-
}
|
4453 |
-
$.each( layoutValue, function( type ) {
|
4454 |
-
if ( self.editorVariationId === type ) {
|
4455 |
-
layoutValue[type] = String( layoutId );
|
4456 |
-
}
|
4457 |
-
} );
|
4458 |
-
|
4459 |
-
// Highlight the active layout
|
4460 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4461 |
-
//self.dittyUpdatedDraftLayouts( self.editorVariationId, layoutId );
|
4462 |
-
//dittyDraftItemUpdateData( self, self.editorItemId, 'layout_id', layoutId );
|
4463 |
-
dittyDraftItemUpdateData( self, self.editorItemId, 'layout_value', layoutValue );
|
4464 |
-
self._activateLayout( $layout );
|
4465 |
-
|
4466 |
-
// Use ajax to load the new layout
|
4467 |
-
var data = {
|
4468 |
-
action : 'ditty_editor_select_layout',
|
4469 |
-
layout_id : layoutId,
|
4470 |
-
item_id : self.editorItemId,
|
4471 |
-
ditty_id : self.editorDittyId,
|
4472 |
-
draft_values : self.settings.editor.getDraftValues(),
|
4473 |
-
security : dittyVars.security
|
4474 |
-
};
|
4475 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
4476 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
4477 |
-
if ( response.display_items ) {
|
4478 |
-
//self.settings.editor.ditty.updateItems( response.display_items, false, false, true );
|
4479 |
-
self.settings.editor.ditty.updateItems( response.display_items, self.editorItemId );
|
4480 |
-
}
|
4481 |
-
if ( response.editor_item ) {
|
4482 |
-
var $newEditorItem = $( response.editor_item );
|
4483 |
-
self.$editorItem.replaceWith( $newEditorItem );
|
4484 |
-
}
|
4485 |
-
|
4486 |
-
// Update the current Ditty
|
4487 |
-
self.$editorItem.attr( 'data-layout_value', layoutValue ).data( 'layout_value', layoutValue );
|
4488 |
-
self.$editorVariation.attr( 'data-layout_id', layoutId ).data( 'layout_id', layoutId );
|
4489 |
-
self.$editorVariation.find( '.ditty-layout-variation__template > span' ).text( response.layout_label );
|
4490 |
-
if ( layoutVersion ) {
|
4491 |
-
self.$editorVariation.find( '.ditty-layout-variation__template > small' ).text( '(' + layoutVersion + ')' );
|
4492 |
-
} else {
|
4493 |
-
self.$editorVariation.find( '.ditty-layout-variation__template > small' ).text( '' );
|
4494 |
-
}
|
4495 |
-
}, 'json' );
|
4496 |
-
},
|
4497 |
-
|
4498 |
-
/**
|
4499 |
-
* Clone a layout
|
4500 |
-
*
|
4501 |
-
* @since 3.0
|
4502 |
-
* @return null
|
4503 |
-
*/
|
4504 |
-
_cloneLayout: function( e ) {
|
4505 |
-
e.preventDefault();
|
4506 |
-
var self = e.data.self,
|
4507 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
4508 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
4509 |
-
layoutId = $item.data( 'layout_id' );
|
4510 |
-
|
4511 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4512 |
-
|
4513 |
-
// Use ajax to clone the layout
|
4514 |
-
var data = {
|
4515 |
-
action : 'ditty_editor_layout_clone',
|
4516 |
-
layout_id : layoutId,
|
4517 |
-
draft_values : self.settings.editor.getDraftValues(),
|
4518 |
-
security : dittyVars.security
|
4519 |
-
};
|
4520 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
4521 |
-
if ( response.editor_layout ) {
|
4522 |
-
var $new = $( response.editor_layout );
|
4523 |
-
$new.hide();
|
4524 |
-
$item.after( $new );
|
4525 |
-
$new.slideDown();
|
4526 |
-
}
|
4527 |
-
if ( response.draft_id && response.draft_meta ) {
|
4528 |
-
dittyDraftLayoutUpdate( self, response.draft_id, null, response.draft_meta );
|
4529 |
-
}
|
4530 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
4531 |
-
}, 'json' );
|
4532 |
-
},
|
4533 |
-
|
4534 |
-
/**
|
4535 |
-
* Delete a layout
|
4536 |
-
*
|
4537 |
-
* @since 3.0
|
4538 |
-
* @return null
|
4539 |
-
*/
|
4540 |
-
_deleteLayout: function( e ) {
|
4541 |
-
e.preventDefault();
|
4542 |
-
|
4543 |
-
var self = e.data.self,
|
4544 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
4545 |
-
$item = $button.parents( '.ditty-data-list__item' ),
|
4546 |
-
$nextItem = null,
|
4547 |
-
layoutId = $item.data( 'layout_id' );
|
4548 |
-
|
4549 |
-
// Find the layout to load if this one is active
|
4550 |
-
if ( $item.hasClass( 'active' ) ) {
|
4551 |
-
if ( $item.prev().length ) {
|
4552 |
-
$nextItem = $item.prev();
|
4553 |
-
} else if ( $item.next().length ) {
|
4554 |
-
$nextItem = $item.next();
|
4555 |
-
}
|
4556 |
-
}
|
4557 |
-
|
4558 |
-
// Remove the layout
|
4559 |
-
$item.slideUp( function() {
|
4560 |
-
$( this ).remove();
|
4561 |
-
} );
|
4562 |
-
dittyDraftLayoutDelete( self, layoutId );
|
4563 |
-
|
4564 |
-
// Possibly select another layout
|
4565 |
-
if ( null !== $nextItem ) {
|
4566 |
-
$nextItem.trigger( 'click' );
|
4567 |
-
}
|
4568 |
-
},
|
4569 |
-
|
4570 |
-
/**
|
4571 |
-
* Edit the html or css of a layout
|
4572 |
-
*
|
4573 |
-
* @since 3.0
|
4574 |
-
* @return null
|
4575 |
-
*/
|
4576 |
-
_editLayout: function( e ) {
|
4577 |
-
e.preventDefault();
|
4578 |
-
var self = e.data.self,
|
4579 |
-
editType = e.data.editType,
|
4580 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
4581 |
-
$layout = $button.parents( '.ditty-data-list__item' ),
|
4582 |
-
layoutId = $layout.data( 'layout_id' );
|
4583 |
-
|
4584 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4585 |
-
self.$list.find( '.ditty-data-list__item' ).removeClass( 'editing' );
|
4586 |
-
$layout.addClass( 'editing' );
|
4587 |
-
|
4588 |
-
// Load the new display fields
|
4589 |
-
var data = {
|
4590 |
-
action : 'ditty_editor_layout_fields',
|
4591 |
-
layout_id : layoutId,
|
4592 |
-
item_id : self.editorItemId,
|
4593 |
-
edit_type : editType,
|
4594 |
-
draft_values : self.settings.editor.getDraftValues(),
|
4595 |
-
security : dittyVars.security
|
4596 |
-
};
|
4597 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
4598 |
-
if ( response ) {
|
4599 |
-
var slideId = 'layout_' + editType + '_editor',
|
4600 |
-
html = '<div class="ditty-editor__panel ditty-editor__panel--' + slideId + '">' + response.form + '</div>';
|
4601 |
-
|
4602 |
-
self.settings.editor.panelOptions( 'transition', 'slideLeft' );
|
4603 |
-
self.settings.editor.showPanel( slideId, html );
|
4604 |
-
}
|
4605 |
-
}, 'json' );
|
4606 |
-
},
|
4607 |
-
|
4608 |
-
/**
|
4609 |
-
* Trigger an actions when a button is clicked
|
4610 |
-
*
|
4611 |
-
* @since 3.0
|
4612 |
-
* @return null
|
4613 |
-
*/
|
4614 |
-
_actionClick: function( e ) {
|
4615 |
-
e.preventDefault();
|
4616 |
-
var self = e.data.self,
|
4617 |
-
$button = $( e.target ).is( 'a' ) ? $( e.target ) : $( e.target ).parent( 'a' ),
|
4618 |
-
$layout = $button.parents( '.ditty-data-list__item' ),
|
4619 |
-
layoutId = $layout.data( 'layout_id' );
|
4620 |
-
|
4621 |
-
dittyVars.editor.currentLayout = $layout; // Set the current layout
|
4622 |
-
|
4623 |
-
$( 'body' ).trigger( 'ditty_editor_layout_action_click', [$button, $layout, layoutId, self.editorDittyId, self.settings.editor] );
|
4624 |
-
},
|
4625 |
-
|
4626 |
-
/**
|
4627 |
-
* Setup triggers
|
4628 |
-
*
|
4629 |
-
* @since 3.0
|
4630 |
-
* @return null
|
4631 |
-
*/
|
4632 |
-
trigger: function ( fn, customParams ) {
|
4633 |
-
var params = [this.settings];
|
4634 |
-
if ( customParams ) {
|
4635 |
-
params = customParams;
|
4636 |
-
}
|
4637 |
-
|
4638 |
-
this.$elmt.trigger( 'ditty_layouts_panel_' + fn, params );
|
4639 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
4640 |
-
this.settings[fn].apply( this.$elmt, params );
|
4641 |
-
}
|
4642 |
-
},
|
4643 |
-
|
4644 |
-
/**
|
4645 |
-
* Allow settings to be modified
|
4646 |
-
*
|
4647 |
-
* @since 3.0
|
4648 |
-
* @return null
|
4649 |
-
*/
|
4650 |
-
options: function ( key, value ) {
|
4651 |
-
if ( typeof key === 'object' ) {
|
4652 |
-
this.settings = $.extend( {}, defaults, $.ditty_layouts_panel.defaults, key );
|
4653 |
-
} else if ( typeof key === 'string' ) {
|
4654 |
-
if ( value === undefined ) {
|
4655 |
-
return this.settings[key];
|
4656 |
-
}
|
4657 |
-
this.settings[key] = value;
|
4658 |
-
} else {
|
4659 |
-
return this.settings;
|
4660 |
-
}
|
4661 |
-
|
4662 |
-
this.trigger( 'options_update' );
|
4663 |
-
},
|
4664 |
-
|
4665 |
-
|
4666 |
-
/**
|
4667 |
-
* Destroy the editor
|
4668 |
-
*
|
4669 |
-
* @since 3.0
|
4670 |
-
* @return null
|
4671 |
-
*/
|
4672 |
-
destroy: function () {
|
4673 |
-
|
4674 |
-
// Remove the init class
|
4675 |
-
this.$elmt.removeClass( 'init' );
|
4676 |
-
|
4677 |
-
// Remove actions
|
4678 |
-
this.$back.off( 'click', { self: this }, this._backClick );
|
4679 |
-
this.$elmt.off( 'click', '.ditty-data-list__item', { self: this }, this._selectLayout );
|
4680 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__edit_html', { self: this, editType: 'html' }, this._editLayout );
|
4681 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__edit_css', { self: this, editType: 'css' }, this._editLayout );
|
4682 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__clone', { self: this }, this._cloneLayout );
|
4683 |
-
this.$elmt.off( 'click', '.ditty-data-list__item__delete', { self: this }, this._deleteLayout );
|
4684 |
-
this.$list.off( 'click', '.ditty-editor-layout > a', { self: this }, this._actionClick );
|
4685 |
-
$( 'body' ).off( 'ditty_editor_save_ditty_response', { self: this }, this._dittyEditorSaveResponse );
|
4686 |
-
|
4687 |
-
this.elmt._ditty_layouts_panel = null;
|
4688 |
-
}
|
4689 |
-
};
|
4690 |
-
|
4691 |
-
/**
|
4692 |
-
* Create the data list
|
4693 |
-
*
|
4694 |
-
* @since 3.0
|
4695 |
-
* @return null
|
4696 |
-
*/
|
4697 |
-
$.fn.ditty_layouts_panel = function( options ) {
|
4698 |
-
var args = arguments,
|
4699 |
-
error = false,
|
4700 |
-
returns;
|
4701 |
-
|
4702 |
-
if ( options === undefined || typeof options === 'object' ) {
|
4703 |
-
return this.each( function () {
|
4704 |
-
if ( ! this._ditty_layouts_panel ) {
|
4705 |
-
this._ditty_layouts_panel = new Ditty_Layouts_Panel( this, options );
|
4706 |
-
}
|
4707 |
-
});
|
4708 |
-
} else if ( typeof options === 'string' ) {
|
4709 |
-
this.each( function () {
|
4710 |
-
var instance = this._ditty_layouts_panel;
|
4711 |
-
|
4712 |
-
if ( ! instance ) {
|
4713 |
-
throw new Error( 'No Ditty_Layouts_Panel applied to this element.' );
|
4714 |
-
}
|
4715 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
4716 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
4717 |
-
} else {
|
4718 |
-
error = true;
|
4719 |
-
}
|
4720 |
-
} );
|
4721 |
-
|
4722 |
-
if ( error ) {
|
4723 |
-
throw new Error( 'No method "' + options + '" in Ditty_Layouts_Panel.' );
|
4724 |
-
}
|
4725 |
-
|
4726 |
-
return returns !== undefined ? returns : this;
|
4727 |
-
}
|
4728 |
-
};
|
4729 |
-
|
4730 |
-
$.ditty_layouts_panel = {};
|
4731 |
-
$.ditty_layouts_panel.defaults = defaults;
|
4732 |
-
|
4733 |
-
} )( jQuery );
|
4734 |
-
|
4735 |
-
|
4736 |
-
/* global wp:true */
|
4737 |
-
/* global _:true */
|
4738 |
-
|
4739 |
-
/**
|
4740 |
-
* Ditty Layout HTML Editor Panel
|
4741 |
-
* @since 3.0
|
4742 |
-
* @return null
|
4743 |
-
*/
|
4744 |
-
|
4745 |
-
(function ($) {
|
4746 |
-
'use strict';
|
4747 |
-
|
4748 |
-
var defaults = {
|
4749 |
-
editor : null,
|
4750 |
-
prevPanel : ''
|
4751 |
-
};
|
4752 |
-
|
4753 |
-
var Ditty_Layout_Html_Editor_Panel = function ( elmt, options ) {
|
4754 |
-
|
4755 |
-
this.elmt = elmt;
|
4756 |
-
this.settings = $.extend( {}, defaults, $.ditty_layout_html_editor_panel.defaults, options );
|
4757 |
-
this.$elmt = $( elmt );
|
4758 |
-
this.$form = this.$elmt.find( '.ditty-editor-options' );
|
4759 |
-
this.$textarea = this.$elmt.find( '.ditty-editor-options__code' );
|
4760 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
4761 |
-
this.$preview = this.$elmt.find( '.ditty-editor-options__preview' );
|
4762 |
-
this.$editCss = this.$elmt.find( '.ditty-editor-options__edit-css' );
|
4763 |
-
this.$title = this.$elmt.find( '.ditty-editor-options__title' );
|
4764 |
-
this.$tags = this.$elmt.find( '.ditty-editor-options__tags' );
|
4765 |
-
this.itemType = this.$form.data( 'item_type' );
|
4766 |
-
this.layoutId = this.$form.data( 'layout_id' );
|
4767 |
-
this.$editorItem = dittyVars.editor.currentItem;
|
4768 |
-
this.$editorLayout = dittyVars.editor.currentLayout;
|
4769 |
-
this.$editorLayoutTitle = this.$editorLayout ? this.$editorLayout.find( '.ditty-data-list__item__label' ) : false;
|
4770 |
-
this.$editorLayoutVariation = dittyVars.editor.currentLayoutVariation;
|
4771 |
-
this.$editorLayoutVariationTitle = this.$editorLayoutVariation.find( '.ditty-layout-variation__template span' );
|
4772 |
-
this.editorDittyId = this.$editorItem.data( 'ditty_id' );
|
4773 |
-
this.editorItemId = this.$editorItem.data( 'item_id' );
|
4774 |
-
this.codeEditor = null;
|
4775 |
-
this.codeHasUpdates = false;
|
4776 |
-
this.initData = null;
|
4777 |
-
this.afterUpdateAction = '';
|
4778 |
-
this._init();
|
4779 |
-
};
|
4780 |
-
|
4781 |
-
|
4782 |
-
Ditty_Layout_Html_Editor_Panel.prototype = {
|
4783 |
-
|
4784 |
-
/**
|
4785 |
-
* Initialize the data list
|
4786 |
-
* @since 3.0
|
4787 |
-
* @return null
|
4788 |
-
*/
|
4789 |
-
_init: function () {
|
4790 |
-
|
4791 |
-
// Save the initial data
|
4792 |
-
this.initData = this.$form.serialize();
|
4793 |
-
|
4794 |
-
// Initialize dynamic fields
|
4795 |
-
this._initEditor();
|
4796 |
-
|
4797 |
-
// Add actions
|
4798 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
4799 |
-
this.$preview.on( 'click', { self: this }, this._previewClick );
|
4800 |
-
this.$editCss.on( 'click', { self: this }, this._editCss );
|
4801 |
-
this.$form.on( 'submit', { self: this }, this._submitForm );
|
4802 |
-
this.$form.on( 'click', '.ditty-editor-options__tag', { self: this }, this._insertTag );
|
4803 |
-
this.$title.on( 'keyup', { self: this }, this._titleUpdate );
|
4804 |
-
this.settings.editor.$elmt.on( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
4805 |
-
this.settings.editor.$elmt.on( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
4806 |
-
},
|
4807 |
-
|
4808 |
-
/**
|
4809 |
-
* Return to the previous panel
|
4810 |
-
* @since 3.0
|
4811 |
-
* @return null
|
4812 |
-
*/
|
4813 |
-
_showPrevPanel: function() {
|
4814 |
-
this.settings.editor.$panels.ditty_slider( 'options', 'transition', 'slideRight' );
|
4815 |
-
this.settings.editor.$panels.ditty_slider( 'showSlideById', this.settings.prevPanel );
|
4816 |
-
},
|
4817 |
-
|
4818 |
-
/**
|
4819 |
-
* Editor updated listener
|
4820 |
-
* @since 3.0
|
4821 |
-
* @return null
|
4822 |
-
*/
|
4823 |
-
_titleUpdate: function( e ) {
|
4824 |
-
var self = e.data.self;
|
4825 |
-
self.settings.editor.addUpdate( 'layoutUpdate', self.layoutId );
|
4826 |
-
},
|
4827 |
-
|
4828 |
-
/**
|
4829 |
-
* Preview button add updates class
|
4830 |
-
* @since 3.0
|
4831 |
-
* @return null
|
4832 |
-
*/
|
4833 |
-
_enablePreviewButton: function() {
|
4834 |
-
this.$preview.addClass( 'ditty-has-updates' );
|
4835 |
-
},
|
4836 |
-
|
4837 |
-
/**
|
4838 |
-
* Preview button remove updates class
|
4839 |
-
* @since 3.0
|
4840 |
-
* @return null
|
4841 |
-
*/
|
4842 |
-
_disablePreviewButton: function() {
|
4843 |
-
this.$preview.removeClass( 'ditty-has-updates' );
|
4844 |
-
this.$preview.children( 'i' ).attr( 'class', this.$preview.children( 'i' ).data( 'class' ) );
|
4845 |
-
},
|
4846 |
-
|
4847 |
-
/**
|
4848 |
-
* Return item ids of current layout
|
4849 |
-
* @since 3.0
|
4850 |
-
* @return null
|
4851 |
-
*/
|
4852 |
-
_getLayoutItems: function() {
|
4853 |
-
var items = this.settings.editor.ditty.options( 'items' ),
|
4854 |
-
itemIds = [];
|
4855 |
-
|
4856 |
-
$.each( items, function( key, value ) {
|
4857 |
-
if ( String( value.layoutId ) === String( this.layoutId ) ) {
|
4858 |
-
itemIds.push( value.id );
|
4859 |
-
}
|
4860 |
-
} );
|
4861 |
-
return itemIds;
|
4862 |
-
},
|
4863 |
-
|
4864 |
-
/**
|
4865 |
-
* Editor tabs listener
|
4866 |
-
* @since 3.0
|
4867 |
-
* @return null
|
4868 |
-
*/
|
4869 |
-
_addDrafts: function( e ) {
|
4870 |
-
var self = e.data.self;
|
4871 |
-
self.codeEditor.codemirror.save();
|
4872 |
-
|
4873 |
-
var currentData = self.$form.serialize();
|
4874 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
4875 |
-
self.$form.trigger( 'submit' );
|
4876 |
-
}
|
4877 |
-
},
|
4878 |
-
|
4879 |
-
/**
|
4880 |
-
* Editor updated listener
|
4881 |
-
* @since 3.0
|
4882 |
-
* @return null
|
4883 |
-
*/
|
4884 |
-
_saveDrafts: function( e ) {
|
4885 |
-
var self = e.data.self;
|
4886 |
-
self.codeEditor.codemirror.save();
|
4887 |
-
|
4888 |
-
var currentData = self.$form.serialize();
|
4889 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
4890 |
-
self.afterUpdateAction = 'save';
|
4891 |
-
self.$form.trigger( 'submit' );
|
4892 |
-
}
|
4893 |
-
},
|
4894 |
-
|
4895 |
-
/**
|
4896 |
-
* Back click
|
4897 |
-
* @since 3.0
|
4898 |
-
* @return null
|
4899 |
-
*/
|
4900 |
-
_backClick: function( e ) {
|
4901 |
-
e.preventDefault();
|
4902 |
-
var self = e.data.self;
|
4903 |
-
|
4904 |
-
self.codeEditor.codemirror.save();
|
4905 |
-
var currentData = self.$form.serialize();
|
4906 |
-
|
4907 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
4908 |
-
self.afterUpdateAction = 'return';
|
4909 |
-
self.$form.trigger( 'submit' );
|
4910 |
-
} else {
|
4911 |
-
self._showPrevPanel();
|
4912 |
-
}
|
4913 |
-
},
|
4914 |
-
|
4915 |
-
/**
|
4916 |
-
* Preview any changes
|
4917 |
-
* @since 3.0
|
4918 |
-
* @return null
|
4919 |
-
*/
|
4920 |
-
_previewClick: function( e ) {
|
4921 |
-
e.preventDefault();
|
4922 |
-
var self = e.data.self;
|
4923 |
-
|
4924 |
-
self.codeEditor.codemirror.save(); // Update the textarea
|
4925 |
-
var currentData = self.$form.serialize();
|
4926 |
-
|
4927 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
4928 |
-
self.$preview.children( 'i' ).attr( 'class', dittyVars.updateIcon );
|
4929 |
-
self.$form.trigger( 'submit' );
|
4930 |
-
}
|
4931 |
-
},
|
4932 |
-
|
4933 |
-
/**
|
4934 |
-
* Edit the css of the layout
|
4935 |
-
* @since 3.0
|
4936 |
-
* @return null
|
4937 |
-
*/
|
4938 |
-
_editCss: function( e ) {
|
4939 |
-
e.preventDefault();
|
4940 |
-
var self = e.data.self,
|
4941 |
-
panelId = 'layout_css_editor';
|
4942 |
-
|
4943 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4944 |
-
self.codeEditor.codemirror.save(); // Update the textarea
|
4945 |
-
var currentData = self.$form.serialize();
|
4946 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
4947 |
-
self.$preview.children( 'i' ).attr( 'class', dittyVars.updateIcon );
|
4948 |
-
self.$form.trigger( 'submit' );
|
4949 |
-
}
|
4950 |
-
|
4951 |
-
// Show the panel if it exists
|
4952 |
-
if ( self.settings.editor.panelExists( panelId ) ) {
|
4953 |
-
self.settings.editor.$elmt.find( '.ditty-editor__panel--layout_css_editor input.ditty-editor-options__title' ).val( self.$title.val() );
|
4954 |
-
self.settings.editor.panelOptions( 'transition', 'fade' );
|
4955 |
-
self.settings.editor.showPanel( panelId );
|
4956 |
-
|
4957 |
-
// Else, load the new panel and show
|
4958 |
-
} else {
|
4959 |
-
var data = {
|
4960 |
-
action : 'ditty_editor_layout_fields',
|
4961 |
-
layout_id : self.layoutId,
|
4962 |
-
layout_title : self.$title.val(),
|
4963 |
-
ditty_id : self.editorDittyId,
|
4964 |
-
item_id : self.editorItemId,
|
4965 |
-
item_type : self.itemType,
|
4966 |
-
edit_type : 'css',
|
4967 |
-
draft_values : self.settings.editor.getDraftValues(),
|
4968 |
-
security : dittyVars.security
|
4969 |
-
};
|
4970 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
4971 |
-
if ( response ) {
|
4972 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--' + panelId + '">' + response.form + '</div>';
|
4973 |
-
self.settings.editor.panelOptions( 'transition', 'fade' );
|
4974 |
-
self.settings.editor.showPanel( panelId, html );
|
4975 |
-
}
|
4976 |
-
}, 'json' );
|
4977 |
-
}
|
4978 |
-
},
|
4979 |
-
|
4980 |
-
/**
|
4981 |
-
* Submit updates
|
4982 |
-
* @since 3.0
|
4983 |
-
* @return null
|
4984 |
-
*/
|
4985 |
-
_submitForm: function( e ) {
|
4986 |
-
e.preventDefault();
|
4987 |
-
|
4988 |
-
var self = e.data.self,
|
4989 |
-
layoutId = self.layoutId,
|
4990 |
-
itemType = self.itemType,
|
4991 |
-
itemIds = self._getLayoutItems();
|
4992 |
-
|
4993 |
-
if ( self.$form.hasClass( 'ditty-editor-has-errors' ) ) {
|
4994 |
-
return false;
|
4995 |
-
}
|
4996 |
-
|
4997 |
-
self.codeEditor.codemirror.save(); // Update the textarea
|
4998 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
4999 |
-
|
5000 |
-
var data = {
|
5001 |
-
action : 'ditty_editor_layout_update',
|
5002 |
-
layout_id : layoutId,
|
5003 |
-
item_type : itemType,
|
5004 |
-
item_ids : itemIds,
|
5005 |
-
edit_type : 'html',
|
5006 |
-
draft_values : self.settings.editor.getDraftValues(),
|
5007 |
-
security : dittyVars.security
|
5008 |
-
};
|
5009 |
-
self.$form.ajaxSubmit({
|
5010 |
-
url : dittyVars.ajaxurl,
|
5011 |
-
type : 'post',
|
5012 |
-
dataType : 'json',
|
5013 |
-
data : data,
|
5014 |
-
success : function( response ) {
|
5015 |
-
self.initData = self.$form.serialize();
|
5016 |
-
self._disablePreviewButton();
|
5017 |
-
|
5018 |
-
// Update labels
|
5019 |
-
if ( response.label ) {
|
5020 |
-
if ( self.$editorLayoutTitle ) {
|
5021 |
-
self.$editorLayoutTitle.html( response.label );
|
5022 |
-
}
|
5023 |
-
self.$editorLayoutVariationTitle.html( response.label );
|
5024 |
-
}
|
5025 |
-
// Remove the template version numbers
|
5026 |
-
if ( self.$editorLayoutTitle ) {
|
5027 |
-
self.$editorLayoutTitle.find( '.ditty-layout-version' ).remove();
|
5028 |
-
}
|
5029 |
-
if ( self.$editorLayoutVariationTitle ) {
|
5030 |
-
self.$editorLayoutVariationTitle.find( '.ditty-layout-version' ).remove();
|
5031 |
-
}
|
5032 |
-
|
5033 |
-
if ( response.display_items ) {
|
5034 |
-
self.settings.editor.ditty.updateItems( response.display_items, false, false, true );
|
5035 |
-
}
|
5036 |
-
if ( response.draft_id && response.draft_meta ) {
|
5037 |
-
dittyDraftLayoutUpdate( self, response.draft_id, null, response.draft_meta );
|
5038 |
-
}
|
5039 |
-
|
5040 |
-
self.codeHasUpdates = false;
|
5041 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
5042 |
-
self.settings.editor.delayedSubmitDisable(); // Remove the delayed submit since we just submitted
|
5043 |
-
|
5044 |
-
if ( 'return' === self.afterUpdateAction ) {
|
5045 |
-
self._showPrevPanel(); // Show the items list
|
5046 |
-
}
|
5047 |
-
if ( 'save' === self.afterUpdateAction ) {
|
5048 |
-
self.settings.editor.saveDitty( { return_items: 0 } ); // Update the ticker
|
5049 |
-
}
|
5050 |
-
self.afterUpdateAction = '';
|
5051 |
-
}
|
5052 |
-
} );
|
5053 |
-
},
|
5054 |
-
|
5055 |
-
/**
|
5056 |
-
* Initialize the editor
|
5057 |
-
* @since 3.0
|
5058 |
-
* @return null
|
5059 |
-
*/
|
5060 |
-
_initEditor: function() {
|
5061 |
-
var self = this,
|
5062 |
-
codeEditorSettings = wp.codeEditor.defaultSettings ? _.clone( wp.codeEditor.defaultSettings ) : {};
|
5063 |
-
|
5064 |
-
codeEditorSettings.codemirror = _.extend(
|
5065 |
-
{},
|
5066 |
-
codeEditorSettings.codemirror,
|
5067 |
-
{
|
5068 |
-
indentUnit : 2,
|
5069 |
-
tabSize : 2
|
5070 |
-
}
|
5071 |
-
);
|
5072 |
-
this.codeEditor = wp.codeEditor.initialize( this.$textarea[0], codeEditorSettings );
|
5073 |
-
this.codeEditor.codemirror.on( 'change', function() {
|
5074 |
-
self.codeEditor.codemirror.save();
|
5075 |
-
self.settings.editor.addUpdate( 'layout_html_update', self.layoutId );
|
5076 |
-
self.codeHasUpdates = true;
|
5077 |
-
self._enablePreviewButton();
|
5078 |
-
self.settings.editor.delayedSubmitEnable(); // Enable the delayed submit since we have changes
|
5079 |
-
} );
|
5080 |
-
},
|
5081 |
-
|
5082 |
-
/**
|
5083 |
-
* Insert a tag
|
5084 |
-
* @since 3.0
|
5085 |
-
* @return null
|
5086 |
-
*/
|
5087 |
-
_insertTag: function( e ) {
|
5088 |
-
var self = e.data.self,
|
5089 |
-
$tag = $( e.target ),
|
5090 |
-
text = $tag.text(),
|
5091 |
-
atts = $tag.data( 'atts' ),
|
5092 |
-
cursor = self.codeEditor.codemirror.getCursor();
|
5093 |
-
|
5094 |
-
if ( e.shiftKey && atts ) {
|
5095 |
-
var attsString = '',
|
5096 |
-
insertPoint = text.length - 1;
|
5097 |
-
|
5098 |
-
$.each( atts, function( key, value ) {
|
5099 |
-
attsString += ' ' + key + '="' + value.toString() + '"';
|
5100 |
-
} );
|
5101 |
-
text = text.substring( 0, insertPoint ) + attsString + text.substring( insertPoint );
|
5102 |
-
}
|
5103 |
-
self.codeEditor.codemirror.replaceRange( text, cursor );
|
5104 |
-
|
5105 |
-
// Move the cursor position
|
5106 |
-
cursor.ch = cursor.ch + text.length;
|
5107 |
-
self.codeEditor.codemirror.setCursor( cursor );
|
5108 |
-
},
|
5109 |
-
|
5110 |
-
/**
|
5111 |
-
* Return a specific setting
|
5112 |
-
* @since 3.0
|
5113 |
-
* @return null
|
5114 |
-
*/
|
5115 |
-
_options: function ( key ) {
|
5116 |
-
return this.settings[key];
|
5117 |
-
},
|
5118 |
-
|
5119 |
-
/**
|
5120 |
-
* Setup triggers
|
5121 |
-
* @since 3.0
|
5122 |
-
* @return null
|
5123 |
-
*/
|
5124 |
-
trigger: function ( fn, customParams ) {
|
5125 |
-
var params = [this.settings];
|
5126 |
-
if ( customParams ) {
|
5127 |
-
params = customParams;
|
5128 |
-
}
|
5129 |
-
|
5130 |
-
this.$elmt.trigger( 'ditty_layout_html_editor_panel_' + fn, params );
|
5131 |
-
|
5132 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
5133 |
-
this.settings[fn].apply( this.$elmt, params );
|
5134 |
-
}
|
5135 |
-
},
|
5136 |
-
|
5137 |
-
/**
|
5138 |
-
* Allow settings to be modified
|
5139 |
-
* @since 3.0
|
5140 |
-
* @return null
|
5141 |
-
*/
|
5142 |
-
options: function ( key, value ) {
|
5143 |
-
if ( typeof key === 'object' ) {
|
5144 |
-
this.settings = $.extend( {}, defaults, $.ditty_layout_html_editor_panel.defaults, key );
|
5145 |
-
} else if ( typeof key === 'string' ) {
|
5146 |
-
if ( value === undefined ) {
|
5147 |
-
return this.settings[key];
|
5148 |
-
}
|
5149 |
-
this.settings[key] = value;
|
5150 |
-
} else {
|
5151 |
-
return this.settings;
|
5152 |
-
}
|
5153 |
-
this.trigger( 'options_update' );
|
5154 |
-
},
|
5155 |
-
|
5156 |
-
/**
|
5157 |
-
* Destroy the class
|
5158 |
-
* @since 3.0
|
5159 |
-
* @return null
|
5160 |
-
*/
|
5161 |
-
destroy: function () {
|
5162 |
-
this.$back.off( 'click', { self: this }, this._backClick );
|
5163 |
-
this.$preview.off( 'click', { self: this }, this._previewClick );
|
5164 |
-
this.$editCss.off( 'click', { self: this }, this._editCss );
|
5165 |
-
this.$form.off( 'submit', { self: this }, this._submitForm );
|
5166 |
-
this.$form.off( 'click', '.ditty-editor-options__tag', { self: this }, this._insertTag );
|
5167 |
-
this.$title.off( 'keyup', { self: this }, this._titleUpdate );
|
5168 |
-
this.settings.editor.$elmt.off( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
5169 |
-
this.settings.editor.$elmt.off( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
5170 |
-
this.codeEditor.codemirror.off( 'change' );
|
5171 |
-
this.codeEditor.codemirror.toTextArea();
|
5172 |
-
|
5173 |
-
this.elmt._ditty_layout_html_editor_panel = null;
|
5174 |
-
}
|
5175 |
-
};
|
5176 |
-
|
5177 |
-
/**
|
5178 |
-
* Create the data list
|
5179 |
-
* @since 3.0
|
5180 |
-
* @return null
|
5181 |
-
*/
|
5182 |
-
$.fn.ditty_layout_html_editor_panel = function( options ) {
|
5183 |
-
var args = arguments,
|
5184 |
-
error = false,
|
5185 |
-
returns;
|
5186 |
-
|
5187 |
-
if ( options === undefined || typeof options === 'object' ) {
|
5188 |
-
return this.each( function () {
|
5189 |
-
if ( ! this._ditty_layout_html_editor_panel ) {
|
5190 |
-
this._ditty_layout_html_editor_panel = new Ditty_Layout_Html_Editor_Panel( this, options );
|
5191 |
-
}
|
5192 |
-
});
|
5193 |
-
} else if ( typeof options === 'string' ) {
|
5194 |
-
this.each( function () {
|
5195 |
-
var instance = this._ditty_layout_html_editor_panel;
|
5196 |
-
|
5197 |
-
if ( ! instance ) {
|
5198 |
-
throw new Error( 'No Ditty_Layout_Html_Editor_Panel applied to this element.' );
|
5199 |
-
}
|
5200 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
5201 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
5202 |
-
} else {
|
5203 |
-
error = true;
|
5204 |
-
}
|
5205 |
-
} );
|
5206 |
-
|
5207 |
-
if ( error ) {
|
5208 |
-
throw new Error( 'No method "' + options + '" in Ditty_Layout_Html_Editor_Panel.' );
|
5209 |
-
}
|
5210 |
-
|
5211 |
-
return returns !== undefined ? returns : this;
|
5212 |
-
}
|
5213 |
-
};
|
5214 |
-
|
5215 |
-
$.ditty_layout_html_editor_panel = {};
|
5216 |
-
$.ditty_layout_html_editor_panel.defaults = defaults;
|
5217 |
-
|
5218 |
-
} )( jQuery );
|
5219 |
-
|
5220 |
-
|
5221 |
-
/* global dittyLayoutCss:true */
|
5222 |
-
|
5223 |
-
/**
|
5224 |
-
* Ditty Layout CSS Editor Panel
|
5225 |
-
* @since 3.0
|
5226 |
-
* @return null
|
5227 |
-
*/
|
5228 |
-
|
5229 |
-
(function ($) {
|
5230 |
-
'use strict';
|
5231 |
-
|
5232 |
-
var defaults = {
|
5233 |
-
editor : null,
|
5234 |
-
prevPanel : ''
|
5235 |
-
};
|
5236 |
-
|
5237 |
-
var Ditty_Layout_Css_Editor_Panel = function ( elmt, options ) {
|
5238 |
-
|
5239 |
-
this.elmt = elmt;
|
5240 |
-
this.settings = $.extend( {}, defaults, $.ditty_layout_css_editor_panel.defaults, options );
|
5241 |
-
this.$elmt = $( elmt );
|
5242 |
-
this.$form = this.$elmt.find( '.ditty-editor-options' );
|
5243 |
-
this.$textarea = this.$elmt.find( '.ditty-editor-options__code' );
|
5244 |
-
this.$back = this.$elmt.find( '.ditty-editor-options__back' );
|
5245 |
-
this.$preview = this.$elmt.find( '.ditty-editor-options__preview' );
|
5246 |
-
this.$editHtml = this.$elmt.find( '.ditty-editor-options__edit-html' );
|
5247 |
-
this.$title = this.$elmt.find( '.ditty-editor-options__title' );
|
5248 |
-
this.$body = this.$elmt.find( '.ditty-editor-options__body' );
|
5249 |
-
this.$tags = this.$elmt.find( '.ditty-editor-options__tags' );
|
5250 |
-
this.itemType = this.$form.data( 'item_type' );
|
5251 |
-
this.layoutId = this.$form.data( 'layout_id' );
|
5252 |
-
this.$editorItem = dittyVars.editor.currentItem;
|
5253 |
-
this.$editorLayout = dittyVars.editor.currentLayout;
|
5254 |
-
this.$editorLayoutTitle = this.$editorLayout ? this.$editorLayout.find( '.ditty-data-list__item__label' ) : false;
|
5255 |
-
this.$editorLayoutVariation = dittyVars.editor.currentLayoutVariation;
|
5256 |
-
this.$editorLayoutVariationTitle = this.$editorLayoutVariation.find( '.ditty-layout-variation__template span' );
|
5257 |
-
this.editorDittyId = this.$editorItem.data( 'ditty_id' );
|
5258 |
-
this.editorItemId = this.$editorItem.data( 'item_id' );
|
5259 |
-
this.itemSelector = '';
|
5260 |
-
this.codeEditor = null;
|
5261 |
-
this.codeHasUpdates = false;
|
5262 |
-
this.initData = null;
|
5263 |
-
this.afterUpdateAction = '';
|
5264 |
-
|
5265 |
-
this._init();
|
5266 |
-
};
|
5267 |
-
|
5268 |
-
|
5269 |
-
Ditty_Layout_Css_Editor_Panel.prototype = {
|
5270 |
-
|
5271 |
-
/**
|
5272 |
-
* Initialize the data list
|
5273 |
-
* @since 3.0
|
5274 |
-
* @return null
|
5275 |
-
*/
|
5276 |
-
_init: function () {
|
5277 |
-
|
5278 |
-
// Save the initial data
|
5279 |
-
this.initData = this.$form.serialize();
|
5280 |
-
|
5281 |
-
// Set the css item selector
|
5282 |
-
this._setCssSelector();
|
5283 |
-
|
5284 |
-
// Initialize dynamic fields
|
5285 |
-
this._initEditor();
|
5286 |
-
|
5287 |
-
// Add actions
|
5288 |
-
this.$back.on( 'click', { self: this }, this._backClick );
|
5289 |
-
this.$preview.on( 'click', { self: this }, this._previewClick );
|
5290 |
-
this.$editHtml.on( 'click', { self: this }, this._editHtml );
|
5291 |
-
this.$form.on( 'submit', { self: this }, this._submitForm );
|
5292 |
-
this.$form.on( 'click', '.ditty-editor-options__tag', { self: this }, this._insertTag );
|
5293 |
-
this.$title.on( 'keyup', { self: this }, this._titleUpdate );
|
5294 |
-
this.$body.on( 'click', '.ditty-editor-options__body__error', { self: this }, this._removeErrorNotice );
|
5295 |
-
this.settings.editor.$elmt.on( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
5296 |
-
this.settings.editor.$elmt.on( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
5297 |
-
},
|
5298 |
-
|
5299 |
-
/**
|
5300 |
-
* Set the css item selector
|
5301 |
-
* @since 3.0
|
5302 |
-
* @return null
|
5303 |
-
*/
|
5304 |
-
_setCssSelector: function() {
|
5305 |
-
if ( dittyVars.isTickerPost ) {
|
5306 |
-
this.itemSelector = '#poststuff .ditty-layout--' + this.layoutId;
|
5307 |
-
} else {
|
5308 |
-
this.itemSelector = '.ditty-layout--' + this.layoutId;
|
5309 |
-
}
|
5310 |
-
},
|
5311 |
-
|
5312 |
-
/**
|
5313 |
-
* Return to the previous panel
|
5314 |
-
* @since 3.0
|
5315 |
-
* @return null
|
5316 |
-
*/
|
5317 |
-
_showPrevPanel: function() {
|
5318 |
-
this.settings.editor.$panels.ditty_slider( 'options', 'transition', 'slideRight' );
|
5319 |
-
this.settings.editor.$panels.ditty_slider( 'showSlideById', this.settings.prevPanel );
|
5320 |
-
},
|
5321 |
-
|
5322 |
-
/**
|
5323 |
-
* Editor updated listener
|
5324 |
-
* @since 3.0
|
5325 |
-
* @return null
|
5326 |
-
*/
|
5327 |
-
_titleUpdate: function( e ) {
|
5328 |
-
var self = e.data.self;
|
5329 |
-
self.settings.editor.addUpdate( 'layoutUpdate', self.layoutId );
|
5330 |
-
},
|
5331 |
-
|
5332 |
-
/**
|
5333 |
-
* Preview button add updates class
|
5334 |
-
* @since 3.0
|
5335 |
-
* @return null
|
5336 |
-
*/
|
5337 |
-
_enablePreviewButton: function() {
|
5338 |
-
this.$preview.addClass( 'ditty-has-updates' );
|
5339 |
-
},
|
5340 |
-
|
5341 |
-
/**
|
5342 |
-
* Preview button remove updates class
|
5343 |
-
* @since 3.0
|
5344 |
-
* @return null
|
5345 |
-
*/
|
5346 |
-
_disablePreviewButton: function() {
|
5347 |
-
this.$preview.removeClass( 'ditty-has-updates' );
|
5348 |
-
this.$preview.children( 'i' ).attr( 'class', this.$preview.children( 'i' ).data( 'class' ) );
|
5349 |
-
},
|
5350 |
-
|
5351 |
-
/**
|
5352 |
-
* Editor tabs listener
|
5353 |
-
* @since 3.0
|
5354 |
-
* @return null
|
5355 |
-
*/
|
5356 |
-
_addDrafts: function( e ) {
|
5357 |
-
var self = e.data.self;
|
5358 |
-
self.codeEditor.codemirror.save();
|
5359 |
-
|
5360 |
-
var currentData = self.$form.serialize();
|
5361 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
5362 |
-
self.$form.trigger( 'submit' );
|
5363 |
-
}
|
5364 |
-
},
|
5365 |
-
|
5366 |
-
/**
|
5367 |
-
* Editor updated listener
|
5368 |
-
* @since 3.0
|
5369 |
-
* @return null
|
5370 |
-
*/
|
5371 |
-
_saveDrafts: function( e ) {
|
5372 |
-
var self = e.data.self;
|
5373 |
-
self.codeEditor.codemirror.save();
|
5374 |
-
|
5375 |
-
var currentData = self.$form.serialize();
|
5376 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
5377 |
-
self.afterUpdateAction = 'save';
|
5378 |
-
self.$form.trigger( 'submit' );
|
5379 |
-
}
|
5380 |
-
},
|
5381 |
-
|
5382 |
-
/**
|
5383 |
-
* Back click
|
5384 |
-
* @since 3.0
|
5385 |
-
* @return null
|
5386 |
-
*/
|
5387 |
-
_backClick: function( e ) {
|
5388 |
-
e.preventDefault();
|
5389 |
-
var self = e.data.self;
|
5390 |
-
|
5391 |
-
self.codeEditor.codemirror.save();
|
5392 |
-
var currentData = self.$form.serialize();
|
5393 |
-
|
5394 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
5395 |
-
self.afterUpdateAction = 'return';
|
5396 |
-
self.$form.trigger( 'submit' );
|
5397 |
-
} else {
|
5398 |
-
self._showPrevPanel();
|
5399 |
-
}
|
5400 |
-
},
|
5401 |
-
|
5402 |
-
/**
|
5403 |
-
* Preview any changes
|
5404 |
-
* @since 3.0
|
5405 |
-
* @return null
|
5406 |
-
*/
|
5407 |
-
_previewClick: function( e ) {
|
5408 |
-
e.preventDefault();
|
5409 |
-
var self = e.data.self;
|
5410 |
-
|
5411 |
-
self.codeEditor.codemirror.save(); // Update the textarea
|
5412 |
-
var currentData = self.$form.serialize();
|
5413 |
-
|
5414 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
5415 |
-
self.$preview.children( 'i' ).attr( 'class', dittyVars.updateIcon );
|
5416 |
-
self.$form.trigger( 'submit' );
|
5417 |
-
}
|
5418 |
-
},
|
5419 |
-
|
5420 |
-
/**
|
5421 |
-
* Edit the html of the layout
|
5422 |
-
* @since 3.0
|
5423 |
-
* @return null
|
5424 |
-
*/
|
5425 |
-
_editHtml: function( e ) {
|
5426 |
-
e.preventDefault();
|
5427 |
-
var self = e.data.self,
|
5428 |
-
panelId = 'layout_html_editor';
|
5429 |
-
|
5430 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
5431 |
-
self.codeEditor.codemirror.save(); // Update the textarea
|
5432 |
-
var currentData = self.$form.serialize();
|
5433 |
-
if ( currentData !== self.initData || self.codeHasUpdates ) {
|
5434 |
-
self.$preview.children( 'i' ).attr( 'class', dittyVars.updateIcon );
|
5435 |
-
self.$form.trigger( 'submit' );
|
5436 |
-
}
|
5437 |
-
|
5438 |
-
// Show the panel if it exists
|
5439 |
-
if ( self.settings.editor.panelExists( panelId ) ) {
|
5440 |
-
self.settings.editor.$elmt.find( '.ditty-editor__panel--layout_html_editor input.ditty-editor-options__title' ).val( self.$title.val() );
|
5441 |
-
self.settings.editor.panelOptions( 'transition', 'fade' );
|
5442 |
-
self.settings.editor.showPanel( panelId );
|
5443 |
-
|
5444 |
-
// Else, load the new panel and show
|
5445 |
-
} else {
|
5446 |
-
var data = {
|
5447 |
-
action : 'ditty_editor_layout_fields',
|
5448 |
-
layout_id : self.layoutId,
|
5449 |
-
layout_title : self.$title.val(),
|
5450 |
-
ditty_id : self.editorDittyId,
|
5451 |
-
item_id : self.editorItemId,
|
5452 |
-
item_type : self.itemType,
|
5453 |
-
edit_type : 'html',
|
5454 |
-
draft_values : self.settings.editor.getDraftValues(),
|
5455 |
-
security : dittyVars.security
|
5456 |
-
};
|
5457 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
5458 |
-
if ( response ) {
|
5459 |
-
var html = '<div class="ditty-editor__panel ditty-editor__panel--' + panelId + '">' + response.form + '</div>';
|
5460 |
-
self.settings.editor.panelOptions( 'transition', 'fade' );
|
5461 |
-
self.settings.editor.showPanel( panelId, html );
|
5462 |
-
}
|
5463 |
-
}, 'json' );
|
5464 |
-
}
|
5465 |
-
},
|
5466 |
-
|
5467 |
-
/**
|
5468 |
-
* Add an error notice
|
5469 |
-
* @since 3.0
|
5470 |
-
* @return null
|
5471 |
-
*/
|
5472 |
-
_showErrorNotice: function() {
|
5473 |
-
var $error = $( '<div class="ditty-editor-options__body__error"><span>' + dittyVars.strings.layout_css_error + '</span></div>' );
|
5474 |
-
this.$body.append( $error );
|
5475 |
-
|
5476 |
-
},
|
5477 |
-
|
5478 |
-
/**
|
5479 |
-
* Remove the error notice
|
5480 |
-
* @since 3.0
|
5481 |
-
* @return null
|
5482 |
-
*/
|
5483 |
-
_removeErrorNotice: function( e ) {
|
5484 |
-
var self = e.data.self;
|
5485 |
-
self.$body.find( '.ditty-editor-options__body__error' ).remove();
|
5486 |
-
},
|
5487 |
-
|
5488 |
-
/**
|
5489 |
-
* Submit updates
|
5490 |
-
* @since 3.0
|
5491 |
-
* @return null
|
5492 |
-
*/
|
5493 |
-
_submitForm: function( e ) {
|
5494 |
-
e.preventDefault();
|
5495 |
-
|
5496 |
-
var self = e.data.self,
|
5497 |
-
layoutId = self.layoutId,
|
5498 |
-
itemType = self.itemType;
|
5499 |
-
|
5500 |
-
if ( self.$form.hasClass( 'ditty-editor-has-errors' ) ) {
|
5501 |
-
return false;
|
5502 |
-
}
|
5503 |
-
|
5504 |
-
self.codeEditor.codemirror.save(); // Update the textarea
|
5505 |
-
self.settings.editor.updateStart(); // Start the update overlay
|
5506 |
-
|
5507 |
-
var data = {
|
5508 |
-
action : 'ditty_editor_layout_update',
|
5509 |
-
layout_id : layoutId,
|
5510 |
-
item_type : itemType,
|
5511 |
-
edit_type : 'css',
|
5512 |
-
draft_values : self.settings.editor.getDraftValues(),
|
5513 |
-
security : dittyVars.security
|
5514 |
-
};
|
5515 |
-
self.$form.ajaxSubmit( {
|
5516 |
-
url : dittyVars.ajaxurl,
|
5517 |
-
type : 'post',
|
5518 |
-
dataType: 'json',
|
5519 |
-
data : data,
|
5520 |
-
success: function( response ) {
|
5521 |
-
self.initData = self.$form.serialize();
|
5522 |
-
self._disablePreviewButton();
|
5523 |
-
if ( response.label ) {
|
5524 |
-
if ( self.$editorLayoutTitle ) {
|
5525 |
-
self.$editorLayoutTitle.html( response.label );
|
5526 |
-
}
|
5527 |
-
self.$editorLayoutVariationTitle.html( response.label );
|
5528 |
-
}
|
5529 |
-
// Remove the template version numbers
|
5530 |
-
if ( self.$editorLayoutTitle ) {
|
5531 |
-
self.$editorLayoutTitle.find( '.ditty-layout-version' ).remove();
|
5532 |
-
}
|
5533 |
-
if ( self.$editorLayoutVariationTitle ) {
|
5534 |
-
self.$editorLayoutVariationTitle.find( '.ditty-layout-version' ).remove();
|
5535 |
-
}
|
5536 |
-
|
5537 |
-
if ( response.code ) {
|
5538 |
-
dittyLayoutCss( response.code, self.layoutId, 'update' );
|
5539 |
-
} else {
|
5540 |
-
self._showErrorNotice();
|
5541 |
-
}
|
5542 |
-
if ( response.draft_id && response.draft_meta ) {
|
5543 |
-
dittyDraftLayoutUpdate( self, response.draft_id, null, response.draft_meta );
|
5544 |
-
}
|
5545 |
-
|
5546 |
-
self.codeHasUpdates = false;
|
5547 |
-
self.settings.editor.updateStop(); // Stop the update overlay
|
5548 |
-
self.settings.editor.delayedSubmitDisable(); // Remove the delayed submit since we just submitted
|
5549 |
-
|
5550 |
-
if ( 'return' === self.afterUpdateAction ) {
|
5551 |
-
self._showPrevPanel(); // Show the items list
|
5552 |
-
}
|
5553 |
-
if ( 'save' === self.afterUpdateAction ) {
|
5554 |
-
self.settings.editor.saveDitty(); // Update the ticker
|
5555 |
-
}
|
5556 |
-
self.afterUpdateAction = '';
|
5557 |
-
}
|
5558 |
-
} );
|
5559 |
-
},
|
5560 |
-
|
5561 |
-
/**
|
5562 |
-
* Initialize the editor
|
5563 |
-
* @since 3.0
|
5564 |
-
* @return null
|
5565 |
-
*/
|
5566 |
-
_initEditor: function() {
|
5567 |
-
var self = this,
|
5568 |
-
codeEditorSettings = wp.codeEditor.defaultSettings ? _.clone( wp.codeEditor.defaultSettings ) : {},
|
5569 |
-
mode = dittyVars.editor.ditty_layouts_sass ? 'sass' : 'css';
|
5570 |
-
|
5571 |
-
codeEditorSettings.codemirror = _.extend(
|
5572 |
-
{},
|
5573 |
-
codeEditorSettings.codemirror,
|
5574 |
-
{
|
5575 |
-
mode : mode,
|
5576 |
-
indentUnit : 2,
|
5577 |
-
tabSize : 2
|
5578 |
-
}
|
5579 |
-
);
|
5580 |
-
this.codeEditor = wp.codeEditor.initialize( this.$textarea[0], codeEditorSettings );
|
5581 |
-
this.codeEditor.codemirror.on( 'change', function() {
|
5582 |
-
self.codeEditor.codemirror.save();
|
5583 |
-
self.settings.editor.addUpdate( 'layoutCssUpdate', self.layoutId );
|
5584 |
-
self.codeHasUpdates = true;
|
5585 |
-
self._enablePreviewButton();
|
5586 |
-
self.settings.editor.delayedSubmitEnable(); // Enable the delayed submit since we have changes
|
5587 |
-
} );
|
5588 |
-
},
|
5589 |
-
|
5590 |
-
/**
|
5591 |
-
* Insert a tag
|
5592 |
-
* @since 3.0
|
5593 |
-
* @return null
|
5594 |
-
*/
|
5595 |
-
_insertTag: function( e ) {
|
5596 |
-
var self = e.data.self,
|
5597 |
-
$tag = $( e.target ),
|
5598 |
-
text = $tag.text(),
|
5599 |
-
cursor = self.codeEditor.codemirror.getCursor();
|
5600 |
-
|
5601 |
-
self.codeEditor.codemirror.replaceRange( text, cursor );
|
5602 |
-
|
5603 |
-
// Move the cursor position
|
5604 |
-
cursor.ch = cursor.ch + text.length;
|
5605 |
-
self.codeEditor.codemirror.setCursor( cursor );
|
5606 |
-
//self.codeEditor.codemirror.trigger( 'focus' );
|
5607 |
-
},
|
5608 |
-
|
5609 |
-
/**
|
5610 |
-
* Return a specific setting
|
5611 |
-
* @since 3.0
|
5612 |
-
* @return null
|
5613 |
-
*/
|
5614 |
-
_options: function ( key ) {
|
5615 |
-
return this.settings[key];
|
5616 |
-
},
|
5617 |
-
|
5618 |
-
/**
|
5619 |
-
* Setup triggers
|
5620 |
-
* @since 3.0
|
5621 |
-
* @return null
|
5622 |
-
*/
|
5623 |
-
trigger: function ( fn, customParams ) {
|
5624 |
-
var params = [this.settings];
|
5625 |
-
if ( customParams ) {
|
5626 |
-
params = customParams;
|
5627 |
-
}
|
5628 |
-
|
5629 |
-
this.$elmt.trigger( 'ditty_layout_css_editor_panel_' + fn, params );
|
5630 |
-
|
5631 |
-
if ( typeof this.settings[fn] === 'function' ) {
|
5632 |
-
this.settings[fn].apply( this.$elmt, params );
|
5633 |
-
}
|
5634 |
-
},
|
5635 |
-
|
5636 |
-
/**
|
5637 |
-
* Allow settings to be modified
|
5638 |
-
* @since 3.0
|
5639 |
-
* @return null
|
5640 |
-
*/
|
5641 |
-
options: function ( key, value ) {
|
5642 |
-
if ( typeof key === 'object' ) {
|
5643 |
-
this.settings = $.extend( {}, defaults, $.ditty_layout_css_editor_panel.defaults, key );
|
5644 |
-
} else if ( typeof key === 'string' ) {
|
5645 |
-
if ( value === undefined ) {
|
5646 |
-
return this.settings[key];
|
5647 |
-
}
|
5648 |
-
this.settings[key] = value;
|
5649 |
-
} else {
|
5650 |
-
return this.settings;
|
5651 |
-
}
|
5652 |
-
this.trigger( 'options_update' );
|
5653 |
-
},
|
5654 |
-
|
5655 |
-
/**
|
5656 |
-
* Destroy the class
|
5657 |
-
* @since 3.0
|
5658 |
-
* @return null
|
5659 |
-
*/
|
5660 |
-
destroy: function () {
|
5661 |
-
|
5662 |
-
// Remove actions
|
5663 |
-
this.$back.off( 'click', { self: this }, this._backClick );
|
5664 |
-
this.$preview.off( 'click', { self: this }, this._previewClick );
|
5665 |
-
this.$editHtml.off( 'click', { self: this }, this._editHtml );
|
5666 |
-
this.$form.off( 'submit', { self: this }, this._submitForm );
|
5667 |
-
this.$form.off( 'click', '.ditty-editor-options__tag', { self: this }, this._insertTag );
|
5668 |
-
this.$title.off( 'keyup', { self: this }, this._titleUpdate );
|
5669 |
-
this.$body.off( 'click', '.ditty-editor-options__body__error', { self: this }, this._removeErrorNotice );
|
5670 |
-
this.settings.editor.$elmt.off( 'ditty_editor_add_drafts', { self: this }, this._addDrafts );
|
5671 |
-
this.settings.editor.$elmt.off( 'ditty_editor_save_drafts', { self: this }, this._saveDrafts );
|
5672 |
-
this.codeEditor.codemirror.off( 'change' );
|
5673 |
-
this.codeEditor.codemirror.toTextArea();
|
5674 |
-
|
5675 |
-
this.elmt._ditty_layout_css_editor_panel = null;
|
5676 |
-
}
|
5677 |
-
};
|
5678 |
-
|
5679 |
-
/**
|
5680 |
-
* Create the data list
|
5681 |
-
* @since 3.0
|
5682 |
-
* @return null
|
5683 |
-
*/
|
5684 |
-
$.fn.ditty_layout_css_editor_panel = function( options ) {
|
5685 |
-
var args = arguments,
|
5686 |
-
error = false,
|
5687 |
-
returns;
|
5688 |
-
|
5689 |
-
if ( options === undefined || typeof options === 'object' ) {
|
5690 |
-
return this.each( function () {
|
5691 |
-
if ( ! this._ditty_layout_css_editor_panel ) {
|
5692 |
-
this._ditty_layout_css_editor_panel = new Ditty_Layout_Css_Editor_Panel( this, options );
|
5693 |
-
}
|
5694 |
-
});
|
5695 |
-
} else if ( typeof options === 'string' ) {
|
5696 |
-
this.each( function () {
|
5697 |
-
var instance = this._ditty_layout_css_editor_panel;
|
5698 |
-
|
5699 |
-
if ( ! instance ) {
|
5700 |
-
throw new Error( 'No Ditty_Layout_Css_Editor_Panel applied to this element.' );
|
5701 |
-
}
|
5702 |
-
if ( typeof instance[options] === 'function' && options[0] !== '_' ) {
|
5703 |
-
returns = instance[options].apply( instance, [].slice.call( args, 1 ) );
|
5704 |
-
} else {
|
5705 |
-
error = true;
|
5706 |
-
}
|
5707 |
-
} );
|
5708 |
-
|
5709 |
-
if ( error ) {
|
5710 |
-
throw new Error( 'No method "' + options + '" in Ditty_Layout_Css_Editor_Panel.' );
|
5711 |
-
}
|
5712 |
-
|
5713 |
-
return returns !== undefined ? returns : this;
|
5714 |
-
}
|
5715 |
-
};
|
5716 |
-
|
5717 |
-
$.ditty_layout_css_editor_panel = {};
|
5718 |
-
$.ditty_layout_css_editor_panel.defaults = defaults;
|
5719 |
-
|
5720 |
-
} )( jQuery );
|
5721 |
-
|
5722 |
-
|
5723 |
-
/* global dittyVars:true */
|
5724 |
-
|
5725 |
-
jQuery( document ).ready( function( $ ) {
|
5726 |
-
|
5727 |
-
// Setup strict mode
|
5728 |
-
(function() {
|
5729 |
-
|
5730 |
-
"use strict";
|
5731 |
-
|
5732 |
-
function modifyItemsPerPage( $perPage, pagingValue ) {
|
5733 |
-
if ( 0 === parseInt( pagingValue ) ) {
|
5734 |
-
$perPage.hide();
|
5735 |
-
} else {
|
5736 |
-
$perPage.show();
|
5737 |
-
}
|
5738 |
-
}
|
5739 |
-
|
5740 |
-
function modifyArrows( arrowSiblings, arrowsValue ) {
|
5741 |
-
if ( 'none' === arrowsValue ) {
|
5742 |
-
arrowSiblings.hide();
|
5743 |
-
} else {
|
5744 |
-
arrowSiblings.show();
|
5745 |
-
}
|
5746 |
-
}
|
5747 |
-
|
5748 |
-
function modifyBullets( bulletSiblings, bulletsValue ) {
|
5749 |
-
if ( 'none' === bulletsValue ) {
|
5750 |
-
bulletSiblings.hide();
|
5751 |
-
} else {
|
5752 |
-
bulletSiblings.show();
|
5753 |
-
}
|
5754 |
-
}
|
5755 |
-
|
5756 |
-
$( '#ditty-editor' ).on( 'ditty_display_editor_panel_init', '.ditty-editor__panel--displayEditor', function( e, editorPanel ) {
|
5757 |
-
if ( 'list' === editorPanel.displayType ) {
|
5758 |
-
var $form = editorPanel.$form,
|
5759 |
-
$perPage = $form.find( '.ditty-field--perPage' ),
|
5760 |
-
arrowSiblings = $form.find( '.ditty-field--arrows' ).siblings(),
|
5761 |
-
bulletSiblings = $form.find( '.ditty-field--bullets' ).siblings();
|
5762 |
-
|
5763 |
-
// Set paging
|
5764 |
-
modifyItemsPerPage( $perPage, $form.find( 'input[name="paging"]:checked' ).val() );
|
5765 |
-
$form.find( 'input[name="paging"]' ).on( 'change', function() {
|
5766 |
-
modifyItemsPerPage( $perPage, $( this ).val() );
|
5767 |
-
} );
|
5768 |
-
|
5769 |
-
// Set arrows
|
5770 |
-
modifyArrows( arrowSiblings, $form.find( 'select[name="arrows"]' ).val() );
|
5771 |
-
$form.find( 'select[name="arrows"]' ).on( 'change', function() {
|
5772 |
-
modifyArrows( arrowSiblings, $( this ).val() );
|
5773 |
-
} );
|
5774 |
-
|
5775 |
-
// Set bullets
|
5776 |
-
modifyBullets( bulletSiblings, $form.find( 'select[name="bullets"]' ).val() );
|
5777 |
-
$form.find( 'select[name="bullets"]' ).on( 'change', function() {
|
5778 |
-
modifyBullets( bulletSiblings, $( this ).val() );
|
5779 |
-
} );
|
5780 |
-
}
|
5781 |
-
} );
|
5782 |
-
|
5783 |
-
}() );
|
5784 |
-
|
5785 |
-
} );
|
5786 |
-
|
5787 |
-
/* global dittyVars:true */
|
5788 |
-
|
5789 |
-
jQuery( document ).ready( function( $ ) {
|
5790 |
-
|
5791 |
-
// Setup strict mode
|
5792 |
-
(function() {
|
5793 |
-
|
5794 |
-
"use strict";
|
5795 |
-
|
5796 |
-
function modifyHeights( $minHeight, $maxHeight, directionValue ) {
|
5797 |
-
if ( 'down' === directionValue || 'up' === directionValue ) {
|
5798 |
-
$minHeight.show();
|
5799 |
-
$maxHeight.show();
|
5800 |
-
} else {
|
5801 |
-
$minHeight.hide();
|
5802 |
-
$maxHeight.hide();
|
5803 |
-
}
|
5804 |
-
}
|
5805 |
-
|
5806 |
-
$( '#ditty-editor' ).on( 'ditty_display_editor_panel_init', '.ditty-editor__panel--displayEditor', function( e, editorPanel ) {
|
5807 |
-
if ( 'ticker' === editorPanel.displayType ) {
|
5808 |
-
var $form = editorPanel.$form,
|
5809 |
-
$minHeight = $form.find( '.ditty-field--minHeight' ),
|
5810 |
-
$maxHeight = $form.find( '.ditty-field--maxHeight' );
|
5811 |
-
|
5812 |
-
// Set heights
|
5813 |
-
modifyHeights( $minHeight, $maxHeight, $form.find( 'input[name="direction"]:checked' ).val() );
|
5814 |
-
$form.find( 'input[name="direction"]' ).on( 'change', function() {
|
5815 |
-
modifyHeights( $minHeight, $maxHeight, $( this ).val() );
|
5816 |
-
} );
|
5817 |
-
}
|
5818 |
-
} );
|
5819 |
-
|
5820 |
-
}() );
|
5821 |
-
|
5822 |
-
} );
|
1 |
+
function dittyEditorInit(t){if(!t)return!1;var i="auto-draft"===t.options("status")&&"settings";jQuery("#ditty-editor__settings").ditty_editor({ditty:t,panel:i})}function dittyGetItemsById(t,i){var e=[];return jQuery.each(t,(function(t,s){String(s.id)===String(i)&&e.push(s)})),e}function dittyItemsReorder(t,i){var e=[];return jQuery.each(i,(function(i,s){e=jQuery.merge(e,dittyGetItemsById(t,s))})),e}function dittyDraftUpdate(t,i,e,s){var a=t.settings.editor.getDraftValues(i);return a||(a={}),e?a[e]=s:a=s,t.settings.editor.updateDraftValues(i,a)}function dittyDraftGet(t,i,e){var s=t.settings.editor.getDraftValues(i);return!!s&&(e&&s[e]?s[e]:s)}function dittyDraftDelete(t,i,e){var s=i.settings.editor.getDraftValues(t),a={};return jQuery.each(s,(function(t,i){String(e)!==String(t)&&(a[t]=i)})),"new-"!==String(e).substring(0,4)&&(a[e]="DELETE"),i.settings.editor.updateDraftValues(t,a)}function dittyDraftItemDelete(t,i){return dittyDraftDelete("items",t,i)}function dittyDraftLayoutDelete(t,i){return dittyDraftDelete("layouts",t,i)}function dittyDraftDisplayDelete(t,i){return dittyDraftDelete("displays",t,i)}function dittyDraftItemUpdateData(t,i,e,s){var a=t.settings.editor.getDraftValues("items");return a||(a={}),a[i]||(a[i]={}),a[i].data||(a[i].data={}),e?a[i].data[e]=s:a[i].data=s,t.settings.editor.updateDraftValues("items",a)}function dittyDraftItemGetData(t,i,e){var s=t.settings.editor.getDraftValues("items");return!!s[i]&&(!!s[i].data&&(e?s[i].data[e]?s[i].data[e]:void 0:s[i].data))}function dittyDraftItemUpdateMeta(t,i,e,s){var a=t.settings.editor.getDraftValues("items");return a||(a={}),a[i]||(a[i]={}),a[i].meta||(a[i].meta={}),e?a[i].meta[e]=s:a[i].meta=s,t.settings.editor.updateDraftValues("items",a)}function dittyDraftItemGetMeta(t,i,e){var s=t.settings.editor.getDraftValues("items");return!!s[i]&&(!!s[i].meta&&(e?s[i].meta[e]?s[i].meta[e]:void 0:s[i].meta))}function dittyDraftLayoutUpdate(t,i,e,s){var a=t.settings.editor.getDraftValues("layouts");return a||(a={}),a[i]||(a[i]={}),e?a[i][e]=s:a[i]=s,t.settings.editor.updateDraftValues("layouts",a)}function dittyDraftLayoutGet(t,i,e){var s=t.settings.editor.getDraftValues("layouts");return!!s[i]&&(e?s[i][e]?s[i][e]:void 0:s[i])}function dittyDraftDisplayUpdate(t,i,e,s){var a=t.settings.editor.getDraftValues("displays");return a||(a={}),a[i]||(a[i]={}),e?a[i][e]=s:a[i]=s,t.settings.editor.updateDraftValues("displays",a)}function dittyDraftDisplayGet(t,i,e){var s=t.settings.editor.getDraftValues("layouts");return!!s[i]&&(e?s[i][e]?s[i][e]:void 0:s[i])}jQuery(document).ready((function($){!function(){"use strict";$("body").on("ditty_editor_before_panel_update",(function(t,i,e,s,a,d){switch(d.delayedSubmitDisable(),$.protip({defaults:{position:"top",size:"small",scheme:"black",classes:"ditty-protip"}}),i){case"settings":e.hasClass("init")||e.ditty_settings_panel({editor:d});break;case"items":e.hasClass("init")?e.ditty_items_panel("panelVisible"):e.ditty_items_panel({editor:d});break;case"displays":e.find(".ditty-data-list__item").removeClass("editing"),e.hasClass("init")?e.ditty_displays_panel("panelVisible"):e.ditty_displays_panel({editor:d});break;case"item_types":e.find(".ditty-data-list__item").removeClass("editing"),e.hasClass("init")?e.ditty_item_types_panel("panelVisible"):e.ditty_item_types_panel({editor:d});break;case"item_editor":e.ditty_item_editor_panel({editor:d});break;case"display_editor":e.ditty_display_editor_panel({editor:d});break;case"layouts":"layoutHtmlEditor"!==s&&"layoutCssEditor"!==s&&e.ditty_layouts_panel({editor:d});break;case"layout_variations":e.hasClass("init")?e.ditty_layout_variations_panel("panelVisible"):e.ditty_layout_variations_panel({editor:d});break;case"layout_html_editor":e.ditty_layout_html_editor_panel({editor:d,prevPanel:s});break;case"layout_css_editor":e.ditty_layout_css_editor_panel({editor:d,prevPanel:s})}})),$("body").on("ditty_editor_panel_removed",(function(t,i,e){switch(i){case"item_editor":e.ditty_item_editor_panel&&e.ditty_item_editor_panel("destroy");break;case"display_editor":e.ditty_display_editor_panel&&e.ditty_display_editor_panel("destroy");break;case"layouts":case"layouts":e.ditty_layouts_panel&&e.ditty_layouts_panel("destroy");break;case"layout_variations":e.ditty_layout_variations_panel&&e.ditty_layout_variations_panel("destroy");break;case"layout_html_editor":e.ditty_layout_html_editor_panel&&e.ditty_layout_html_editor_panel("destroy");break;case"layout_css_editor":e.ditty_layout_css_editor_panel&&e.ditty_layout_css_editor_panel("destroy")}}))}()})),dittyEditorInit(),function($){"use strict";var t={listType:"toggle",showAll:!0,activeFilter:"*",filter:".ditty-data-list__filter",filterSelector:"filter",item:".ditty-data-list__item",itemSelector:"filter"},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_ui_data_list.defaults,e),this.$elmt=$(i),this.filters=[],this._init()};i.prototype={_init:function(){var t=this;this.$elmt.on("click",this.settings.filter,{self:this},this._filterClick),this.$elmt.find(this.settings.filter+".active").each((function(){t._filterList($(this).data(t.settings.filterSelector))})),"*"!==this.settings.activeFilter&&this._filterList(this.settings.activeFilter),setTimeout((function(){t.trigger("init")}),1)},_filterList:function(t){var i=this,e=this.filters;if("toggle"===this.settings.listType)this.filters.includes(t)?this.settings.showAll&&(this.filters=[],this.$elmt.find(this.settings.filter).removeClass("active"),this.$elmt.find(this.settings.item).show()):(this.filters=[t],this.$elmt.find(this.settings.filter).removeClass("active"),this.$elmt.find(this.settings.filter+"[data-"+this.settings.filterSelector+'="'+t+'"]').addClass("active"),this.$elmt.find(this.settings.item).hide(),this.$elmt.find(this.settings.item+"[data-"+this.settings.itemSelector+'="'+t+'"]').show());else if("filter"===this.settings.listType){if(this.$elmt.find(this.settings.item).hide(),this.filters.includes(t)){this.$elmt.find(this.settings.filter+"[data-"+this.settings.filterSelector+'="'+t+'"]').removeClass("active");for(var s=0;s<this.filters.length;s++)i.filters[s]===t&&i.filters.splice(s,1)}else this.$elmt.find(this.settings.filter+"[data-"+this.settings.filterSelector+'="'+t+'"]').addClass("active"),this.filters.push(t);$.each(this.filters,(function(t,e){i.$elmt.find(this.settings.item+"[data-"+this.settings.itemSelector+'="'+e+'"]').show()})),0===this.filters.length&&i.$elmt.find(this.settings.item).show()}e!==this.filters&&i.trigger("update")},_filterClick:function(t){t.preventDefault();var i=t.data.self,e=$(t.target);e.is("a")||(e=e.parents("a")),i._filterList(e.data(i.settings.filterSelector))},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings,this.filters];i&&(e=i),this.$elmt.trigger("ditty_ui_data_list_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_ui_data_list.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.off("click",this.settings.filter,{self:this},this._filterClick),this.trigger("destroy"),this.elmt._ditty_ui_data_list=null}},$.fn.ditty_ui_data_list=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_ui_data_list||(this._ditty_ui_data_list=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_ui_data_list;if(!i)throw new Error("No Ditty_UI_Data_List applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_UI_Data_List.');return void 0!==e?e:this}},$.ditty_ui_data_list={},$.ditty_ui_data_list.defaults=t}(jQuery),function($){"use strict";var t={screen:"admin",ditty:null,panel:""},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_editor.defaults,e),this.$elmt=$(i),this.ditty=this.settings.ditty,this.dittyId=this.settings.ditty.options("id"),this.dittyType=this.settings.ditty.options("type"),this.displayId=0,this.panelsLoaded=0,this.unsavedUpdates={},this.draftValues={},this.$overlay=null,this.$contents=null,this.$header=null,this.$update=null,this.$updateCount=null,this.$updateLabel=null,this.$tabs=null,this.$panels=null,this.currentTab=0,this.currentPanel=this.settings.panel,this.delayedSubmit=!1,this.tabs=[],this.panels=[],this.activeItems=[],this._init()};i.prototype={_init:function(){var t,i,e,s,a,d,r,o=this;t=$('<div class="ditty-editor__contents"></div>'),this.$contents=t,i=$('<div class="ditty-editor__header"></div>'),this.$header=i,e=$('<span class="ditty-editor__update__count"></span>'),this.$updateCount=e,s=$('<span class="ditty-editor__update__label">Save Ditty</span>'),this.$updateLabel=s,a=$('<button type="submit" class="ditty-editor__update ditty-button ditty-button--primary"></button>'),this.$update=a,d=$('<div class="ditty-editor__tabs"></div>'),this.$tabs=d,r=$('<div class="ditty-editor__panels"></div>'),this.$panels=r,a.prepend(e,s),i.append(a),t.append(i,d,r),this.$elmt.append(t),this.$overlay=$('<div class="ditty-updating-overlay ditty-admin-item__overlay"><div class="ditty-updating-overlay__inner"><i class="fas fa-sync-alt fa-spin"></i></div></div>'),this.$elmt.append(this.$overlay),$(document).on("postbox-moved",{self:this},this._postboxMoved),$(document).on("postboxes-columnchange",{self:this},this._postboxMoved),$(window).on("beforeunload",{self:this},this._beforeunload),this.ditty.$elmt.on("ditty_active_items_update",{self:this},this._dittyItemsUpdated),this.ditty.$elmt.on("ditty_disabled_items_update",{self:this},this._disabledItemsUpdate),this.$tabs.on("click",".ditty-editor__tab",{self:this},this._showPanel),this.$update.on("click",{self:this},this._saveClick),this.$panels.on("ditty_slider_init",{self:this},this._editorLoaded),this.$panels.on("ditty_slider_before_slide_update",{self:this},this._beforeSlideUpdate),this.$panels.on("ditty_slider_after_slide_update",{self:this},this._afterSlideUpdate),this.$panels.on("ditty_slider_slide_removed",{self:this},this._slideRemoved),this._loadContents(),this.trigger("stop_live_updates"),setTimeout((function(){o.trigger("init")}),1)},_loadContents:function(){var t=this,i={action:"ditty_editor_load_contents",ditty_id:this.dittyId,security:dittyVars.security};$.post(dittyVars.ajaxurl,i,(function(i){t._initTabs(i.tabs),t._initPanels(i.panels),t._initSlider()}),"json")},_editorLoaded:function(t){var i=t.data.self;$("body").trigger("ditty_editor_loaded",[i])},_setUpdateCount:function(){},_initSlider:function(){var t=this.tabs[0].id;this.currentPanel&&""!==this.currentPanel&&(t=this.currentPanel),this.$panels.ditty_slider({transition:"fade",transitionSpeed:.75,heightSpeed:.75,touchSwipe:!1,slides:this.panels,slideId:t})},_beforeSlideUpdate:function(t,i,e,s,a){var d=t.data.self;d.updateStart(),d._updateTab(e.id),$("body").trigger("ditty_editor_before_panel_update",[e.id,e.$elmt,a.id,a.$elmt,d])},_afterSlideUpdate:function(t,i,e,s,a){var d=t.data.self;d.updateStop(),$("body").trigger("ditty_editor_after_panel_update",[e.id,e.$elmt,a.id,a.$elmt,d])},_slideRemoved:function(t,i){var e=t.data.self;$("body").trigger("ditty_editor_panel_removed",[i.id,i.$elmt,e])},_showPanel:function(t){t.preventDefault();var i=t.data.self,e=$(t.target).is("a")?$(t.target):$(t.target).parent("a"),s=e.data("panel"),a=parseInt(e.data("index"));if(s===i.currentTab)return!1;var d=a>i.currentTab?"slideLeft":"slideRight";i.$panels.ditty_slider("options","transition",d),i.$panels.ditty_slider("showSlideById",s),i.currentTab=a,i.$elmt.trigger("ditty_editor_add_drafts")},_updateTab:function(t){var i=$('.ditty-editor__tab[data-panel="'+t+'"]');void 0!==i[0]&&($(".ditty-editor__tab").removeClass("active"),i.addClass("active"),this.currentTab=parseInt(i.data("index")))},_initTabs:function(t){var i=this,e=0;$.each(t,(function(t,s){var a=$('<a href="#" class="ditty-editor__tab ditty-editor__tab--'+t+'" data-panel="'+t+'" data-index="'+e+'"><i class="'+s.icon+'"></i><span>'+s.label+"</span></a>");i.$tabs.append(a),i.tabs.push({id:t,tab:a}),e++}))},_initPanels:function(t){var i=this;$.each(t,(function(t,e){var s='<div class="ditty-editor__panel ditty-editor__panel--'+t+'">'+e+"</div>";i.panels.push({id:t,html:s,cache:!0})}))},_initFields:function(t){t.find(".ditty-data-list").ditty_ui_data_list(),t.trigger("ditty_init_fields"),$.protip({defaults:{position:"top",size:"small",scheme:"black",classes:"ditty-protip"}})},saveDitty:function(t){var i=this,e=i.dittyId;i.$updateLabel.text("Updating..."),i.updateStart();var s={action:"ditty_editor_save",ditty_id:e,draft_values:i.draftValues,return_items:1,security:dittyVars.security};s=$.extend({},s,t),$.post(dittyVars.ajaxurl,s,(function(t){$("body").trigger("ditty_editor_save_ditty_response",[t]),t.display_items&&i.ditty.options("items",t.display_items),i.draftValues={},i.unsavedUpdates={},i._setUpdateCount(),i.$elmt.removeClass("ditty-editor--updates-exist"),i.$updateLabel.text("Ditty Saved!"),setTimeout((function(){i.$updateLabel.text("Save Ditty")}),2e3),i.updateStop(),t.new_ditty_url&&window.history.pushState(null,"","/wp-admin/post.php?post="+e+"&action=edit")}))},_saveClick:function(t){t.preventDefault();var i=t.data.self;i.$elmt.trigger("ditty_editor_save_drafts"),i.delayedSubmit||i.saveDitty()},_dittyItemsUpdated:function(t,i,e){var s=t.data.self;s.activeItems=e,s.trigger("active_items_update")},_disabledItemsUpdate:function(t,i){var e=t.data.self;$.each(i,(function(t,i){"disabled"===i?e.$elmt.find("#ditty-editor-item--"+t).addClass("ditty-editor-item--disabled"):e.$elmt.find("#ditty-editor-item--"+t).removeClass("ditty-editor-item--disabled")}))},_postboxMoved:function(t,i){if(!window.tinymce)return!1;$(i).find(".wp-editor-area").each((function(){var t=$(this).attr("id");tinymce.execCommand("mceRemoveEditor",!0,t),tinymce.execCommand("mceAddEditor",!0,t)}))},_beforeunload:function(t){var i=t.data.self;return Object.keys(i.unsavedUpdates).length>0||void 0},_windowResize:function(t){t.preventDefault()},_options:function(t){return this.settings[t]},panelExists:function(t){var i=this.$panels.ditty_slider("options","slides"),e=!1;return $.each(i,(function(i,s){String(s.id)!==String(t)||(e=!0)})),e},showPanel:function(t,i){i&&this.$panels.ditty_slider("addSlideById",t,i),this.$panels.ditty_slider("showSlideById",t,!0)},updateExists:function(t,i){if(void 0===this.unsavedUpdates[t]&&(this.unsavedUpdates[t]=[]),-1!==$.inArray(i,this.unsavedUpdates[t]))return!0},addUpdate:function(t,i){var e=!1;return void 0===this.unsavedUpdates[t]&&(this.unsavedUpdates[t]=[]),-1===$.inArray(i,this.unsavedUpdates[t])&&(e=!0,this.unsavedUpdates[t].push(i)),this._setUpdateCount(),this.$elmt.addClass("ditty-editor--updates-exist"),e},removeUpdate:function(t,i){if(void 0===this.unsavedUpdates[t])return!1;if(-1===$.inArray(i,this.unsavedUpdates[t]))return!1;var e=!1,s=[];return $.each(this.unsavedUpdates[t],(function(t,a){String(i)===String(a)?e=!0:s.push(a)})),this.unsavedUpdates[t]=s,this._setUpdateCount(),""===this.$updateCount.text()&&this.$elmt.removeClass("ditty-editor--updates-exist"),e},updateStart:function(){this.$overlay.fadeIn()},updateStop:function(){this.$overlay.fadeOut()},initFields:function(t){this._initFields(t)},updateDraftValues:function(t,i){return this.$elmt.addClass("ditty-editor--updates-exist"),t?(this.draftValues[t]=i,"development"===dittyVars.mode&&window.console&&console.log("draftValues:",this.draftValues),this.draftValues[t]):(this.draftValues=i,"development"===dittyVars.mode&&window.console&&console.log("draftValues:",this.draftValues),this.draftValues)},getDraftValues:function(t){return t?!!this.draftValues[t]&&this.draftValues[t]:this.draftValues},delayedSubmitEnable:function(){this.delayedSubmit=!0},delayedSubmitDisable:function(){this.delayedSubmit=!1},trigger:function(t,i){var e=[];switch(t){case"active_items_update":e=[this.ditty,this.activeItems];break;case"stop_live_updates":e=[this.dittyId];break;default:e=[this.settings]}i&&(e=i),this.$elmt.trigger("ditty_editor_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e),$("body").trigger("ditty_"+t,e)},_getPanelOption:function(t){return"elmnt"===t?this.$panels:this.settings[t]},_setPanelOption:function(t,i){if(void 0===i)return!1;this.$panels.ditty_slider("options",t,i),this.trigger("update")},panelOptions:function(t,i){var e=this;if("object"==typeof t)$.each(t,(function(t,i){e._setPanelOption(t,i)}));else{if("string"!=typeof t)return e.$panels.ditty_slider("options");if(void 0===i)return e._getPanelOption(t);e._setPanelOption(t,i)}},_getOption:function(t){return"elmnt"===t?this:this.settings[t]},_setOption:function(t,i){if(void 0===i)return!1;this.settings[t]=i,this.trigger("update")},options:function(t,i){var e=this;if("object"==typeof t)$.each(t,(function(t,i){e._setOption(t,i)}));else{if("string"!=typeof t)return e.settings;if(void 0===i)return e._getOption(t);e._setOption(t,i)}},destroy:function(){this.$panels.ditty_slider&&this.$panels.ditty_slider("destroy"),$(document).off("postbox-moved",{self:this},this._postboxMoved),$(document).off("postboxes-columnchange",{self:this},this._postboxMoved),$(window).off("beforeunload",{self:this},this._beforeunload),this.ditty.$elmt.off("ditty_active_items_update",{self:this},this._dittyItemsUpdated),this.ditty.$elmt.off("ditty_disabled_items_update",{self:this},this._disabledItemsUpdate),this.$tabs.off("click","ditty-editor__tab",{self:this},this._showPanel),this.$update.off("click",{self:this},this._saveClick),this.$panels.off("ditty_slider_init",{self:this},this._editorLoaded),this.$panels.off("ditty_slider_before_slide_update",{self:this},this._beforeSlideUpdate),this.$panels.off("ditty_slider_after_slide_update",{self:this},this._afterSlideUpdate),this.$panels.off("ditty_slider_slide_removed",{self:this},this._slideRemoved),this.trigger("destroy"),this.elmt._ditty_editor=null}},$.fn.ditty_editor=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_editor||(this._ditty_editor=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_editor;if(!i)throw new Error("No Ditty_Editor applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Editor.');return void 0!==e?e:this}},$.ditty_editor={},$.ditty_editor.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_settings_panel.defaults,e),this.$elmt=$(i),this.$form=this.$elmt.find(".ditty-editor-options"),this.$title=this.$elmt.find('input[name="title]'),this.$previewBg=this.$elmt.find('input[name="previewBg"]'),this.$previewPaddingTop=this.$elmt.find('input[name="previewPadding[paddingTop]"]'),this.$previewPaddingBottom=this.$elmt.find('input[name="previewPadding[paddingBottom]"]'),this.$previewPaddingLeft=this.$elmt.find('input[name="previewPadding[paddingLeft]"]'),this.$previewPaddingRight=this.$elmt.find('input[name="previewPadding[paddingRight]"]'),this.$postTitle=$(".ditty-post__title"),this.$editorPreview=$("#ditty-editor__preview"),this.dittyId=this.$form.data("ditty_id"),this.initData=null,this.afterUpdateAction="",this._init()};i.prototype={_init:function(){this.initData=this.$form.serialize(),this.settings.editor.initFields(this.$elmt),this.settings.editor.$elmt.on("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.on("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.$form.on("submit",{self:this},this._submitForm),this.$form.on("keyup change",'input[type="text"], input[type="number"], textarea, select',{self:this},this._checkUpdates),this.$form.on("click",'input[type="radio"], input[type="checkbox"]',{self:this},this._checkUpdates),this.$form.on("ditty_input_wysiwyg_update",".ditty-input--wysiwyg",{self:this},this._checkUpdates),this.$form.on("keyup change",'input[name="title"]',{self:this},this._titleChange),this.$form.on("keyup change",".ditty-field--preview_settings *",{self:this},this._previewBgChange),this.$elmt.addClass("init")},_checkUpdates:function(t){var i=t?t.data.self:this;i.$form.serialize()!==i.initData?(i.settings.editor.addUpdate("settings",i.itemId),i.settings.editor.delayedSubmitEnable()):i.settings.editor.removeUpdate("settings",i.itemId)},_titleChange:function(t){var i=t?t.data.self:this,e=$(t.target).val();i.$postTitle.text(e)},_previewBgChange:function(t){var i=t?t.data.self:this,e={backgroundColor:i.$previewBg.val(),paddingTop:i.$previewPaddingTop.val(),paddingBottom:i.$previewPaddingBottom.val(),paddingLeft:i.$previewPaddingLeft.val(),paddingRight:i.$previewPaddingRight.val()};i.$editorPreview.css(e)},_addDrafts:function(t){var i=t.data.self;i.$form.serialize()!==i.initData&&i.$form.trigger("submit")},_saveDrafts:function(t){var i=t.data.self;i.$form.serialize()!==i.initData&&(i.afterUpdateAction="save",i.$form.trigger("submit"))},_submitForm:function(t){t.preventDefault();var i=t.data.self,e=i.dittyId;i.settings.editor.updateStart();var s={action:"ditty_editor_settings_update",ditty_id:e,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};i.$form.ajaxSubmit({url:dittyVars.ajaxurl,type:"post",dataType:"json",data:s,success:function(t){i.initData=i.$form.serialize(),dittyDraftUpdate(i,"settings",!1,t),i.settings.editor.delayedSubmitDisable(),"save"===i.afterUpdateAction&&i.settings.editor.saveDitty({return_items:0}),i.afterUpdateAction=""}})},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_settings_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_settings_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.removeClass("init"),this.settings.editor.$elmt.off("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.settings.editor.$elmt.off("ditty_editor_add_drafts",{self:this},this._addDrafts),this.$form.off("submit",{self:this},this._submitForm),this.$form.off("keyup change",'input[type="text"], input[type="number"], textarea, select',{self:this},this._checkUpdates),this.$form.off("keyup change",'input[name="previewBg"]',{self:this},this._previewBg_cahnge),this.$form.off("keyup change",'input[name="title"]',{self:this},this._titleChange),this.$form.off("click",'input[type="radio"], input[type="checkbox"]',{self:this},this._checkUpdates),this.$form.off("ditty_input_wysiwyg_update",".ditty-input--wysiwyg",{self:this},this._checkUpdates),this.trigger("destroy"),this.elmt._ditty_settings_panel=null}},$.fn.ditty_settings_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_settings_panel||(this._ditty_settings_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_settings_panel;if(!i)throw new Error("No Ditty_Settings_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Settings_Panel.');return void 0!==e?e:this}},$.ditty_settings_panel={},$.ditty_settings_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_items_panel.defaults,e),this.$elmt=$(i),this.$add=$(i).find(".ditty-editor-options__add"),this.$contents=$(i).find(".ditty-editor__panel__contents"),this.$list=$(i).find(".ditty-data-list"),this.$listItems=$(i).find(".ditty-data-list__items"),this.isEmptyTicker=!1,this._init()};i.prototype={_init:function(){this.$elmt.addClass("init"),this.settings.editor.$elmt.on("ditty_editor_aactive_items_update",{self:this},this._dittyActiveItemsUpdated),this.$add.on("click",{self:this},this._add_item),this.$elmt.on("click",".ditty-data-list__item",{self:this},this._showItem),this.$elmt.on("click",".ditty-data-list__item__icon",{self:this},this._editType),this.$elmt.on("click",".ditty-data-list__item__edit",{self:this},this._editItem),this.$elmt.on("click",".ditty-data-list__item__layout",{self:this},this._editLayoutVariations),this.$elmt.on("click",".ditty-data-list__item__clone",{self:this},this._cloneItem),this.$elmt.on("click",".ditty-data-list__item__delete",{self:this},this._deleteItem),this.$list.on("click",".ditty-editor-item > a",{self:this},this._actionClick),$("body").on("ditty_editor_save_ditty_response",{self:this},this._dittyEditorSaveResponse),1>this.$elmt.find(".ditty-data-list__item").length&&(this.isEmptyTicker=!0,this.$add.trigger("click")),this._initializeSorting(),this._highlightListItems(this.settings.editor.activeItems)},dittyUpdateSavedDraftLayouts:function(t,i){$.each($(".ditty-editor-item"),(function(){var e=$(this).data("layout_value");$.each(e,(function(s,a){String(a)===String(t)&&(e[s]=String(i))})),$(this).attr("data-layout_value",e).data("layout_value",e)}))},_dittyEditorSaveResponse:function(t,i){var e=t.data.self;i.ditty_new_item_ids&&$.each(i.ditty_new_item_ids,(function(t,i){var e=$("#ditty-editor-item--"+t);e.length&&(e.attr("id","ditty-editor-item--"+i),e.attr("data-item_id",i).data("item_id",i))})),i.ditty_new_layout_ids&&$.each(i.ditty_new_layout_ids,(function(t,i){e.dittyUpdateSavedDraftLayouts(t,i)}))},_highlightListItem:function(t){var i=t.id+"";i=i.split("_"),this.$elmt.find("#ditty-editor-item--"+i[0]).addClass("active")},_highlightListItems:function(t){this.$elmt.find(".ditty-data-list__item").removeClass("active");var i=this;Array.isArray(t)?$.each(t,(function(t,e){i._highlightListItem(e)})):i._highlightListItem(t)},_dittyActiveItemsUpdated:function(t,i,e){t.data.self._highlightListItems(e)},_initializeSorting:function(){var t=this;this.$listItems.sortable({handle:".ditty-data-list__item__move",items:".ditty-data-list__item",axis:"y",start:function(t,i){$(i.item).addClass("ditty-data-list__item--moving")},stop:function(i,e){$(e.item).removeClass("ditty-data-list__item--moving"),t.settings.editor.addUpdate("item_order",t.settings.editor.dittyId)},update:function(){t._updateItemIndexes("updateDitty")}})},_showItem:function(t){t.preventDefault();var i=t.data.self;if(!$(t.target).is("a")&&!$(t.target).parent().is("a")){var e=($(t.target).is(".ditty-data-list__item")?$(t.target):$(t.target).parents(".ditty-data-list__item")).data("item_id");i.settings.editor.ditty.showItem(e)}},_actionClick:function(t){t.preventDefault();var i=t.data.self,e=$(t.target).is("a")?$(t.target):$(t.target).parent("a"),s=e.parents(".ditty-data-list__item"),a=s.data("ditty_id"),d=s.data("item_id");dittyVars.editor.currentItem=s,$("body").trigger("ditty_editor_item_action_click",[e,s,d,a,i.settings.editor])},_editType:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item");e.trigger("click"),e.addClass("editing"),i.settings.editor.updateStart(),i.settings.editor.panelOptions("transition","slideRight"),i.settings.editor.showPanel("item_types")},_editItem:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("item_id");e.trigger("click"),e.addClass("editing"),i.settings.editor.updateStart();var a={action:"ditty_editor_item_fields",item_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,a,(function(t){if(t){var e='<div class="ditty-editor__panel ditty-editor__panel--item_editor">'+t+"</div>";i.settings.editor.panelOptions("transition","slideLeft"),i.settings.editor.showPanel("item_editor",e)}}))},_editLayoutVariations:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("item_type"),a=e.data("layout_value"),d=e.find(".ditty-data-list__item__label").html();e.trigger("click"),e.addClass("editing"),i.settings.editor.updateStart();var r={action:"ditty_editor_layout_variations",ditty_id:i.settings.editor.dittyId,item_type:s,item_label:d,layout_value:a,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,r,(function(t){if(t){var e='<div class="ditty-editor__panel ditty-editor__panel--layout-variations">'+t+"</div>";i.settings.editor.panelOptions("transition","slideLeft"),i.settings.editor.showPanel("layout_variations",e)}}))},_add_item:function(t){t.preventDefault();var i=t.data.self,e={action:"ditty_editor_item_add",ditty_id:i.settings.editor.dittyId,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,e,(function(t){if(t.display_items){if(i.isEmptyTicker){var e=i.settings.editor.ditty.options("items");$.each(e,(function(t,e){i.settings.editor.ditty.deleteItem(e.id)})),i.isEmptyTicker=!1}$.each(t.display_items,(function(t,e){i.settings.editor.ditty.addItem(e,0)}))}if(t.editor_item){var s=$(t.editor_item);s.hide(),i.$listItems.prepend(s),s.slideDown(),i._updateItemIndexes()}t.draft_id&&t.draft_data&&dittyDraftItemUpdateData(i,t.draft_id,null,t.draft_data),t.draft_id&&t.draft_meta&&dittyDraftItemUpdateMeta(i,t.draft_id,null,t.draft_meta)}),"json")},_cloneItem:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("item_id");i.settings.editor.updateStart();var a={action:"ditty_editor_item_clone",item_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,a,(function(t){if(t.display_items&&t.display_items.length&&i.settings.editor.ditty.updateItems(t.display_items,s,"after"),t.editor_item){var a=$(t.editor_item);a.hide(),e.after(a),a.slideDown(),i._updateItemIndexes()}t.draft_id&&t.draft_data&&dittyDraftItemUpdateData(i,t.draft_id,null,t.draft_data),t.draft_id&&t.draft_meta&&dittyDraftItemUpdateMeta(i,t.draft_id,null,t.draft_meta),i.settings.editor.updateStop()}),"json")},_deleteItem:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("item_id");1>=i.$elmt.find(".ditty-data-list__item").length&&i.$add.trigger("click"),e.slideUp((function(){$(this).remove()})),i.settings.editor.ditty.deleteItem(s),dittyDraftItemDelete(i,s)},_updateItemIndexes:function(t){var i=this,e=[];if(this.$elmt.find(".ditty-data-list__item").each((function(t){var s=$(this).data("item_id");e.push(s),dittyDraftItemUpdateData(i,s,"item_index",t)})),"updateDitty"===t){var s=dittyItemsReorder(i.settings.editor.ditty.options("items"),e);i.settings.editor.ditty.options("items",s)}},panelVisible:function(){this.$elmt.find(".ditty-data-list__item").removeClass("editing")},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_items_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_items_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.removeClass("init"),this.settings.editor.$elmt.off("ditty_editor_active_items_update",{self:this},this._dittyActiveItemsUpdated),this.$add.off("click",{self:this},this._add_item),this.$elmt.off("click",".ditty-data-list__item",{self:this},this._showItem),this.$elmt.off("click",".ditty-data-list__item__icon",{self:this},this._editType),this.$elmt.off("click",".ditty-data-list__item__edit",{self:this
|
2 |
+
},this._editItem),this.$elmt.off("click",".ditty-data-list__item__layout",{self:this},this._editLayoutVariations),this.$elmt.off("click",".ditty-data-list__item__clone",{self:this},this._cloneItem),this.$elmt.off("click",".ditty-data-list__item__delete",{self:this},this._deleteItem),this.$list.off("click",".ditty-editor-item > a",{self:this},this._actionClick),$("body").off("ditty_editor_save_ditty_response",{self:this},this._dittyEditorSaveResponse),this.trigger("destroy"),this.elmt._ditty_items_panel=null}},$.fn.ditty_items_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_items_panel||(this._ditty_items_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_items_panel;if(!i)throw new Error("No Ditty_Items_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Items_Panel.');return void 0!==e?e:this}},$.ditty_items_panel={},$.ditty_items_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_item_types_panel.defaults,e),this.$elmt=$(i),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$editorItem=this.settings.editor.$panels.find(".ditty-editor__panel--items").find(".ditty-data-list__item.editing"),this.editorDittyId=this.$editorItem.data("ditty_id"),this.editorItemId=this.$editorItem.data("item_id"),this.currentType=null,this._init()};i.prototype={_init:function(){this.$elmt.addClass("init"),this.settings.editor.initFields(this.$elmt),this.$back.on("click",{self:this},this._backClick),this.$elmt.on("click",".ditty-editor-item-type",{self:this},this._typeClick),this.panelVisible()},_showItemsList:function(){this.settings.editor.panelOptions("transition","slideLeft"),this.settings.editor.showPanel("items")},_backClick:function(t){t.preventDefault(),t.data.self._showItemsList()},_typeClick:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is(".ditty-editor-item-type")?$(t.target):$(t.target).parents(".ditty-editor-item-type")).data("item_type");if(e===i.currentType)i._showItemsList();else{i.settings.editor.updateStart();var s={action:"ditty_editor_item_type_update",item_id:i.editorItemId,item_type:e,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,s,(function(t){if(t.display_items&&i.settings.editor.ditty.updateItems(t.display_items,i.editorItemId),t.editor_item){var e=$(t.editor_item);i.$editorItem.after(e),i.$editorItem.remove(),i.$editorItem=e}t.draft_id&&t.draft_data&&dittyDraftItemUpdateData(i,t.draft_id,null,t.draft_data),i._showItemsList(),i.settings.editor.updateStop()}),"json")}},panelVisible:function(){this.$editorItem=this.settings.editor.$panels.find(".ditty-editor__panel--items").find(".ditty-data-list__item.editing"),this.editorDittyId=this.$editorItem.data("ditty_id"),this.editorItemId=this.$editorItem.data("item_id"),this.currentType=this.$editorItem.data("item_type"),this.$elmt.find(".ditty-editor-item-type").removeClass("active"),this.$elmt.find('.ditty-editor-item-type[data-itemType="'+this.currentType+'"]').addClass("active")},panelHidden:function(){var t=this.$editorItem.find(".ditty-data-list__item__icon").children("i");t.attr("class",t.data("class"))},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_item_types_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_item_types_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.removeClass("init"),this.$back.off("click",{self:this},this._backClick),this.$elmt.off("click",".ditty-editor-item-type",{self:this},this._typeClick),this.trigger("destroy"),this.elmt._ditty_item_types_panel=null}},$.fn.ditty_item_types_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_item_types_panel||(this._ditty_item_types_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_item_types_panel;if(!i)throw new Error("No Ditty_Item_Types_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Item_Types_Panel.');return void 0!==e?e:this}},$.ditty_item_types_panel={},$.ditty_item_types_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_item_editor_panel.defaults,e),this.$elmt=$(i),this.$form=this.$elmt.find(".ditty-editor-options"),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$preview=this.$elmt.find(".ditty-editor-options__preview"),this.$title=this.$elmt.find(".ditty-editor-options__title"),this.itemId=this.$form.data("item_id"),this.itemType=this.$form.data("item_type"),this.dittyId=this.$form.data("ditty_id"),this.$editorItem=this.settings.editor.$panels.find(".ditty-editor__panel--items").find(".ditty-data-list__item.editing"),this.$editorItemTitle=this.$editorItem.find(".ditty-data-list__item__label"),this.initData=null,this.afterUpdateAction="",this._init()};i.prototype={_init:function(){this.initData=this.$form.serialize(),this.settings.editor.initFields(this.$elmt),this.settings.editor.$elmt.on("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.on("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.$form.on("submit",{self:this},this._submitForm),this.$back.on("click",{self:this},this._backClick),this.$preview.on("click",{self:this},this._previewClick),this.$form.on("keyup change",'input[type="text"], input[type="number"], textarea, select',{self:this},this._checkUpdates),this.$form.on("click",'input[type="radio"], input[type="checkbox"]',{self:this},this._checkUpdates),this.$form.on("ditty_input_wysiwyg_update",".ditty-input--wysiwyg",{self:this},this._checkUpdates),this.$form.on("ditty_field_update",".ditty-field__input",{self:this},this._checkUpdates)},_showItemList:function(){this.settings.editor.$panels.ditty_slider("options","transition","slideRight"),this.settings.editor.$panels.ditty_slider("showSlideById","items")},_enablePreviewButton:function(){this.$preview.addClass("ditty-has-updates")},_disablePreviewButton:function(){this.$preview.removeClass("ditty-has-updates"),this.$preview.children("i").attr("class",this.$preview.children("i").data("class"))},_checkUpdates:function(t){var i=t?t.data.self:this;i.$form.serialize()!==i.initData?(i._enablePreviewButton(),i.settings.editor.addUpdate("item_settings",i.itemId),i.settings.editor.delayedSubmitEnable()):(i._disablePreviewButton(),i.settings.editor.removeUpdate("item_settings",i.itemId))},_addDrafts:function(t){var i=t.data.self;i.$form.serialize()!==i.initData&&i.$form.trigger("submit")},_saveDrafts:function(t){var i=t.data.self;i.$form.serialize()!==i.initData&&(i.afterUpdateAction="save",i.$form.trigger("submit"))},_backClick:function(t){t.preventDefault();var i=t.data.self;i.$form.serialize()===i.initData?i._showItemList():(i.afterUpdateAction="return",i.$form.trigger("submit"))},_previewClick:function(t){t.preventDefault();var i=t.data.self;i.$form.serialize()!==i.initData&&(i.$preview.children("i").attr("class",dittyVars.updateIcon),i.$form.trigger("submit"))},_submitForm:function(t){t.preventDefault();var i=t.data.self,e=i.itemId;i.settings.editor.updateStart();var s={action:"ditty_editor_item_update",item_id:e,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};i.$form.ajaxSubmit({url:dittyVars.ajaxurl,type:"post",dataType:"json",data:s,error:function(){},success:function(t){if(t.value_updates&&i._updateValues(t.value_updates),i.initData=i.$form.serialize(),i._disablePreviewButton(),t.display_items&&i.settings.editor.ditty.updateItems(t.display_items,e),t.editor_item){var s=$(t.editor_item).children(".ditty-data-list__item__label").text();i.$title.html(s),i.$editorItemTitle.html(s)}t.draft_id&&t.draft_data&&dittyDraftItemUpdateData(i,t.draft_id,null,t.draft_data),t.draft_id&&t.draft_meta&&dittyDraftItemUpdateMeta(i,t.draft_id,null,t.draft_meta),i.settings.editor.updateStop(),i.settings.editor.delayedSubmitDisable(),"return"===i.afterUpdateAction&&i._showItemList(),"save"===i.afterUpdateAction&&i.settings.editor.saveDitty({return_items:0}),i.afterUpdateAction=""}})},_updateValues:function(t){var i=this;$.each(t,(function(t,e){var s=i.$form.find('[name="'+t+'"]');s.length&&s.val(e)}))},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_item_editor_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_item_editor_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.settings.editor.$elmt.off("ditty_editor_add_drafts",{self:this},this._saveDrafts),this.settings.editor.$elmt.off("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.$form.off("submit",{self:this},this._submitForm),this.$back.off("click",{self:this},this._backClick),this.$preview.off("click",{self:this},this._previewClick),this.$form.off("keyup change",'input[type="text"], input[type="number"], textarea, select',{self:this},this._checkUpdates),this.$form.off("click",'input[type="radio"], input[type="checkbox"]',{self:this},this._checkUpdates),this.$form.off("ditty_input_wysiwyg_update",".ditty-input--wysiwyg",{self:this},this._checkUpdates),this.$form.off("ditty_field_update",".ditty-field__input",{self:this},this._checkUpdates),this.elmt._ditty_item_editor_panel=null}},$.fn.ditty_item_editor_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_item_editor_panel||(this._ditty_item_editor_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_item_editor_panel;if(!i)throw new Error("No Ditty_Item_Editor_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Item_Editor_Panel.');return void 0!==e?e:this}},$.ditty_item_editor_panel={},$.ditty_item_editor_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_displays_panel.defaults,e),this.$elmt=$(i),this.$list=$(i).find(".ditty-data-list__items"),this.$contents=$(i).find(".ditty-editor__panel__contents"),this.initDisplay=null,this._init()};i.prototype={_init:function(){this.$elmt.addClass("init"),this.$elmt.ditty_ui_data_list({filter:".ditty-display-panel__filter",item:".ditty-editor-display",itemSelector:"display_type"}),this.initDisplay=this.$list.data("active"),this._activateDisplay(this.$list.find("#ditty-editor-display--"+this.initDisplay)),this.$elmt.on("click",".ditty-data-list__item",{self:this},this._selectDisplay),this.$elmt.on("click",".ditty-data-list__item__edit",{self:this},this._editDisplay),this.$elmt.on("click",".ditty-data-list__item__clone",{self:this},this._cloneDisplay),this.$elmt.on("click",".ditty-data-list__item__delete",{self:this},this._deleteDisplay),this.settings.editor.$elmt.on("ditty_editor_saveDrafts",{self:this},this._saveDrafts)},_saveDrafts:function(t){var i=t.data.self;i.initDisplay=i.$list.find(".ditty-editor-display.active").data("display_id")},_activateDisplay:function(t){this.$list.find(".ditty-editor-display").removeClass("active"),t.addClass("active")},_initDitty:function(t,i,e){var s=this.settings.editor.ditty.$elmt;e.display=i,e.id=this.settings.editor.ditty.options("id"),e.items=this.settings.editor.ditty.options("items"),e.height=this.settings.editor.ditty.options("height"),this.settings.editor.ditty.destroy(),s["ditty_"+t](e),this.settings.editor.ditty=s["ditty_"+t]("options","ditty")},_selectDisplay:function(t){t.preventDefault();var i=t.data.self;if($(t.target).parent().is("a"))return!1;var e=$(t.target).is(".ditty-data-list__item")?$(t.target):$(t.target).parents(".ditty-data-list__item"),s=e.data("display_id"),a=e.data("display_type");if(e.hasClass("active"))return!1;i.settings.editor.updateStart(),dittyDraftUpdate(i,"post_meta","_ditty_display",s),i._activateDisplay(e);var d={action:"ditty_editor_select_display",display_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,d,(function(t){if(!t)return!1;i._initDitty(a,s,t),i.settings.editor.updateStop()}),"json")},_cloneDisplay:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("display_id");i.settings.editor.updateStart();var a={action:"ditty_editor_display_clone",display_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,a,(function(t){if(t.editor_display){var s=$(t.editor_display);s.hide(),e.after(s),s.slideDown()}t.draft_id&&t.draft_data&&dittyDraftDisplayUpdate(i,t.draft_id,null,t.draft_data),i.settings.editor.updateStop()}),"json")},_deleteDisplay:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=null,a=e.data("display_id");e.hasClass("active")&&(e.prev().length?s=e.prev():e.next().length&&(s=e.next())),e.slideUp((function(){$(this).remove()})),dittyDraftDisplayDelete(i,a),null!==s&&s.trigger("click")},_editDisplay:function(t){t.preventDefault();var i=t.data.self;i.$displayEdit=$(this).parents(".ditty-data-list__item");var e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("display_id");i.settings.editor.updateStart(),e.addClass("editing");var a={action:"ditty_editor_display_fields",display_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,a,(function(t){if(t){var e='<div class="ditty-editor__panel ditty-editor__panel--displayEditor">'+t+"</div>";i.settings.editor.panelOptions("transition","slideLeft"),i.settings.editor.showPanel("display_editor",e)}}))},panelVisible:function(){this.$elmt.find(".ditty-data-list__item").removeClass("editing")},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_displays_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_displays_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.removeClass("init"),this.$elmt.ditty_ui_data_list("destroy"),this.$elmt.off("click",".ditty-data-list__item",{self:this},this._selectDisplay),this.$elmt.off("click",".ditty-data-list__item__edit",{self:this},this._editDisplay),this.$elmt.off("click",".ditty-data-list__item__clone",{self:this},this._cloneDisplay),this.$elmt.off("click",".ditty-data-list__item__delete",{self:this},this._deleteDisplay),this.settings.editor.$elmt.off("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.trigger("destroy"),this.elmt._ditty_displays_panel=null}},$.fn.ditty_displays_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_displays_panel||(this._ditty_displays_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_displays_panel;if(!i)throw new Error("No Ditty_Displays_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Displays_Panel.');return void 0!==e?e:this}},$.ditty_displays_panel={},$.ditty_displays_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_display_editor_panel.defaults,e),this.$elmt=$(i),this.$form=this.$elmt.find(".ditty-editor-options"),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$optionsTitle=this.$elmt.find(".ditty-editor-options__title"),this.$importExportField=this.$elmt.find(".ditty-editor__import-export__field"),this.$importExportUpdate=this.$elmt.find(".ditty-editor__import-export__update"),this.displayTitle=null,this.displayId=this.settings.editor.ditty.options("display"),this.displayType=this.settings.editor.ditty.options("type"),this.$editorDisplay=this.settings.editor.$panels.find(".ditty-editor__panel--displays").find(".ditty-data-list__item.editing"),this.$editorDisplayTitle=this.$editorDisplay.find(".ditty-data-list__item__label"),this.displayOptions=null,this.initData=null,this.afterUpdateAction="",this._init()};i.prototype={_init:function(){var t,i=this;this.initData=this.$form.serialize(),this.settings.editor.initFields(this.$elmt),t=this.settings.editor.ditty.$elmt["ditty_"+this.displayType]("options"),this.displayOptions=$.extend({},t),this.displayTitle=this.$optionsTitle.val(),this.$importExportUpdate.on("click",{self:this},this._importUpdate),this.settings.editor.$elmt.on("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.on("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.$form.on("submit",{self:this},this._submitForm),this.$back.on("click",{self:this},this._backClick),this.$elmt.on("change",'input[type="text"], input[type="number"]',{self:this},this._textfieldListeners),this.$form.on("click",'input[type="radio"]',{self:this},this._radioListeners),this.$form.on("click",'input[type="checkbox"]',{self:this},this._checkboxListeners),this.$form.on("change","select",{self:this},this._selectListeners),this.$form.on("ditty_field_clone_update",{self:this},this._cloneListeners),setTimeout((function(){i.trigger("init",[i])}),1)},_showDisplayList:function(){this.settings.editor.$panels.ditty_slider("options","transition","slideRight"),this.settings.editor.$panels.ditty_slider("showSlideById","displays")},_checkUpdates:function(){this.$form.serialize()!==this.initData?(this.settings.editor.addUpdate("displaySettings",this.displayId),this.settings.editor.delayedSubmitEnable()):this.settings.editor.removeUpdate("displaySettings",this.displayId)},_addDrafts:function(t){var i=t.data.self;i.$form.serialize()!==i.initData&&i.$form.trigger("submit")},_saveDrafts:function(t){var i=t.data.self;i.$form.serialize()!==i.initData&&(i.afterUpdateAction="save",i.$form.trigger("submit"))},_backClick:function(t){t.preventDefault();var i=t.data.self;i.$form.serialize()===i.initData?i._showDisplayList():(i.afterUpdateAction="return",i.$form.trigger("submit"))},_submitForm:function(t){t.preventDefault();var i=t.data.self;i.settings.editor.updateStart();var e={action:"ditty_editor_display_update",display_id:i.displayId,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};i.$form.ajaxSubmit({url:dittyVars.ajaxurl,type:"post",dataType:"json",data:e,success:function(t){i.initData=i.$form.serialize(),t.draft_id&&t.draft_label&&(i.displayTitle=t.draft_label,i.$editorDisplayTitle.text(t.draft_label),dittyDraftDisplayUpdate(i,t.draft_id,"label",t.draft_label)),t.draft_id&&t.draft_settings&&(i.displayOptions=t.draft_settings,dittyDraftDisplayUpdate(i,t.draft_id,"settings",t.draft_settings)),t.draft_settings_json&&i.$importExportField.length&&i.$importExportField.val(t.draft_settings_json),i.settings.editor.updateStop(),i.settings.editor.delayedSubmitDisable(),"return"===i.afterUpdateAction&&i._showDisplayList(),"save"===i.afterUpdateAction&&i.settings.editor.saveDitty(),i.afterUpdateAction=""}})},_importUpdate:function(t){t.preventDefault()},_cloneListeners:function(t,i,e){var s=t.data.self;$(t.target);s.settings.editor.ditty.options(e,i)},_textfieldListeners:function(t){var i=t.data.self,e=$(t.target),s=e.attr("name"),a=e.parents(".ditty-input--spacing__group, .ditty-input--radius__group");if(a.length){var d="",r={};a.find("input").each((function(){s=$(this).attr("name"),d=(d=s.split("["))[0];var t=s.match(/\[(.*)\]/);r[t[1]]=$(this).val()})),i.settings.editor.ditty.options(d,r)}else i.settings.editor.ditty.options(s,e.val());i._checkUpdates()},_radioListeners:function(t){var i=t.data.self,e=$(t.target),s=e.val(),a=e.attr("name");i.settings.editor.ditty.options(a,s),i._checkUpdates()},_checkboxListeners:function(t){var i=t.data.self,e=$(t.target),s=!!e.is(":checked")&&$(this).val(),a=e.attr("name");i.settings.editor.ditty.options(a,s),i._checkUpdates()},_selectListeners:function(t){var i=t.data.self,e=$(t.target),s=e.val(),a=e.attr("name");i.settings.editor.ditty.options(a,s),i._checkUpdates()},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_display_editor_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_display_editor_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.trigger("destroy",[this]),this.$importExportUpdate.off("click",{this:this},this._importUpdate),this.settings.editor.$elmt.off("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.off("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.$form.off("submit",{this:this},this._submitForm),this.$back.off("click",{this:this},this._cancel_click),this.$elmt.off("change",'input[type="text"], input[type="number"]',{self:this},this._textfieldListeners),this.$form.off("click",'input[type="radio"]',{self:this},this._radioListeners),this.$form.off("click",'input[type="checkbox"]',{self:this},this._checkboxListeners),this.$form.off("change","select",{self:this},this._selectListeners),this.$form.off("ditty_field_clone_update",{self:this},this._cloneListeners),this.elmt._ditty_display_editor_panel=null}},$.fn.ditty_display_editor_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_display_editor_panel||(this._ditty_display_editor_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_display_editor_panel;if(!i)throw new Error("No Ditty_Display_Editor_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Display_Editor_Panel.');return void 0!==e?e:this}},$.ditty_display_editor_panel={},$.ditty_display_editor_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_layout_variations_panel.defaults,e),this.$elmt=$(i),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$list=$(i).find(".ditty-data-list__items"),this.$editorItem=dittyVars.editor.currentItem,this.editorItemLabel=this.$editorItem.find(".ditty-data-list__item__label").text(),this.editorDittyId=this.$editorItem.data("ditty_id"),this.editorItemId=this.$editorItem.data("item_id"),this.editorItemType=this.$editorItem.data("item_type"),this._init()};i.prototype={_init:function(){this.$elmt.addClass("init"),this.$back.on("click",{self:this},this._backClick),this.$elmt.on("click",".ditty-layout-variation__change",{self:this},this._changeTemplate),this.$elmt.on("click",".ditty-layout-variation__edit_html",{self:this,editType:"html"},this._editLayout),this.$elmt.on("click",".ditty-layout-variation__edit_css",{self:this,editType:"css"},this._editLayout),$("body").on("ditty_editor_save_ditty_response",{self:this},this._dittyEditorSaveResponse)},_showItemList:function(){this.settings.editor.$panels.ditty_slider("options","transition","slideRight"),this.settings.editor.$panels.ditty_slider("showSlideById","items")},_backClick:function(t){t.preventDefault(),t.data.self._showItemList()},_dittyEditorSaveResponse:function(t,i){t.data.self;i.ditty_new_layout_ids&&$.each(i.ditty_new_layout_ids,(function(t,i){var e=$('.ditty-layout-variation[data-layout_id="'+t+'"]');e.length&&e.attr("data-layout_id",i).data("layout_id",i)}))},_changeTemplate:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("layout_id"),a=e.data("layout_variation_id"),d=e.data("layout_variation_label");dittyVars.editor.currentLayoutVariation=e,i.settings.editor.updateStart(),e.addClass("editing");var r={action:"ditty_editor_layouts",ditty_id:i.editorDittyId,item_type:i.editorItemType,variation_id:a,variation_label:d,layout_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,r,(function(t){if(t){var e='<div class="ditty-editor__panel ditty-editor__panel--layouts">'+t+"</div>";i.settings.editor.panelOptions("transition","slideLeft"),i.settings.editor.showPanel("layouts",e)}}))},_editLayout:function(t){t.preventDefault();var i=t.data.self,e=t.data.editType,s=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),a=s.data("layout_id"),d=s.data("item_type");dittyVars.editor.currentLayoutVariation=s,i.settings.editor.updateStart(),i.$list.find(".ditty-data-list__item").removeClass("editing"),s.addClass("editing");var r=[],o=i.settings.editor.ditty.options("items");$.each(o,(function(t,i){r.push(i.uniqId)}));var n={action:"ditty_editor_layout_fields",layout_id:a,item_type:d,ditty_id:i.editorDittyId,item_id:i.editorItemId,item_ids:r,edit_type:e,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,n,(function(t){if(t){var s="layout_"+e+"_editor",a='<div class="ditty-editor__panel ditty-editor__panel--'+s+'">'+t.form+"</div>";i.settings.editor.panelOptions("transition","slideLeft"),i.settings.editor.showPanel(s,a)}}),"json")},panelVisible:function(){this.$list.find(".ditty-layout-variation").removeClass("editing")},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_layout_variations_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_layout_variations_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.removeClass("init"),this.$back.off("click",{self:this},this._backClick),this.$elmt.off("click",".ditty-layout-variation__change",{self:this},this._changeTemplate),this.$elmt.off("click",".ditty-layout-variation__edit_html",{self:this,editType:"html"},this._editLayout),this.$elmt.off("click",".ditty-layout-variation__edit_css",{self:this,editType:"css"},this._editLayout),$("body").off("ditty_editor_save_ditty_response",{self:this},this._dittyEditorSaveResponse),this.elmt._ditty_layout_variations_panel=null}},$.fn.ditty_layout_variations_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_layout_variations_panel||(this._ditty_layout_variations_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_layout_variations_panel;if(!i)throw new Error("No Ditty_Layout_Variations_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Layout_Variations_Panel.');return void 0!==e?e:this}},$.ditty_layout_variations_panel={},$.ditty_layout_variations_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_layouts_panel.defaults,e),this.$elmt=$(i),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$list=$(i).find(".ditty-data-list__items"),this.$editorItem=dittyVars.editor.currentItem,this.editorDittyId=this.$editorItem.data("ditty_id"),this.editorItemId=this.$editorItem.data("item_id"),this.editorItemtype=this.$editorItem.data("item_type"),this.$editorVariation=dittyVars.editor.currentLayoutVariation,this.editorVariationId=this.$editorVariation.data("layout_variation_id"),this.editorLayoutId=this.$editorVariation.data("layout_id"),this._init()};i.prototype={_init:function(){this.$elmt.addClass("init"),this.$back.on("click",{self:this},this._backClick),this.$elmt.on("click",".ditty-data-list__item",{self:this},this._selectLayout),this.$elmt.on("click",".ditty-data-list__item__edit_html",{self:this,editType:"html"},this._editLayout),this.$elmt.on("click",".ditty-data-list__item__edit_css",{self:this,editType:"css"},this._editLayout),this.$elmt.on("click",".ditty-data-list__item__clone",{self:this},this._cloneLayout),this.$elmt.on("click",".ditty-data-list__item__delete",{self:this},this._deleteLayout),this.$list.on("click",".ditty-editor-layout > a",{self:this},this._actionClick),$("body").on("ditty_editor_save_ditty_response",{self:this},this._dittyEditorSaveResponse),this._activateLayout(this.$list.find("#ditty-editor-layout--"+this.editorLayoutId))},_activateLayout:function(t){this.$list.find(".ditty-editor-layout").removeClass("active"),t.addClass("active")},_showVariationsList:function(){this.settings.editor.$panels.ditty_slider("options","transition","slideRight"),this.settings.editor.$panels.ditty_slider("showSlideById","layout_variations")},_backClick:function(t){t.preventDefault(),t.data.self._showVariationsList()},_dittyEditorSaveResponse:function(t,i){t.data.self;i.ditty_new_layout_ids&&$.each(i.ditty_new_layout_ids,(function(t,i){var e=$("#ditty-editor-layout--"+t);e.length&&(e.attr("id","ditty-editor-layout--"+i),e.attr("data-layout_id",i).data("layout_id",i))}))},_selectLayout:function(t){t.preventDefault();var i=t.data.self;if($(t.target).parent().is("a"))return!1;var e=$(t.target).is(".ditty-data-list__item")?$(t.target):$(t.target).parents(".ditty-data-list__item"),s=e.data("layout_id"),a=e.data("layout_version"),d=i.$editorItem.data("layout_value");if(e.hasClass("active"))return!1;$.each(d,(function(t){i.editorVariationId===t&&(d[t]=String(s))})),i.settings.editor.updateStart(),dittyDraftItemUpdateData(i,i.editorItemId,"layout_value",d),i._activateLayout(e);var r={action:"ditty_editor_select_layout",layout_id:s,item_id:i.editorItemId,ditty_id:i.editorDittyId,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,r,(function(t){if(i.settings.editor.updateStop(),t.display_items&&i.settings.editor.ditty.updateItems(t.display_items,i.editorItemId),t.editor_item){var e=$(t.editor_item);i.$editorItem.replaceWith(e)}i.$editorItem.attr("data-layout_value",d).data("layout_value",d),i.$editorVariation.attr("data-layout_id",s).data("layout_id",s),i.$editorVariation.find(".ditty-layout-variation__template > span").text(t.layout_label),a?i.$editorVariation.find(".ditty-layout-variation__template > small").text("("+a+")"):i.$editorVariation.find(".ditty-layout-variation__template > small").text("")}),"json")},_cloneLayout:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=e.data("layout_id");i.settings.editor.updateStart();var a={action:"ditty_editor_layout_clone",layout_id:s,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,a,(function(t){if(t.editor_layout){var s=$(t.editor_layout);s.hide(),e.after(s),
|
3 |
+
s.slideDown()}t.draft_id&&t.draft_meta&&dittyDraftLayoutUpdate(i,t.draft_id,null,t.draft_meta),i.settings.editor.updateStop()}),"json")},_deleteLayout:function(t){t.preventDefault();var i=t.data.self,e=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),s=null,a=e.data("layout_id");e.hasClass("active")&&(e.prev().length?s=e.prev():e.next().length&&(s=e.next())),e.slideUp((function(){$(this).remove()})),dittyDraftLayoutDelete(i,a),null!==s&&s.trigger("click")},_editLayout:function(t){t.preventDefault();var i=t.data.self,e=t.data.editType,s=($(t.target).is("a")?$(t.target):$(t.target).parent("a")).parents(".ditty-data-list__item"),a=s.data("layout_id");i.settings.editor.updateStart(),i.$list.find(".ditty-data-list__item").removeClass("editing"),s.addClass("editing");var d={action:"ditty_editor_layout_fields",layout_id:a,item_id:i.editorItemId,edit_type:e,draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,d,(function(t){if(t){var s="layout_"+e+"_editor",a='<div class="ditty-editor__panel ditty-editor__panel--'+s+'">'+t.form+"</div>";i.settings.editor.panelOptions("transition","slideLeft"),i.settings.editor.showPanel(s,a)}}),"json")},_actionClick:function(t){t.preventDefault();var i=t.data.self,e=$(t.target).is("a")?$(t.target):$(t.target).parent("a"),s=e.parents(".ditty-data-list__item"),a=s.data("layout_id");dittyVars.editor.currentLayout=s,$("body").trigger("ditty_editor_layout_action_click",[e,s,a,i.editorDittyId,i.settings.editor])},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_layouts_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_layouts_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$elmt.removeClass("init"),this.$back.off("click",{self:this},this._backClick),this.$elmt.off("click",".ditty-data-list__item",{self:this},this._selectLayout),this.$elmt.off("click",".ditty-data-list__item__edit_html",{self:this,editType:"html"},this._editLayout),this.$elmt.off("click",".ditty-data-list__item__edit_css",{self:this,editType:"css"},this._editLayout),this.$elmt.off("click",".ditty-data-list__item__clone",{self:this},this._cloneLayout),this.$elmt.off("click",".ditty-data-list__item__delete",{self:this},this._deleteLayout),this.$list.off("click",".ditty-editor-layout > a",{self:this},this._actionClick),$("body").off("ditty_editor_save_ditty_response",{self:this},this._dittyEditorSaveResponse),this.elmt._ditty_layouts_panel=null}},$.fn.ditty_layouts_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_layouts_panel||(this._ditty_layouts_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_layouts_panel;if(!i)throw new Error("No Ditty_Layouts_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Layouts_Panel.');return void 0!==e?e:this}},$.ditty_layouts_panel={},$.ditty_layouts_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null,prevPanel:""},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_layout_html_editor_panel.defaults,e),this.$elmt=$(i),this.$form=this.$elmt.find(".ditty-editor-options"),this.$textarea=this.$elmt.find(".ditty-editor-options__code"),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$preview=this.$elmt.find(".ditty-editor-options__preview"),this.$editCss=this.$elmt.find(".ditty-editor-options__edit-css"),this.$title=this.$elmt.find(".ditty-editor-options__title"),this.$tags=this.$elmt.find(".ditty-editor-options__tags"),this.itemType=this.$form.data("item_type"),this.layoutId=this.$form.data("layout_id"),this.$editorItem=dittyVars.editor.currentItem,this.$editorLayout=dittyVars.editor.currentLayout,this.$editorLayoutTitle=!!this.$editorLayout&&this.$editorLayout.find(".ditty-data-list__item__label"),this.$editorLayoutVariation=dittyVars.editor.currentLayoutVariation,this.$editorLayoutVariationTitle=this.$editorLayoutVariation.find(".ditty-layout-variation__template span"),this.editorDittyId=this.$editorItem.data("ditty_id"),this.editorItemId=this.$editorItem.data("item_id"),this.codeEditor=null,this.codeHasUpdates=!1,this.initData=null,this.afterUpdateAction="",this._init()};i.prototype={_init:function(){this.initData=this.$form.serialize(),this._initEditor(),this.$back.on("click",{self:this},this._backClick),this.$preview.on("click",{self:this},this._previewClick),this.$editCss.on("click",{self:this},this._editCss),this.$form.on("submit",{self:this},this._submitForm),this.$form.on("click",".ditty-editor-options__tag",{self:this},this._insertTag),this.$title.on("keyup",{self:this},this._titleUpdate),this.settings.editor.$elmt.on("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.on("ditty_editor_save_drafts",{self:this},this._saveDrafts)},_showPrevPanel:function(){this.settings.editor.$panels.ditty_slider("options","transition","slideRight"),this.settings.editor.$panels.ditty_slider("showSlideById",this.settings.prevPanel)},_titleUpdate:function(t){var i=t.data.self;i.settings.editor.addUpdate("layoutUpdate",i.layoutId)},_enablePreviewButton:function(){this.$preview.addClass("ditty-has-updates")},_disablePreviewButton:function(){this.$preview.removeClass("ditty-has-updates"),this.$preview.children("i").attr("class",this.$preview.children("i").data("class"))},_getLayoutItems:function(){var t=this.settings.editor.ditty.options("items"),i=[];return $.each(t,(function(t,e){String(e.layoutId)===String(this.layoutId)&&i.push(e.id)})),i},_addDrafts:function(t){var i=t.data.self;i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&i.$form.trigger("submit")},_saveDrafts:function(t){var i=t.data.self;i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&(i.afterUpdateAction="save",i.$form.trigger("submit"))},_backClick:function(t){t.preventDefault();var i=t.data.self;i.codeEditor.codemirror.save(),i.$form.serialize()!==i.initData||i.codeHasUpdates?(i.afterUpdateAction="return",i.$form.trigger("submit")):i._showPrevPanel()},_previewClick:function(t){t.preventDefault();var i=t.data.self;i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&(i.$preview.children("i").attr("class",dittyVars.updateIcon),i.$form.trigger("submit"))},_editCss:function(t){t.preventDefault();var i=t.data.self,e="layout_css_editor";if(i.settings.editor.updateStart(),i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&(i.$preview.children("i").attr("class",dittyVars.updateIcon),i.$form.trigger("submit")),i.settings.editor.panelExists(e))i.settings.editor.$elmt.find(".ditty-editor__panel--layout_css_editor input.ditty-editor-options__title").val(i.$title.val()),i.settings.editor.panelOptions("transition","fade"),i.settings.editor.showPanel(e);else{var s={action:"ditty_editor_layout_fields",layout_id:i.layoutId,layout_title:i.$title.val(),ditty_id:i.editorDittyId,item_id:i.editorItemId,item_type:i.itemType,edit_type:"css",draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,s,(function(t){if(t){var s='<div class="ditty-editor__panel ditty-editor__panel--'+e+'">'+t.form+"</div>";i.settings.editor.panelOptions("transition","fade"),i.settings.editor.showPanel(e,s)}}),"json")}},_submitForm:function(t){t.preventDefault();var i=t.data.self,e=i.layoutId,s=i.itemType,a=i._getLayoutItems();if(i.$form.hasClass("ditty-editor-has-errors"))return!1;i.codeEditor.codemirror.save(),i.settings.editor.updateStart();var d={action:"ditty_editor_layout_update",layout_id:e,item_type:s,item_ids:a,edit_type:"html",draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};i.$form.ajaxSubmit({url:dittyVars.ajaxurl,type:"post",dataType:"json",data:d,success:function(t){i.initData=i.$form.serialize(),i._disablePreviewButton(),t.label&&(i.$editorLayoutTitle&&i.$editorLayoutTitle.html(t.label),i.$editorLayoutVariationTitle.html(t.label)),i.$editorLayoutTitle&&i.$editorLayoutTitle.find(".ditty-layout-version").remove(),i.$editorLayoutVariationTitle&&i.$editorLayoutVariationTitle.find(".ditty-layout-version").remove(),t.display_items&&i.settings.editor.ditty.updateItems(t.display_items,!1,!1,!0),t.draft_id&&t.draft_meta&&dittyDraftLayoutUpdate(i,t.draft_id,null,t.draft_meta),i.codeHasUpdates=!1,i.settings.editor.updateStop(),i.settings.editor.delayedSubmitDisable(),"return"===i.afterUpdateAction&&i._showPrevPanel(),"save"===i.afterUpdateAction&&i.settings.editor.saveDitty({return_items:0}),i.afterUpdateAction=""}})},_initEditor:function(){var t=this,i=wp.codeEditor.defaultSettings?_.clone(wp.codeEditor.defaultSettings):{};i.codemirror=_.extend({},i.codemirror,{indentUnit:2,tabSize:2}),this.codeEditor=wp.codeEditor.initialize(this.$textarea[0],i),this.codeEditor.codemirror.on("change",(function(){t.codeEditor.codemirror.save(),t.settings.editor.addUpdate("layout_html_update",t.layoutId),t.codeHasUpdates=!0,t._enablePreviewButton(),t.settings.editor.delayedSubmitEnable()}))},_insertTag:function(t){var i=t.data.self,e=$(t.target),s=e.text(),a=e.data("atts"),d=i.codeEditor.codemirror.getCursor();if(t.shiftKey&&a){var r="",o=s.length-1;$.each(a,(function(t,i){r+=" "+t+'="'+i.toString()+'"'})),s=s.substring(0,o)+r+s.substring(o)}i.codeEditor.codemirror.replaceRange(s,d),d.ch=d.ch+s.length,i.codeEditor.codemirror.setCursor(d)},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_layout_html_editor_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_layout_html_editor_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$back.off("click",{self:this},this._backClick),this.$preview.off("click",{self:this},this._previewClick),this.$editCss.off("click",{self:this},this._editCss),this.$form.off("submit",{self:this},this._submitForm),this.$form.off("click",".ditty-editor-options__tag",{self:this},this._insertTag),this.$title.off("keyup",{self:this},this._titleUpdate),this.settings.editor.$elmt.off("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.off("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.codeEditor.codemirror.off("change"),this.codeEditor.codemirror.toTextArea(),this.elmt._ditty_layout_html_editor_panel=null}},$.fn.ditty_layout_html_editor_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_layout_html_editor_panel||(this._ditty_layout_html_editor_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_layout_html_editor_panel;if(!i)throw new Error("No Ditty_Layout_Html_Editor_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Layout_Html_Editor_Panel.');return void 0!==e?e:this}},$.ditty_layout_html_editor_panel={},$.ditty_layout_html_editor_panel.defaults=t}(jQuery),function($){"use strict";var t={editor:null,prevPanel:""},i=function(i,e){this.elmt=i,this.settings=$.extend({},t,$.ditty_layout_css_editor_panel.defaults,e),this.$elmt=$(i),this.$form=this.$elmt.find(".ditty-editor-options"),this.$textarea=this.$elmt.find(".ditty-editor-options__code"),this.$back=this.$elmt.find(".ditty-editor-options__back"),this.$preview=this.$elmt.find(".ditty-editor-options__preview"),this.$editHtml=this.$elmt.find(".ditty-editor-options__edit-html"),this.$title=this.$elmt.find(".ditty-editor-options__title"),this.$body=this.$elmt.find(".ditty-editor-options__body"),this.$tags=this.$elmt.find(".ditty-editor-options__tags"),this.itemType=this.$form.data("item_type"),this.layoutId=this.$form.data("layout_id"),this.$editorItem=dittyVars.editor.currentItem,this.$editorLayout=dittyVars.editor.currentLayout,this.$editorLayoutTitle=!!this.$editorLayout&&this.$editorLayout.find(".ditty-data-list__item__label"),this.$editorLayoutVariation=dittyVars.editor.currentLayoutVariation,this.$editorLayoutVariationTitle=this.$editorLayoutVariation.find(".ditty-layout-variation__template span"),this.editorDittyId=this.$editorItem.data("ditty_id"),this.editorItemId=this.$editorItem.data("item_id"),this.itemSelector="",this.codeEditor=null,this.codeHasUpdates=!1,this.initData=null,this.afterUpdateAction="",this._init()};i.prototype={_init:function(){this.initData=this.$form.serialize(),this._setCssSelector(),this._initEditor(),this.$back.on("click",{self:this},this._backClick),this.$preview.on("click",{self:this},this._previewClick),this.$editHtml.on("click",{self:this},this._editHtml),this.$form.on("submit",{self:this},this._submitForm),this.$form.on("click",".ditty-editor-options__tag",{self:this},this._insertTag),this.$title.on("keyup",{self:this},this._titleUpdate),this.$body.on("click",".ditty-editor-options__body__error",{self:this},this._removeErrorNotice),this.settings.editor.$elmt.on("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.on("ditty_editor_save_drafts",{self:this},this._saveDrafts)},_setCssSelector:function(){dittyVars.isTickerPost?this.itemSelector="#poststuff .ditty-layout--"+this.layoutId:this.itemSelector=".ditty-layout--"+this.layoutId},_showPrevPanel:function(){this.settings.editor.$panels.ditty_slider("options","transition","slideRight"),this.settings.editor.$panels.ditty_slider("showSlideById",this.settings.prevPanel)},_titleUpdate:function(t){var i=t.data.self;i.settings.editor.addUpdate("layoutUpdate",i.layoutId)},_enablePreviewButton:function(){this.$preview.addClass("ditty-has-updates")},_disablePreviewButton:function(){this.$preview.removeClass("ditty-has-updates"),this.$preview.children("i").attr("class",this.$preview.children("i").data("class"))},_addDrafts:function(t){var i=t.data.self;i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&i.$form.trigger("submit")},_saveDrafts:function(t){var i=t.data.self;i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&(i.afterUpdateAction="save",i.$form.trigger("submit"))},_backClick:function(t){t.preventDefault();var i=t.data.self;i.codeEditor.codemirror.save(),i.$form.serialize()!==i.initData||i.codeHasUpdates?(i.afterUpdateAction="return",i.$form.trigger("submit")):i._showPrevPanel()},_previewClick:function(t){t.preventDefault();var i=t.data.self;i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&(i.$preview.children("i").attr("class",dittyVars.updateIcon),i.$form.trigger("submit"))},_editHtml:function(t){t.preventDefault();var i=t.data.self,e="layout_html_editor";if(i.settings.editor.updateStart(),i.codeEditor.codemirror.save(),(i.$form.serialize()!==i.initData||i.codeHasUpdates)&&(i.$preview.children("i").attr("class",dittyVars.updateIcon),i.$form.trigger("submit")),i.settings.editor.panelExists(e))i.settings.editor.$elmt.find(".ditty-editor__panel--layout_html_editor input.ditty-editor-options__title").val(i.$title.val()),i.settings.editor.panelOptions("transition","fade"),i.settings.editor.showPanel(e);else{var s={action:"ditty_editor_layout_fields",layout_id:i.layoutId,layout_title:i.$title.val(),ditty_id:i.editorDittyId,item_id:i.editorItemId,item_type:i.itemType,edit_type:"html",draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};$.post(dittyVars.ajaxurl,s,(function(t){if(t){var s='<div class="ditty-editor__panel ditty-editor__panel--'+e+'">'+t.form+"</div>";i.settings.editor.panelOptions("transition","fade"),i.settings.editor.showPanel(e,s)}}),"json")}},_showErrorNotice:function(){var t=$('<div class="ditty-editor-options__body__error"><span>'+dittyVars.strings.layout_css_error+"</span></div>");this.$body.append(t)},_removeErrorNotice:function(t){t.data.self.$body.find(".ditty-editor-options__body__error").remove()},_submitForm:function(t){t.preventDefault();var i=t.data.self,e=i.layoutId,s=i.itemType;if(i.$form.hasClass("ditty-editor-has-errors"))return!1;i.codeEditor.codemirror.save(),i.settings.editor.updateStart();var a={action:"ditty_editor_layout_update",layout_id:e,item_type:s,edit_type:"css",draft_values:i.settings.editor.getDraftValues(),security:dittyVars.security};i.$form.ajaxSubmit({url:dittyVars.ajaxurl,type:"post",dataType:"json",data:a,success:function(t){i.initData=i.$form.serialize(),i._disablePreviewButton(),t.label&&(i.$editorLayoutTitle&&i.$editorLayoutTitle.html(t.label),i.$editorLayoutVariationTitle.html(t.label)),i.$editorLayoutTitle&&i.$editorLayoutTitle.find(".ditty-layout-version").remove(),i.$editorLayoutVariationTitle&&i.$editorLayoutVariationTitle.find(".ditty-layout-version").remove(),t.code?dittyLayoutCss(t.code,i.layoutId,"update"):i._showErrorNotice(),t.draft_id&&t.draft_meta&&dittyDraftLayoutUpdate(i,t.draft_id,null,t.draft_meta),i.codeHasUpdates=!1,i.settings.editor.updateStop(),i.settings.editor.delayedSubmitDisable(),"return"===i.afterUpdateAction&&i._showPrevPanel(),"save"===i.afterUpdateAction&&i.settings.editor.saveDitty(),i.afterUpdateAction=""}})},_initEditor:function(){var t=this,i=wp.codeEditor.defaultSettings?_.clone(wp.codeEditor.defaultSettings):{},e=dittyVars.editor.ditty_layouts_sass?"sass":"css";i.codemirror=_.extend({},i.codemirror,{mode:e,indentUnit:2,tabSize:2}),this.codeEditor=wp.codeEditor.initialize(this.$textarea[0],i),this.codeEditor.codemirror.on("change",(function(){t.codeEditor.codemirror.save(),t.settings.editor.addUpdate("layoutCssUpdate",t.layoutId),t.codeHasUpdates=!0,t._enablePreviewButton(),t.settings.editor.delayedSubmitEnable()}))},_insertTag:function(t){var i=t.data.self,e=$(t.target).text(),s=i.codeEditor.codemirror.getCursor();i.codeEditor.codemirror.replaceRange(e,s),s.ch=s.ch+e.length,i.codeEditor.codemirror.setCursor(s)},_options:function(t){return this.settings[t]},trigger:function(t,i){var e=[this.settings];i&&(e=i),this.$elmt.trigger("ditty_layout_css_editor_panel_"+t,e),"function"==typeof this.settings[t]&&this.settings[t].apply(this.$elmt,e)},options:function(i,e){if("object"==typeof i)this.settings=$.extend({},t,$.ditty_layout_css_editor_panel.defaults,i);else{if("string"!=typeof i)return this.settings;if(void 0===e)return this.settings[i];this.settings[i]=e}this.trigger("options_update")},destroy:function(){this.$back.off("click",{self:this},this._backClick),this.$preview.off("click",{self:this},this._previewClick),this.$editHtml.off("click",{self:this},this._editHtml),this.$form.off("submit",{self:this},this._submitForm),this.$form.off("click",".ditty-editor-options__tag",{self:this},this._insertTag),this.$title.off("keyup",{self:this},this._titleUpdate),this.$body.off("click",".ditty-editor-options__body__error",{self:this},this._removeErrorNotice),this.settings.editor.$elmt.off("ditty_editor_add_drafts",{self:this},this._addDrafts),this.settings.editor.$elmt.off("ditty_editor_save_drafts",{self:this},this._saveDrafts),this.codeEditor.codemirror.off("change"),this.codeEditor.codemirror.toTextArea(),this.elmt._ditty_layout_css_editor_panel=null}},$.fn.ditty_layout_css_editor_panel=function(t){var e,s=arguments,a=!1;if(void 0===t||"object"==typeof t)return this.each((function(){this._ditty_layout_css_editor_panel||(this._ditty_layout_css_editor_panel=new i(this,t))}));if("string"==typeof t){if(this.each((function(){var i=this._ditty_layout_css_editor_panel;if(!i)throw new Error("No Ditty_Layout_Css_Editor_Panel applied to this element.");"function"==typeof i[t]&&"_"!==t[0]?e=i[t].apply(i,[].slice.call(s,1)):a=!0})),a)throw new Error('No method "'+t+'" in Ditty_Layout_Css_Editor_Panel.');return void 0!==e?e:this}},$.ditty_layout_css_editor_panel={},$.ditty_layout_css_editor_panel.defaults=t}(jQuery),jQuery(document).ready((function($){!function(){"use strict";function t(t,i){0===parseInt(i)?t.hide():t.show()}function i(t,i){"none"===i?t.hide():t.show()}function e(t,i){"none"===i?t.hide():t.show()}$("#ditty-editor").on("ditty_display_editor_panel_init",".ditty-editor__panel--displayEditor",(function(s,a){if("list"===a.displayType){var d=a.$form,r=d.find(".ditty-field--perPage"),o=d.find(".ditty-field--arrows").siblings(),n=d.find(".ditty-field--bullets").siblings();t(r,d.find('input[name="paging"]:checked').val()),d.find('input[name="paging"]').on("change",(function(){t(r,$(this).val())})),i(o,d.find('select[name="arrows"]').val()),d.find('select[name="arrows"]').on("change",(function(){i(o,$(this).val())})),e(n,d.find('select[name="bullets"]').val()),d.find('select[name="bullets"]').on("change",(function(){e(n,$(this).val())}))}}))}()})),jQuery(document).ready((function($){!function(){"use strict";function t(t,i,e){"down"===e||"up"===e?(t.show(),i.show()):(t.hide(),i.hide())}$("#ditty-editor").on("ditty_display_editor_panel_init",".ditty-editor__panel--displayEditor",(function(i,e){if("ticker"===e.displayType){var s=e.$form,a=s.find(".ditty-field--minHeight"),d=s.find(".ditty-field--maxHeight");t(a,d,s.find('input[name="direction"]:checked').val()),s.find('input[name="direction"]').on("change",(function(){t(a,d,$(this).val())}))}}))}()}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/js/ditty.js
CHANGED
@@ -83,7 +83,7 @@ jQuery( document ).ready( function( $ ) {
|
|
83 |
/**
|
84 |
* Check for live updates
|
85 |
*
|
86 |
-
* @since 3.0
|
87 |
* @return null
|
88 |
*/
|
89 |
function checkLiveUpdates() {
|
@@ -96,7 +96,7 @@ jQuery( document ).ready( function( $ ) {
|
|
96 |
if ( response.updated_items ) {
|
97 |
$.each( response.updated_items, function( dittyId, items ) {
|
98 |
liveUpdate( dittyId, items );
|
99 |
-
liveIds[dittyId] = Math.floor( $.now() / 1000 );
|
100 |
} );
|
101 |
}
|
102 |
}, 'json' );
|
@@ -204,7 +204,7 @@ jQuery( document ).ready( function( $ ) {
|
|
204 |
/**
|
205 |
* Load all the dittys
|
206 |
*
|
207 |
-
* @since 3.0
|
208 |
* @return null
|
209 |
*/
|
210 |
function dittyInit() {
|
@@ -213,11 +213,12 @@ jQuery( document ).ready( function( $ ) {
|
|
213 |
setupGlobalDitty();
|
214 |
|
215 |
$( '.ditty' ).each( function() {
|
216 |
-
var $ditty
|
217 |
-
ajax_load
|
218 |
-
live_updates
|
219 |
-
|
220 |
-
|
|
|
221 |
|
222 |
// Load the Dittys via ajax
|
223 |
if ( ajax_load ) {
|
@@ -226,9 +227,9 @@ jQuery( document ).ready( function( $ ) {
|
|
226 |
id : $ditty.data( 'id' ) ? $ditty.data( 'id' ) : false,
|
227 |
uniqid : $ditty.data( 'uniqid' ) ? $ditty.data( 'uniqid' ) : false,
|
228 |
display : $ditty.data( 'display' ) ? $ditty.data( 'display' ) : '',
|
229 |
-
display_settings :
|
|
|
230 |
editor : editor,
|
231 |
-
load_type : load_type,
|
232 |
security : dittyVars.security
|
233 |
};
|
234 |
$.post( dittyVars.ajaxurl, data, function( response ) {
|
@@ -245,14 +246,20 @@ jQuery( document ).ready( function( $ ) {
|
|
245 |
|
246 |
// Add to the liveIds
|
247 |
if ( ! editor && live_updates ) {
|
248 |
-
liveIds[$ditty.data( 'id' )] =
|
|
|
|
|
|
|
249 |
}
|
250 |
}, 'json' );
|
251 |
|
252 |
} else {
|
253 |
|
254 |
if ( ! editor && live_updates ) {
|
255 |
-
liveIds[$ditty.data( 'id' )] =
|
|
|
|
|
|
|
256 |
}
|
257 |
}
|
258 |
} );
|
83 |
/**
|
84 |
* Check for live updates
|
85 |
*
|
86 |
+
* @since 3.0.11
|
87 |
* @return null
|
88 |
*/
|
89 |
function checkLiveUpdates() {
|
96 |
if ( response.updated_items ) {
|
97 |
$.each( response.updated_items, function( dittyId, items ) {
|
98 |
liveUpdate( dittyId, items );
|
99 |
+
liveIds[dittyId].timestamp = Math.floor( $.now() / 1000 );
|
100 |
} );
|
101 |
}
|
102 |
}, 'json' );
|
204 |
/**
|
205 |
* Load all the dittys
|
206 |
*
|
207 |
+
* @since 3.0.11
|
208 |
* @return null
|
209 |
*/
|
210 |
function dittyInit() {
|
213 |
setupGlobalDitty();
|
214 |
|
215 |
$( '.ditty' ).each( function() {
|
216 |
+
var $ditty = $( this ),
|
217 |
+
ajax_load = $ditty.data( 'ajax_load' ) ? $ditty.data( 'ajax_load' ) : false,
|
218 |
+
live_updates = $ditty.data( 'live_updates' ) ? $ditty.data( 'live_updates' ) : false,
|
219 |
+
display_settings = $ditty.data( 'display_settings' ) ? $ditty.data( 'display_settings' ) : false,
|
220 |
+
layout_settings = $ditty.data( 'layout_settings' ) ? $ditty.data( 'layout_settings' ) : false,
|
221 |
+
editor = $ditty.data( 'show_editor' ) ? $ditty.data( 'show_editor' ) : false;
|
222 |
|
223 |
// Load the Dittys via ajax
|
224 |
if ( ajax_load ) {
|
227 |
id : $ditty.data( 'id' ) ? $ditty.data( 'id' ) : false,
|
228 |
uniqid : $ditty.data( 'uniqid' ) ? $ditty.data( 'uniqid' ) : false,
|
229 |
display : $ditty.data( 'display' ) ? $ditty.data( 'display' ) : '',
|
230 |
+
display_settings : display_settings,
|
231 |
+
layout_settings : layout_settings,
|
232 |
editor : editor,
|
|
|
233 |
security : dittyVars.security
|
234 |
};
|
235 |
$.post( dittyVars.ajaxurl, data, function( response ) {
|
246 |
|
247 |
// Add to the liveIds
|
248 |
if ( ! editor && live_updates ) {
|
249 |
+
liveIds[$ditty.data( 'id' )] = {
|
250 |
+
timestamp : Math.floor( $.now()/1000 ),
|
251 |
+
layout_settings : layout_settings
|
252 |
+
};
|
253 |
}
|
254 |
}, 'json' );
|
255 |
|
256 |
} else {
|
257 |
|
258 |
if ( ! editor && live_updates ) {
|
259 |
+
liveIds[$ditty.data( 'id' )] = {
|
260 |
+
timestamp : Math.floor( $.now()/1000 ),
|
261 |
+
layout_settings : layout_settings
|
262 |
+
};
|
263 |
}
|
264 |
}
|
265 |
} );
|
includes/js/ditty.min.js
CHANGED
@@ -1,364 +1 @@
|
|
1 |
-
|
2 |
-
/* global dittyVars:true */
|
3 |
-
|
4 |
-
// @codekit-append 'partials/helpers.js';
|
5 |
-
|
6 |
-
jQuery( document ).ready( function( $ ) {
|
7 |
-
|
8 |
-
// Setup strict mode
|
9 |
-
(function() {
|
10 |
-
|
11 |
-
"use strict";
|
12 |
-
|
13 |
-
var liveIds = {},
|
14 |
-
liveInterval = null;
|
15 |
-
|
16 |
-
/**
|
17 |
-
* Listen for ditty live update start triggers
|
18 |
-
*
|
19 |
-
* @since 3.0
|
20 |
-
* @return null
|
21 |
-
*/
|
22 |
-
/*
|
23 |
-
$( 'body' ).on( 'ditty_start_live_updates', function( event, dittyId ) {
|
24 |
-
liveIds[dittyId] = Math.floor( $.now()/1000 );
|
25 |
-
startLiveUpdates();
|
26 |
-
} );
|
27 |
-
*/
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Listen for ditty live update stop triggers
|
31 |
-
*
|
32 |
-
* @since 3.0
|
33 |
-
* @return null
|
34 |
-
*/
|
35 |
-
/*
|
36 |
-
$( 'body' ).on( 'ditty_stop_live_updates', function( event, dittyId ) {
|
37 |
-
var updated_liveIds = {};
|
38 |
-
$.each( liveIds, function( dittyId, timestamp ) {
|
39 |
-
if ( parseInt( dittyId ) !== parseInt( dittyId ) ) {
|
40 |
-
updated_liveIds[dittyId] = timestamp;
|
41 |
-
}
|
42 |
-
} );
|
43 |
-
liveIds = updated_liveIds;
|
44 |
-
if ( undefined === liveIds.length ) {
|
45 |
-
stopLiveUpdates();
|
46 |
-
}
|
47 |
-
} );
|
48 |
-
*/
|
49 |
-
|
50 |
-
/**
|
51 |
-
* Live update a Ditty
|
52 |
-
*
|
53 |
-
* @since 3.0
|
54 |
-
* @return null
|
55 |
-
*/
|
56 |
-
function liveUpdate( dittyId, items ) {
|
57 |
-
$( '.ditty[data-id="' + dittyId + '"]' ).each( function() {
|
58 |
-
var displayType = $( this ).data( 'type' );
|
59 |
-
if ( 'development' === dittyVars.mode && window.console ) {
|
60 |
-
console.log( 'LIVE UPDATE' );
|
61 |
-
}
|
62 |
-
$( this )['ditty_' + displayType]( 'options', 'items', items );
|
63 |
-
} );
|
64 |
-
}
|
65 |
-
|
66 |
-
/**
|
67 |
-
* Get current API IDs
|
68 |
-
*
|
69 |
-
* @since 3.0
|
70 |
-
* @return null
|
71 |
-
*/
|
72 |
-
// function getApiIds() {
|
73 |
-
// var apiIds = {};
|
74 |
-
// $( '.ditty-item' ).each( function() {
|
75 |
-
// var apiId = $( this ).data( 'api_id' );
|
76 |
-
// if ( apiId ) {
|
77 |
-
// apiIds[apiId] = apiId;
|
78 |
-
// }
|
79 |
-
// } );
|
80 |
-
// return apiIds;
|
81 |
-
// }
|
82 |
-
|
83 |
-
/**
|
84 |
-
* Check for live updates
|
85 |
-
*
|
86 |
-
* @since 3.0
|
87 |
-
* @return null
|
88 |
-
*/
|
89 |
-
function checkLiveUpdates() {
|
90 |
-
var data = {
|
91 |
-
action : 'ditty_live_updates',
|
92 |
-
live_ids : liveIds,
|
93 |
-
security : dittyVars.security
|
94 |
-
};
|
95 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
96 |
-
if ( response.updated_items ) {
|
97 |
-
$.each( response.updated_items, function( dittyId, items ) {
|
98 |
-
liveUpdate( dittyId, items );
|
99 |
-
liveIds[dittyId] = Math.floor( $.now() / 1000 );
|
100 |
-
} );
|
101 |
-
}
|
102 |
-
}, 'json' );
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* Stop listening for live updates
|
107 |
-
*
|
108 |
-
* @since 3.0
|
109 |
-
* @return null
|
110 |
-
*/
|
111 |
-
// function stopLiveUpdates() {
|
112 |
-
// if ( null !== liveInterval ) {
|
113 |
-
// cancelAnimationFrame( liveInterval );
|
114 |
-
// liveInterval = null;
|
115 |
-
// }
|
116 |
-
// }
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Start listening for live updates
|
120 |
-
*
|
121 |
-
* @since 3.0
|
122 |
-
* @return null
|
123 |
-
*/
|
124 |
-
function startLiveUpdates() {
|
125 |
-
if ( null !== liveInterval || 1 > Object.keys( liveIds ).length ) {
|
126 |
-
return false;
|
127 |
-
}
|
128 |
-
|
129 |
-
cancelAnimationFrame( liveInterval );
|
130 |
-
|
131 |
-
var updateInterval = dittyVars.updateInterval ? parseInt( dittyVars.updateInterval ) : 60,
|
132 |
-
startTime = Date.now();
|
133 |
-
|
134 |
-
function dittyLiveUpdatesLoop() {
|
135 |
-
var currTime = Date.now(),
|
136 |
-
passedTime = Math.floor( ( currTime - startTime ) / 1000 );
|
137 |
-
|
138 |
-
if ( passedTime >= updateInterval ) {
|
139 |
-
startTime = currTime;
|
140 |
-
checkLiveUpdates();
|
141 |
-
}
|
142 |
-
liveInterval = requestAnimationFrame( dittyLiveUpdatesLoop );
|
143 |
-
}
|
144 |
-
liveInterval = requestAnimationFrame( dittyLiveUpdatesLoop );
|
145 |
-
}
|
146 |
-
|
147 |
-
/**
|
148 |
-
* Update extension API calls
|
149 |
-
*
|
150 |
-
* @since 3.0
|
151 |
-
* @return null
|
152 |
-
*/
|
153 |
-
// function updateExtensionApis() {
|
154 |
-
// var data = {
|
155 |
-
// action : 'ditty_api_background_updates',
|
156 |
-
// security : dittyVars.security
|
157 |
-
// };
|
158 |
-
// $.post( dittyVars.ajaxurl, data, function() {
|
159 |
-
// }, 'json' );
|
160 |
-
// }
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Setup the global Dittys
|
164 |
-
*
|
165 |
-
* @since 3.0
|
166 |
-
* @return null
|
167 |
-
*/
|
168 |
-
function setupGlobalDitty() {
|
169 |
-
$.each( dittyVars.globals, function( index, data ) {
|
170 |
-
var selector = $( data.selector );
|
171 |
-
if ( ! data.ditty || undefined === selector[0] ) {
|
172 |
-
return;
|
173 |
-
}
|
174 |
-
var $ditty = $( '<div class="ditty" data-id="' + data.ditty + '" data-ajax_load="1"></div>' );
|
175 |
-
if ( data.display && '' !== data.display ) {
|
176 |
-
$ditty.attr( 'data-display', data.display );
|
177 |
-
}
|
178 |
-
if ( data.live_updates && '1' === String( data.live_updates ) ) {
|
179 |
-
$ditty.attr( 'data-live_updates', '1' );
|
180 |
-
}
|
181 |
-
if ( data.customId && '' !== data.customId ) {
|
182 |
-
$ditty.attr( 'id', data.customId );
|
183 |
-
}
|
184 |
-
if ( data.customClasses && '' !== data.customClasses ) {
|
185 |
-
$ditty.addClass( data.customClasses );
|
186 |
-
}
|
187 |
-
switch( data.position ) {
|
188 |
-
case 'prepend':
|
189 |
-
$( selector[0] ).prepend( $ditty );
|
190 |
-
break;
|
191 |
-
case 'before':
|
192 |
-
$( selector[0] ).before( $ditty );
|
193 |
-
break;
|
194 |
-
case 'after':
|
195 |
-
$( selector[0] ).after( $ditty );
|
196 |
-
break;
|
197 |
-
default:
|
198 |
-
$( selector[0] ).append( $ditty );
|
199 |
-
break;
|
200 |
-
}
|
201 |
-
} );
|
202 |
-
}
|
203 |
-
|
204 |
-
/**
|
205 |
-
* Load all the dittys
|
206 |
-
*
|
207 |
-
* @since 3.0
|
208 |
-
* @return null
|
209 |
-
*/
|
210 |
-
function dittyInit() {
|
211 |
-
|
212 |
-
// Add the global Dittys
|
213 |
-
setupGlobalDitty();
|
214 |
-
|
215 |
-
$( '.ditty' ).each( function() {
|
216 |
-
var $ditty = $( this ),
|
217 |
-
ajax_load = $ditty.data( 'ajax_load' ) ? $ditty.data( 'ajax_load' ) : false,
|
218 |
-
live_updates = $ditty.data( 'live_updates' ) ? $ditty.data( 'live_updates' ) : false,
|
219 |
-
editor = $ditty.data( 'show_editor' ) ? $ditty.data( 'show_editor' ) : false,
|
220 |
-
load_type = $ditty.data( 'load_type' ) ? $ditty.data( 'load_type' ) : false;
|
221 |
-
|
222 |
-
// Load the Dittys via ajax
|
223 |
-
if ( ajax_load ) {
|
224 |
-
var data = {
|
225 |
-
action : 'ditty_init',
|
226 |
-
id : $ditty.data( 'id' ) ? $ditty.data( 'id' ) : false,
|
227 |
-
uniqid : $ditty.data( 'uniqid' ) ? $ditty.data( 'uniqid' ) : false,
|
228 |
-
display : $ditty.data( 'display' ) ? $ditty.data( 'display' ) : '',
|
229 |
-
display_settings : $ditty.data( 'display_settings' ) ? $ditty.data( 'display_settings' ) : false,
|
230 |
-
editor : editor,
|
231 |
-
load_type : load_type,
|
232 |
-
security : dittyVars.security
|
233 |
-
};
|
234 |
-
$.post( dittyVars.ajaxurl, data, function( response ) {
|
235 |
-
// Make sure the display type exists
|
236 |
-
if ( ! response.display_type || ( 'function' !== typeof $ditty['ditty_' + response.display_type] ) ) {
|
237 |
-
if ( window.console ) {
|
238 |
-
console.log( 'Ditty Display type not loaded:', response.display_type );
|
239 |
-
}
|
240 |
-
return false;
|
241 |
-
}
|
242 |
-
|
243 |
-
// Load the ditty
|
244 |
-
$ditty['ditty_' + response.display_type]( response.args );
|
245 |
-
|
246 |
-
// Add to the liveIds
|
247 |
-
if ( ! editor && live_updates ) {
|
248 |
-
liveIds[$ditty.data( 'id' )] = Math.floor( $.now()/1000 );
|
249 |
-
}
|
250 |
-
}, 'json' );
|
251 |
-
|
252 |
-
} else {
|
253 |
-
|
254 |
-
if ( ! editor && live_updates ) {
|
255 |
-
liveIds[$ditty.data( 'id' )] = Math.floor( $.now()/1000 );
|
256 |
-
}
|
257 |
-
}
|
258 |
-
} );
|
259 |
-
|
260 |
-
if ( $( '.ditty' ).length && dittyVars.updateInterval ) {
|
261 |
-
startLiveUpdates();
|
262 |
-
}
|
263 |
-
}
|
264 |
-
dittyInit();
|
265 |
-
|
266 |
-
}() );
|
267 |
-
|
268 |
-
} );
|
269 |
-
|
270 |
-
/**
|
271 |
-
* Update item layout css
|
272 |
-
*
|
273 |
-
* @since 3.0
|
274 |
-
* @return null
|
275 |
-
*/
|
276 |
-
function dittyLayoutCss( layoutCss, layoutId, updateCSS ) {
|
277 |
-
var $styles = jQuery( 'style#ditty-layout--' + layoutId );
|
278 |
-
if ( undefined === $styles[0] ) {
|
279 |
-
$styles = jQuery( '<style id="ditty-layout--' + layoutId + '"></style>' );
|
280 |
-
jQuery( 'head' ).append( $styles );
|
281 |
-
updateCSS = 'update';
|
282 |
-
}
|
283 |
-
if ( 'update' === updateCSS ) {
|
284 |
-
layoutCss = layoutCss.replace( '>', '>' );
|
285 |
-
$styles.html( layoutCss );
|
286 |
-
}
|
287 |
-
}
|
288 |
-
|
289 |
-
/**
|
290 |
-
* Update item display css
|
291 |
-
*
|
292 |
-
* @since 3.0
|
293 |
-
* @return null
|
294 |
-
*/
|
295 |
-
function dittyDisplayCss( displayCss, displayId ) {
|
296 |
-
var $styles = jQuery( 'style#ditty-display--' + displayId );
|
297 |
-
if ( undefined === $styles[0] ) {
|
298 |
-
$styles = jQuery( '<style id="ditty-display--' + displayId + '"></style>' );
|
299 |
-
jQuery( 'head' ).append( $styles );
|
300 |
-
}
|
301 |
-
displayCss = displayCss.replace( '>', '>' );
|
302 |
-
$styles.html( displayCss );
|
303 |
-
}
|
304 |
-
|
305 |
-
/**
|
306 |
-
* Update items
|
307 |
-
*
|
308 |
-
* @since 3.0.10
|
309 |
-
* @return null
|
310 |
-
*/
|
311 |
-
function dittyUpdateItems( itemSwaps ) {
|
312 |
-
var animationSpeed = 500;
|
313 |
-
|
314 |
-
jQuery.each( itemSwaps, function( index, data ) {
|
315 |
-
var $current = data.currentItem,
|
316 |
-
$new = data.newItem;
|
317 |
-
|
318 |
-
$current.wrap( '<div class="ditty-update-wrapper"></div>' );
|
319 |
-
var $updateWrapper = $current.parent(),
|
320 |
-
newStyle = $new.attr( 'style' );
|
321 |
-
|
322 |
-
$updateWrapper.stop().css( {
|
323 |
-
height: $current.outerHeight()
|
324 |
-
} );
|
325 |
-
$current.stop().css( {
|
326 |
-
position: 'absolute',
|
327 |
-
top: 0,
|
328 |
-
left: 0,
|
329 |
-
width: '100%'
|
330 |
-
} );
|
331 |
-
$new.stop().css( {
|
332 |
-
position: 'absolute',
|
333 |
-
top: 0,
|
334 |
-
left: 0,
|
335 |
-
width: '100%',
|
336 |
-
opacity: 0
|
337 |
-
} );
|
338 |
-
$current.after( $new );
|
339 |
-
|
340 |
-
$current.stop().animate( {
|
341 |
-
opacity : 0
|
342 |
-
}, animationSpeed * 0.75, 'linear' );
|
343 |
-
|
344 |
-
$new.stop().animate( {
|
345 |
-
opacity : 1
|
346 |
-
}, animationSpeed * 0.75, 'linear' );
|
347 |
-
|
348 |
-
$updateWrapper.stop().animate( {
|
349 |
-
height : $new.outerHeight()
|
350 |
-
}, animationSpeed, 'easeOutQuint', function() {
|
351 |
-
$updateWrapper.removeAttr( 'style' );
|
352 |
-
$current.unwrap();
|
353 |
-
$current.remove();
|
354 |
-
if ( newStyle ) {
|
355 |
-
$new.attr( 'style', newStyle );
|
356 |
-
} else {
|
357 |
-
$new.removeAttr( 'style' );
|
358 |
-
}
|
359 |
-
if ( $new.hasClass( 'ditty-temp-item' ) ) {
|
360 |
-
$new.remove();
|
361 |
-
}
|
362 |
-
} );
|
363 |
-
} );
|
364 |
-
}
|
1 |
+
function dittyLayoutCss(t,a,e){var i=jQuery("style#ditty-layout--"+a);void 0===i[0]&&(i=jQuery('<style id="ditty-layout--'+a+'"></style>'),jQuery("head").append(i),e="update"),"update"===e&&(t=t.replace(">",">"),i.html(t))}function dittyDisplayCss(t,a){var e=jQuery("style#ditty-display--"+a);void 0===e[0]&&(e=jQuery('<style id="ditty-display--'+a+'"></style>'),jQuery("head").append(e)),t=t.replace(">",">"),e.html(t)}function dittyUpdateItems(t){jQuery.each(t,(function(t,a){var e=a.currentItem,i=a.newItem;e.wrap('<div class="ditty-update-wrapper"></div>');var s=e.parent(),d=i.attr("style");s.stop().css({height:e.outerHeight()}),e.stop().css({position:"absolute",top:0,left:0,width:"100%"}),i.stop().css({position:"absolute",top:0,left:0,width:"100%",opacity:0}),e.after(i),e.stop().animate({opacity:0},375,"linear"),i.stop().animate({opacity:1},375,"linear"),s.stop().animate({height:i.outerHeight()},500,"easeOutQuint",(function(){s.removeAttr("style"),e.unwrap(),e.remove(),d?i.attr("style",d):i.removeAttr("style"),i.hasClass("ditty-temp-item")&&i.remove()}))}))}jQuery(document).ready((function($){!function(){"use strict";var t={},a=null;function e(){var a={action:"ditty_live_updates",live_ids:t,security:dittyVars.security};$.post(dittyVars.ajaxurl,a,(function(a){a.updated_items&&$.each(a.updated_items,(function(a,e){!function(t,a){$('.ditty[data-id="'+t+'"]').each((function(){var t=$(this).data("type");"development"===dittyVars.mode&&window.console&&console.log("LIVE UPDATE"),$(this)["ditty_"+t]("options","items",a)}))}(a,e),t[a].timestamp=Math.floor($.now()/1e3)}))}),"json")}$.each(dittyVars.globals,(function(t,a){var e=$(a.selector);if(a.ditty&&void 0!==e[0]){var i=$('<div class="ditty" data-id="'+a.ditty+'" data-ajax_load="1"></div>');switch(a.display&&""!==a.display&&i.attr("data-display",a.display),a.live_updates&&"1"===String(a.live_updates)&&i.attr("data-live_updates","1"),a.customId&&""!==a.customId&&i.attr("id",a.customId),a.customClasses&&""!==a.customClasses&&i.addClass(a.customClasses),a.position){case"prepend":$(e[0]).prepend(i);break;case"before":$(e[0]).before(i);break;case"after":$(e[0]).after(i);break;default:$(e[0]).append(i)}}})),$(".ditty").each((function(){var a=$(this),e=!!a.data("ajax_load")&&a.data("ajax_load"),i=!!a.data("live_updates")&&a.data("live_updates"),s=!!a.data("display_settings")&&a.data("display_settings"),d=!!a.data("layout_settings")&&a.data("layout_settings"),o=!!a.data("show_editor")&&a.data("show_editor");if(e){var n={action:"ditty_init",id:!!a.data("id")&&a.data("id"),uniqid:!!a.data("uniqid")&&a.data("uniqid"),display:a.data("display")?a.data("display"):"",display_settings:s,layout_settings:d,editor:o,security:dittyVars.security};$.post(dittyVars.ajaxurl,n,(function(e){if(!e.display_type||"function"!=typeof a["ditty_"+e.display_type])return window.console&&console.log("Ditty Display type not loaded:",e.display_type),!1;a["ditty_"+e.display_type](e.args),!o&&i&&(t[a.data("id")]={timestamp:Math.floor($.now()/1e3),layout_settings:d})}),"json")}else!o&&i&&(t[a.data("id")]={timestamp:Math.floor($.now()/1e3),layout_settings:d})})),$(".ditty").length&&dittyVars.updateInterval&&function(){if(null!==a||1>Object.keys(t).length)return!1;cancelAnimationFrame(a);var i=dittyVars.updateInterval?parseInt(dittyVars.updateInterval):60,s=Date.now();a=requestAnimationFrame((function t(){var d=Date.now();Math.floor((d-s)/1e3)>=i&&(s=d,e()),a=requestAnimationFrame(t)}))}()}()}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: metaphorcreations
|
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FUZKZGAJSBAE6
|
4 |
Tags: ticker, post ticker, news ticker, content aggregator, latest posts, live refresh, rotator, data rotator, lists, data, aggregator
|
5 |
Requires at least: 4.5
|
6 |
-
Tested up to: 5.
|
7 |
-
Stable tag: 3.0.
|
8 |
License: GPL2
|
9 |
|
10 |
Formerly Ditty News Ticker. Ditty is a multi-functional data display plugin.
|
@@ -66,6 +66,11 @@ The most common cause for an unresponsive Ditty (when using scroll or rotate mod
|
|
66 |
|
67 |
== Changelog ==
|
68 |
|
|
|
|
|
|
|
|
|
|
|
69 |
= 3.0.10 =
|
70 |
* Resolved hammer warning
|
71 |
* Added Post Duplicator integration
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FUZKZGAJSBAE6
|
4 |
Tags: ticker, post ticker, news ticker, content aggregator, latest posts, live refresh, rotator, data rotator, lists, data, aggregator
|
5 |
Requires at least: 4.5
|
6 |
+
Tested up to: 5.9
|
7 |
+
Stable tag: 3.0.11
|
8 |
License: GPL2
|
9 |
|
10 |
Formerly Ditty News Ticker. Ditty is a multi-functional data display plugin.
|
66 |
|
67 |
== Changelog ==
|
68 |
|
69 |
+
= 3.0.11 =
|
70 |
+
* Resolved bug in ditty_add_scripts function that was causing a javascript error
|
71 |
+
* Only possibly load cached ditty on live_updates
|
72 |
+
* Added option to disable fontawesome on front-end
|
73 |
+
|
74 |
= 3.0.10 =
|
75 |
* Resolved hammer warning
|
76 |
* Added Post Duplicator integration
|