first commit
@@ -0,0 +1,80 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Extension_Builder extends FW_Extension
|
||||
{
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _init()
|
||||
{
|
||||
add_action('fw_option_types_init', array($this, '_action_option_types_init'),
|
||||
9 // Other option types requires it
|
||||
);
|
||||
spl_autoload_register(array($this, '_spl_autoload'));
|
||||
|
||||
add_filter(
|
||||
'fw:options-default-values:skip-types',
|
||||
array($this, '_filter_skip_builder_option_types_default_value_process')
|
||||
);
|
||||
}
|
||||
|
||||
public function _action_option_types_init() {
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/builder/builder.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Backwards compatibility when builder-types and builder-item-types were registered right away
|
||||
* @param string $class
|
||||
*/
|
||||
public function _spl_autoload($class) {
|
||||
if ('FW_Option_Type_Builder' === $class) {
|
||||
$this->_action_option_types_init();
|
||||
|
||||
if (
|
||||
is_admin()
|
||||
&&
|
||||
// https://github.com/ThemeFuse/Unyson-Extensions-Approval/issues/258
|
||||
version_compare(fw()->manifest->get_version(), '2.6.2', '>')
|
||||
) {
|
||||
FW_Flash_Messages::add(
|
||||
'builder-option-type-register-wrong',
|
||||
__("Please register builder types on 'fw_option_types_init' action", 'fw'),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
} elseif ('FW_Option_Type_Builder_Item' === $class) {
|
||||
if (
|
||||
is_admin()
|
||||
&&
|
||||
// https://github.com/ThemeFuse/Unyson-Extensions-Approval/issues/258
|
||||
version_compare(fw()->manifest->get_version(), '2.6.2', '>')
|
||||
) {
|
||||
FW_Flash_Messages::add(
|
||||
'builder-item-type-register-wrong',
|
||||
__("Please register builder item-types on 'fw_option_type_builder:{builder-type}:register_items' action", 'fw'),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip Builders from default value extract via $option_type->get_value_from_input() because it's process intensive
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @since 1.2.9
|
||||
*/
|
||||
public function _filter_skip_builder_option_types_default_value_process(array $types) {
|
||||
if (version_compare(fw()->manifest->get_version(), '2.6.11', '<')) {
|
||||
return $types; // fw()->backend->get_option_types() is not available
|
||||
}
|
||||
|
||||
foreach (fw()->backend->get_option_types() as $type) {
|
||||
if (fw()->backend->option_type($type) instanceof FW_Option_Type_Builder) {
|
||||
$types[$type] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
$cfg = array();
|
||||
|
||||
/**
|
||||
* Default item widths for all builders
|
||||
*
|
||||
* It is better to use fw_ext_builder_get_item_width() function to retrieve the item widths
|
||||
* because it has a filter and users will be able to customize the widths for a specific builder
|
||||
*
|
||||
* @see fw_ext_builder_get_item_width()
|
||||
* @since 1.2.0
|
||||
*
|
||||
* old $cfg['default_item_widths'] https://github.com/ThemeFuse/Unyson-Builder-Extension/issues/8
|
||||
* https://github.com/ThemeFuse/Unyson-Builder-Extension/blob/v1.1.17/config.php#L13
|
||||
*/
|
||||
$cfg['grid.columns'] = array(
|
||||
'1_6' => array(
|
||||
'title' => '1/6',
|
||||
'backend_class' => 'fw-col-sm-2',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-2',
|
||||
),
|
||||
'1_5' => array(
|
||||
'title' => '1/5',
|
||||
'backend_class' => 'fw-col-sm-15',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-15',
|
||||
),
|
||||
'1_4' => array(
|
||||
'title' => '1/4',
|
||||
'backend_class' => 'fw-col-sm-3',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-3',
|
||||
),
|
||||
'1_3' => array(
|
||||
'title' => '1/3',
|
||||
'backend_class' => 'fw-col-sm-4',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-4',
|
||||
),
|
||||
'1_2' => array(
|
||||
'title' => '1/2',
|
||||
'backend_class' => 'fw-col-sm-6',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-6',
|
||||
),
|
||||
'2_3' => array(
|
||||
'title' => '2/3',
|
||||
'backend_class' => 'fw-col-sm-8',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-8',
|
||||
),
|
||||
'3_4' => array(
|
||||
'title' => '3/4',
|
||||
'backend_class' => 'fw-col-sm-9',
|
||||
'frontend_class' => 'fw-col-xs-12 fw-col-sm-9',
|
||||
),
|
||||
'1_1' => array(
|
||||
'title' => '1/1',
|
||||
'backend_class' => 'fw-col-sm-12',
|
||||
'frontend_class' => 'fw-col-xs-12',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* @since 1.2.0
|
||||
*/
|
||||
$cfg['grid.row.class'] = 'fw-row';
|
||||
|
||||
/**
|
||||
* @deprecated since 1.2.0
|
||||
* if this is empty fw_ext_builder_get_item_width() will use $cfg['grid.columns']
|
||||
*/
|
||||
$cfg['default_item_widths'] = false;
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Get builder item width data
|
||||
*
|
||||
* Default widths are specified in the config, but some builder types can have custom widths
|
||||
*
|
||||
* Usage example:
|
||||
* <div class="<?php echo esc_attr(fw_ext_builder_get_item_width('builder-type', $item['width'] .'/frontend_class')) ?>" >
|
||||
*
|
||||
* @param string $builder_type Builder option type (some builders can have different item widths)
|
||||
* @param null|string $width_id Specify width id (accepts multikey) or leave empty to get all widths
|
||||
* @param null|mixed $default_value Return this value if specified key does not exist
|
||||
* @return array
|
||||
*/
|
||||
function fw_ext_builder_get_item_width($builder_type, $width_id = null, $default_value = null) {
|
||||
try {
|
||||
$cache_key = fw()->extensions->get('builder')->get_cache_key('item_widths/'. $builder_type);
|
||||
|
||||
$widths = FW_Cache::get($cache_key);
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
if ($widths = fw()->extensions->get('builder')->get_config('default_item_widths')) {
|
||||
// Custom (old config key) widths are defined in theme (by default $cfg['default_item_widths'] is empty)
|
||||
} else {
|
||||
$widths = fw()->extensions->get('builder')->get_config('grid.columns'); // new config key
|
||||
}
|
||||
|
||||
$widths = apply_filters('fw_builder_item_widths:'. $builder_type, $widths);
|
||||
|
||||
FW_Cache::set($cache_key, $widths);
|
||||
}
|
||||
|
||||
if (is_null($width_id)) {
|
||||
return $widths;
|
||||
} else {
|
||||
return fw_akg($width_id, $widths, $default_value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get builder item widths for using in js (wp_localize_script() or json_encode())
|
||||
*
|
||||
* @param string $builder_type Builder option type (some builders can have different item widths)
|
||||
* @return array
|
||||
*/
|
||||
function fw_ext_builder_get_item_widths_for_js($builder_type) {
|
||||
$item_widths = array();
|
||||
|
||||
foreach (fw_ext_builder_get_item_width($builder_type) as $width_id => $width_data) {
|
||||
$width_data['id'] = $width_id;
|
||||
|
||||
$item_widths[] = $width_data;
|
||||
}
|
||||
|
||||
return $item_widths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icon A string that is meant to be an icon (an image, a font icon class, or something else)
|
||||
* @return string
|
||||
*/
|
||||
function fw_ext_builder_string_to_icon_html($icon) {
|
||||
if (preg_match('/\.(png|jpg|jpeg|gif|svg|webp)$/', $icon)) {
|
||||
// http://.../image.png
|
||||
return fw_html_tag('img', array(
|
||||
'class' => 'fw-ext-builder-icon',
|
||||
'src' => $icon
|
||||
));
|
||||
} elseif (preg_match('/^[a-zA-Z0-9\-_ ]+$/', $icon)) {
|
||||
// 'font-icon font-icon-class'
|
||||
return fw_html_tag('span', array(
|
||||
'class' => 'fw-ext-builder-icon '. trim($icon)
|
||||
), true);
|
||||
} else {
|
||||
// can't detect. maybe it's raw html '<span ...'
|
||||
return $icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_ext_builder_includes_autoload' );
|
||||
function _fw_ext_builder_includes_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Option_Type_Builder' :
|
||||
require_once dirname( __FILE__ ) . '/option-types/builder/extends/class-fw-option-type-builder.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Builder_Item' :
|
||||
require_once dirname( __FILE__ ) . '/option-types/builder/extends/class-fw-option-type-builder-item.php';
|
||||
break;
|
||||
case '_FW_Ext_Builder_Fullscreen' :
|
||||
require_once dirname( __FILE__ ) . '/option-types/builder/includes/fullscreen.php';
|
||||
break;
|
||||
case 'FW_Ext_Builder_Templates' :
|
||||
require_once dirname( __FILE__ ) . '/option-types/builder/includes/templates/class-fw-ext-builder-templates.php';
|
||||
break;
|
||||
case 'FW_Ext_Builder_Templates_Component' :
|
||||
require_once dirname( __FILE__ ) . '/option-types/builder/includes/templates/class-fw-ext-builder-templates-component.php';
|
||||
break;
|
||||
case 'FW_Ext_Builder_Templates_Component_Full' :
|
||||
require_once dirname( __FILE__ ) . '/option-types/builder/includes/templates/components/full/class-fw-ext-builder-templates-component-full.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
require_once dirname( __FILE__ ) . '/includes/templates/init.php';
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
abstract class FW_Option_Type_Builder_Item {
|
||||
/**
|
||||
* Specify which builder type this item type belongs to
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_builder_type();
|
||||
|
||||
/**
|
||||
* The item type
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_type();
|
||||
|
||||
/**
|
||||
* The boxes that appear on top of the builder and can be dragged down or clicked to create items
|
||||
* @return array(
|
||||
* array(
|
||||
* 'html' =>
|
||||
* '<div class="item-type-icon-title">'.
|
||||
* ' <div class="item-type-icon"><span class="dashicons dashicons-smiley"></span></div>'.
|
||||
* ' <div class="item-type-title">Item Title</div>'.
|
||||
* '</div>',
|
||||
* ),
|
||||
* array(
|
||||
* 'tab' => __('Tab Title', 'fw'),
|
||||
* 'html' =>
|
||||
* '<div class="item-type-icon-title">'.
|
||||
* ' <div class="item-type-icon"><span class="dashicons dashicons-smiley"></span></div>'.
|
||||
* ' <div class="item-type-title">Item Title</div>'.
|
||||
* '</div>',
|
||||
* ),
|
||||
* ...
|
||||
* )
|
||||
*/
|
||||
abstract public function get_thumbnails();
|
||||
|
||||
/**
|
||||
* Enqueue item type scripts and styles
|
||||
*/
|
||||
abstract public function enqueue_static();
|
||||
|
||||
final public function __construct() {
|
||||
// Maybe in the future this method will have some functionality
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Access_Key $access_key
|
||||
*
|
||||
* @internal
|
||||
* This must be called right after an instance of builder item type has been created
|
||||
* and was added to the registered array, so it is available through
|
||||
* builder->get_item_types()
|
||||
*/
|
||||
final public function _call_init( $access_key ) {
|
||||
if ( $access_key->get_key() !== 'fw_ext_builder_option_type' ) {
|
||||
trigger_error( 'Method call not allowed', E_USER_ERROR );
|
||||
}
|
||||
|
||||
if ( method_exists( $this, '_init' ) ) {
|
||||
$this->_init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FW_Option_Type::storage_save()
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $params
|
||||
*
|
||||
* @return array $item
|
||||
* @since 1.2.0
|
||||
*/
|
||||
final public function storage_save( array $item, array $params = array() ) {
|
||||
if ( $this->get_type() === $item['type'] ) {
|
||||
return $this->_storage_save( $item, $params );
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FW_Option_Type::storage_load()
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $params
|
||||
*
|
||||
* @return array
|
||||
* @since 1.2.0
|
||||
*/
|
||||
final public function storage_load( array $item, array $params = array() ) {
|
||||
if ( $this->get_type() === $item['type'] ) {
|
||||
return $this->_storage_load( $item, $params );
|
||||
} else {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite this method if you want to change/fix attributes that comes from js
|
||||
*
|
||||
* @param $attributes array Backbone Item (Model) attributes
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_value_from_attributes( $attributes ) {
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FW_Option_Type::_storage_save()
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $params
|
||||
*
|
||||
* @return array $item
|
||||
* @since 1.2.0
|
||||
* @internal
|
||||
*/
|
||||
protected function _storage_save( array $item, array $params ) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see FW_Option_Type::_storage_load()
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $params
|
||||
*
|
||||
* @return mixed
|
||||
* @since 1.2.0
|
||||
* @internal
|
||||
*/
|
||||
protected function _storage_load( array $item, array $params ) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,732 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
abstract class FW_Option_Type_Builder extends FW_Option_Type {
|
||||
|
||||
/**
|
||||
* Registered item types of the current builder type
|
||||
* @var array {item-type => item-instance}
|
||||
*/
|
||||
private static $item_types = array();
|
||||
|
||||
/**
|
||||
* @var FW_Access_Key
|
||||
*/
|
||||
private static $access_key;
|
||||
|
||||
/**
|
||||
* @param string|FW_Option_Type_Builder_Item $item_type_class
|
||||
* @param $type $item_type_class
|
||||
* @param string $builder_type
|
||||
*/
|
||||
public static function register_item_type( $item_type_class, $type = null, $builder_type = null ) {
|
||||
if ( empty( $type ) || empty( $builder_type ) ) {
|
||||
|
||||
if ( ! is_subclass_of( $item_type_class, 'FW_Option_Type_Builder_Item' ) ) {
|
||||
trigger_error( "Invalid builder item type class $item_type_class", E_USER_WARNING );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$instance = $item_type_class instanceof FW_Option_Type_Builder_Item
|
||||
? $item_type_class
|
||||
: self::get_instance( $item_type_class );
|
||||
|
||||
$type = $instance->get_type();
|
||||
$builder_type = $instance->get_builder_type();
|
||||
|
||||
unset( $instance );
|
||||
}
|
||||
|
||||
if ( ! isset( self::$item_types[ $builder_type ] ) ) {
|
||||
if ( ! is_subclass_of( $item_type_class, 'FW_Option_Type_Builder_Item' ) ) {
|
||||
trigger_error( "Invalid builder type $builder_type", E_USER_WARNING );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( self::$item_types[ $builder_type ][ $type ] ) ) {
|
||||
if ( ! is_subclass_of( $item_type_class, 'FW_Option_Type_Builder_Item' ) ) {
|
||||
trigger_error( "Builder item type $type is already registered", E_USER_WARNING );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( apply_filters(
|
||||
'fw_ext_builder:option_type:' . $builder_type . ':exclude_item_type:' . $type,
|
||||
false
|
||||
) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$item_types[ $builder_type ][ $type ] = $item_type_class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return FW_Option_Type_Builder_Item
|
||||
*/
|
||||
protected function get_item_type( $type ) {
|
||||
try {
|
||||
return FW_Cache::get( "fw-option-type-builder:{$this->get_type()}:items:$type" );
|
||||
} catch ( FW_Cache_Not_Found_Exception $e ) {
|
||||
$instance = $this->get_item_instance( $type );
|
||||
FW_Cache::set( "fw-option-type-builder:{$this->get_type()}:items:$type", $instance );
|
||||
|
||||
$instance->_call_init( self::get_access_key() );
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Option_Type_Builder_Item[]
|
||||
*/
|
||||
protected function get_item_types() {
|
||||
static $did_action = false;
|
||||
|
||||
if ( ! $did_action ) {
|
||||
/**
|
||||
* @since 1.2.4
|
||||
*/
|
||||
do_action( 'fw_option_type_builder:' . $this->get_type() . ':register_items' );
|
||||
$did_action = true;
|
||||
}
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ( array_keys( $this->get_items_classes() ) as $type ) {
|
||||
$items[ $type ] = $this->get_item_type( $type );
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get correct value from items
|
||||
*
|
||||
* @param array $items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_value_from_items( $items ) {
|
||||
/**
|
||||
* @var FW_Option_Type_Builder_Item[] $item_types
|
||||
*/
|
||||
$item_types = $this->get_item_types();
|
||||
|
||||
$fixed_items = array();
|
||||
|
||||
foreach ( $items as $item_attributes ) {
|
||||
if ( ! isset( $item_attributes['type'] ) || ! isset( $item_types[ $item_attributes['type'] ] ) ) {
|
||||
// invalid item type
|
||||
continue;
|
||||
}
|
||||
|
||||
$fixed_item_attributes = $item_types[ $item_attributes['type'] ]
|
||||
->get_value_from_attributes( $item_attributes );
|
||||
|
||||
if ( isset( $fixed_item_attributes['_items'] ) ) {
|
||||
$fixed_item_attributes['_items'] = $this->get_value_from_items( $fixed_item_attributes['_items'] );
|
||||
}
|
||||
|
||||
$fixed_items[] = $fixed_item_attributes;
|
||||
}
|
||||
|
||||
return $fixed_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _get_backend_width_type() {
|
||||
return 'full';
|
||||
}
|
||||
|
||||
private function fix_base_defaults( $option = array() ) {
|
||||
return array_merge( array(
|
||||
'fullscreen' => false,
|
||||
'template_saving' => false,
|
||||
'history' => false,
|
||||
/**
|
||||
* Enable fixed header so it follows you on scroll down.
|
||||
* It's convenient when you have many elements in builder and it's tedious to:
|
||||
* scroll up -> add element -> scroll down -> configure it -> scroll up -> ...
|
||||
*/
|
||||
'fixed_header' => false,
|
||||
/**
|
||||
* Enable drag and drop manipulation of every collection from Builder.
|
||||
* Sometimes, when your creating your own builder,
|
||||
* it's convenient to throw it away in order to wire up your own
|
||||
* drag and drop behavior.
|
||||
*/
|
||||
'drag_and_drop' => true,
|
||||
|
||||
/**
|
||||
* Builder may be read_only. This may be necessary if we want
|
||||
* to provide some content to user just for presentation,
|
||||
* without the user to be able to interact with the items
|
||||
* or change the way they are alligned.
|
||||
*
|
||||
* This is not some magick option that will make your builder
|
||||
* read-only only by making it true. Every builder is responsible
|
||||
* to give their read-only experience as they want.
|
||||
* That's why it is turned off by default. You may not need this
|
||||
* option.
|
||||
*
|
||||
* This option will add a data-read-only attribute to the builder
|
||||
* if it's set to true. You are responsible to handle it
|
||||
* accordingly in your client-side logic.
|
||||
*/
|
||||
'read_only' => false,
|
||||
|
||||
/**
|
||||
* Option-type html input json value will be compressed.
|
||||
* Prevent max_post_size error when builder contains a lot of elements.
|
||||
*/
|
||||
'compress_form_value' => false,
|
||||
),
|
||||
$option );
|
||||
}
|
||||
|
||||
private function get_static_uri( $append = '' ) {
|
||||
return fw()->extensions->get( 'builder' )->get_uri( '/includes/option-types/builder/static' . $append );
|
||||
}
|
||||
|
||||
private static function get_access_key() {
|
||||
if ( ! self::$access_key ) {
|
||||
self::$access_key = new FW_Access_Key( 'fw_ext_builder_option_type' );
|
||||
}
|
||||
|
||||
return self::$access_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function get_items_classes() {
|
||||
return fw_akg( $this->get_type(), self::$item_types, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return string
|
||||
* @throws FW_Option_Type_Exception_Not_Found
|
||||
*/
|
||||
protected function get_item_class( $type ) {
|
||||
$class = fw_akg( $type, $this->get_items_classes() );
|
||||
|
||||
if ( $class == null ) {
|
||||
throw new FW_Option_Type_Exception_Not_Found();
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
*
|
||||
* @return FW_Option_Type_Builder_Item
|
||||
* @throws FW_Option_Type_Exception_Not_Found
|
||||
* @throws FW_Option_Type_Exception_Invalid_Class
|
||||
*/
|
||||
protected function get_item_instance( $type ) {
|
||||
$class = $this->get_item_class( $type );
|
||||
|
||||
if ( ! is_subclass_of( $class, 'FW_Option_Type_Builder_Item' ) ) {
|
||||
throw new FW_Option_Type_Exception_Invalid_Class();
|
||||
}
|
||||
|
||||
return $this->get_instance( $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $class
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function get_instance( $class ) {
|
||||
return new $class();
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite this method to force your builder type items to extend custom class or to have custom requirements
|
||||
*
|
||||
* @param FW_Option_Type_Builder_Item $item_type_instance
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function item_type_is_valid( $item_type_instance ) {
|
||||
return is_subclass_of( $item_type_instance, 'FW_Option_Type_Builder_Item' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _get_defaults() {
|
||||
return $this->fix_base_defaults( array(
|
||||
'value' => array(
|
||||
'json' => '[]',
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $option
|
||||
* @return bool
|
||||
* @since 1.2.8
|
||||
*/
|
||||
protected function compression_is_enabled($option) {
|
||||
return isset($option['compress_form_value']) && $option['compress_form_value'] && function_exists('gzinflate');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ZIPContentStr
|
||||
*
|
||||
* @return string
|
||||
* @source http://stackoverflow.com/a/15966905
|
||||
*/
|
||||
private function decompress_first_file_from_zip( $ZIPContentStr ) {
|
||||
// Input: ZIP archive - content of entire ZIP archive as a string
|
||||
// Output: decompressed content of the first file packed in the ZIP archive
|
||||
// let's parse the ZIP archive
|
||||
// (see 'http://en.wikipedia.org/wiki/ZIP_%28file_format%29' for details)
|
||||
// parse 'local file header' for the first file entry in the ZIP archive
|
||||
if ( strlen( $ZIPContentStr ) < 102 ) {
|
||||
// any ZIP file smaller than 102 bytes is invalid
|
||||
printf( "error: input data too short<br />\n" );
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$CompressedSize = $this->binstrtonum( substr( $ZIPContentStr, 18, 4 ) );
|
||||
$UncompressedSize = $this->binstrtonum( substr( $ZIPContentStr, 22, 4 ) );
|
||||
$FileNameLen = $this->binstrtonum( substr( $ZIPContentStr, 26, 2 ) );
|
||||
$ExtraFieldLen = $this->binstrtonum( substr( $ZIPContentStr, 28, 2 ) );
|
||||
$Offs = 30 + $FileNameLen + $ExtraFieldLen;
|
||||
$ZIPData = substr( $ZIPContentStr, $Offs, $CompressedSize );
|
||||
$Data = gzinflate( $ZIPData );
|
||||
|
||||
if ( strlen( $Data ) != $UncompressedSize ) {
|
||||
printf( "error: uncompressed data have wrong size<br />\n" );
|
||||
|
||||
return '';
|
||||
} else {
|
||||
return $Data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $Str
|
||||
* @return int
|
||||
* @see decompress_first_file_from_zip()
|
||||
*/
|
||||
private function binstrtonum( $Str ) {
|
||||
// Returns a number represented in a raw binary data passed as string.
|
||||
// This is useful for example when reading integers from a file,
|
||||
// when we have the content of the file in a string only.
|
||||
// Examples:
|
||||
// chr(0xFF) will result as 255
|
||||
// chr(0xFF).chr(0xFF).chr(0x00).chr(0x00) will result as 65535
|
||||
// chr(0xFF).chr(0xFF).chr(0xFF).chr(0x00) will result as 16777215
|
||||
$Num = 0;
|
||||
for ( $TC1 = strlen( $Str ) - 1; $TC1 >= 0; $TC1 -- ) { // go from most significant byte
|
||||
$Num <<= 8; // shift to left by one byte (8 bits)
|
||||
$Num |= ord( $Str[ $TC1 ] ); // add new byte
|
||||
}
|
||||
|
||||
return $Num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $input_value
|
||||
* @param array $option
|
||||
* @return string
|
||||
* @since 1.2.8
|
||||
*/
|
||||
protected function maybe_decompress($input_value, $option) {
|
||||
if (!$this->compression_is_enabled($option) || $input_value[0] === '[') {
|
||||
return $input_value;
|
||||
} else {
|
||||
return $this->decompress_first_file_from_zip(base64_decode($input_value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _enqueue_static( $id, $option, $data ) {
|
||||
$option = $this->fix_base_defaults( $option );
|
||||
$version = fw_ext( 'builder' )->manifest->get_version();
|
||||
|
||||
do_action( 'fw_ext_builder:option_type:builder:before_enqueue',
|
||||
array(
|
||||
'option' => $option,
|
||||
'version' => $version,
|
||||
) );
|
||||
|
||||
wp_register_script(
|
||||
'jszip',
|
||||
$this->get_static_uri('/lib/jszip.min.js'),
|
||||
array(),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
{
|
||||
wp_enqueue_style(
|
||||
'fw-option-builder',
|
||||
$this->get_static_uri( '/css/builder.css' ),
|
||||
version_compare( fw()->manifest->get_version(), '2.4.0', '<' )
|
||||
? array( 'fw' )
|
||||
: array( 'fw', 'fw-unycon' ),
|
||||
$version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder',
|
||||
$this->get_static_uri( '/js/builder.js' ),
|
||||
array(
|
||||
'jquery-ui-draggable',
|
||||
'jquery-ui-sortable',
|
||||
'fw',
|
||||
'fw-events',
|
||||
'backbone',
|
||||
'backbone-relational'
|
||||
),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
wp_enqueue_media();
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-initialize',
|
||||
$this->get_static_uri( '/js/initialize-builder.js' ),
|
||||
array( 'fw-option-builder', 'jszip' ),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
{
|
||||
wp_enqueue_style(
|
||||
'fw-option-builder-helpers',
|
||||
$this->get_static_uri( '/css/helpers.css' ),
|
||||
array( 'fw-option-builder' ),
|
||||
$version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-helpers',
|
||||
$this->get_static_uri( '/js/helpers.js' ),
|
||||
array( 'fw-option-builder' ),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-qtips',
|
||||
$this->get_static_uri( '/js/qtips.js' ),
|
||||
array( 'fw-option-builder' ),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'fw-option-builder-helpers',
|
||||
'_fw_option_type_builder_helpers',
|
||||
array(
|
||||
'l10n' => array(
|
||||
'save' => __( 'Save', 'fw' ),
|
||||
),
|
||||
'item_widths' => fw_ext_builder_get_item_widths_for_js( $this->get_type() )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $option['fullscreen'] ) {
|
||||
wp_enqueue_style(
|
||||
'fw-option-builder-fullscreen',
|
||||
$this->get_static_uri( '/css/fullscreen.css' ),
|
||||
array( 'fw-option-builder' ),
|
||||
$version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-fullscreen',
|
||||
$this->get_static_uri( '/js/fullscreen.js' ),
|
||||
array( 'fw-option-builder', ),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'fw-option-builder-fullscreen',
|
||||
'_fw_option_type_builder_fullscreen',
|
||||
array(
|
||||
'l10n' => array(
|
||||
'fullscreen' => __( 'Full Screen', 'fw' ),
|
||||
'exit_fullscreen' => __( 'Exit Full Screen', 'fw' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $option['history'] ) {
|
||||
wp_enqueue_style(
|
||||
'fw-option-builder-history',
|
||||
$this->get_static_uri( '/css/history.css' ),
|
||||
array( 'fw-option-builder' ),
|
||||
$version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-history',
|
||||
$this->get_static_uri( '/js/history.js' ),
|
||||
array( 'fw-option-builder', ),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'fw-option-builder-history',
|
||||
'_fw_option_type_builder_history',
|
||||
array(
|
||||
'l10n' => array(
|
||||
'undo' => __( 'Undo', 'fw' ),
|
||||
'redo' => __( 'Redo', 'fw' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
do_action( 'fw_ext_builder:option_type:builder:enqueue',
|
||||
array(
|
||||
'option' => $option,
|
||||
'version' => $version,
|
||||
'uri' => fw()->extensions->get( 'builder' )->get_uri( '/includes/option-types/builder' )
|
||||
) );
|
||||
|
||||
foreach ( $this->get_item_types() as $item ) {
|
||||
/** @var FW_Option_Type_Builder_Item $item */
|
||||
|
||||
$item->enqueue_static();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _render( $id, $option, $data ) {
|
||||
$option = $this->fix_base_defaults( $option );
|
||||
|
||||
/**
|
||||
* array(
|
||||
* 'Tab title' => array(
|
||||
* '<thumbnail html>',
|
||||
* '<thumbnail html>',
|
||||
* '<thumbnail html>',
|
||||
* ),
|
||||
* 'Tab title' => array(
|
||||
* '<thumbnail html>',
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
$thumbnails = array();
|
||||
|
||||
/**
|
||||
* If you want to customize what css class your thumbnails receive
|
||||
* you can implement `get_thumbnail_class` in your
|
||||
* FW_Option_Type_Builder subclass. Whatever you return from this
|
||||
* method is inserted right into html.
|
||||
*
|
||||
* You can add additional classes by concatenating them to the
|
||||
* default class. You receive default class as an argument to the
|
||||
* method.
|
||||
*
|
||||
* class Some_Cool_Builder extends FW_Option_Type_Builder {
|
||||
* // initialization
|
||||
*
|
||||
* public function get_thumbnail_class ($default_css_class, $item) {
|
||||
* return $default_css_class . ' some-cool-class-that-you-really-need';
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // Don't forget to register your builder
|
||||
* FW_Option_Type::register('Some_Cool_Builder');
|
||||
*/
|
||||
foreach ( $this->get_item_types() as $item ) {
|
||||
/** @var FW_Option_Type_Builder_Item $item */
|
||||
|
||||
$item_classes = 'builder-item-type';
|
||||
|
||||
if ( method_exists( $this, 'get_thumbnail_class' ) ) {
|
||||
$item_classes = $this->get_thumbnail_class( $item_classes, $item );
|
||||
}
|
||||
|
||||
$item_classes = esc_attr( $item_classes );
|
||||
|
||||
foreach ( $item->get_thumbnails() as $key => $thumbnail ) {
|
||||
if ( ! isset( $thumbnail['tab'] ) ) {
|
||||
$tab_title = '~';
|
||||
} else {
|
||||
$tab_title = $thumbnail['tab'];
|
||||
}
|
||||
|
||||
if ( ! isset( $thumbnails[ $tab_title ] ) ) {
|
||||
$thumbnails[ $tab_title ] = array();
|
||||
}
|
||||
|
||||
if ( empty( $thumbnail['html'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset( $thumbnails[ $tab_title ][ $key ] ) ) {
|
||||
$thumbnails[ $tab_title ][ $key ] =
|
||||
'<div class="' . $item_classes . '" data-builder-item-type="' . esc_attr( $item->get_type() ) . '">' .
|
||||
$thumbnail['html'] .
|
||||
'</div>';
|
||||
} else {
|
||||
$thumbnails[ $tab_title ][] =
|
||||
'<div class="' . $item_classes . '" data-builder-item-type="' . esc_attr( $item->get_type() ) . '">' .
|
||||
$thumbnail['html'] .
|
||||
'</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $thumbnails as &$type ) {
|
||||
ksort( $type );
|
||||
}
|
||||
|
||||
if ( method_exists( $this, 'sort_thumbnails' ) ) {
|
||||
$this->sort_thumbnails( $thumbnails );
|
||||
}
|
||||
|
||||
// prepare attr
|
||||
{
|
||||
$option['attr']['data-builder-option-type'] = $this->get_type();
|
||||
|
||||
$option['attr']['class'] .= ' fw-option-type-builder';
|
||||
|
||||
if ( $option['fullscreen'] ) {
|
||||
$option['attr']['class'] .= apply_filters( 'fw_builder_fullscreen_add_classes', '' );
|
||||
}
|
||||
|
||||
if ( $option['fixed_header'] ) {
|
||||
$option['attr']['data-fixed-header'] = '~';
|
||||
}
|
||||
|
||||
if ( $option['drag_and_drop'] ) {
|
||||
$option['attr']['data-drag-and-drop'] = '~';
|
||||
}
|
||||
|
||||
if ( $option['read_only'] ) {
|
||||
$option['attr']['data-read-only'] = '~';
|
||||
}
|
||||
|
||||
if ($this->compression_is_enabled($option)) {
|
||||
$option['attr']['data-compression'] = '~';
|
||||
}
|
||||
}
|
||||
|
||||
return fw_render_view( dirname( __FILE__ ) . '/../view.php',
|
||||
array(
|
||||
'id' => $id,
|
||||
'option' => $option,
|
||||
'data' => $data,
|
||||
'thumbnails' => $thumbnails,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _get_value_from_input( $option, $input_value ) {
|
||||
if ( empty( $input_value ) || ! is_string( $input_value ) ) {
|
||||
$input_value = $option['value']['json'];
|
||||
} else {
|
||||
$input_value = $this->maybe_decompress($input_value, $option);
|
||||
}
|
||||
|
||||
if ( ! ($items = json_decode( $input_value, true )) ) {
|
||||
$items = array();
|
||||
}
|
||||
|
||||
return array(
|
||||
'json' => json_encode($this->get_value_from_items( $items )),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _storage_save( $id, array $option, $value, array $params ) {
|
||||
$value['json'] = json_encode( $this->storage_save_recursive( json_decode( $value['json'], true ), $params ) );
|
||||
|
||||
return fw_db_option_storage_save( $id, $option, $value, $params );
|
||||
}
|
||||
|
||||
protected function storage_save_recursive( array $items, array $params ) {
|
||||
/**
|
||||
* @var FW_Option_Type_Builder_Item[] $item_types
|
||||
*/
|
||||
$item_types = $this->get_item_types();
|
||||
|
||||
foreach ( $items as &$atts ) {
|
||||
if ( ! isset( $atts['type'] ) || ! isset( $item_types[ $atts['type'] ] ) ) {
|
||||
continue; // invalid item
|
||||
}
|
||||
|
||||
$atts = $item_types[ $atts['type'] ]->storage_save( $atts, $params );
|
||||
|
||||
if ( isset( $atts['_items'] ) ) {
|
||||
$atts['_items'] = $this->storage_save_recursive( $atts['_items'], $params );
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _storage_load( $id, array $option, $value, array $params ) {
|
||||
$value = fw_db_option_storage_load( $id, $option, $value, $params );
|
||||
|
||||
$value['json'] = json_decode( $value['json'], true );
|
||||
$value['json'] = $this->storage_load_recursive( $value['json'] ? $value['json'] : array(), $params );
|
||||
$value['json'] = json_encode( $value['json'] );
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
protected function storage_load_recursive( array $items, array $params ) {
|
||||
/**
|
||||
* @var FW_Option_Type_Builder_Item[] $item_types
|
||||
*/
|
||||
$item_types = $this->get_item_types();
|
||||
|
||||
foreach ( $items as &$atts ) {
|
||||
if ( ! isset( $atts['type'] ) || ! isset( $item_types[ $atts['type'] ] ) ) {
|
||||
continue; // invalid item
|
||||
}
|
||||
|
||||
$atts = $item_types[ $atts['type'] ]->storage_load( $atts, $params );
|
||||
|
||||
if ( isset( $atts['_items'] ) ) {
|
||||
$atts['_items'] = $this->storage_load_recursive( $atts['_items'], $params );
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Builder FullScreen functionality
|
||||
* @internal
|
||||
*/
|
||||
final class _FW_Ext_Builder_Fullscreen
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
add_action('wp_ajax_fw_builder_fullscreen_set_storage_item', array(__CLASS__, '_action_ajax_set_storage_item'));
|
||||
add_action('wp_ajax_fw_builder_fullscreen_unset_storage_item', array(__CLASS__, '_action_ajax_unset_storage_item'));
|
||||
|
||||
add_filter('fw_builder_fullscreen_add_classes', array(__CLASS__, '_filter_add_builder_classes'));
|
||||
add_action('fw_builder_fullscreen_add_backdrop', array(__CLASS__, '_action_add_builder_backdrop'));
|
||||
}
|
||||
|
||||
private static function get_storage_items()
|
||||
{
|
||||
return fw_get_db_extension_data('builder', 'fullscreen', array());
|
||||
}
|
||||
|
||||
private static function set_storage_items($items)
|
||||
{
|
||||
fw_set_db_extension_data('builder', 'fullscreen', $items);
|
||||
}
|
||||
|
||||
public static function _action_ajax_set_storage_item()
|
||||
{
|
||||
if (!current_user_can('edit_posts')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
self::set_storage_items(
|
||||
array_unique(
|
||||
array_merge(
|
||||
self::get_storage_items(),
|
||||
array( (int)FW_Request::POST('post_id') )
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public static function _action_ajax_unset_storage_item()
|
||||
{
|
||||
if (!current_user_can('edit_posts')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$storage_items = self::get_storage_items();
|
||||
$key = array_search(
|
||||
(int)FW_Request::POST('post_id'),
|
||||
$storage_items
|
||||
);
|
||||
unset($storage_items[$key]);
|
||||
|
||||
self::set_storage_items($storage_items);
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public static function is_fullscreen_on()
|
||||
{
|
||||
$post_id = get_the_ID();
|
||||
return (false !== $post_id && in_array($post_id, self::get_storage_items()));
|
||||
}
|
||||
|
||||
public static function _filter_add_builder_classes($str)
|
||||
{
|
||||
return self::is_fullscreen_on() ? ($str . ' builder-fullscreen') : $str;
|
||||
}
|
||||
|
||||
public static function _action_add_builder_backdrop()
|
||||
{
|
||||
echo
|
||||
'<div class="fw-option-type-builder-fullscreen-backdrop' . (self::is_fullscreen_on() ? '' : ' fw-hidden') . '" >'.
|
||||
' <div class="buttons-wrapper">'.
|
||||
' <span class="spinner"></span>'.
|
||||
' <a class="preview button">'. __('Preview Changes', 'fw') .'</a>'.
|
||||
' <a class="button button-primary">'. __('Update', 'fw') .'</a>'.
|
||||
' </div>'.
|
||||
'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
_FW_Ext_Builder_Fullscreen::init();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
### Create new component
|
||||
|
||||
* Create a class that extends `FW_Ext_Builder_Templates_Component`
|
||||
|
||||
```php
|
||||
class FW_Ext_Builder_Templates_Component_Demo extends FW_Ext_Builder_Templates_Component {
|
||||
// Create all required abstract methods ...
|
||||
}
|
||||
```
|
||||
|
||||
* Register the class on special action
|
||||
|
||||
```php
|
||||
add_action('fw_ext_builder:template_components_register', '_action_fw_ext_builder_template_component_demo');
|
||||
function _action_fw_ext_builder_template_component_demo() {
|
||||
require_once dirname(__FILE__) .'/.../path/to/class.php';
|
||||
|
||||
FW_Ext_Builder_Templates::register_component(
|
||||
new FW_Ext_Builder_Templates_Component_Demo()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
* In javascript, init the html returned by `FW_Ext_Builder_Templates_Component_Demo::_render()`
|
||||
|
||||
```javascript
|
||||
fwEvents.on('fw:option-type:builder:templates:init', function(data){
|
||||
data.$elements.find('.fw-builder-templates-type-COMPONENT_TYPE .whatever-element a').on('click', function(){
|
||||
alert('Hello World!');
|
||||
});
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
abstract class FW_Ext_Builder_Templates_Component
|
||||
{
|
||||
/**
|
||||
* Unique type
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_type();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_title();
|
||||
|
||||
/**
|
||||
* @param array $data {'builder_type': '...'}
|
||||
* @return string HTML for tooltip
|
||||
* @internal
|
||||
*/
|
||||
abstract public function _render($data);
|
||||
|
||||
/**
|
||||
* Enqueue css and js
|
||||
* @param array $data {'builder_type': '...'}
|
||||
* @internal
|
||||
*/
|
||||
abstract public function _enqueue($data);
|
||||
|
||||
/**
|
||||
* Called right after the component was fully registered
|
||||
* @internal
|
||||
*/
|
||||
public function _init() {}
|
||||
|
||||
/**
|
||||
* @param string $builder_type Builder option type
|
||||
* @return bool
|
||||
*/
|
||||
protected function builder_type_is_valid($builder_type)
|
||||
{
|
||||
if (
|
||||
empty($builder_type)
|
||||
||
|
||||
!fw()->backend->option_type($builder_type)
|
||||
||
|
||||
!(fw()->backend->option_type($builder_type) instanceof FW_Option_Type_Builder)
|
||||
) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $builder_type
|
||||
* @return array|mixed
|
||||
* @since 1.1.14
|
||||
*/
|
||||
protected function get_predefined_templates($builder_type)
|
||||
{
|
||||
$cache_id = 'fw_ext_builder/predefined_templates/'. $builder_type .'/'. $this->get_type();
|
||||
|
||||
try {
|
||||
return FW_Cache::get($cache_id);
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
$templates = array();
|
||||
|
||||
foreach(apply_filters('fw_ext_builder:predefined_templates:'. $builder_type .':'. $this->get_type(), array(
|
||||
// 'id' => array('title' => 'Title', 'json' => '[]')
|
||||
)) as $id => $template) {
|
||||
if (
|
||||
isset($template['title']) && is_string($template['title'])
|
||||
&&
|
||||
isset($template['json']) && is_string($template['json']) && null !== json_decode($template['json'])
|
||||
) {
|
||||
$templates[ $id ] = array(
|
||||
'title' => $template['title'],
|
||||
'json' => $template['json'],
|
||||
'type' => 'predefined'
|
||||
);
|
||||
} else {
|
||||
trigger_error('Invalid predefined template: '. $id, E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
FW_Cache::set($cache_id, $templates);
|
||||
|
||||
return $templates;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Builder templates functionality
|
||||
*/
|
||||
final class FW_Ext_Builder_Templates
|
||||
{
|
||||
/**
|
||||
* @var FW_Ext_Builder_Templates_Component[]
|
||||
*/
|
||||
private static $components;
|
||||
|
||||
private static $registration_is_allowed = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function _init()
|
||||
{
|
||||
add_action('fw_ext_builder:option_type:builder:enqueue', array(__CLASS__, '_action_builder_enqueue'));
|
||||
add_action('wp_ajax_fw_builder_templates_render', array(__CLASS__, '_action_ajax_render'));
|
||||
add_action('init', array(__CLASS__, '_action_init'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function _action_init()
|
||||
{
|
||||
if (defined('DOING_AJAX') && DOING_AJAX === true) {
|
||||
/**
|
||||
* Load and init components
|
||||
* Some of them may have add_action('wp_ajax_...')
|
||||
*/
|
||||
self::get_components();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function _action_ajax_render()
|
||||
{
|
||||
if (!current_user_can('edit_posts')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$builder_type = (string)FW_Request::POST('builder_type');
|
||||
|
||||
if (!fw()->backend->option_type($builder_type)) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$first = true;
|
||||
|
||||
$html = '<div class="fw-builder-templates-types">';
|
||||
|
||||
foreach (self::get_components() as $component) {
|
||||
$component_html = $component->_render(array('builder_type' => $builder_type));
|
||||
|
||||
if (empty($component_html)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html .=
|
||||
'<div class="fw-builder-templates-type fw-builder-templates-type-'. esc_attr($component->get_type()) .'"'.
|
||||
' data-type="'. esc_attr($component->get_type()) .'">'
|
||||
. '<a class="fw-builder-templates-type-title" href="#" onclick="return false;">'
|
||||
. $component->get_title()
|
||||
. '</a>'
|
||||
. '<div class="fw-builder-templates-type-content'. ($first ? '' : ' fw-hidden') .'">'
|
||||
. $component_html
|
||||
. '</div>'
|
||||
. '</div>';
|
||||
|
||||
$first = false;
|
||||
|
||||
unset($component_html);
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
wp_send_json_success(array(
|
||||
'html' => $html
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function _action_builder_enqueue($data)
|
||||
{
|
||||
if (!
|
||||
apply_filters(
|
||||
'fw_builder_has_template_saving_feature',
|
||||
$data['option']['template_saving'],
|
||||
$data['option']
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uri = $data['uri'] .'/includes/templates/static';
|
||||
|
||||
wp_enqueue_style(
|
||||
'fw-option-builder-templates',
|
||||
$uri .'/styles.css',
|
||||
array('fw-option-builder'),
|
||||
$data['version']
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-templates',
|
||||
$uri .'/scripts.js',
|
||||
array('fw-option-builder'),
|
||||
$data['version'],
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'fw-option-builder-templates',
|
||||
'_fw_option_type_builder_templates',
|
||||
array(
|
||||
'l10n' => array(
|
||||
'templates' => __('Templates', 'fw'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
foreach (self::get_components() as $component) {
|
||||
$component->_enqueue(array('builder_type' => $data['option']['type']));
|
||||
}
|
||||
}
|
||||
|
||||
public static function register_component(FW_Ext_Builder_Templates_Component $component)
|
||||
{
|
||||
if (!self::$registration_is_allowed) {
|
||||
trigger_error('Registration is not allowed. Tried to register component: '. $component->get_type(), E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (isset(self::$components[ $component->get_type() ])) {
|
||||
trigger_error('Component already registered: '. $component->get_type(), E_USER_ERROR);
|
||||
}
|
||||
|
||||
self::$components[ $component->get_type() ] = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Ext_Builder_Templates_Component[]
|
||||
*/
|
||||
private static function get_components()
|
||||
{
|
||||
if (is_null(self::$components)) {
|
||||
self::$components = array();
|
||||
|
||||
self::$registration_is_allowed = true;
|
||||
do_action('fw_ext_builder:template_components_register');
|
||||
self::$registration_is_allowed = false;
|
||||
|
||||
foreach (self::$components as $component) {
|
||||
$component->_init();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$components;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Ext_Builder_Templates_Component_Full extends FW_Ext_Builder_Templates_Component
|
||||
{
|
||||
public function get_type()
|
||||
{
|
||||
return 'full';
|
||||
}
|
||||
|
||||
public function get_title()
|
||||
{
|
||||
return __('Full Templates', 'fw');
|
||||
}
|
||||
|
||||
public function _render($data)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
$templates = $this->get_templates($data['builder_type']);
|
||||
|
||||
{
|
||||
$this->fake_created_value = 0;
|
||||
|
||||
$templates = array_map( // make this to keep elements order after applying uasort()
|
||||
array($this, 'array_map_add_fake_created_key'),
|
||||
$templates
|
||||
);
|
||||
}
|
||||
|
||||
uasort($templates, array($this, 'sort_templates'));
|
||||
|
||||
foreach ($templates as $template_id => $template) {
|
||||
if (isset($template['type']) && $template['type'] === 'predefined') {
|
||||
$delete_btn = '';
|
||||
} else {
|
||||
$delete_btn = '<a href="#" onclick="return false;" data-delete-template="'. fw_htmlspecialchars($template_id) .'"'
|
||||
. ' class="template-delete dashicons fw-x"></a>';
|
||||
}
|
||||
|
||||
$html .=
|
||||
'<li>'
|
||||
. $delete_btn
|
||||
. '<a href="#" onclick="return false;" data-load-template="'. fw_htmlspecialchars($template_id) .'"'
|
||||
. ' class="template-title">'
|
||||
. fw_htmlspecialchars($template['title'])
|
||||
. '</a>'
|
||||
. '</li>';
|
||||
}
|
||||
|
||||
if (empty($html)) {
|
||||
$html = '<div class="fw-text-muted no-'. $this->get_type() .'-templates">'. __('No Templates Saved', 'fw') .'</div>';
|
||||
} else {
|
||||
$html =
|
||||
'<p class="fw-text-muted load-template-title">'. __('Load Template', 'fw') .':</p>'
|
||||
. '<ul class="std">'. $html .'</ul>';
|
||||
}
|
||||
|
||||
$html =
|
||||
'<div class="save-template-wrapper">'
|
||||
. '<a href="#" onclick="return false;" class="save-template button button-primary">'
|
||||
. __('Save Full Template', 'fw')
|
||||
. '</a>'
|
||||
. '</div>'
|
||||
. $html;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function _enqueue($data)
|
||||
{
|
||||
$uri = fw_ext('builder')->get_uri('/includes/option-types/builder/includes/templates/components/'. $this->get_type());
|
||||
$version = fw_ext('builder')->manifest->get_version();
|
||||
|
||||
wp_enqueue_style(
|
||||
'fw-option-builder-templates-'. $this->get_type(),
|
||||
$uri .'/styles.css',
|
||||
array('fw-option-builder-templates'),
|
||||
$version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-option-builder-templates-'. $this->get_type(),
|
||||
$uri .'/scripts.js',
|
||||
array('fw-option-builder-templates'),
|
||||
$version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'fw-option-builder-templates-'. $this->get_type(),
|
||||
'_fw_option_type_builder_templates_'. $this->get_type(),
|
||||
array(
|
||||
'l10n' => array(
|
||||
'template_name' => __('Template Name', 'fw'),
|
||||
'save_template' => __('Save Builder Template', 'fw'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function _init()
|
||||
{
|
||||
add_action('wp_ajax_fw_builder_templates_'. $this->get_type() .'_load', array($this, '_action_ajax_load_template'));
|
||||
add_action('wp_ajax_fw_builder_templates_'. $this->get_type() .'_save', array($this, '_action_ajax_save_template'));
|
||||
add_action('wp_ajax_fw_builder_templates_'. $this->get_type() .'_delete', array($this, '_action_ajax_delete_template'));
|
||||
}
|
||||
|
||||
private $fake_created_value;
|
||||
|
||||
private function array_map_add_fake_created_key($el)
|
||||
{
|
||||
if (!isset($el['created'])) {
|
||||
/**
|
||||
* Before 1.1.14 templates were appended
|
||||
* After 1.1.14 templates are prepended
|
||||
* So reverse old templates to be in the same order as the new ones
|
||||
*/
|
||||
$el['created'] = (++$this->fake_created_value);
|
||||
}
|
||||
|
||||
return $el;
|
||||
}
|
||||
|
||||
private function get_templates($builder_type)
|
||||
{
|
||||
return $this->get_db_templates($builder_type) + $this->get_predefined_templates($builder_type);
|
||||
}
|
||||
|
||||
private function get_wp_option_prefix($builder_type)
|
||||
{
|
||||
return 'fw:bt:f:'. $builder_type .':';
|
||||
}
|
||||
|
||||
private function sort_templates($a, $b)
|
||||
{
|
||||
$at = isset($a['created']) ? $a['created'] : 0;
|
||||
$bt = isset($b['created']) ? $b['created'] : 0;
|
||||
|
||||
if ($at == $bt) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($at > $bt) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_load_template()
|
||||
{
|
||||
if (!current_user_can('edit_posts')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$builder_type = (string)FW_Request::POST('builder_type');
|
||||
|
||||
if (!$this->builder_type_is_valid($builder_type)) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$templates = $this->get_templates($builder_type);
|
||||
|
||||
$template_id = (string)FW_Request::POST('template_id');
|
||||
|
||||
if (!isset($templates[$template_id])) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
wp_send_json_success(array(
|
||||
'json' => $templates[$template_id]['json']
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_save_template()
|
||||
{
|
||||
if (!current_user_can('edit_posts')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$builder_type = (string)FW_Request::POST('builder_type');
|
||||
|
||||
if (!$this->builder_type_is_valid($builder_type)) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$template = array(
|
||||
'title' => trim((string)FW_Request::POST('template_name')),
|
||||
'json' => trim((string)FW_Request::POST('builder_json')),
|
||||
'created' => time(),
|
||||
);
|
||||
|
||||
if (
|
||||
empty($template['json'])
|
||||
||
|
||||
($decoded_json = json_decode($template['json'], true)) === null
|
||||
) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
unset($decoded_json);
|
||||
|
||||
if (empty($template['title'])) {
|
||||
$template['title'] = __('No Title', 'fw');
|
||||
}
|
||||
|
||||
$template_id = md5($template['json']);
|
||||
|
||||
update_option(
|
||||
$this->get_wp_option_prefix($builder_type) . $template_id,
|
||||
$template,
|
||||
false
|
||||
);
|
||||
|
||||
/**
|
||||
* Remove from old storage (to prevent array key merge with old value on get)
|
||||
*/
|
||||
{
|
||||
$old_templates = fw_get_db_extension_data('builder', 'templates/'. $builder_type, array());
|
||||
|
||||
unset($old_templates[$template_id]);
|
||||
|
||||
fw_set_db_extension_data('builder', 'templates/'. $builder_type, $old_templates);
|
||||
|
||||
unset($old_templates);
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_delete_template()
|
||||
{
|
||||
if (!current_user_can('edit_posts')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$builder_type = (string)FW_Request::POST('builder_type');
|
||||
|
||||
if (!$this->builder_type_is_valid($builder_type)) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$template_id = (string)FW_Request::POST('template_id');
|
||||
|
||||
delete_option($this->get_wp_option_prefix($builder_type) . $template_id);
|
||||
|
||||
/**
|
||||
* Remove from old storage
|
||||
*/
|
||||
{
|
||||
$old_templates = fw_get_db_extension_data('builder', 'templates/'. $builder_type, array());
|
||||
|
||||
unset($old_templates[$template_id]);
|
||||
|
||||
fw_set_db_extension_data('builder', 'templates/'. $builder_type, $old_templates);
|
||||
|
||||
unset($old_templates);
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $builder_type
|
||||
* @return mixed|null
|
||||
*
|
||||
* Note: Templates can be very big and saving them in a single wp option can throw mysql error on update query
|
||||
*/
|
||||
protected function get_db_templates($builder_type)
|
||||
{
|
||||
$templates = array();
|
||||
|
||||
/**
|
||||
* Note: 'prefix + name' max length should be 64
|
||||
*/
|
||||
$option_prefix = $this->get_wp_option_prefix($builder_type); // + md5 (length=32)
|
||||
|
||||
/**
|
||||
* @var WPDB $wpdb
|
||||
*/
|
||||
global $wpdb;
|
||||
|
||||
foreach ((array)$wpdb->get_results($wpdb->prepare(
|
||||
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s",
|
||||
$wpdb->esc_like( $option_prefix ) .'%'
|
||||
), ARRAY_A) as $row) {
|
||||
$templates[
|
||||
// extract (suffix) md5 used as id
|
||||
preg_replace('/^'. preg_quote($option_prefix, '/') .'/', '', $row['option_name'])
|
||||
] = get_option($row['option_name']);
|
||||
}
|
||||
|
||||
$templates +=
|
||||
/**
|
||||
* Append old templates
|
||||
* This can't be removed because a lot of installations already use this
|
||||
*/
|
||||
fw_get_db_extension_data('builder', 'templates/'. $builder_type, array());
|
||||
|
||||
return $templates;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
add_action('fw_ext_builder:template_components_register', '_action_fw_ext_builder_template_component_full', 3);
|
||||
function _action_fw_ext_builder_template_component_full() {
|
||||
FW_Ext_Builder_Templates::register_component(
|
||||
new FW_Ext_Builder_Templates_Component_Full()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
(function($, localized){
|
||||
var eventsNamespace = '.templates-full',
|
||||
loadingId = 'fw-builder-templates-type-full',
|
||||
modal,
|
||||
lazyInitModal = function () {
|
||||
lazyInitModal = function () {};
|
||||
|
||||
modal = new fw.OptionsModal({
|
||||
title: localized.l10n.save_template,
|
||||
options: [
|
||||
{
|
||||
'template_name': {
|
||||
'type': 'text',
|
||||
'label': localized.l10n.template_name
|
||||
}
|
||||
}
|
||||
],
|
||||
values: ''
|
||||
});
|
||||
};
|
||||
|
||||
fwEvents.on('fw:option-type:builder:templates:init', function(data){
|
||||
var loading = data.tooltipLoading,
|
||||
builder = data.builder,
|
||||
tooltipHideCallback = data.tooltipHideCallback,
|
||||
tooltipRefreshCallback = data.tooltipRefreshCallback;
|
||||
|
||||
data.$elements.find('.fw-builder-templates-type-full')
|
||||
.off(eventsNamespace)
|
||||
.on('click'+ eventsNamespace, 'a[data-load-template]', function(){
|
||||
var templateId = $(this).attr('data-load-template');
|
||||
|
||||
loading.show();
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'fw_builder_templates_full_load',
|
||||
'builder_type': builder.get('type'),
|
||||
'template_id': templateId
|
||||
}
|
||||
})
|
||||
.done(function(json){
|
||||
loading.hide();
|
||||
|
||||
if (!json.success) {
|
||||
console.error('Failed to load builder template', json);
|
||||
return;
|
||||
}
|
||||
|
||||
if (JSON.stringify(builder.rootItems) === json.data.json) {
|
||||
console.log('Loaded value is the same as current');
|
||||
} else {
|
||||
builder.rootItems.reset(JSON.parse(json.data.json));
|
||||
}
|
||||
|
||||
tooltipHideCallback();
|
||||
})
|
||||
.fail(function(xhr, status, error){
|
||||
loading.hide();
|
||||
|
||||
console.error('Ajax error', error);
|
||||
});
|
||||
})
|
||||
.on('click'+ eventsNamespace, 'a[data-delete-template]', function(){
|
||||
var templateId = $(this).attr('data-delete-template');
|
||||
|
||||
loading.show();
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'fw_builder_templates_full_delete',
|
||||
'builder_type': builder.get('type'),
|
||||
'template_id': templateId
|
||||
}
|
||||
})
|
||||
.done(function(json){
|
||||
loading.hide();
|
||||
|
||||
if (!json.success) {
|
||||
console.error('Failed to delete builder template', json);
|
||||
return;
|
||||
}
|
||||
|
||||
tooltipRefreshCallback();
|
||||
})
|
||||
.fail(function(xhr, status, error){
|
||||
loading.hide();
|
||||
|
||||
console.error('Ajax error', error);
|
||||
});
|
||||
})
|
||||
.on('click'+ eventsNamespace, 'a.save-template', function () {
|
||||
tooltipHideCallback();
|
||||
|
||||
lazyInitModal();
|
||||
|
||||
// reset previous values
|
||||
modal.set('values', {}, {silent: true});
|
||||
|
||||
// remove previous listener
|
||||
modal.off('change:values');
|
||||
|
||||
modal.on('change:values', function (modal, values) {
|
||||
fw.loading.show(loadingId);
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'fw_builder_templates_full_save',
|
||||
'template_name': values.template_name,
|
||||
'builder_json': JSON.stringify(builder.rootItems),
|
||||
'builder_type': builder.get('type')
|
||||
}
|
||||
})
|
||||
.done(function (json) {
|
||||
fw.loading.hide(loadingId);
|
||||
|
||||
if (!json.success) {
|
||||
console.error('Failed to save builder template', json);
|
||||
return;
|
||||
}
|
||||
})
|
||||
.fail(function (xhr, status, error) {
|
||||
fw.loading.hide(loadingId);
|
||||
|
||||
console.error('Ajax save error', error);
|
||||
});
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
});
|
||||
})(jQuery, _fw_option_type_builder_templates_full);
|
||||
@@ -0,0 +1,4 @@
|
||||
.fw-builder-templates-type-full .save-template-wrapper a {
|
||||
text-decoration: none !important;
|
||||
font-style: normal;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
foreach (array('full') as $component_id) {
|
||||
require_once dirname(__FILE__) .'/components/'. $component_id .'/init.php';
|
||||
}
|
||||
|
||||
FW_Ext_Builder_Templates::_init();
|
||||
@@ -0,0 +1,182 @@
|
||||
(function ($, fwe, _, localized) {
|
||||
$(document.body).on('fw:option-type:builder:init', function(e, data) {
|
||||
var inst = {
|
||||
$el: {
|
||||
builder: $(e.target),
|
||||
tooltipContent: $('<div class="fw-builder-templates-tooltip-content"></div>'),
|
||||
tooltipLoading: $(
|
||||
'<div class="fw-builder-templates-tooltip-loading">'+
|
||||
/**/'<div class="loading-icon fw-animation-rotate-reverse-180 unycon unycon-unyson-o"></div>'+
|
||||
'</div>'
|
||||
),
|
||||
headerTools: data.$headerTools
|
||||
},
|
||||
builder: data.builder,
|
||||
isBusy: false,
|
||||
tooltipLoading: {
|
||||
show: function() {
|
||||
inst.$el.tooltipContent.prepend(inst.$el.tooltipLoading);
|
||||
},
|
||||
hide: function() {
|
||||
inst.$el.tooltipLoading.detach();
|
||||
}
|
||||
},
|
||||
tooltipApi: null, // initialized below
|
||||
refresh: function() {
|
||||
if (this.isBusy) {
|
||||
console.log('Working... Try again later');
|
||||
return;
|
||||
}
|
||||
|
||||
this.isBusy = true;
|
||||
this.tooltipLoading.show();
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
dataType: 'json',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'fw_builder_templates_render',
|
||||
'builder_type': this.builder.get('type')
|
||||
}
|
||||
})
|
||||
.done(_.bind(function(json){
|
||||
this.isBusy = false;
|
||||
this.tooltipLoading.hide();
|
||||
|
||||
if (!json.success) {
|
||||
console.error('Failed to render builder templates', json);
|
||||
return;
|
||||
}
|
||||
|
||||
this.$el.tooltipContent.html(json.data.html);
|
||||
|
||||
/**
|
||||
* Html was replaced
|
||||
* Components that have html in tooltip, must init js events
|
||||
*/
|
||||
fwe.trigger('fw:option-type:builder:templates:init', {
|
||||
$elements: this.$el.tooltipContent,
|
||||
builder: this.builder,
|
||||
tooltipLoading: this.tooltipLoading,
|
||||
tooltipRefreshCallback: _.bind(this.refresh, this),
|
||||
tooltipHideCallback: _.bind(function(){ this.tooltipApi.hide(); }, this)
|
||||
});
|
||||
|
||||
this.$el.tooltipContent.trigger('fw:option-type:builder:templates:after-html-replace');
|
||||
}, this))
|
||||
.fail(_.bind(function(xhr, status, error){
|
||||
this.isBusy = false;
|
||||
this.tooltipLoading.hide();
|
||||
|
||||
fw.soleModal.show(
|
||||
'fw-builder-templates-error',
|
||||
'<h4>Ajax Error</h4><p class="fw-text-danger">'+ String(error) +'</p>',
|
||||
{showCloseButton: false}
|
||||
);
|
||||
}, this));
|
||||
}
|
||||
};
|
||||
|
||||
inst.$el.headerTools
|
||||
.removeClass('fw-hidden')
|
||||
.append(
|
||||
'<div class="template-container fw-pull-right">' +
|
||||
/**/'<a class="template-btn" href="#" onclick="return false;">'+ localized.l10n.templates +'</a>' +
|
||||
'</div>'
|
||||
);
|
||||
|
||||
inst.tooltipApi = inst.$el.headerTools
|
||||
.find('.template-container .template-btn')
|
||||
.qtip({
|
||||
show: 'click',
|
||||
hide: 'unfocus',
|
||||
position: {
|
||||
at: 'bottom center',
|
||||
my: 'top center',
|
||||
viewport: $(document.body)
|
||||
},
|
||||
events: {
|
||||
show: function () {
|
||||
inst.refresh();
|
||||
}
|
||||
},
|
||||
style: {
|
||||
classes: 'qtip-fw qtip-fw-builder',
|
||||
tip: {
|
||||
width: 12,
|
||||
height: 5
|
||||
},
|
||||
width: 180
|
||||
},
|
||||
content: {
|
||||
text: inst.$el.tooltipContent
|
||||
}
|
||||
})
|
||||
.qtip('api');
|
||||
|
||||
/**
|
||||
* Accordion
|
||||
*/
|
||||
inst.$el.tooltipContent
|
||||
.on(
|
||||
'click',
|
||||
'.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-title',
|
||||
function() {
|
||||
var $wrapper = $(this).closest('.fw-builder-templates-type'),
|
||||
$content = $wrapper.find('> .fw-builder-templates-type-content'),
|
||||
$root = $wrapper.closest('.fw-builder-templates-types'),
|
||||
specialClass = 'current';
|
||||
|
||||
if ($root.hasClass('is-busy')) {
|
||||
return;
|
||||
} else {
|
||||
$root.addClass('is-busy');
|
||||
}
|
||||
|
||||
$content.addClass(specialClass);
|
||||
|
||||
$root
|
||||
.find('> .fw-builder-templates-type > .fw-builder-templates-type-content:not(.'+specialClass+'):not(.fw-hidden)')
|
||||
.slideUp(function(){
|
||||
$(this).addClass('fw-hidden').removeAttr('style');
|
||||
});
|
||||
|
||||
$content.removeClass(specialClass);
|
||||
inst.$el.tooltipContent.removeAttr('data-open-type');
|
||||
|
||||
if ($content.hasClass('fw-hidden')) {
|
||||
$content
|
||||
.css('display', 'none')
|
||||
.removeClass('fw-hidden')
|
||||
.slideDown(function(){
|
||||
$root.removeClass('is-busy');
|
||||
$(this).removeAttr('style');
|
||||
inst.$el.tooltipContent.attr('data-open-type', $wrapper.attr('data-type'));
|
||||
});
|
||||
} else {
|
||||
$content.slideUp(function(){
|
||||
$root.removeClass('is-busy');
|
||||
$(this).addClass('fw-hidden').removeAttr('style');
|
||||
});
|
||||
}
|
||||
}
|
||||
)
|
||||
.on('fw:option-type:builder:templates:after-html-replace', function(){
|
||||
// reopen accordion type that was open before tooltip html replace
|
||||
{
|
||||
var openType = inst.$el.tooltipContent.attr('data-open-type');
|
||||
|
||||
if (openType) {
|
||||
inst.$el.tooltipContent // close all
|
||||
.find('.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-content')
|
||||
.addClass('fw-hidden');
|
||||
|
||||
inst.$el.tooltipContent // open one
|
||||
.find('.fw-builder-templates-types > .fw-builder-templates-type-'+ openType +' > .fw-builder-templates-type-content')
|
||||
.removeClass('fw-hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery, fwEvents, _, _fw_option_type_builder_templates);
|
||||
@@ -0,0 +1,146 @@
|
||||
body.rtl .fw-option-type-builder .template-container {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .template-container .template-btn {
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .template-container .template-btn:before {
|
||||
content: "\f135";
|
||||
font-family: dashicons;
|
||||
padding-right: 3px;
|
||||
vertical-align: text-bottom;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .template-container a:focus {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.fw-builder-templates-tooltip-content {
|
||||
text-align: left;
|
||||
padding: 5px;
|
||||
min-height: 70px; /* space for loading */
|
||||
}
|
||||
|
||||
.fw-builder-templates-tooltip-content .fw-builder-templates-tooltip-loading {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #333333;
|
||||
}
|
||||
.fw-builder-templates-tooltip-content .fw-builder-templates-tooltip-loading .loading-icon {
|
||||
display: block;
|
||||
position: relative;
|
||||
top: 50%;
|
||||
margin: -15px auto 0 auto;
|
||||
font-size: 30px;
|
||||
color: #555;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type {
|
||||
border-bottom: 1px solid #4B4B4B;
|
||||
border-bottom: 1px solid rgba(208, 208, 208, 0.15);
|
||||
padding-bottom: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type:last-child {
|
||||
border-bottom-width: 0;
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-title {
|
||||
display: block;
|
||||
font-style: normal;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-title:focus {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-content {
|
||||
border-top: 1px dashed #4B4B4B;
|
||||
border-top: 1px dashed rgba(208, 208, 208, 0.15);
|
||||
|
||||
padding-top: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-content .no-full-templates {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type > .fw-builder-templates-type-content .load-template-title {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
max-height: 200px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li {
|
||||
font-style: normal;
|
||||
padding-bottom: 10px;
|
||||
margin-bottom: 0px;
|
||||
list-style-type: none;
|
||||
margin-left: 4px;
|
||||
text-align: left;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li a.template-title {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li a.template-title:before {
|
||||
content: "•"; /* emulate native list bullet */
|
||||
font-size: 1.6em;
|
||||
vertical-align: sub;
|
||||
line-height: 1px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li,
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li a {
|
||||
color: #b1b1b1 !important;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li:hover,
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li:hover a {
|
||||
color: #eee !important;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li a {
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li a:focus {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li:last-child {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li a.template-delete {
|
||||
float: right;
|
||||
visibility: hidden;
|
||||
margin-top: 3px;
|
||||
text-decoration: none !important;
|
||||
}
|
||||
|
||||
.fw-builder-templates-types > .fw-builder-templates-type ul.std li:hover a.template-delete {
|
||||
visibility: visible;
|
||||
}
|
||||
@@ -0,0 +1,437 @@
|
||||
.fw-option-type-builder > .builder-items-types {
|
||||
padding: 0;
|
||||
margin-bottom: 1px; /* space for border that will appear on fixed header */
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.fixed-header {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.fixed-header > .builder-items-types {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
.fw-option-type-builder.fixed-header.has-header-tools > .builder-items-types {
|
||||
margin-bottom: 0;
|
||||
border-bottom: 1px solid #eeeeee;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types > .fw-options-tabs-wrapper {
|
||||
padding-bottom: 15px;
|
||||
border-bottom: 1px solid #eeeeee;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types > .fw-builder-header-tools {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types > .fw-builder-header-tools .fw-builder-header-post-save-button {
|
||||
position: relative;
|
||||
top: -5px;
|
||||
margin-bottom: -10px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .fw-option-type-builder-thumbnails-tab > .fw-backend-option-type-html {
|
||||
padding: 0 16px;
|
||||
}
|
||||
.fw-modal .fw-option-type-builder .fw-option-type-builder-thumbnails-tab > .fw-backend-option-type-html {
|
||||
padding: 1px 16px; /* 1px vertical padding for thumbnails outline */
|
||||
}
|
||||
|
||||
.fw-option-type-builder span.fw-ext-builder-icon {
|
||||
font-size: 16px;
|
||||
color: #b3b3b3;
|
||||
}
|
||||
|
||||
.fw-option-type-builder span.fw-ext-builder-icon.dashicons {
|
||||
/* dashicons are smaller than font grid (it's like padding), I don't know why the font was created like that */
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
|
||||
/* tabs */
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .fw-options-tabs-contents {
|
||||
margin: 20px 0 0 !important;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .fw-option-type-builder-thumbnails-tab > .fw-backend-option-type-html {
|
||||
padding: 0 16px !important;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .ui-tabs-nav li {
|
||||
margin-right: 1px !important;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .ui-tabs-nav a {
|
||||
font-size: 12px !important;
|
||||
font-weight: 400 !important;
|
||||
padding: 1px 14px 0 14px !important;
|
||||
line-height: 25px !important;
|
||||
color: #222222 !important;
|
||||
background-color: #F1F1F1;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .ui-tabs-nav .ui-state-active a {
|
||||
color: #0074a2 !important;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.fw-option-type-builder-tabs-count-1 > .builder-items-types .fw-options-tabs-wrapper .fw-options-tabs-list {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.fw-option-type-builder-tabs-count-1 > .builder-items-types .fw-options-tabs-wrapper .fw-options-tabs-contents {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
@media (max-width: 782px) {
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper .fw-options-tabs-list {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
body.rtl .fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .fw-options-tabs-list > ul {
|
||||
float: none;
|
||||
}
|
||||
|
||||
body.rtl .fw-option-type-builder > .builder-items-types .fullscreen-btn {
|
||||
float: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 782px) {
|
||||
body.rtl .fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .fw-options-tabs-list > ul {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
||||
/* end: tabs */
|
||||
|
||||
|
||||
/* builder-item-type */
|
||||
|
||||
.fw-option-type-builder .builder-item-type {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
font-size: 11px;
|
||||
background-color: #ffffff;
|
||||
float: left;
|
||||
display: table;
|
||||
position: relative;
|
||||
outline: 1px solid #e1e1e1;
|
||||
margin: 0 1px 1px 0;
|
||||
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
|
||||
-webkit-transition: outline-color .1s ease-in;
|
||||
transition: outline-color .1s ease-in;
|
||||
}
|
||||
|
||||
body.rtl .fw-option-type-builder .builder-item-type {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type:hover {
|
||||
outline-color: #8f8f8f;
|
||||
z-index: 9999;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type.ui-draggable-dragging {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type .item-type-icon-title {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type .item-type-icon-title .item-type-icon {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type .item-type-icon-title .item-type-icon .dashicons {
|
||||
font-size: 24px;
|
||||
display: inline-table;
|
||||
color: #b3b3b3;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type:hover .item-type-icon-title .item-type-icon .dashicons,
|
||||
.fw-option-type-builder .builder-item-type:hover span.fw-ext-builder-icon {
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type .item-type-icon-title .item-type-icon img {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
opacity: 0.66;
|
||||
|
||||
-webkit-transition: opacity .1s ease-in;
|
||||
transition: opacity .1s ease-in;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type:hover .item-type-icon-title .item-type-icon img {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-item-type .item-type-icon-title .item-type-title {
|
||||
text-align: center;
|
||||
line-height: 1.2;
|
||||
font-size: 10px;
|
||||
color: #666;
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
|
||||
/* builder builder-item-type add animation */
|
||||
|
||||
@-webkit-keyframes fwBuilderItemTypeAdd {
|
||||
0% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
70% {
|
||||
opacity: 0;
|
||||
|
||||
-webkit-transform: translate3d(0, 100%, 0);
|
||||
transform: translate3d(0, 100%, 0);
|
||||
}
|
||||
|
||||
71% {
|
||||
opacity: 0;
|
||||
|
||||
-webkit-transform: translate3d(0, 0, 0);
|
||||
transform: translate3d(0, 0, 0);
|
||||
|
||||
-webkit-transform: scale3d(.3, .3, .3);
|
||||
transform: scale3d(.3, .3, .3);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes fwBuilderItemTypeAdd {
|
||||
0% {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
70% {
|
||||
opacity: 0;
|
||||
|
||||
-webkit-transform: translate3d(0, 100%, 0);
|
||||
transform: translate3d(0, 100%, 0);
|
||||
}
|
||||
|
||||
71% {
|
||||
opacity: 0;
|
||||
|
||||
-webkit-transform: translate3d(0, 0, 0);
|
||||
transform: translate3d(0, 0, 0);
|
||||
|
||||
-webkit-transform: scale3d(.3, .3, .3);
|
||||
transform: scale3d(.3, .3, .3);
|
||||
}
|
||||
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.fw-builder-animation-item-type-add {
|
||||
-webkit-animation-name: fwBuilderItemTypeAdd;
|
||||
animation-name: fwBuilderItemTypeAdd;
|
||||
|
||||
-webkit-animation-duration: 500ms;
|
||||
animation-duration: 500ms;
|
||||
}
|
||||
|
||||
/* end: builder-item-type add animation */
|
||||
|
||||
/* end: builder-item-type */
|
||||
|
||||
|
||||
.fw-option-type-builder > .builder-root-items {
|
||||
padding-top: 0px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items > .builder-items {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.has-header-tools > .builder-root-items > .builder-items {
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.has-header-tools > .builder-root-items > .builder-items:before {
|
||||
margin-top: -10px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items > .builder-items span.fw-ext-builder-icon {
|
||||
bottom: -2px; /* fix for text smaller size */
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items > .builder-items span.fw-ext-builder-icon.dashicons {
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items > .builder-items span.fw-ext-builder-icon {
|
||||
color: #8c8c8c;
|
||||
margin-right: 9px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.fw-option-type-builder-tabs-count-0 > .builder-root-items {
|
||||
border-top-width: 0;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item {
|
||||
float: none;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item .controls > * {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item .controls .unycon,
|
||||
.fw-option-type-builder .builder-items .builder-item .controls .fa {
|
||||
margin-left: 4px;
|
||||
margin-right: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item .controls .dashicons {
|
||||
height: 16px;
|
||||
line-height: 14px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.ui-sortable-helper {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.new-item {
|
||||
animation: fwDropIn .3s ease-in;
|
||||
animation-iteration-count: 1;
|
||||
|
||||
-webkit-animation: fwDropIn .3s ease-in;
|
||||
-webkit-animation-iteration-count: 1;
|
||||
|
||||
-moz-animation: fwDropIn .3s ease-in;
|
||||
-moz-animation-iteration-count: 1;
|
||||
|
||||
-o-animation: fwDropIn .3s ease-in;
|
||||
-o-animation-iteration-count: 1;
|
||||
|
||||
-ms-animation: fwDropIn .3s ease-in;
|
||||
-ms-animation-iteration-count: 1;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items .fw-builder-placeholder {
|
||||
display: inline-block;
|
||||
float: none;
|
||||
padding: 10px;
|
||||
min-height: 50px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items .fw-builder-placeholder:before {
|
||||
content: ' ';
|
||||
border: 1px dashed #d8d8d8;
|
||||
background-color: rgba(85, 85, 85, 0.03);
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
bottom: 10px;
|
||||
left: 10px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-root-items .fw-builder-placeholder.no-top:before {
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.fw-builder-item-deny-incoming-type > div > .builder-items > .fw-builder-placeholder {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
/* allow/deny items in _items */
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.fw-builder-item-allow-incoming-type > div > .builder-items {
|
||||
/*background-color: #DDFFD2;*/
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.fw-builder-item-deny-incoming-type > div > .builder-items {
|
||||
/*background-color: #FFEFE7;*/
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.fw-builder-item-deny-incoming-type > div {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .builder-items .builder-item.fw-builder-item-deny-incoming-type > div > .builder-items:before {
|
||||
content: ' ';
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background: transparent url('../img/gradient-slash.png') repeat scroll 0 0;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
/* end: allow/deny*/
|
||||
|
||||
|
||||
/* backend fixes */
|
||||
[class*="-collapsed"] .builder-items,
|
||||
[class*="-collapsed"] .builder-items * {
|
||||
height:0;
|
||||
display:none;
|
||||
}
|
||||
|
||||
.fw-backend-option-type-builder {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.fw-backend-option-type-builder > .fw-backend-option-desc {
|
||||
padding: 15px 25px 0;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .fw-backend-option-type-html {
|
||||
padding-top: 0;
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
/* end: backend fixes */
|
||||
|
||||
|
||||
/* qtip */
|
||||
|
||||
.qtip-fw-builder {
|
||||
padding: 5px 10px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.qtip-fw-builder .qtip-content {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* end: qtip */
|
||||
@@ -0,0 +1,101 @@
|
||||
.fw-option-type-builder-fullscreen-backdrop {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 99997;
|
||||
margin: 0;
|
||||
background-color: #E1E1E1;
|
||||
}
|
||||
|
||||
body.admin-bar .fw-option-type-builder-fullscreen-backdrop {
|
||||
top: 32px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder-fullscreen-backdrop .buttons-wrapper {
|
||||
float: right;
|
||||
margin: 10px 20px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder-fullscreen-backdrop .button {
|
||||
margin-left: 5px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fw-option-type-builder-fullscreen-backdrop .buttons-wrapper .spinner {
|
||||
float: left;
|
||||
margin-top: 4px;
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fullscreen-btn {
|
||||
float: right;
|
||||
cursor: pointer;
|
||||
color: #0074a2;
|
||||
margin: -5px 10px 10px 0;
|
||||
}
|
||||
|
||||
body.rtl .fw-option-type-builder > .builder-items-types .fullscreen-btn {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fullscreen-btn div {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fullscreen-btn .icon-fullscreen-on {
|
||||
width: 9px;
|
||||
height: 18px;
|
||||
margin-right: 5px;
|
||||
background-position: center;
|
||||
background-image: url(../img/fullscreen/fullscreen-on.png);
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.fw-option-type-builder > .builder-items-types .fullscreen-btn .icon-fullscreen-off {
|
||||
width: 9px;
|
||||
height: 18px;
|
||||
margin-right: 5px;
|
||||
background-position: center;
|
||||
background-image: url(../img/fullscreen/fullscreen-off.png);
|
||||
background-repeat: no-repeat;
|
||||
|
||||
}
|
||||
|
||||
@media (max-width: 782px) {
|
||||
.fw-option-type-builder > .builder-items-types .fullscreen-btn {
|
||||
float: none;
|
||||
margin: 0 auto 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 783px) {
|
||||
.fw-option-type-builder > .builder-items-types .fw-options-tabs-wrapper.fw-options-tabs-first-level .fw-options-tabs-list > ul {
|
||||
float: left; /* needed when the Fullscreen button goes on top of tabs when page width is small http://bit.ly/1FSCB7p */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.fw-option-type-builder .ui-tabs-nav.ui-helper-clearfix:after {
|
||||
clear: none;
|
||||
}
|
||||
|
||||
|
||||
.fw-option-type-builder.builder-fullscreen {
|
||||
position: fixed;
|
||||
padding-top: 10px;
|
||||
top: 82px;
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
z-index: 99998;
|
||||
margin: 0;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.fw-option-type-builder.builder-fullscreen > .builder-root-items {
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/* Width Changer */
|
||||
|
||||
.fw-builder-item-width-changer {
|
||||
white-space: nowrap;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.fw-builder-item-width-changer a {
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
line-height: 18px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.fw-builder-item-width-changer.is-first a.decrease-width,
|
||||
.fw-builder-item-width-changer.is-last a.increase-width {
|
||||
color: #b2b2b2;
|
||||
}
|
||||
|
||||
.fw-builder-col-1-5{
|
||||
width: 20%;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
.fw-option-type-builder .history-container {
|
||||
float: left;
|
||||
}
|
||||
|
||||
body.rtl .fw-option-type-builder .history-container {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .history-container a {
|
||||
margin-right: 10px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .history-container a:focus {
|
||||
-webkit-box-shadow: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.fw-option-type-builder .history-container a.disabled {
|
||||
margin-right: 10px;
|
||||
text-decoration: none;
|
||||
color: #b2b2b2;
|
||||
}
|
||||
|
||||
.fw-option-type-builder a.undo {
|
||||
background-image: url(../img/history/undo.png);
|
||||
background-repeat: no-repeat;
|
||||
padding-left: 14px;
|
||||
background-position: left center;
|
||||
}
|
||||
|
||||
.fw-option-type-builder a.undo.disabled {
|
||||
background-image: url(../img/history/undo_disabled.png);
|
||||
}
|
||||
|
||||
.fw-option-type-builder a.redo {
|
||||
background-image: url(../img/history/redo.png);
|
||||
background-repeat: no-repeat;
|
||||
padding-left: 14px;
|
||||
background-position: left center;
|
||||
margin-left: 14px;
|
||||
}
|
||||
|
||||
.fw-option-type-builder a.redo.disabled {
|
||||
background-image: url(../img/history/redo_disabled.png);
|
||||
}
|
||||
|
After Width: | Height: | Size: 162 B |
|
After Width: | Height: | Size: 163 B |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 256 B |
|
After Width: | Height: | Size: 273 B |
|
After Width: | Height: | Size: 264 B |
|
After Width: | Height: | Size: 273 B |
@@ -0,0 +1,979 @@
|
||||
jQuery( document ).ready( function ( $ ) {
|
||||
/** Some functions */
|
||||
{
|
||||
/**
|
||||
* Loop recursive through all items in given collection
|
||||
*/
|
||||
function forEachItemRecursive( collection, callback ) {
|
||||
collection.each( function ( item ) {
|
||||
callback( item );
|
||||
|
||||
forEachItemRecursive( item.get( '_items' ), callback );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
var Builder = Backbone.Model.extend( {
|
||||
defaults: {
|
||||
type: null // required
|
||||
},
|
||||
/**
|
||||
* Extract item type from class
|
||||
* @param {this.classes.Item} ItemClass
|
||||
* @returns {String}
|
||||
*/
|
||||
getItemClassType: function ( ItemClass ) {
|
||||
return (
|
||||
typeof ItemClass.prototype.defaults === 'function'
|
||||
)
|
||||
? ItemClass.prototype.defaults().type
|
||||
: ItemClass.prototype.defaults.type;
|
||||
},
|
||||
/**
|
||||
* @param {String} type
|
||||
* @returns {this.classes.Item}
|
||||
*/
|
||||
getRegisteredItemClassByType: function ( type ) {
|
||||
return this.registeredItemsClasses[type];
|
||||
},
|
||||
/**
|
||||
* Register Item Class (with unique type)
|
||||
* @param {this.classes.Item} ItemClass
|
||||
* @returns {boolean}
|
||||
*/
|
||||
registerItemClass: function ( ItemClass ) {
|
||||
if ( ! (
|
||||
ItemClass.prototype instanceof this.classes.Item
|
||||
) ) {
|
||||
console.error( 'Tried to register Item Type Class that does not extend this.classes.Item', ItemClass );
|
||||
return false;
|
||||
}
|
||||
|
||||
var type = this.getItemClassType( ItemClass );
|
||||
|
||||
if ( typeof type != 'string' ) {
|
||||
console.error( 'Invalid Builder Item type: ' + type, ItemClass );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( typeof this.registeredItemsClasses[type] != 'undefined' ) {
|
||||
console.error( 'Builder Item type "' + type + '" already registered', ItemClass );
|
||||
return false;
|
||||
}
|
||||
|
||||
this.registeredItemsClasses[type] = ItemClass;
|
||||
|
||||
return true;
|
||||
},
|
||||
/**
|
||||
* Find Item instance recursive in Items collection
|
||||
* @param {Object} itemAttr (can be specified cid)
|
||||
* @param {this.classes.Items} [items]
|
||||
* @return {this.classes.Item|null}
|
||||
*/
|
||||
findItemRecursive: function ( itemAttr, items ) {
|
||||
if ( arguments.length < 2 ) {
|
||||
items = this.rootItems;
|
||||
}
|
||||
|
||||
var item = items.get( itemAttr );
|
||||
|
||||
if ( item ) {
|
||||
return item;
|
||||
}
|
||||
|
||||
var that = this;
|
||||
|
||||
items.each( function ( _item ) {
|
||||
if ( item ) {
|
||||
// stop search if item found
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var {builder.classes.Item} _item */
|
||||
item = that.findItemRecursive(
|
||||
itemAttr,
|
||||
_item.get( '_items' )
|
||||
);
|
||||
} );
|
||||
|
||||
return item;
|
||||
},
|
||||
/**
|
||||
* ! Do not rewrite this (it's final)
|
||||
* @private
|
||||
*
|
||||
* Properties created in initialize():
|
||||
*
|
||||
* Classes to extend
|
||||
* - classes.Item
|
||||
* - classes.ItemView
|
||||
* - classes.Items
|
||||
* - classes.ItemsView
|
||||
*
|
||||
* From this classes will be created items instances
|
||||
* { 'type' => Class }
|
||||
* - registeredItemsClasses
|
||||
*
|
||||
* Reference to root this.classes.Items Collection instance that contains all items
|
||||
* - rootItems
|
||||
*
|
||||
* Hidden input that stores JSON.stringify(this.rootItems)
|
||||
* - $input
|
||||
*/
|
||||
initialize: function ( attributes, options ) {
|
||||
var builder = this;
|
||||
|
||||
/**
|
||||
* todo: To be able to extend and customize for e.g. only Item class. To not rewrite entire .initialize()
|
||||
* this.__definePrivateMethods()
|
||||
* this.__defineItem()
|
||||
* this.__defineItemView()
|
||||
* this.__defineItems()
|
||||
* this.__defineItemsView()
|
||||
*/
|
||||
|
||||
/**
|
||||
* Assign a value to define this property inside this, not in prototype
|
||||
* Instances of Builder should not share items
|
||||
*/
|
||||
this.registeredItemsClasses = {};
|
||||
|
||||
/** Define private functions accessible only within this method */
|
||||
{
|
||||
/**
|
||||
* (Re)Create Items from json
|
||||
*
|
||||
* Used on collection.reset([...]) to create nested items
|
||||
*
|
||||
* @param {this.classes.Item} item
|
||||
* @param {Array} _items
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
*/
|
||||
function createItemsFromJSON( item, _items ) {
|
||||
if ( ! _items ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_.each( _items, function ( _item ) {
|
||||
var ItemClass = builder.getRegisteredItemClassByType( _item['type'] );
|
||||
|
||||
if ( ! ItemClass ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var __items = _item['_items'];
|
||||
|
||||
delete _item['_items'];
|
||||
|
||||
var subItem = new ItemClass( _item );
|
||||
|
||||
item.get( '_items' ).add( subItem );
|
||||
|
||||
createItemsFromJSON( subItem, __items );
|
||||
} );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Mark new added items with special class, to be able to add css effects to it
|
||||
{
|
||||
var markItemAsNew;
|
||||
|
||||
(
|
||||
function () {
|
||||
var lastNewItem = false;
|
||||
|
||||
var rootItemsInitialized = false;
|
||||
|
||||
var removeClassTimeout;
|
||||
var removeClassAfter = 700;
|
||||
|
||||
markItemAsNew = function ( item ) {
|
||||
clearTimeout( removeClassTimeout );
|
||||
|
||||
if ( lastNewItem ) {
|
||||
lastNewItem.view.$el.removeClass( 'new-item' );
|
||||
}
|
||||
|
||||
item.view.$el.addClass( 'new-item' );
|
||||
|
||||
lastNewItem = item;
|
||||
|
||||
removeClassTimeout = setTimeout( function () {
|
||||
if ( lastNewItem ) {
|
||||
lastNewItem.view.$el.removeClass( 'new-item' );
|
||||
}
|
||||
}, removeClassAfter );
|
||||
|
||||
if ( ! rootItemsInitialized ) {
|
||||
builder.rootItems.on( 'builder:change', function () {
|
||||
if ( lastNewItem ) {
|
||||
lastNewItem.view.$el.removeClass( 'new-item' );
|
||||
}
|
||||
|
||||
lastNewItem = false;
|
||||
} );
|
||||
|
||||
rootItemsInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
)();
|
||||
}
|
||||
}
|
||||
|
||||
/** Define classes */
|
||||
{
|
||||
this.classes = {};
|
||||
|
||||
/** Items */
|
||||
{
|
||||
this.classes.Items = Backbone.Collection.extend( {
|
||||
/**
|
||||
* Guess which item type to create from json
|
||||
* (usually called on .reset())
|
||||
*/
|
||||
model: function ( attrs, options ) {
|
||||
do {
|
||||
if ( typeof attrs == 'function' ) {
|
||||
// It's a class. Check if has correct type
|
||||
if ( builder.getItemClassType( attrs ) ) {
|
||||
return attrs;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if ( typeof attrs == 'object' ) {
|
||||
/**
|
||||
* it's an object with attributes for new instance
|
||||
* check if has correct type in it (get registered class with this type)
|
||||
*/
|
||||
|
||||
var ItemClass = builder.getRegisteredItemClassByType( attrs['type'] );
|
||||
|
||||
if ( ! ItemClass ) {
|
||||
break;
|
||||
}
|
||||
|
||||
var _items = attrs['_items'];
|
||||
|
||||
delete attrs['_items'];
|
||||
|
||||
var item = new ItemClass( attrs );
|
||||
|
||||
createItemsFromJSON( item, _items );
|
||||
|
||||
return item;
|
||||
}
|
||||
} while ( false );
|
||||
|
||||
console.error( 'Cannot detect Item type', attrs, options );
|
||||
|
||||
return new builder.classes.Item;
|
||||
},
|
||||
/**
|
||||
* View that contains sortable with items views
|
||||
*/
|
||||
view: null,
|
||||
initialize: function () {
|
||||
this.defaultInitialize();
|
||||
|
||||
this.view = new builder.classes.ItemsView( {
|
||||
collection: this
|
||||
} );
|
||||
},
|
||||
/**
|
||||
* It is required to call this method in .initialize()
|
||||
*/
|
||||
defaultInitialize: function () {
|
||||
this.on( 'add', function ( item ) {
|
||||
// trigger custom event on rootItems to update input value
|
||||
builder.rootItems.trigger( 'builder:change' );
|
||||
|
||||
// markItemAsNew(item); // prevent glitches
|
||||
} );
|
||||
|
||||
this.on( 'remove', function ( item ) {
|
||||
// trigger custom event on rootItems to update input value
|
||||
builder.rootItems.trigger( 'builder:change' );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
this.classes.ItemsView = Backbone.View.extend( {
|
||||
// required
|
||||
|
||||
collection: null,
|
||||
|
||||
// end: required
|
||||
|
||||
tagName: 'div',
|
||||
className: 'builder-items fw-row fw-border-box-sizing',
|
||||
template: _.template( '' ),
|
||||
events: {},
|
||||
initSortableTimeout: 0,
|
||||
initialize: function () {
|
||||
this.defaultInitialize();
|
||||
},
|
||||
/**
|
||||
* It is required to call this method in .initialize()
|
||||
*/
|
||||
defaultInitialize: function () {
|
||||
this.listenTo( this.collection, 'add change remove reset', this.render );
|
||||
|
||||
this.render();
|
||||
},
|
||||
render: function () {
|
||||
/**
|
||||
* First .detach() elements
|
||||
* to prevent them to be removed (reset) on .html('...') replace
|
||||
*/
|
||||
{
|
||||
this.collection.each( function ( item ) {
|
||||
item.view.$el.detach();
|
||||
} );
|
||||
}
|
||||
|
||||
if ( this.$el.hasClass( 'ui-sortable' ) ) {
|
||||
this.$el.sortable( 'destroy' );
|
||||
}
|
||||
|
||||
this.$el.html( this.template( {
|
||||
items: this.collection
|
||||
} ) );
|
||||
|
||||
var that = this;
|
||||
|
||||
this.collection.each( function ( item ) {
|
||||
that.$el.append( item.view.$el );
|
||||
} );
|
||||
|
||||
/**
|
||||
* init sortable with delay, after element added to DOM
|
||||
* fixes bug: sortable sometimes not initialized if element is not in DOM
|
||||
*/
|
||||
{
|
||||
clearTimeout( this.initSortableTimeout );
|
||||
|
||||
this.initSortableTimeout = setTimeout( function () {
|
||||
that.initSortable();
|
||||
}, 12 );
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
initSortable: function () {
|
||||
var hasDragAndDrop = builder.rootItems.view.$el
|
||||
.closest( '.fw-option-type-builder' )
|
||||
.attr( 'data-drag-and-drop' );
|
||||
|
||||
if ( ! hasDragAndDrop ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( this.$el.hasClass( 'ui-sortable' ) ) {
|
||||
// already initialized
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove "allowed" and "denied" classes from all items
|
||||
function itemsRemoveAllowedDeniedClasses() {
|
||||
builder.rootItems.view.$el.removeClass(
|
||||
'fw-builder-item-allow-incoming-type fw-builder-item-deny-incoming-type'
|
||||
);
|
||||
|
||||
forEachItemRecursive( builder.rootItems, function ( item ) {
|
||||
item.view.$el.removeClass(
|
||||
'fw-builder-item-allow-incoming-type fw-builder-item-deny-incoming-type'
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
var rearrangeTimeout;
|
||||
|
||||
var additionalSortableOptions = {}
|
||||
|
||||
fwEvents.trigger(
|
||||
'fw-builder:'+ builder.get('type') +':sortable-additional-options',
|
||||
additionalSortableOptions
|
||||
)
|
||||
|
||||
this.$el.sortable(_.extend({
|
||||
items: '> .builder-item',
|
||||
helper: 'original',
|
||||
connectWith: '#' + builder.$input.closest( '.fw-option-type-builder' ).attr( 'id' ) + ' .builder-root-items .builder-items',
|
||||
distance: 10,
|
||||
opacity: 0.6,
|
||||
scrollSpeed: 10,
|
||||
placeholder: 'fw-builder-placeholder',
|
||||
tolerance: 'pointer',
|
||||
start: function ( event, ui ) {
|
||||
{
|
||||
ui.placeholder
|
||||
.addClass( ui.item.attr( 'class' ) )
|
||||
.css( 'height', ui.helper.outerHeight() );
|
||||
|
||||
if ( ! parseInt( ui.placeholder.css( 'padding-top' ) ) ) {
|
||||
ui.placeholder.addClass( 'no-top' );
|
||||
}
|
||||
|
||||
if ( ui.item.hasClass( 'builder-item-type' ) ) {
|
||||
ui.placeholder.removeClass( 'builder-item-type' ).css( 'width', '100%' );
|
||||
}
|
||||
}
|
||||
|
||||
// check if it is an exiting item (and create variables)
|
||||
{
|
||||
// extract cid from view id
|
||||
var movedItemCid = ui.item.attr( 'id' );
|
||||
|
||||
if ( ! movedItemCid ) {
|
||||
// not an existing item, it's a thumbnail from draggable
|
||||
return;
|
||||
}
|
||||
|
||||
movedItemCid = movedItemCid.split( '-' ).pop();
|
||||
|
||||
if ( ! movedItemCid ) {
|
||||
// not an existing item, it's a thumbnail from draggable
|
||||
return;
|
||||
}
|
||||
|
||||
var movedItem = builder.findItemRecursive( {cid: movedItemCid} );
|
||||
|
||||
if ( ! movedItem ) {
|
||||
console.warn( 'Item not found (cid: "' + movedItemCid + '")' );
|
||||
return;
|
||||
}
|
||||
|
||||
// fixme: this is hardcode. need to think a better/general solution
|
||||
if ( movedItem.attributes.type != 'column'
|
||||
&& movedItem.attributes.type != 'section' ) {
|
||||
ui.item.parents( '.builder-root-items' ).addClass( 'fw-move-simple-item' );
|
||||
}
|
||||
}
|
||||
|
||||
var movedItemType = movedItem.get( 'type' );
|
||||
|
||||
/**
|
||||
* add "allowed" classes to items vies where allowIncomingType(movedItemType) returned true
|
||||
* else add "denied" class
|
||||
*/
|
||||
{
|
||||
{
|
||||
if ( movedItem.allowDestinationType( null ) ) {
|
||||
builder.rootItems.view.$el.addClass( 'fw-builder-item-allow-incoming-type' );
|
||||
} else {
|
||||
builder.rootItems.view.$el.addClass( 'fw-builder-item-deny-incoming-type' );
|
||||
}
|
||||
}
|
||||
|
||||
forEachItemRecursive( builder.rootItems, function ( item ) {
|
||||
if ( item.cid === movedItemCid ) {
|
||||
// this is current moved item
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
item.allowIncomingType( movedItemType )
|
||||
&&
|
||||
movedItem.allowDestinationType( item.get( 'type' ) )
|
||||
) {
|
||||
item.view.$el.addClass( 'fw-builder-item-allow-incoming-type' );
|
||||
} else {
|
||||
item.view.$el.addClass( 'fw-builder-item-deny-incoming-type' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
// Freeze the container height
|
||||
{
|
||||
var container = builder.$input.closest( '.fw-option-type-builder' )
|
||||
.find( '.builder-root-items > .builder-items' );
|
||||
|
||||
container.css( 'min-height', container.height() + 'px' );
|
||||
}
|
||||
},
|
||||
stop: function ( event, ui ) {
|
||||
clearTimeout( rearrangeTimeout );
|
||||
|
||||
itemsRemoveAllowedDeniedClasses();
|
||||
|
||||
ui.item.parents( '.builder-root-items' ).removeClass( 'fw-move-simple-item' );
|
||||
|
||||
// unfreeze the container height
|
||||
{
|
||||
var container = builder.$input.closest( '.fw-option-type-builder' )
|
||||
.find( '.builder-root-items > .builder-items' );
|
||||
|
||||
container.css( 'min-height', '' );
|
||||
}
|
||||
|
||||
if (ui.helper) {
|
||||
$(ui.helper).remove()
|
||||
}
|
||||
},
|
||||
receive: function ( event, ui ) {
|
||||
// sometimes the "stop" event is not triggered and classes remains
|
||||
itemsRemoveAllowedDeniedClasses();
|
||||
|
||||
{
|
||||
var currentItemType = null; // will remain null if it is root collection
|
||||
var currentItem;
|
||||
|
||||
if ( this.collection._item ) {
|
||||
currentItemType = this.collection._item.get( 'type' );
|
||||
currentItem = this.collection._item;
|
||||
}
|
||||
}
|
||||
|
||||
var incomingItemType = ui.item.attr( 'data-builder-item-type' );
|
||||
|
||||
if ( incomingItemType ) {
|
||||
// received item type from draggable
|
||||
|
||||
var IncomingItemClass = builder.getRegisteredItemClassByType( incomingItemType );
|
||||
|
||||
if ( IncomingItemClass ) {
|
||||
if (
|
||||
IncomingItemClass.prototype.allowDestinationType( currentItemType )
|
||||
&&
|
||||
(
|
||||
! currentItemType
|
||||
||
|
||||
currentItem.allowIncomingType( incomingItemType )
|
||||
)
|
||||
) {
|
||||
this.collection.add(
|
||||
new IncomingItemClass( {}, {
|
||||
$thumb: ui.item
|
||||
} ),
|
||||
{
|
||||
at: this.$el.find( '> .builder-item-type' ).index()
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// replace all html, so dragged element will be removed
|
||||
this.render();
|
||||
}
|
||||
} else {
|
||||
console.error( 'Unregistered item type: ' + incomingItemType );
|
||||
|
||||
this.render();
|
||||
}
|
||||
} else {
|
||||
// received existing item from another sortable
|
||||
|
||||
if ( ! ui.item.attr( 'id' ) ) {
|
||||
console.warn( 'Invalid view id', ui.item );
|
||||
return;
|
||||
}
|
||||
|
||||
// extract cid from view id
|
||||
var incomingItemCid = ui.item.attr( 'id' ).split( '-' ).pop();
|
||||
|
||||
var incomingItem = builder.findItemRecursive( {cid: incomingItemCid} );
|
||||
|
||||
if ( ! incomingItem ) {
|
||||
console.warn( 'Item not found (cid: "' + incomingItemCid + '")' );
|
||||
return;
|
||||
}
|
||||
|
||||
var incomingItemType = incomingItem.get( 'type' );
|
||||
var IncomingItemClass = builder.getRegisteredItemClassByType( incomingItemType );
|
||||
|
||||
if (
|
||||
IncomingItemClass.prototype.allowDestinationType( currentItemType )
|
||||
&&
|
||||
(
|
||||
! currentItemType
|
||||
||
|
||||
currentItem.allowIncomingType( incomingItemType )
|
||||
)
|
||||
) {
|
||||
// move item from one collection to another
|
||||
{
|
||||
var at = ui.item.index();
|
||||
|
||||
// prevent 'remove', that will remove all events from the element
|
||||
incomingItem.view.$el.detach();
|
||||
|
||||
incomingItem.collection.remove( incomingItem );
|
||||
|
||||
this.collection.add( incomingItem, {
|
||||
at: at
|
||||
} );
|
||||
}
|
||||
} else {
|
||||
console.warn( '[Builder] Item move denied' );
|
||||
ui.sender.sortable( 'cancel' );
|
||||
}
|
||||
}
|
||||
}.bind( this ),
|
||||
update: function ( event, ui ) {
|
||||
if ( ui.item.attr( 'data-ignore-update-once' ) ) {
|
||||
ui.item.removeAttr( 'data-ignore-update-once' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ui.item.attr( 'data-builder-item-type' ) ) {
|
||||
// element just received from draggable, it is not builder item yet, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! ui.item.attr( 'id' ) ) {
|
||||
console.warn( 'Invalid item, no id' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $( this ).find( '> #' + ui.item.attr( 'id' ) + ':first' ).length ) {
|
||||
// Item not in sortable, probably moved to another sortable, do nothing
|
||||
|
||||
/**
|
||||
* Right after this event, is expected to be next 'update' for on same item.
|
||||
* But between this two 'update' is a 'receive' that takes care about item move from
|
||||
* one collection to another and place ar right index position in destination model,
|
||||
* so it is better to ignore next coming 'update'.
|
||||
* Set a special attribute to ignore 'update' once
|
||||
*/
|
||||
ui.item.attr( 'data-ignore-update-once', 'true' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// extract cid from view id
|
||||
var itemCid = ui.item.attr( 'id' ).split( '-' ).pop();
|
||||
|
||||
var item = builder.findItemRecursive( {cid: itemCid} );
|
||||
|
||||
if ( ! item ) {
|
||||
console.warn( 'Item not found (cid: "' + itemCid + '")' );
|
||||
return;
|
||||
}
|
||||
|
||||
var index = ui.item.index();
|
||||
|
||||
// change item position in collection
|
||||
{
|
||||
var collection = item.collection;
|
||||
|
||||
// prevent 'remove', that will remove all events from the element
|
||||
item.view.$el.detach();
|
||||
|
||||
collection.remove( item );
|
||||
|
||||
collection.add( item, {at: index} );
|
||||
}
|
||||
}
|
||||
}, additionalSortableOptions) );
|
||||
|
||||
/**
|
||||
* Delay placeholder possition change to prevent "jumping"
|
||||
* Fixes https://github.com/ThemeFuse/Unyson-PageBuilder-Extension/issues/25
|
||||
* Original code https://github.com/jquery/jquery-ui/blob/1.12.0-rc.2/ui/widgets/sortable.js#L1384
|
||||
* Note: Uses the above `var rearrangeTimeout;`
|
||||
*/
|
||||
this.$el.sortable( 'instance' )._rearrange = function ( event, i, a, hardRefresh ) {
|
||||
clearTimeout( rearrangeTimeout );
|
||||
|
||||
rearrangeTimeout = setTimeout( function () {
|
||||
/* The Original Code:
|
||||
a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction === "down" ? i.item[0] : i.item[0].nextSibling));
|
||||
*/
|
||||
if ( this.a ) {
|
||||
this.a[0].appendChild( this.instance.placeholder[0] );
|
||||
} else {
|
||||
if ( this.instance.placeholder.parent().length ) {
|
||||
this.i.item[0].parentNode.insertBefore(
|
||||
this.instance.placeholder[0],
|
||||
(
|
||||
this.direction === "down" ? this.i.item[0] : this.i.item[0].nextSibling
|
||||
)
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* This happens for draggable items
|
||||
* Do nothing to prevent DOM flood with orphaned placeholders
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/* The Original Code:
|
||||
//Various things done here to improve the performance:
|
||||
// 1. we create a setTimeout, that calls refreshPositions
|
||||
// 2. on the instance, we have a counter variable, that get's higher after every append
|
||||
// 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
|
||||
// 4. this lets only the last addition to the timeout stack through
|
||||
this.counter = this.counter ? ++this.counter : 1;
|
||||
var counter = this.counter;
|
||||
|
||||
this._delay(function() {
|
||||
if(counter === this.counter) {
|
||||
this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
|
||||
}
|
||||
});
|
||||
*/
|
||||
this.instance.refreshPositions( ! this.hardRefresh );
|
||||
}.bind( {
|
||||
instance: this,
|
||||
i: i,
|
||||
a: a,
|
||||
hardRefresh: hardRefresh,
|
||||
direction: this.direction
|
||||
} ), 100 );
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/** Item */
|
||||
{
|
||||
this.classes.Item = Backbone.RelationalModel.extend( {
|
||||
// required
|
||||
|
||||
defaults: {
|
||||
/** @type {String} Your item unique type (withing the builder) */
|
||||
type: null
|
||||
},
|
||||
|
||||
/** @type {builder.classes.ItemView} */
|
||||
view: null,
|
||||
|
||||
// end: required
|
||||
|
||||
/** ! Do not overwrite this property */
|
||||
relations: [
|
||||
{
|
||||
type: Backbone.HasMany,
|
||||
key: '_items',
|
||||
//relatedModel: builder.classes.Item, // class does not exists at this point, initialized below
|
||||
collectionType: builder.classes.Items,
|
||||
collectionKey: '_item'
|
||||
}
|
||||
],
|
||||
initialize: function () {
|
||||
this.view = new builder.classes.ItemView( {
|
||||
id: 'fw-builder-item-' + this.cid,
|
||||
model: this
|
||||
} );
|
||||
|
||||
this.defaultInitialize();
|
||||
},
|
||||
/**
|
||||
* It is required to call this method in .initialize()
|
||||
*/
|
||||
defaultInitialize: function () {
|
||||
// trigger custom event on rootItems to update input value
|
||||
this.on( 'change', function () {
|
||||
builder.rootItems.trigger( 'builder:change' );
|
||||
} );
|
||||
},
|
||||
/**
|
||||
* Item decide if allows an incoming item type to be placed inside it's _items
|
||||
*
|
||||
* @param {String} type
|
||||
* @returns {boolean}
|
||||
*/
|
||||
allowIncomingType: function ( type ) {
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* Item decide if allows to be placed into _items of another item type
|
||||
*
|
||||
* ! Do not use "this" in this method, it will be called without an instance via Class.prototype.allowDestinationType()
|
||||
*
|
||||
* @param {String|null} type String - item type; null - root items
|
||||
* @returns {boolean}
|
||||
*/
|
||||
allowDestinationType: function ( type ) {
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
|
||||
{
|
||||
this.classes.Item.prototype.relations[0].relatedModel = this.classes.Item;
|
||||
}
|
||||
|
||||
this.classes.ItemView = Backbone.View.extend( {
|
||||
// required
|
||||
|
||||
/** @type {builder.classes.Item} */
|
||||
model: null,
|
||||
/** @type {String} 'any-string-'+ this.model.cid */
|
||||
id: null,
|
||||
|
||||
// end: required
|
||||
|
||||
tagName: 'div',
|
||||
className: 'builder-item fw-border-box-sizing fw-col-xs-12',
|
||||
template: _.template( [
|
||||
'<div style="border: 1px solid #CCC; padding: 5px; color: #999; background: #fff;">',
|
||||
'<em class="fw-text-muted">Default View</em>',
|
||||
'<a href="#" onclick="return false;" class="dashicons fw-x"></a>',
|
||||
'<div class="builder-items"></div>',
|
||||
'</div>'
|
||||
].join( '' ) ),
|
||||
events: {
|
||||
'click a.dashicons.fw-x': 'defaultRemove'
|
||||
},
|
||||
initialize: function () {
|
||||
this.defaultInitialize();
|
||||
this.render();
|
||||
},
|
||||
/**
|
||||
* It is required to call this method in .initialize()
|
||||
*/
|
||||
defaultInitialize: function () {
|
||||
this.listenTo( this.model, 'change', this.render );
|
||||
},
|
||||
render: function () {
|
||||
this.defaultRender();
|
||||
},
|
||||
defaultRender: function ( templateData ) {
|
||||
var _items = this.model.get( '_items' );
|
||||
|
||||
/**
|
||||
* First .detach() elements
|
||||
* to prevent them to be removed (reset) on .html('...') replace
|
||||
*/
|
||||
_items.view.$el.detach();
|
||||
|
||||
this.$el.html(
|
||||
this.template(
|
||||
templateData || {}
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Sometimes sub items sortable view is not initialized or (destroyed if was initialized)
|
||||
* Tell it to render and maybe it will fix itself
|
||||
*/
|
||||
if ( ! _items.view.$el.hasClass( 'ui-sortable' ) ) {
|
||||
_items.view.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* replace <div class="builder-items"> with builder.classes.ItemsView.$el
|
||||
*/
|
||||
this.$el.find( '.builder-items:first' ).replaceWith(
|
||||
_items.view.$el
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
defaultRemove: function () {
|
||||
this.remove();
|
||||
|
||||
this.model.collection.remove( this.model );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
this.rootItems = new this.classes.Items;
|
||||
|
||||
/**
|
||||
* Something happened in WP 4.5 (or backbone.relational compatibility with latest backbone)
|
||||
* and items restored from input doesn't have the .collection property
|
||||
* and it's impossible to remove them from builder (console errors).
|
||||
* So loop recursive and fix item.collection
|
||||
*/
|
||||
{
|
||||
function _fixItemsCollections( collection, c ) {
|
||||
if ( typeof collection.cid != 'undefined' ) {
|
||||
// it's a model, the second param is the collection
|
||||
collection = c;
|
||||
}
|
||||
|
||||
collection.each( function ( item ) {
|
||||
item.collection = collection;
|
||||
|
||||
item.collection.off( null, _fixItemsCollections );
|
||||
item.collection.on( 'reset add', _fixItemsCollections );
|
||||
|
||||
/**
|
||||
* Sometimes item.get('_items') is empty at this point, wait a few milliseconds
|
||||
* Bad solution, I home BackboneRelation will be fixed and this code will be removed
|
||||
*/
|
||||
setTimeout( _.bind( function () {
|
||||
_fixItemsCollections( this.get( '_items' ) );
|
||||
}, item ), 0 );
|
||||
} );
|
||||
}
|
||||
|
||||
this.rootItems.on( 'reset add', _fixItemsCollections );
|
||||
}
|
||||
|
||||
// prepare this.$input
|
||||
{
|
||||
if ( typeof options.$input == 'undefined' ) {
|
||||
console.warn( '$input not specified. Items will no be saved' );
|
||||
|
||||
this.$input = $( '<input type="hidden">' );
|
||||
} else {
|
||||
this.$input = options.$input;
|
||||
}
|
||||
|
||||
fwEvents.trigger( 'fw-builder:' + this.get( 'type' ) + ':register-items', this );
|
||||
/**
|
||||
* @since 1.2.11
|
||||
*/
|
||||
fwEvents.trigger( 'fw-builder:' + this.get( 'type' ) + ':after-register-items', this );
|
||||
|
||||
// load saved items from input
|
||||
{
|
||||
try {
|
||||
this.rootItems.reset( JSON.parse( this.$input.val() || '[]' ) );
|
||||
|
||||
fwEvents.trigger( 'fw-builder:' + this.get( 'type' ) + ':items-loaded', this );
|
||||
} catch ( e ) {
|
||||
console.error( 'Failed to recover items from input', e );
|
||||
}
|
||||
}
|
||||
|
||||
// listen to items changes and update input
|
||||
(
|
||||
function () {
|
||||
function saveBuilderValueToInput() {
|
||||
builder.$input.val( JSON.stringify( builder.rootItems ) );
|
||||
builder.$input.trigger( 'fw-builder:input:change' );
|
||||
builder.$input.trigger( 'change' );
|
||||
}
|
||||
|
||||
/**
|
||||
* use timeout to not load browser/cpu when there are many changes at once (for e.g. on .reset())
|
||||
*/
|
||||
var saveTimeout = 0;
|
||||
|
||||
builder.listenTo( builder.rootItems, 'builder:change', function () {
|
||||
clearTimeout( saveTimeout );
|
||||
|
||||
saveTimeout = setTimeout( function () {
|
||||
saveTimeout = 0;
|
||||
|
||||
saveBuilderValueToInput();
|
||||
}, 100 );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Save value to input if there is a pending timeout on form submit
|
||||
*/
|
||||
builder.$input.closest( 'form' ).on( 'submit', function () {
|
||||
if ( saveTimeout ) {
|
||||
clearTimeout( saveTimeout );
|
||||
saveTimeout = 0;
|
||||
|
||||
saveBuilderValueToInput();
|
||||
}
|
||||
} );
|
||||
}
|
||||
)();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
fwExtBuilderInitialize.init( Builder );
|
||||
} );
|
||||
@@ -0,0 +1,131 @@
|
||||
(function ($, fwe, _, localized) {
|
||||
fwe.on('fw:option-type:builder:init', function (data) {
|
||||
if (!data.$elements.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$('#post_ID').length) {
|
||||
/**
|
||||
* Don't enable fullscreen if not on post edit page
|
||||
* Because this script requires the Publish and Preview post buttons
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
var elements = {
|
||||
$saveButton: $('#publish'),
|
||||
$previewButton: $('#post-preview')
|
||||
};
|
||||
|
||||
var utils = {
|
||||
toogleFullscreen: function ($builder) {
|
||||
if ($builder.hasClass('builder-fullscreen')) {
|
||||
utils.fullscreenOff.call($builder);
|
||||
utils.unsetStorageItem();
|
||||
} else {
|
||||
utils.fullscreenOn.call($builder);
|
||||
}
|
||||
},
|
||||
getFullscreenHeight: function () {
|
||||
var $diffHeight = parseInt($('.builder-items-types').height() + 80);
|
||||
return parseInt($('body').height() - $diffHeight);
|
||||
},
|
||||
selectBackdrop: function ($builder) {
|
||||
return $builder.next('.fw-option-type-builder-fullscreen-backdrop');
|
||||
},
|
||||
fullscreenOn: function () {
|
||||
var $builder = $(this);
|
||||
|
||||
utils.selectBackdrop($builder).removeClass('fw-hidden');
|
||||
$builder.addClass('builder-fullscreen');
|
||||
$(document.body).css('overflow-y', 'hidden'); // remove body scroll
|
||||
|
||||
$builder.find('> .builder-items-types .fullscreen-btn .text').text(localized.l10n.exit_fullscreen);
|
||||
$builder.find('> .builder-items-types .fullscreen-btn .icon').removeClass('icon-fullscreen-on').addClass('icon-fullscreen-off');
|
||||
$builder.find('> .builder-root-items')
|
||||
.css({'max-height': utils.getFullscreenHeight() + 'px'})
|
||||
.on('scroll.builder-fullscreen', function(){
|
||||
$builder.find('> .builder-items-types').css(
|
||||
'border-bottom-color',
|
||||
$(this).scrollTop() ? '#eee' : ''
|
||||
);
|
||||
});
|
||||
},
|
||||
fullscreenOff: function () {
|
||||
var $builder = $(this);
|
||||
|
||||
utils.selectBackdrop($builder).addClass('fw-hidden');
|
||||
$builder.removeClass('builder-fullscreen');
|
||||
$(document.body).css('overflow-y', '');
|
||||
|
||||
$builder.find('> .builder-items-types .fullscreen-btn .text').text(localized.l10n.fullscreen);
|
||||
$builder.find('> .builder-items-types .fullscreen-btn .icon').removeClass('icon-fullscreen-off').addClass('icon-fullscreen-on');
|
||||
$builder.find('> .builder-root-items')
|
||||
.css({'max-height': ''})
|
||||
.off('.builder-fullscreen');
|
||||
$builder.find('> .builder-items-types').css('border-bottom-color', '');
|
||||
},
|
||||
getPostId: function () {
|
||||
return $('#post_ID').val();
|
||||
},
|
||||
setStorageItem: function () {
|
||||
return $.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'fw_builder_fullscreen_set_storage_item',
|
||||
'post_id': utils.getPostId()
|
||||
}
|
||||
});
|
||||
},
|
||||
unsetStorageItem: function () {
|
||||
return $.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'fw_builder_fullscreen_unset_storage_item',
|
||||
'post_id': utils.getPostId()
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
data.$elements.each(function(){
|
||||
var $builder = $(this);
|
||||
|
||||
$builder.find('.fw-options-tabs-list ul').before(
|
||||
'<div class="fullscreen-btn">'+
|
||||
' <div class="icon icon-fullscreen-on"></div>'+
|
||||
' <div class="text">'+ localized.l10n.fullscreen +'</div>'+
|
||||
'</div>'
|
||||
);
|
||||
|
||||
$builder.find('> .builder-items-types .fullscreen-btn').on('click', function(e){
|
||||
e.preventDefault();
|
||||
utils.toogleFullscreen($builder);
|
||||
});
|
||||
|
||||
utils.selectBackdrop($builder)
|
||||
.on('click', '.preview', function (e) {
|
||||
e.preventDefault();
|
||||
utils.setStorageItem();
|
||||
elements.$previewButton.trigger('click');
|
||||
})
|
||||
.one('click', '.button-primary', function (e) {
|
||||
e.preventDefault();
|
||||
utils.selectBackdrop($builder).removeClass('fw-hidden');
|
||||
utils.setStorageItem().done(function () {
|
||||
elements.$saveButton.focus().trigger('click');
|
||||
});
|
||||
});
|
||||
|
||||
if ($builder.hasClass('builder-fullscreen')) {
|
||||
$builder.removeClass('builder-fullscreen');
|
||||
utils.toogleFullscreen($builder);
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery, fwEvents, _, _fw_option_type_builder_fullscreen);
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
var FwBuilderComponents = {
|
||||
Item: {},
|
||||
ItemView: {},
|
||||
Items: {},
|
||||
ItemsView: {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Change item width
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* // in ItemView.initialize()
|
||||
*
|
||||
* this.widthChangerView = new FwBuilderComponents.ItemView.WidthChanger({
|
||||
* model: this.model,
|
||||
* view: this,
|
||||
* widths: [
|
||||
* {
|
||||
* title: '1/12',
|
||||
* id: '1_12',
|
||||
* backend_class: 'fw-col-sm-1',
|
||||
* frontend_class: 'col-sm-1'
|
||||
* },
|
||||
* ...
|
||||
* {
|
||||
* title: '12/12',
|
||||
* id: '12_12',
|
||||
* backend_class: 'fw-col-sm-12',
|
||||
* frontend_class: 'col-sm-12'
|
||||
* }
|
||||
* ],
|
||||
* modelAttribute: 'width',
|
||||
* });
|
||||
*
|
||||
* // in ItemView.render()
|
||||
*
|
||||
* this.$('.some-class').append( this.widthChangerView.$el );
|
||||
*
|
||||
* this.widthChangerView.delegateEvents(); // rebind events after element "remove" happened
|
||||
*/
|
||||
FwBuilderComponents.ItemView.WidthChanger = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'fw-builder-item-width-changer',
|
||||
template: _.template(
|
||||
'<a href="#" class="decrease-width dashicons '+ (
|
||||
jQuery(document.body).hasClass('rtl') ? 'dashicons-arrow-right-alt2' : 'dashicons-arrow-left-alt2'
|
||||
) +'"'+
|
||||
/**//**/' onclick="return false;"></a>'+
|
||||
' <span class="current-width fw-wp-link-color"><%- title %></span> '+
|
||||
'<a href="#" class="increase-width dashicons '+ (
|
||||
jQuery(document.body).hasClass('rtl') ? 'dashicons-arrow-left-alt2' : 'dashicons-arrow-right-alt2'
|
||||
) +'"'+
|
||||
/**//**/' onclick="return false;"></a>'
|
||||
),
|
||||
events: {
|
||||
'click .decrease-width': 'decreaseWidth',
|
||||
'click .increase-width': 'increaseWidth'
|
||||
},
|
||||
widths: _fw_option_type_builder_helpers['item_widths'],
|
||||
/**
|
||||
* The attribute name that will be changed in item on width changes
|
||||
* this.model.set(this.modelAttribute, this.widths[N].id)
|
||||
*/
|
||||
modelAttribute: 'width',
|
||||
initialize: function(options) {
|
||||
_.extend(this, _.pick(options,
|
||||
'view',
|
||||
'widths',
|
||||
'modelAttribute'
|
||||
));
|
||||
|
||||
// set special properties for first and last width
|
||||
{
|
||||
this.widths[0].first = true;
|
||||
this.widths[ this.widths.length - 1 ].last = true;
|
||||
}
|
||||
|
||||
this.listenTo(this.model, 'change:' + this.modelAttribute, this.render);
|
||||
|
||||
this.render();
|
||||
},
|
||||
render: function() {
|
||||
this.updateWidth();
|
||||
|
||||
var widthId = this.model.get(this.modelAttribute);
|
||||
var width = _.findWhere(this.widths, {id: widthId});
|
||||
var widthTitle = '?';
|
||||
|
||||
if (width) {
|
||||
widthTitle = width.title;
|
||||
}
|
||||
|
||||
{
|
||||
this.$el.removeClass('is-first is-last');
|
||||
|
||||
if (!!width.first) {
|
||||
this.$el.addClass('is-first');
|
||||
}
|
||||
|
||||
if (!!width.last) {
|
||||
this.$el.addClass('is-last');
|
||||
}
|
||||
}
|
||||
|
||||
this.$el.html(
|
||||
this.template({
|
||||
title: widthTitle
|
||||
})
|
||||
);
|
||||
},
|
||||
decreaseWidth: function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
var widthId = this.model.get(this.modelAttribute);
|
||||
var widthsIds = _.pluck(this.widths, 'id');
|
||||
var currentWidthIndex = _.indexOf(widthsIds, widthId);
|
||||
|
||||
if (currentWidthIndex == -1) {
|
||||
// Current id does not exists (invalid) set first width
|
||||
widthId = widthsIds[0];
|
||||
} else if (currentWidthIndex == 0) {
|
||||
// Do nothing, this is the smallest width
|
||||
} else {
|
||||
// Set smaller width
|
||||
widthId = widthsIds[currentWidthIndex - 1];
|
||||
}
|
||||
|
||||
this.updateWidth(widthId);
|
||||
},
|
||||
increaseWidth: function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
var widthId = this.model.get(this.modelAttribute);
|
||||
var widthsIds = _.pluck(this.widths, 'id');
|
||||
var currentWidthIndex = _.indexOf(widthsIds, widthId);
|
||||
|
||||
if (currentWidthIndex == -1) {
|
||||
// Current id does not exists (invalid) set last width
|
||||
widthId = widthsIds[ widthsIds.length - 1 ];
|
||||
} else if (currentWidthIndex == widthsIds.length - 1) {
|
||||
// Do nothing, this is the biggest width
|
||||
} else {
|
||||
// Set bigger width
|
||||
widthId = widthsIds[currentWidthIndex + 1];
|
||||
}
|
||||
|
||||
this.updateWidth(widthId);
|
||||
},
|
||||
updateWidth: function(widthId) {
|
||||
if (typeof widthId == 'undefined') {
|
||||
widthId = this.model.get(this.modelAttribute);
|
||||
}
|
||||
|
||||
var widthsIds = _.pluck(this.widths, 'id');
|
||||
|
||||
// check if correct
|
||||
if (-1 == _.indexOf(widthsIds, widthId)) {
|
||||
// set default
|
||||
widthId = widthsIds[
|
||||
parseInt(widthsIds.length / 2) // middle width
|
||||
];
|
||||
}
|
||||
|
||||
if (widthId != this.model.get(this.modelAttribute)) {
|
||||
// set only when is different, to prevent trigger actions on those who listens to model 'change'
|
||||
this.model.set(this.modelAttribute, widthId);
|
||||
}
|
||||
|
||||
this.view.$el
|
||||
.removeClass(
|
||||
_.pluck(this.widths, 'backend_class').join(' ')
|
||||
)
|
||||
.addClass(
|
||||
_.findWhere(this.widths, {id: widthId})['backend_class']
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Usage:
|
||||
*
|
||||
* // in ItemView.initialize()
|
||||
*
|
||||
* this.inlineEditor = new FwBuilderComponents.ItemView.InlineTextEditor({
|
||||
* model: item,
|
||||
* editAttribute: 'model_attr_name' // also is available nested attribute property notation: 'a/b/c' will do {a: {b: {c: 'value'}}}
|
||||
* })
|
||||
*
|
||||
* // in ItemView.render()
|
||||
*
|
||||
* this.$('.some-class').append( this.inlineEditor.$el );
|
||||
*
|
||||
* this.inlineEditor.delegateEvents(); // rebind events after element "remove" happened
|
||||
*/
|
||||
FwBuilderComponents.ItemView.InlineTextEditor = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'fw-builder-item-inline-text-editor',
|
||||
template: _.template(
|
||||
'<input type="text" style="width: auto;" value="<%- value %>" onclick="return false;"> <button class="button" onclick="return false;"><%- save %></button>'
|
||||
),
|
||||
events: {
|
||||
'change input': 'update',
|
||||
'focusout input': 'hide'
|
||||
},
|
||||
render: function() {
|
||||
var localized = _fw_option_type_builder_helpers;
|
||||
|
||||
this.$el.html(
|
||||
this.template({
|
||||
value: this.editAttributeWitoutRoot
|
||||
? fw.opg(this.editAttributeWitoutRoot, this.model.get(this.editAttributeRoot))
|
||||
: this.model.get(this.editAttributeRoot),
|
||||
save: localized.l10n.save
|
||||
})
|
||||
);
|
||||
|
||||
this.$el.addClass('fw-hidden');
|
||||
},
|
||||
initialize: function(options) {
|
||||
_.extend(this, _.pick(options,
|
||||
'editAttribute'
|
||||
));
|
||||
|
||||
this.delimiter = '/';
|
||||
|
||||
/**
|
||||
* From 'a/b/c', extract: 'a' and 'b/c'
|
||||
*/
|
||||
{
|
||||
var editAttributeSplit = this.editAttribute.split(this.delimiter);
|
||||
|
||||
this.editAttributeRoot = editAttributeSplit.shift();
|
||||
this.editAttributeWitoutRoot = editAttributeSplit.join(this.delimiter);
|
||||
}
|
||||
|
||||
this.listenTo(this.model, 'change:'+ this.editAttributeRoot, this.render);
|
||||
|
||||
this.render();
|
||||
},
|
||||
update: function() {
|
||||
var val = this.$el.find('input').val();
|
||||
|
||||
var value = this.editAttributeWitoutRoot
|
||||
? fw.ops(this.editAttributeWitoutRoot, val,
|
||||
// clone to not change by reference, else values will be equal and model.set() will not trigger 'change'
|
||||
_.clone(this.model.get(this.editAttributeRoot)))
|
||||
: val;
|
||||
|
||||
this.model.set(this.editAttributeRoot, value);
|
||||
},
|
||||
hide: function() {
|
||||
this.$el.addClass('fw-hidden');
|
||||
|
||||
this.trigger('hide');
|
||||
},
|
||||
show: function() {
|
||||
this.$el.removeClass('fw-hidden');
|
||||
this.$el.find('input').focus();
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
FwBuilderComponents.ItemView.iconToHtml = function(icon) {
|
||||
if (/\.(png|jpg|jpeg|gif|svg|webp)$/.test(icon)) {
|
||||
// http://.../image.png
|
||||
return jQuery('<div>').append(
|
||||
jQuery('<img />')
|
||||
.attr('class', 'fw-ext-builder-icon')
|
||||
.attr('src', icon)
|
||||
).html();
|
||||
} else if (/^[a-zA-Z0-9\-_ ]+$/.test(icon)) {
|
||||
// 'font-icon font-icon-class'
|
||||
return jQuery('<div>').append(
|
||||
jQuery('<span></span>')
|
||||
.attr('class', 'fw-ext-builder-icon '+ jQuery.trim(icon))
|
||||
).html();
|
||||
} else {
|
||||
// can't detect. maybe it's raw html '<span ...'
|
||||
return icon;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
(function ($, fwe, _, localized) {
|
||||
|
||||
$(document.body).on('fw:option-type:builder:init', function (e, data) {
|
||||
var elements = {
|
||||
$builder: $(e.target),
|
||||
$undo: $('<a class="disabled undo" href="#">'+ localized.l10n.undo +'</a>'),
|
||||
$redo: $('<a class="disabled redo" href="#">'+ localized.l10n.redo +'</a>')
|
||||
},
|
||||
saveStateFlag = true,
|
||||
builder = data.builder,
|
||||
type = builder.get('type');
|
||||
|
||||
data.$headerTools
|
||||
.removeClass('fw-hidden')
|
||||
.append('<div class="history-container"></div>')
|
||||
.find('> .history-container')
|
||||
.append(elements.$undo)
|
||||
.append(elements.$redo);
|
||||
|
||||
var utils = {
|
||||
disableUndo: function () {
|
||||
elements.$undo.addClass('disabled');
|
||||
},
|
||||
enableUndo: function () {
|
||||
elements.$undo.removeClass('disabled');
|
||||
},
|
||||
disableRedo: function () {
|
||||
elements.$redo.addClass('disabled');
|
||||
},
|
||||
enableRedo: function () {
|
||||
elements.$redo.removeClass('disabled');
|
||||
}
|
||||
};
|
||||
|
||||
var history = {
|
||||
storage: [],
|
||||
activeIndex: 0,
|
||||
undo: function () {
|
||||
--this.activeIndex;
|
||||
|
||||
if ((this.activeIndex === 0)) {
|
||||
utils.disableUndo();
|
||||
}
|
||||
|
||||
return this.storage[this.activeIndex];
|
||||
},
|
||||
redo: function () {
|
||||
++this.activeIndex;
|
||||
if (this.activeIndex === this.storage.length - 1) {
|
||||
utils.disableRedo();
|
||||
}
|
||||
|
||||
return this.storage[this.activeIndex];
|
||||
},
|
||||
saveState: function (item) {
|
||||
this.storage = _.initial(this.storage, (this.storage.length-1) - this.activeIndex);
|
||||
this.storage.push(item);
|
||||
this.activeIndex = this.storage.length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
history.saveState(builder.$input.val());
|
||||
|
||||
builder.$input.on('fw-builder:input:change', function () {
|
||||
if (true === saveStateFlag) {
|
||||
history.saveState($(this).val());
|
||||
utils.enableUndo();
|
||||
utils.disableRedo();
|
||||
} else {
|
||||
saveStateFlag = true;
|
||||
}
|
||||
});
|
||||
|
||||
elements.$undo.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
utils.enableUndo();
|
||||
utils.enableRedo();
|
||||
|
||||
saveStateFlag = false;
|
||||
|
||||
var undoSnapshot = history.undo();
|
||||
|
||||
if (undoSnapshot !== undefined) {
|
||||
var parsedUndoSnaphot = JSON.parse(undoSnapshot);
|
||||
builder.rootItems.reset(parsedUndoSnaphot);
|
||||
|
||||
if ( parsedUndoSnaphot.length === 0 ) {
|
||||
builder.$input.val('[]');
|
||||
}
|
||||
} else {
|
||||
utils.disableUndo();
|
||||
}
|
||||
});
|
||||
|
||||
elements.$redo.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
utils.enableRedo();
|
||||
utils.enableUndo();
|
||||
|
||||
saveStateFlag = false;
|
||||
|
||||
var redoSnapshot = history.redo();
|
||||
|
||||
if (redoSnapshot !== undefined) {
|
||||
builder.rootItems.reset(JSON.parse(redoSnapshot));
|
||||
} else {
|
||||
utils.disableRedo();
|
||||
}
|
||||
});
|
||||
});
|
||||
})(jQuery, fwEvents, _, _fw_option_type_builder_history);
|
||||
@@ -0,0 +1,592 @@
|
||||
window.fwExtBuilderInitialize = (function ($) {
|
||||
var fixedHeaderHelpers = {
|
||||
increment: 0,
|
||||
$adminBar: $('#wpadminbar'),
|
||||
getAdminBarHeight: function() {
|
||||
var height = 0;
|
||||
|
||||
if (this.$adminBar.length && this.$adminBar.css('position') === 'fixed') {
|
||||
height = this.$adminBar.height();
|
||||
}
|
||||
|
||||
var gutenbergContainer = $( '#editor.block-editor__container' );
|
||||
|
||||
if ( gutenbergContainer.length > 0 ) {
|
||||
height += gutenbergContainer.find( '.edit-post-header' ).outerHeight() + gutenbergContainer.find( '.components-notice-list' ).height();
|
||||
}
|
||||
|
||||
return height;
|
||||
},
|
||||
fix: function($header, $builder, $scrollParent){
|
||||
var topSpace = this.getAdminBarHeight(),
|
||||
scrollParentHeight = $scrollParent.height(),
|
||||
scrollParentScrollTop = $( document ).scrollTop(),
|
||||
scrollParentOffset = $( document ).offset(),
|
||||
builderHeight = $builder.get(0).clientHeight,
|
||||
builderOffsetTop = $builder.offset().top,
|
||||
headerHeight = $header.get(0).clientHeight;
|
||||
|
||||
/**
|
||||
* Fixes inside options modal
|
||||
*/
|
||||
if (scrollParentOffset) {
|
||||
builderOffsetTop -= scrollParentOffset.top;
|
||||
|
||||
if (builderOffsetTop <= 0) {
|
||||
builderOffsetTop = topSpace;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
if (builderOffsetTop >= scrollParentScrollTop + topSpace) {
|
||||
// scroll top didn't reached the builder
|
||||
break;
|
||||
}
|
||||
|
||||
if (builderHeight < scrollParentHeight - topSpace) {
|
||||
// the builder fits inside the scroll element
|
||||
break;
|
||||
}
|
||||
|
||||
var bottomLimit = Math.floor(scrollParentHeight / 2);
|
||||
if (bottomLimit < headerHeight) {
|
||||
bottomLimit = headerHeight;
|
||||
}
|
||||
if (bottomLimit < 256) {
|
||||
bottomLimit = 256;
|
||||
}
|
||||
|
||||
if (builderHeight < headerHeight + bottomLimit) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (scrollParentHeight < headerHeight + bottomLimit) {
|
||||
// the scroll element must have space to display header and bottomLimit
|
||||
break;
|
||||
}
|
||||
|
||||
var headerTopShift = (scrollParentScrollTop + topSpace) - builderOffsetTop;
|
||||
|
||||
if (headerTopShift + headerHeight + bottomLimit > builderHeight) {
|
||||
// do not allow header to cover last items
|
||||
headerTopShift -= headerTopShift + headerHeight + bottomLimit - builderHeight;
|
||||
}
|
||||
|
||||
// set fixed header
|
||||
{
|
||||
if (!$builder.hasClass('fixed-header')) {
|
||||
$builder.addClass('fixed-header');
|
||||
}
|
||||
|
||||
$builder.css({
|
||||
'padding-top': headerHeight +'px' // set ghost space in builder, like the header is still there
|
||||
});
|
||||
$header.css({
|
||||
'top': headerTopShift +'px'
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
} while(false);
|
||||
|
||||
// remove fixed header
|
||||
{
|
||||
if ($builder.hasClass('fixed-header')) {
|
||||
$builder.removeClass('fixed-header');
|
||||
|
||||
$builder.css({
|
||||
'padding-top': ''
|
||||
});
|
||||
$header.css({
|
||||
'top': ''
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
init: init
|
||||
};
|
||||
|
||||
/**
|
||||
* Loop recursive through all items in given collection
|
||||
*/
|
||||
function forEachItemRecursive(collection, callback) {
|
||||
collection.each(function(item){
|
||||
callback(item);
|
||||
|
||||
forEachItemRecursive(item.get('_items'), callback);
|
||||
});
|
||||
}
|
||||
|
||||
function initDraggable ($this, builder, id) {
|
||||
fwEvents.trigger('fw:options:init:tabs', {$elements: $this.find('> .builder-items-types')});
|
||||
|
||||
var additionalSortableOptions = {}
|
||||
|
||||
fwEvents.trigger(
|
||||
'fw-builder:'+ builder.get('type') +':toolbar-sortable-additional-options',
|
||||
additionalSortableOptions
|
||||
)
|
||||
|
||||
$this.find('> .builder-items-types .builder-item-type').draggable(_.extend({
|
||||
connectToSortable: '#'+ id +' .builder-root-items .builder-items',
|
||||
helper: 'clone',
|
||||
distance: 10,
|
||||
placeholder: 'fw-builder-placeholder',
|
||||
zIndex: 99999,
|
||||
start: function(event, ui) {
|
||||
var movedType = ui.helper.attr('data-builder-item-type');
|
||||
|
||||
if (!movedType) {
|
||||
return;
|
||||
}
|
||||
|
||||
var MovedTypeClass = builder.getRegisteredItemClassByType(movedType);
|
||||
|
||||
if (!MovedTypeClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* add "allowed" classes to items vies where allowIncomingType(movedType) returned true
|
||||
* else add "denied" class
|
||||
*/
|
||||
{
|
||||
{
|
||||
if (MovedTypeClass.prototype.allowDestinationType(null)) {
|
||||
builder.rootItems.view.$el.addClass('fw-builder-item-allow-incoming-type');
|
||||
} else {
|
||||
builder.rootItems.view.$el.addClass('fw-builder-item-deny-incoming-type');
|
||||
}
|
||||
}
|
||||
|
||||
forEachItemRecursive(builder.rootItems, function(item){
|
||||
if (
|
||||
item.allowIncomingType(movedType)
|
||||
&&
|
||||
MovedTypeClass.prototype.allowDestinationType(item.get('type'))
|
||||
) {
|
||||
item.view.$el.addClass('fw-builder-item-allow-incoming-type');
|
||||
} else {
|
||||
item.view.$el.addClass('fw-builder-item-deny-incoming-type');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
stop: function() {
|
||||
// remove "allowed" and "denied" classes from all items
|
||||
{
|
||||
builder.rootItems.view.$el.removeClass(
|
||||
'fw-builder-item-allow-incoming-type fw-builder-item-deny-incoming-type'
|
||||
);
|
||||
|
||||
forEachItemRecursive(builder.rootItems, function(item){
|
||||
item.view.$el.removeClass(
|
||||
'fw-builder-item-allow-incoming-type fw-builder-item-deny-incoming-type'
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, additionalSortableOptions));
|
||||
|
||||
/**
|
||||
* Add item on thumbnail click
|
||||
*/
|
||||
$this.find('.builder-items-types').on('click', '.builder-item-type', function(){
|
||||
var $itemType = $(this);
|
||||
|
||||
var itemType = $itemType.attr('data-builder-item-type');
|
||||
|
||||
if (itemType) {
|
||||
var ItemTypeClass = builder.getRegisteredItemClassByType(itemType);
|
||||
|
||||
if (ItemTypeClass) {
|
||||
if (ItemTypeClass.prototype.allowDestinationType(null)) {
|
||||
builder.rootItems.add(
|
||||
new ItemTypeClass({}, {
|
||||
$thumb: $itemType
|
||||
})
|
||||
);
|
||||
|
||||
// animation
|
||||
{
|
||||
// stop previous animation
|
||||
{
|
||||
clearTimeout($itemType.attr('data-animation-timeout-id'));
|
||||
$itemType.removeClass('fw-builder-animation-item-type-add');
|
||||
}
|
||||
|
||||
$itemType.addClass('fw-builder-animation-item-type-add');
|
||||
|
||||
$itemType.attr('data-animation-timeout-id',
|
||||
setTimeout(function(){
|
||||
$itemType.removeClass('fw-builder-animation-item-type-add');
|
||||
}, 500)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.warn('Item type "'+ itemType +'" is not allowed as first level item');
|
||||
}
|
||||
} else {
|
||||
console.error('Unregistered item type: '+ itemType);
|
||||
}
|
||||
} else {
|
||||
console.error('Cannot extract item type from element', $itemType);
|
||||
}
|
||||
});
|
||||
|
||||
// scroll to the added element
|
||||
builder.rootItems.on('add', function(el){
|
||||
var $el = el.view.$el;
|
||||
|
||||
clearTimeout($this.attr('data-scroll-bottom-timeout'));
|
||||
|
||||
var timeout = setTimeout(function(){
|
||||
if (!$el.length) {
|
||||
return; // not in DOM already
|
||||
}
|
||||
|
||||
var $builderOption = $this,
|
||||
$scrollParent = $builderOption.scrollParent();
|
||||
|
||||
if ($scrollParent.get(0) === document || $scrollParent.get(0) === document.body) {
|
||||
$scrollParent = $(window);
|
||||
}
|
||||
|
||||
if ($builderOption.height() <= $scrollParent.height() + 300) {
|
||||
/**
|
||||
* Do not scroll if the builder can fit or is almost entirely visible
|
||||
* To prevent "jumping" https://github.com/ThemeFuse/Unyson/issues/815
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
var scrollParentHeight = $scrollParent.height()
|
||||
|
||||
$scrollParent.scrollTop(Math.min( // use min() to not allow scroll to far down hiding the fixed header
|
||||
$el.offset().top - scrollParentHeight / 2,
|
||||
$builderOption.offset().top + $builderOption.outerHeight() - scrollParentHeight
|
||||
));
|
||||
}, 100);
|
||||
|
||||
$this.attr('data-scroll-bottom-timeout', timeout);
|
||||
});
|
||||
}
|
||||
|
||||
function init (Builder) {
|
||||
fwEvents.on('fw:options:init', function (data) {
|
||||
var $options = data.$elements.find('.fw-option-type-builder:not(.initialized)');
|
||||
|
||||
if (! $options.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
initBuilderDelayed(Builder, data);
|
||||
});
|
||||
}
|
||||
|
||||
function initBuilderDelayed (Builder, data) {
|
||||
var $options = data.$elements.find('.fw-option-type-builder:not(.initialized)');
|
||||
|
||||
$options.closest('.fw-backend-option').addClass('fw-backend-option-type-builder');
|
||||
|
||||
var triggerInit = _.once(function () {
|
||||
fwEvents.trigger('fw:option-type:builder:init', {
|
||||
$elements: $options
|
||||
});
|
||||
});
|
||||
|
||||
$options.each(function () {
|
||||
var $el = $(this);
|
||||
var type = $el.attr('data-builder-option-type');
|
||||
|
||||
var promises = [];
|
||||
|
||||
fwEvents.trigger(
|
||||
'fw-builder:'+ type + ':collect-async-init-promises',
|
||||
{
|
||||
promises: promises
|
||||
}
|
||||
);
|
||||
|
||||
jQuery.when.apply(jQuery, promises).then(function () {
|
||||
initSingleBuilder($el);
|
||||
triggerInit();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
function initSingleBuilder ($el) {
|
||||
var $this = $el,
|
||||
hasDragAndDrop = $this.attr('data-drag-and-drop'),
|
||||
id = $this.attr('id'),
|
||||
type = $this.attr('data-builder-option-type');
|
||||
|
||||
/**
|
||||
* Create instance of Builder
|
||||
*/
|
||||
{
|
||||
var data = {
|
||||
type: type,
|
||||
$option: $this,
|
||||
$input: $this.find('> [data-fw-option-type="hidden"]:first > input'),
|
||||
$types: $this.find('.builder-items-types:first'),
|
||||
$rootItems: $this.find('.builder-root-items:first'),
|
||||
$headerTools: $('<div class="fw-builder-header-tools fw-clearfix fw-hidden"></div>')
|
||||
};
|
||||
|
||||
var eventData = $.extend({}, data, {
|
||||
/**
|
||||
* In event you can extend (customize/change) and replace this (property) class
|
||||
*/
|
||||
Builder: Builder
|
||||
});
|
||||
|
||||
fwEvents.trigger('fw-builder:'+ type +':before-create', eventData);
|
||||
|
||||
$this.find('> .builder-items-types').append(data.$headerTools);
|
||||
|
||||
var builder = new eventData.Builder(
|
||||
{
|
||||
type: data.type
|
||||
},
|
||||
{
|
||||
$input: data.$input
|
||||
}
|
||||
);
|
||||
|
||||
builder.rootItems.view.$el.appendTo(data.$rootItems);
|
||||
|
||||
new fwExtBuilderRootItemsTips(builder.rootItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init draggable thumbnails just if user wants it to be around
|
||||
*/
|
||||
if (hasDragAndDrop) {
|
||||
initDraggable($this, builder, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tips to thumbnails
|
||||
*/
|
||||
$this.find('.builder-items-types .builder-item-type [data-hover-tip]').each(function(){
|
||||
$(this).qtip({
|
||||
position: {
|
||||
at: 'top center',
|
||||
my: 'bottom center',
|
||||
viewport: $('body')
|
||||
},
|
||||
style: {
|
||||
classes: 'qtip-fw qtip-fw-builder',
|
||||
tip: {
|
||||
width: 12,
|
||||
height: 5
|
||||
}
|
||||
},
|
||||
content: {
|
||||
text: $(this).attr('data-hover-tip')
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Make header follow you when you scroll down
|
||||
*/
|
||||
if ($this.attr('data-fixed-header')) {
|
||||
var fixedHeaderEventsNamespace = '.fw-builder-fixed-header-'+ (++fixedHeaderHelpers.increment),
|
||||
$fixedHeader = $this.find('> .builder-items-types:first'),
|
||||
/**
|
||||
* In OptionsModal we must track the modal scroll not the window scroll
|
||||
*/
|
||||
$scrollParent;
|
||||
|
||||
$scrollParent = $this.scrollParent();
|
||||
if ($scrollParent.get(0) === document || $scrollParent.get(0) === document.body) {
|
||||
$scrollParent = $(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options modal fixed tabs are initialized after options init
|
||||
*/
|
||||
setTimeout(function(){
|
||||
$scrollParent = $this.scrollParent();
|
||||
if ($scrollParent.get(0) === document || $scrollParent.get(0) === document.body) {
|
||||
$scrollParent = $(window);
|
||||
}
|
||||
|
||||
$scrollParent
|
||||
.on('scroll'+ fixedHeaderEventsNamespace, function(){
|
||||
fixedHeaderHelpers.fix($fixedHeader, $this, $scrollParent);
|
||||
})
|
||||
.on('resize'+ fixedHeaderEventsNamespace, function(){
|
||||
fixedHeaderHelpers.fix($fixedHeader, $this, $scrollParent);
|
||||
});
|
||||
|
||||
fixedHeaderHelpers.fix($fixedHeader, $this, $scrollParent);
|
||||
}, 0);
|
||||
|
||||
/**
|
||||
* On thumbnails tab change, the new tab may contain more thumbnails that previous
|
||||
* thus having different height
|
||||
*/
|
||||
$fixedHeader.on('click'+ fixedHeaderEventsNamespace, '.fw-options-tabs-list a, .fullscreen-btn', function(){
|
||||
fixedHeaderHelpers.fix($fixedHeader, $this, $scrollParent);
|
||||
|
||||
/**
|
||||
* When you scroll down to the last items (to the limit when the fixed header stops and begins to go under page)
|
||||
* and you switch to a tab with a bigger height, there are some issues with positioning.
|
||||
* Calling this send time fixes it
|
||||
*/
|
||||
fixedHeaderHelpers.fix($fixedHeader, $this, $scrollParent);
|
||||
});
|
||||
|
||||
/**
|
||||
* Listen builder value/items change
|
||||
* For e.g. when you delete an element from the builder (or press undo/redo buttons)
|
||||
* its height is changed and the fixed header needs repositioning
|
||||
*/
|
||||
builder.$input.on('fw-builder:input:change'+ fixedHeaderEventsNamespace, function(){
|
||||
fixedHeaderHelpers.fix($fixedHeader, $this, $scrollParent);
|
||||
});
|
||||
|
||||
/**
|
||||
* Remove events from external elements
|
||||
* In case the builder is created and remove dynamically multiple times, for e.g. inside fw.OptionsModal
|
||||
*/
|
||||
$this.on('remove', function(){
|
||||
$scrollParent.off(fixedHeaderEventsNamespace);
|
||||
});
|
||||
}
|
||||
|
||||
if ($this.attr('data-compression') && window.JSZip) {
|
||||
var compress = {
|
||||
eventsNamespace: '.fw-builder-compress',
|
||||
isBusy: false,
|
||||
listenFormSubmit: function () {
|
||||
$this.closest('form').on('submit'+ compress.eventsNamespace, function(e){
|
||||
var $form = $(this),
|
||||
$submitButton = $form.find('input[type="submit"]:focus');
|
||||
|
||||
if (!$submitButton.length && $form.find(':focus').is('#post-preview')) {
|
||||
// Do nothing on "Preview Changes" button press
|
||||
return;
|
||||
}
|
||||
|
||||
var builderValue = builder.$input.val();
|
||||
if (builderValue.length < 200000) {
|
||||
// compress only when builder has a lot of elements
|
||||
return;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if (compress.isBusy) {
|
||||
return console.log('Zipping...');
|
||||
} else {
|
||||
fw.loading.show();
|
||||
compress.isBusy = true;
|
||||
}
|
||||
|
||||
var zip = new JSZip();
|
||||
|
||||
zip.file('builder.json', builderValue);
|
||||
zip.generateAsync({type: 'base64', compression: 'DEFLATE'}).then(function(content) {
|
||||
builder.$input.val(content);
|
||||
|
||||
fw.loading.hide();
|
||||
$form.off('submit'+ compress.eventsNamespace);
|
||||
|
||||
$submitButton.length
|
||||
? $submitButton.focus().trigger('click')
|
||||
: $form.submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$this.one('fw:option-type:builder:init', function () {
|
||||
compress.listenFormSubmit();
|
||||
});
|
||||
}
|
||||
|
||||
$this.on('fw:option-type:builder:dump-json', function(e, data){
|
||||
if (typeof data != 'undefined' && typeof data.cid != 'undefined') {
|
||||
console.log('[Builder JSON Dump] Item '+ data.cid +'\n\n'+
|
||||
JSON.stringify(builder.findItemRecursive({cid: data.cid}))
|
||||
);
|
||||
} else {
|
||||
console.log('[Builder JSON Dump] Full\n\n'+
|
||||
JSON.stringify(builder.rootItems)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
$this.trigger('fw:option-type:builder:init', $.extend({}, eventData, {
|
||||
builder: builder
|
||||
}));
|
||||
}
|
||||
|
||||
// add special class for builders that has header tools div
|
||||
$options.find('> .builder-items-types .fw-builder-header-tools:not(.fw-hidden)')
|
||||
.closest('.fw-option-type-builder').addClass('has-header-tools')
|
||||
// Add "Save" post button if the builder is within edit post form
|
||||
.each(function(){
|
||||
var $postForm = $(this).closest('form#post');
|
||||
|
||||
if (!$postForm.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
var isLocalStorageAvailable = function(){
|
||||
var test = 'test';
|
||||
try {
|
||||
localStorage.setItem(test, test);
|
||||
localStorage.removeItem(test);
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
localStorageKey = 'fw-ext-builder-save-scroll-position',
|
||||
$savePostButton = $postForm.find('#publishing-action #publish'),
|
||||
$savePostBuilderButton = $(
|
||||
'<button'+
|
||||
' type="button"'+
|
||||
' class="button button-primary fw-pull-right fw-builder-header-post-save-button"'+
|
||||
' onclick="return false;">' +
|
||||
'</button>')
|
||||
.text($savePostButton.attr('value'))
|
||||
.on('click', function(){
|
||||
$(this).attr('disabled', 'disabled').off('click');
|
||||
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem(localStorageKey, $(window).scrollTop());
|
||||
}
|
||||
|
||||
$savePostButton.trigger('click');
|
||||
});
|
||||
|
||||
$(this).find('.fw-builder-header-tools:first')
|
||||
.prepend('<span class="pull-right"> </span>')
|
||||
.prepend($savePostBuilderButton);
|
||||
|
||||
if (isLocalStorageAvailable()) {
|
||||
var scrollTopOnLastSave = localStorage.getItem(localStorageKey);
|
||||
|
||||
if (scrollTopOnLastSave !== null) {
|
||||
localStorage.removeItem(localStorageKey);
|
||||
|
||||
// http://stackoverflow.com/a/16475234/1794248
|
||||
$('html, body').animate({scrollTop: scrollTopOnLastSave}, '100', 'swing');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$options.addClass('initialized');
|
||||
}
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Create qTips for elements with data-hover-tip="Tip Text" attribute
|
||||
*/
|
||||
window.fwExtBuilderRootItemsTips = (function(rootItems){
|
||||
var $ = jQuery,
|
||||
/**
|
||||
* Store all created qTip instances APIs
|
||||
*/
|
||||
tipsAPIs = [],
|
||||
destroyTips = function(){
|
||||
_.each(tipsAPIs, function(api) { api.destroy(true); });
|
||||
|
||||
tipsAPIs = [];
|
||||
},
|
||||
makeTip = function($el){
|
||||
if ($el.attr('data-hasqtip')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$el.qtip({
|
||||
position: {
|
||||
at: 'top center',
|
||||
my: 'bottom center',
|
||||
viewport: rootItems.view.$el.parent()
|
||||
},
|
||||
style: {
|
||||
classes: 'qtip-fw qtip-fw-builder',
|
||||
tip: {
|
||||
width: 12,
|
||||
height: 5
|
||||
}
|
||||
},
|
||||
content: {
|
||||
text: $el.attr('data-hover-tip')
|
||||
}
|
||||
});
|
||||
|
||||
tipsAPIs.push($el.qtip('api'));
|
||||
|
||||
$el.qtip('api').show();
|
||||
};
|
||||
|
||||
rootItems.view.$el.on('mouseenter', '[data-hover-tip]', function(){
|
||||
makeTip($(this));
|
||||
});
|
||||
|
||||
rootItems.on('builder:change', function(){
|
||||
destroyTips();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @var string $id
|
||||
* @var array $option
|
||||
* @var array $data
|
||||
* @var array $thumbnails
|
||||
*/
|
||||
|
||||
{
|
||||
$tabs_options = array();
|
||||
|
||||
foreach ($thumbnails as $thumbnails_tab_title => &$thumbnails_tab_thumbnails) {
|
||||
$tabs_options[ 'random-'. fw_unique_increment() ] = array(
|
||||
'type' => 'tab',
|
||||
'title' => $thumbnails_tab_title,
|
||||
'attr' => array(
|
||||
'class' => 'fw-option-type-builder-thumbnails-tab',
|
||||
),
|
||||
'options' => array(
|
||||
fw_rand_md5() => array(
|
||||
'type' => 'html',
|
||||
'label' => false,
|
||||
'desc' => false,
|
||||
'html' => implode("\n", $thumbnails_tab_thumbnails),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
$div_attr = $option['attr'];
|
||||
|
||||
unset(
|
||||
$div_attr['value'],
|
||||
$div_attr['name']
|
||||
);
|
||||
|
||||
$div_attr['class'] .= ' fw-option-type-builder-tabs-count-'. count($tabs_options);
|
||||
}
|
||||
?>
|
||||
<div <?php echo fw_attr_to_html($div_attr) ?>>
|
||||
<?php
|
||||
echo fw()->backend->option_type('hidden')->render(
|
||||
$id,
|
||||
array(),
|
||||
array(
|
||||
'value' => $data['value']['json'],
|
||||
'id_prefix' => $data['id_prefix'] .'input--',
|
||||
'name_prefix' => $data['name_prefix']
|
||||
)
|
||||
);
|
||||
?>
|
||||
<div class="builder-items-types fw-clearfix">
|
||||
<?php echo fw()->backend->render_options($tabs_options) ?>
|
||||
</div>
|
||||
<div class="builder-root-items"></div>
|
||||
|
||||
<?php do_action('fw_builder:' . $option['type'] . ':content_below_root_items'); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// do action once to add one backdrop for all builders in page
|
||||
if ($option['fullscreen']) {
|
||||
do_action('fw_builder_fullscreen_add_backdrop');
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
$manifest = array();
|
||||
|
||||
$manifest['name'] = __( 'Builder', 'fw' );
|
||||
$manifest['version'] = '1.2.12';
|
||||
$manifest['github_update'] = 'ThemeFuse/Unyson-Builder-Extension';
|
||||
$manifest['github_repo'] = 'https://github.com/ThemeFuse/Unyson-Builder-Extension';
|
||||
$manifest['uri'] = 'http://manual.unyson.io/en/latest/extension/builder/index.html';
|
||||
$manifest['author'] = 'ThemeFuse';
|
||||
$manifest['author_uri'] = 'http://themefuse.com/';
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
if (!is_admin()) {
|
||||
wp_register_style(
|
||||
'fw-ext-builder-frontend-grid',
|
||||
fw_ext('builder')->get_uri('/static/css/frontend-grid.css'),
|
||||
array(),
|
||||
fw_ext('builder')->manifest->get_version()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,818 @@
|
||||
/*
|
||||
How to overwrite this file http://manual.unyson.io/en/latest/extension/builder/index.html#changing-the-grid
|
||||
*/
|
||||
|
||||
|
||||
/* Utility classes
|
||||
-------------------------------------------------- */
|
||||
.clearfix:before,
|
||||
.clearfix:after,
|
||||
.fw-container:before,
|
||||
.fw-container:after,
|
||||
.fw-container-fluid:before,
|
||||
.fw-container-fluid:after,
|
||||
.fw-row:before,
|
||||
.fw-row:after,
|
||||
.dl-horizontal dd:before,
|
||||
.dl-horizontal dd:after {
|
||||
content: " ";
|
||||
display: table;
|
||||
}
|
||||
|
||||
.clearfix:after,
|
||||
.fw-container:after,
|
||||
.fw-container-fluid:after,
|
||||
.fw-row:after,
|
||||
.dl-horizontal dd:after {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.center-block {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.pull-right,
|
||||
body.rtl .pull-left {
|
||||
float: right !important;
|
||||
}
|
||||
|
||||
.pull-left,
|
||||
body.rtl .pull-right {
|
||||
float: left !important;
|
||||
}
|
||||
|
||||
.clear {
|
||||
clear: both;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.show {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.invisible {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.text-hide {
|
||||
font: 0/0 a;
|
||||
color: transparent;
|
||||
text-shadow: none;
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
|
||||
.affix {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
img,
|
||||
iframe,
|
||||
embed {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
img {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.map img,
|
||||
.fw-shortcode-map-wrapper img {
|
||||
max-width: none !important;
|
||||
}
|
||||
|
||||
/* Grid system */
|
||||
/* -------------------------------------------------- */
|
||||
.fw-main-row,
|
||||
.fw-main-row *,
|
||||
.fw-main-row *:before,
|
||||
.fw-main-row *:after {
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.fw-container {
|
||||
position: relative;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.fw-container {
|
||||
width: 750px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 992px) {
|
||||
.fw-container {
|
||||
width: 970px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 1200px) {
|
||||
.fw-container {
|
||||
width: 1170px;
|
||||
}
|
||||
}
|
||||
.fw-container-fluid {
|
||||
position: relative;
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
||||
.fw-row {
|
||||
margin-left: -15px;
|
||||
margin-right: -15px;
|
||||
}
|
||||
|
||||
.fw-row:before,
|
||||
.fw-row:after {
|
||||
content: " ";
|
||||
display: table;
|
||||
}
|
||||
|
||||
.fw-row:after {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.fw-col-xs-1,
|
||||
.fw-col-sm-1,
|
||||
.fw-col-md-1,
|
||||
.fw-col-lg-1,
|
||||
.fw-col-xs-2,
|
||||
.fw-col-sm-2,
|
||||
.fw-col-md-2,
|
||||
.fw-col-lg-2,
|
||||
.fw-col-xs-3,
|
||||
.fw-col-sm-3,
|
||||
.fw-col-md-3,
|
||||
.fw-col-lg-3,
|
||||
.fw-col-xs-4,
|
||||
.fw-col-sm-4,
|
||||
.fw-col-md-4,
|
||||
.fw-col-lg-4,
|
||||
.fw-col-xs-5,
|
||||
.fw-col-sm-5,
|
||||
.fw-col-md-5,
|
||||
.fw-col-lg-5,
|
||||
.fw-col-xs-6,
|
||||
.fw-col-sm-6,
|
||||
.fw-col-md-6,
|
||||
.fw-col-lg-6,
|
||||
.fw-col-xs-7,
|
||||
.fw-col-sm-7,
|
||||
.fw-col-md-7,
|
||||
.fw-col-lg-7,
|
||||
.fw-col-xs-8,
|
||||
.fw-col-sm-8,
|
||||
.fw-col-md-8,
|
||||
.fw-col-lg-8,
|
||||
.fw-col-xs-9,
|
||||
.fw-col-sm-9,
|
||||
.fw-col-md-9,
|
||||
.fw-col-lg-9,
|
||||
.fw-col-xs-10,
|
||||
.fw-col-sm-10,
|
||||
.fw-col-md-10,
|
||||
.fw-col-lg-10,
|
||||
.fw-col-xs-11,
|
||||
.fw-col-sm-11,
|
||||
.fw-col-md-11,
|
||||
.fw-col-lg-11,
|
||||
.fw-col-xs-12,
|
||||
.fw-col-sm-12,
|
||||
.fw-col-md-12,
|
||||
.fw-col-lg-12,
|
||||
.fw-col-xs-15,
|
||||
.fw-col-sm-15,
|
||||
.fw-col-md-15,
|
||||
.fw-col-lg-15 {
|
||||
position: relative;
|
||||
min-height: 1px;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.fw-col-sm-1,
|
||||
.fw-col-sm-2,
|
||||
.fw-col-sm-3,
|
||||
.fw-col-sm-4,
|
||||
.fw-col-sm-5,
|
||||
.fw-col-sm-6,
|
||||
.fw-col-sm-7,
|
||||
.fw-col-sm-8,
|
||||
.fw-col-sm-9,
|
||||
.fw-col-sm-10,
|
||||
.fw-col-sm-11,
|
||||
.fw-col-sm-12,
|
||||
.fw-col-sm-15 {
|
||||
float: left;
|
||||
}
|
||||
|
||||
body.rtl .fw-col-sm-1,
|
||||
body.rtl .fw-col-sm-2,
|
||||
body.rtl .fw-col-sm-3,
|
||||
body.rtl .fw-col-sm-4,
|
||||
body.rtl .fw-col-sm-5,
|
||||
body.rtl .fw-col-sm-6,
|
||||
body.rtl .fw-col-sm-7,
|
||||
body.rtl .fw-col-sm-8,
|
||||
body.rtl .fw-col-sm-9,
|
||||
body.rtl .fw-col-sm-10,
|
||||
body.rtl .fw-col-sm-11,
|
||||
body.rtl .fw-col-sm-12,
|
||||
body.rtl .fw-col-sm-15 {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.fw-col-sm-15 {
|
||||
width: 20%;
|
||||
}
|
||||
.fw-col-sm-12 {
|
||||
width: 100%;
|
||||
}
|
||||
.fw-col-sm-11 {
|
||||
width: 91.66666667%;
|
||||
}
|
||||
.fw-col-sm-10 {
|
||||
width: 83.33333333%;
|
||||
}
|
||||
.fw-col-sm-9 {
|
||||
width: 75%;
|
||||
}
|
||||
.fw-col-sm-8 {
|
||||
width: 66.66666667%;
|
||||
}
|
||||
.fw-col-sm-7 {
|
||||
width: 58.33333333%;
|
||||
}
|
||||
.fw-col-sm-6 {
|
||||
width: 50%;
|
||||
}
|
||||
.fw-col-sm-5 {
|
||||
width: 41.66666667%;
|
||||
}
|
||||
.fw-col-sm-4 {
|
||||
width: 33.33333333%;
|
||||
}
|
||||
.fw-col-sm-3 {
|
||||
width: 25%;
|
||||
}
|
||||
.fw-col-sm-2 {
|
||||
width: 16.66666667%;
|
||||
}
|
||||
.fw-col-sm-1 {
|
||||
width: 8.33333333%;
|
||||
}
|
||||
|
||||
.fw-col-sm-pull-15 {
|
||||
right: 20%;
|
||||
}
|
||||
.fw-col-sm-pull-12 {
|
||||
right: 100%;
|
||||
}
|
||||
.fw-col-sm-pull-11 {
|
||||
right: 91.66666667%;
|
||||
}
|
||||
.fw-col-sm-pull-10 {
|
||||
right: 83.33333333%;
|
||||
}
|
||||
.fw-col-sm-pull-9 {
|
||||
right: 75%;
|
||||
}
|
||||
.fw-col-sm-pull-8 {
|
||||
right: 66.66666667%;
|
||||
}
|
||||
.fw-col-sm-pull-7 {
|
||||
right: 58.33333333%;
|
||||
}
|
||||
.fw-col-sm-pull-6 {
|
||||
right: 50%;
|
||||
}
|
||||
.fw-col-sm-pull-5 {
|
||||
right: 41.66666667%;
|
||||
}
|
||||
.fw-col-sm-pull-4 {
|
||||
right: 33.33333333%;
|
||||
}
|
||||
.fw-col-sm-pull-3 {
|
||||
right: 25%;
|
||||
}
|
||||
.fw-col-sm-pull-2 {
|
||||
right: 16.66666667%;
|
||||
}
|
||||
.fw-col-sm-pull-1 {
|
||||
right: 8.33333333%;
|
||||
}
|
||||
.fw-col-sm-pull-0 {
|
||||
right: auto;
|
||||
}
|
||||
|
||||
.fw-col-sm-push-15 {
|
||||
left: 20%;
|
||||
}
|
||||
.fw-col-sm-push-12 {
|
||||
left: 100%;
|
||||
}
|
||||
.fw-col-sm-push-11 {
|
||||
left: 91.66666667%;
|
||||
}
|
||||
.fw-col-sm-push-10 {
|
||||
left: 83.33333333%;
|
||||
}
|
||||
.fw-col-sm-push-9 {
|
||||
left: 75%;
|
||||
}
|
||||
.fw-col-sm-push-8 {
|
||||
left: 66.66666667%;
|
||||
}
|
||||
.fw-col-sm-push-7 {
|
||||
left: 58.33333333%;
|
||||
}
|
||||
.fw-col-sm-push-6 {
|
||||
left: 50%;
|
||||
}
|
||||
.fw-col-sm-push-5 {
|
||||
left: 41.66666667%;
|
||||
}
|
||||
.fw-col-sm-push-4 {
|
||||
left: 33.33333333%;
|
||||
}
|
||||
.fw-col-sm-push-3 {
|
||||
left: 25%;
|
||||
}
|
||||
.fw-col-sm-push-2 {
|
||||
left: 16.66666667%;
|
||||
}
|
||||
.fw-col-sm-push-1 {
|
||||
left: 8.33333333%;
|
||||
}
|
||||
.fw-col-sm-push-0 {
|
||||
left: auto;
|
||||
}
|
||||
|
||||
.fw-col-sm-offset-15 {
|
||||
margin-left: 20%;
|
||||
}
|
||||
.fw-col-sm-offset-12 {
|
||||
margin-left: 100%;
|
||||
}
|
||||
.fw-col-sm-offset-11 {
|
||||
margin-left: 91.66666667%;
|
||||
}
|
||||
.fw-col-sm-offset-10 {
|
||||
margin-left: 83.33333333%;
|
||||
}
|
||||
.fw-col-sm-offset-9 {
|
||||
margin-left: 75%;
|
||||
}
|
||||
.fw-col-sm-offset-8 {
|
||||
margin-left: 66.66666667%;
|
||||
}
|
||||
.fw-col-sm-offset-7 {
|
||||
margin-left: 58.33333333%;
|
||||
}
|
||||
.fw-col-sm-offset-6 {
|
||||
margin-left: 50%;
|
||||
}
|
||||
.fw-col-sm-offset-5 {
|
||||
margin-left: 41.66666667%;
|
||||
}
|
||||
.fw-col-sm-offset-4 {
|
||||
margin-left: 33.33333333%;
|
||||
}
|
||||
.fw-col-sm-offset-3 {
|
||||
margin-left: 25%;
|
||||
}
|
||||
.fw-col-sm-offset-2 {
|
||||
margin-left: 16.66666667%;
|
||||
}
|
||||
.fw-col-sm-offset-1 {
|
||||
margin-left: 8.33333333%;
|
||||
}
|
||||
.fw-col-sm-offset-0 {
|
||||
margin-left: 0%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.fw-col-md-1,
|
||||
.fw-col-md-2,
|
||||
.fw-col-md-3,
|
||||
.fw-col-md-4,
|
||||
.fw-col-md-5,
|
||||
.fw-col-md-6,
|
||||
.fw-col-md-7,
|
||||
.fw-col-md-8,
|
||||
.fw-col-md-9,
|
||||
.fw-col-md-10,
|
||||
.fw-col-md-11,
|
||||
.fw-col-md-12,
|
||||
.fw-col-md-15 {
|
||||
float: left;
|
||||
}
|
||||
|
||||
body.rtl .fw-col-md-1,
|
||||
body.rtl .fw-col-md-2,
|
||||
body.rtl .fw-col-md-3,
|
||||
body.rtl .fw-col-md-4,
|
||||
body.rtl .fw-col-md-5,
|
||||
body.rtl .fw-col-md-6,
|
||||
body.rtl .fw-col-md-7,
|
||||
body.rtl .fw-col-md-8,
|
||||
body.rtl .fw-col-md-9,
|
||||
body.rtl .fw-col-md-10,
|
||||
body.rtl .fw-col-md-11,
|
||||
body.rtl .fw-col-md-12,
|
||||
body.rtl .fw-col-md-15 {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.fw-col-md-15 {
|
||||
width: 20%;
|
||||
}
|
||||
.fw-col-md-12 {
|
||||
width: 100%;
|
||||
}
|
||||
.fw-col-md-11 {
|
||||
width: 91.66666667%;
|
||||
}
|
||||
.fw-col-md-10 {
|
||||
width: 83.33333333%;
|
||||
}
|
||||
.fw-col-md-9 {
|
||||
width: 75%;
|
||||
}
|
||||
.fw-col-md-8 {
|
||||
width: 66.66666667%;
|
||||
}
|
||||
.fw-col-md-7 {
|
||||
width: 58.33333333%;
|
||||
}
|
||||
.fw-col-md-6 {
|
||||
width: 50%;
|
||||
}
|
||||
.fw-col-md-5 {
|
||||
width: 41.66666667%;
|
||||
}
|
||||
.fw-col-md-4 {
|
||||
width: 33.33333333%;
|
||||
}
|
||||
.fw-col-md-3 {
|
||||
width: 25%;
|
||||
}
|
||||
.fw-col-md-2 {
|
||||
width: 16.66666667%;
|
||||
}
|
||||
.fw-col-md-1 {
|
||||
width: 8.33333333%;
|
||||
}
|
||||
|
||||
.fw-col-md-pull-15 {
|
||||
right: 20%;
|
||||
}
|
||||
.fw-col-md-pull-12 {
|
||||
right: 100%;
|
||||
}
|
||||
.fw-col-md-pull-11 {
|
||||
right: 91.66666667%;
|
||||
}
|
||||
.fw-col-md-pull-10 {
|
||||
right: 83.33333333%;
|
||||
}
|
||||
.fw-col-md-pull-9 {
|
||||
right: 75%;
|
||||
}
|
||||
.fw-col-md-pull-8 {
|
||||
right: 66.66666667%;
|
||||
}
|
||||
.fw-col-md-pull-7 {
|
||||
right: 58.33333333%;
|
||||
}
|
||||
.fw-col-md-pull-6 {
|
||||
right: 50%;
|
||||
}
|
||||
.fw-col-md-pull-5 {
|
||||
right: 41.66666667%;
|
||||
}
|
||||
.fw-col-md-pull-4 {
|
||||
right: 33.33333333%;
|
||||
}
|
||||
.fw-col-md-pull-3 {
|
||||
right: 25%;
|
||||
}
|
||||
.fw-col-md-pull-2 {
|
||||
right: 16.66666667%;
|
||||
}
|
||||
.fw-col-md-pull-1 {
|
||||
right: 8.33333333%;
|
||||
}
|
||||
.fw-col-md-pull-0 {
|
||||
right: auto;
|
||||
}
|
||||
|
||||
.fw-col-md-push-15 {
|
||||
left: 20%;
|
||||
}
|
||||
.fw-col-md-push-12 {
|
||||
left: 100%;
|
||||
}
|
||||
.fw-col-md-push-11 {
|
||||
left: 91.66666667%;
|
||||
}
|
||||
.fw-col-md-push-10 {
|
||||
left: 83.33333333%;
|
||||
}
|
||||
.fw-col-md-push-9 {
|
||||
left: 75%;
|
||||
}
|
||||
.fw-col-md-push-8 {
|
||||
left: 66.66666667%;
|
||||
}
|
||||
.fw-col-md-push-7 {
|
||||
left: 58.33333333%;
|
||||
}
|
||||
.fw-col-md-push-6 {
|
||||
left: 50%;
|
||||
}
|
||||
.fw-col-md-push-5 {
|
||||
left: 41.66666667%;
|
||||
}
|
||||
.fw-col-md-push-4 {
|
||||
left: 33.33333333%;
|
||||
}
|
||||
.fw-col-md-push-3 {
|
||||
left: 25%;
|
||||
}
|
||||
.fw-col-md-push-2 {
|
||||
left: 16.66666667%;
|
||||
}
|
||||
.fw-col-md-push-1 {
|
||||
left: 8.33333333%;
|
||||
}
|
||||
.fw-col-md-push-0 {
|
||||
left: auto;
|
||||
}
|
||||
|
||||
.fw-col-md-offset-15 {
|
||||
margin-left: 20%;
|
||||
}
|
||||
.fw-col-md-offset-12 {
|
||||
margin-left: 100%;
|
||||
}
|
||||
.fw-col-md-offset-11 {
|
||||
margin-left: 91.66666667%;
|
||||
}
|
||||
.fw-col-md-offset-10 {
|
||||
margin-left: 83.33333333%;
|
||||
}
|
||||
.fw-col-md-offset-9 {
|
||||
margin-left: 75%;
|
||||
}
|
||||
.fw-col-md-offset-8 {
|
||||
margin-left: 66.66666667%;
|
||||
}
|
||||
.fw-col-md-offset-7 {
|
||||
margin-left: 58.33333333%;
|
||||
}
|
||||
.fw-col-md-offset-6 {
|
||||
margin-left: 50%;
|
||||
}
|
||||
.fw-col-md-offset-5 {
|
||||
margin-left: 41.66666667%;
|
||||
}
|
||||
.fw-col-md-offset-4 {
|
||||
margin-left: 33.33333333%;
|
||||
}
|
||||
.fw-col-md-offset-3 {
|
||||
margin-left: 25%;
|
||||
}
|
||||
.fw-col-md-offset-2 {
|
||||
margin-left: 16.66666667%;
|
||||
}
|
||||
.fw-col-md-offset-1 {
|
||||
margin-left: 8.33333333%;
|
||||
}
|
||||
.fw-col-md-offset-0 {
|
||||
margin-left: 0%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
.fw-col-lg-1,
|
||||
.fw-col-lg-2,
|
||||
.fw-col-lg-3,
|
||||
.fw-col-lg-4,
|
||||
.fw-col-lg-5,
|
||||
.fw-col-lg-6,
|
||||
.fw-col-lg-7,
|
||||
.fw-col-lg-8,
|
||||
.fw-col-lg-9,
|
||||
.fw-col-lg-10,
|
||||
.fw-col-lg-11,
|
||||
.fw-col-lg-12,
|
||||
.fw-col-lg-15 {
|
||||
float: left;
|
||||
}
|
||||
|
||||
body.rtl .fw-col-lg-1,
|
||||
body.rtl .fw-col-lg-2,
|
||||
body.rtl .fw-col-lg-3,
|
||||
body.rtl .fw-col-lg-4,
|
||||
body.rtl .fw-col-lg-5,
|
||||
body.rtl .fw-col-lg-6,
|
||||
body.rtl .fw-col-lg-7,
|
||||
body.rtl .fw-col-lg-8,
|
||||
body.rtl .fw-col-lg-9,
|
||||
body.rtl .fw-col-lg-10,
|
||||
body.rtl .fw-col-lg-11,
|
||||
body.rtl .fw-col-lg-12,
|
||||
body.rtl .fw-col-lg-15 {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.fw-col-lg-15 {
|
||||
width: 20%;
|
||||
}
|
||||
.fw-col-lg-12 {
|
||||
width: 100%;
|
||||
}
|
||||
.fw-col-lg-11 {
|
||||
width: 91.66666667%;
|
||||
}
|
||||
.fw-col-lg-10 {
|
||||
width: 83.33333333%;
|
||||
}
|
||||
.fw-col-lg-9 {
|
||||
width: 75%;
|
||||
}
|
||||
.fw-col-lg-8 {
|
||||
width: 66.66666667%;
|
||||
}
|
||||
.fw-col-lg-7 {
|
||||
width: 58.33333333%;
|
||||
}
|
||||
.fw-col-lg-6 {
|
||||
width: 50%;
|
||||
}
|
||||
.fw-col-lg-5 {
|
||||
width: 41.66666667%;
|
||||
}
|
||||
.fw-col-lg-4 {
|
||||
width: 33.33333333%;
|
||||
}
|
||||
.fw-col-lg-3 {
|
||||
width: 25%;
|
||||
}
|
||||
.fw-col-lg-2 {
|
||||
width: 16.66666667%;
|
||||
}
|
||||
.fw-col-lg-1 {
|
||||
width: 8.33333333%;
|
||||
}
|
||||
|
||||
.fw-col-lg-pull-15 {
|
||||
right: 20%;
|
||||
}
|
||||
.fw-col-lg-pull-12 {
|
||||
right: 100%;
|
||||
}
|
||||
.fw-col-lg-pull-11 {
|
||||
right: 91.66666667%;
|
||||
}
|
||||
.fw-col-lg-pull-10 {
|
||||
right: 83.33333333%;
|
||||
}
|
||||
.fw-col-lg-pull-9 {
|
||||
right: 75%;
|
||||
}
|
||||
.fw-col-lg-pull-8 {
|
||||
right: 66.66666667%;
|
||||
}
|
||||
.fw-col-lg-pull-7 {
|
||||
right: 58.33333333%;
|
||||
}
|
||||
.fw-col-lg-pull-6 {
|
||||
right: 50%;
|
||||
}
|
||||
.fw-col-lg-pull-5 {
|
||||
right: 41.66666667%;
|
||||
}
|
||||
.fw-col-lg-pull-4 {
|
||||
right: 33.33333333%;
|
||||
}
|
||||
.fw-col-lg-pull-3 {
|
||||
right: 25%;
|
||||
}
|
||||
.fw-col-lg-pull-2 {
|
||||
right: 16.66666667%;
|
||||
}
|
||||
.fw-col-lg-pull-1 {
|
||||
right: 8.33333333%;
|
||||
}
|
||||
.fw-col-lg-pull-0 {
|
||||
right: auto;
|
||||
}
|
||||
.fw-col-lg-push-15 {
|
||||
left: 20%;
|
||||
}
|
||||
.fw-col-lg-push-12 {
|
||||
left: 100%;
|
||||
}
|
||||
.fw-col-lg-push-11 {
|
||||
left: 91.66666667%;
|
||||
}
|
||||
.fw-col-lg-push-10 {
|
||||
left: 83.33333333%;
|
||||
}
|
||||
.fw-col-lg-push-9 {
|
||||
left: 75%;
|
||||
}
|
||||
.fw-col-lg-push-8 {
|
||||
left: 66.66666667%;
|
||||
}
|
||||
.fw-col-lg-push-7 {
|
||||
left: 58.33333333%;
|
||||
}
|
||||
.fw-col-lg-push-6 {
|
||||
left: 50%;
|
||||
}
|
||||
.fw-col-lg-push-5 {
|
||||
left: 41.66666667%;
|
||||
}
|
||||
.fw-col-lg-push-4 {
|
||||
left: 33.33333333%;
|
||||
}
|
||||
.fw-col-lg-push-3 {
|
||||
left: 25%;
|
||||
}
|
||||
.fw-col-lg-push-2 {
|
||||
left: 16.66666667%;
|
||||
}
|
||||
.fw-col-lg-push-1 {
|
||||
left: 8.33333333%;
|
||||
}
|
||||
.fw-col-lg-push-0 {
|
||||
left: auto;
|
||||
}
|
||||
.fw-col-lg-offset-15 {
|
||||
margin-left: 20%;
|
||||
}
|
||||
|
||||
.fw-col-lg-offset-12 {
|
||||
margin-left: 100%;
|
||||
}
|
||||
.fw-col-lg-offset-11 {
|
||||
margin-left: 91.66666667%;
|
||||
}
|
||||
.fw-col-lg-offset-10 {
|
||||
margin-left: 83.33333333%;
|
||||
}
|
||||
.fw-col-lg-offset-9 {
|
||||
margin-left: 75%;
|
||||
}
|
||||
.fw-col-lg-offset-8 {
|
||||
margin-left: 66.66666667%;
|
||||
}
|
||||
.fw-col-lg-offset-7 {
|
||||
margin-left: 58.33333333%;
|
||||
}
|
||||
.fw-col-lg-offset-6 {
|
||||
margin-left: 50%;
|
||||
}
|
||||
.fw-col-lg-offset-5 {
|
||||
margin-left: 41.66666667%;
|
||||
}
|
||||
.fw-col-lg-offset-4 {
|
||||
margin-left: 33.33333333%;
|
||||
}
|
||||
.fw-col-lg-offset-3 {
|
||||
margin-left: 25%;
|
||||
}
|
||||
.fw-col-lg-offset-2 {
|
||||
margin-left: 16.66666667%;
|
||||
}
|
||||
.fw-col-lg-offset-1 {
|
||||
margin-left: 8.33333333%;
|
||||
}
|
||||
.fw-col-lg-offset-0 {
|
||||
margin-left: 0%;
|
||||
}
|
||||
}
|
||||