diff --git a/README.md b/README.md index 8e819ca..86844cb 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,12 @@ Other languages: +orderПорядок сортировки в секции добавления блока. Этот параметр НЕ влияет на сортировку самих блоков! templates @@ -167,7 +169,9 @@ assets/templates/ + + diff --git a/assets/plugins/pagebuilder/config/2col_photo_text.php.sample b/assets/plugins/pagebuilder/config/2col_photo_text.php.sample new file mode 100644 index 0000000..332374e --- /dev/null +++ b/assets/plugins/pagebuilder/config/2col_photo_text.php.sample @@ -0,0 +1,53 @@ + 'Two columns: image and text', + +// 'show_in_templates' => [ 4 ], + +// 'show_in_docs' => [ 2 ], + +// 'hide_in_docs' => [ 5 ], + +// 'order' => 1, + + 'image' => 'assets/plugins/pagebuilder/images/2col-photo-text.jpg', + +// 'container' => 'default', + + 'templates' => [ + 'owner' => ' +
+
+
+ +
+ +
+
+ [+richtext+] +
+
+
+
+ ', + ], + + 'fields' => [ + 'image' => [ + 'caption' => 'Image', + 'type' => 'image', + ], + + 'richtext' => [ + 'caption' => 'Text', + 'type' => 'richtext', + 'default' => '', + 'theme' => 'mini', + 'options' => [ + 'height' => '200px', + ], + ], + ], + ]; + diff --git a/assets/plugins/pagebuilder/config/2col_text_photo.php.sample b/assets/plugins/pagebuilder/config/2col_text_photo.php.sample new file mode 100644 index 0000000..3c3bfbb --- /dev/null +++ b/assets/plugins/pagebuilder/config/2col_text_photo.php.sample @@ -0,0 +1,53 @@ + 'Two columns: text and image', + +// 'show_in_templates' => [ 4 ], + +// 'show_in_docs' => [ 2 ], + +// 'hide_in_docs' => [ 5 ], + +// 'order' => 1, + + 'image' => 'assets/plugins/pagebuilder/images/2col-text-photo.jpg', + +// 'container' => 'default', + + 'templates' => [ + 'owner' => ' +
+
+
+
+ [+richtext+] +
+
+ +
+ +
+
+
+ ', + ], + + 'fields' => [ + 'image' => [ + 'caption' => 'Image', + 'type' => 'image', + ], + + 'richtext' => [ + 'caption' => 'Text', + 'type' => 'richtext', + 'default' => '', + 'theme' => 'mini', + 'options' => [ + 'height' => '200px', + ], + ], + ], + ]; + diff --git a/assets/plugins/pagebuilder/config/all_fields.php.sample b/assets/plugins/pagebuilder/config/all_fields.php.sample index 2059964..119142d 100644 --- a/assets/plugins/pagebuilder/config/all_fields.php.sample +++ b/assets/plugins/pagebuilder/config/all_fields.php.sample @@ -9,6 +9,10 @@ // 'hide_in_docs' => [ 5 ], +// 'order' => 1, + +// 'container' => 'default', + 'templates' => [ 'owner' => '
Text:
[+text+]
diff --git a/assets/plugins/pagebuilder/config/container.samplecontainer.php.sample b/assets/plugins/pagebuilder/config/container.samplecontainer.php.sample new file mode 100644 index 0000000..fe7b5bd --- /dev/null +++ b/assets/plugins/pagebuilder/config/container.samplecontainer.php.sample @@ -0,0 +1,25 @@ + 'Page Builder Container', + +// 'show_in_templates' => [ 3 ], + +// 'show_in_docs' => [ 2 ], + +// 'hide_in_docs' => [ 10, 63 ], + +// 'addType' => 'images', + + 'placement' => 'content', + + 'templates' => [ + 'owner' => ' +
+ Container: + [+wrap+] +
+ ', + ], + ]; + diff --git a/assets/plugins/pagebuilder/config/groups.php.sample b/assets/plugins/pagebuilder/config/groups.php.sample index 7b3cfd2..a136f7b 100644 --- a/assets/plugins/pagebuilder/config/groups.php.sample +++ b/assets/plugins/pagebuilder/config/groups.php.sample @@ -9,6 +9,10 @@ // 'hide_in_docs' => [ 10, 63 ], +// 'order' => 2, + +// 'container' => ['samplecontainer', 'default'], + 'templates' => [ 'owner' => '
Text:
[+text+]
diff --git a/assets/plugins/pagebuilder/config/image-text.php.sample b/assets/plugins/pagebuilder/config/image-text.php.sample new file mode 100644 index 0000000..d81dc87 --- /dev/null +++ b/assets/plugins/pagebuilder/config/image-text.php.sample @@ -0,0 +1,47 @@ + 'Image with text', + +// 'show_in_templates' => [ 4 ], + +// 'show_in_docs' => [ 2 ], + +// 'hide_in_docs' => [ 5 ], + +// 'order' => 1, + + 'image' => 'assets/plugins/pagebuilder/images/image-title.jpg', + +// 'container' => 'default', + + 'templates' => [ + 'owner' => ' +
+ + +
+ [+richtext+] +
+
+ ', + ], + + 'fields' => [ + 'image' => [ + 'caption' => 'Image', + 'type' => 'image', + ], + + 'richtext' => [ + 'caption' => 'Text', + 'type' => 'richtext', + 'default' => '', + 'theme' => 'mini', + 'options' => [ + 'height' => '100px', + ], + ], + ], + ]; + diff --git a/assets/plugins/pagebuilder/config/image.php.sample b/assets/plugins/pagebuilder/config/image.php.sample new file mode 100644 index 0000000..03644c5 --- /dev/null +++ b/assets/plugins/pagebuilder/config/image.php.sample @@ -0,0 +1,33 @@ + 'Image', + +// 'show_in_templates' => [ 4 ], + +// 'show_in_docs' => [ 2 ], + +// 'hide_in_docs' => [ 5 ], + +// 'order' => 1, + + 'image' => 'assets/plugins/pagebuilder/images/image.jpg', + +// 'container' => 'default', + + 'templates' => [ + 'owner' => ' +
+ +
+ ', + ], + + 'fields' => [ + 'image' => [ + 'caption' => 'Image', + 'type' => 'image', + ], + ], + ]; + diff --git a/assets/plugins/pagebuilder/config/text.php.sample b/assets/plugins/pagebuilder/config/text.php.sample new file mode 100644 index 0000000..43aa3ac --- /dev/null +++ b/assets/plugins/pagebuilder/config/text.php.sample @@ -0,0 +1,40 @@ + 'Text', + +// 'show_in_templates' => [ 4 ], + +// 'show_in_docs' => [ 2 ], + +// 'hide_in_docs' => [ 5 ], + +// 'order' => 1, + + 'image' => 'assets/plugins/pagebuilder/images/text.jpg', + +// 'container' => 'default', + + 'templates' => [ + 'owner' => ' +
+
+ [+richtext+] +
+
+ ', + ], + + 'fields' => [ + 'richtext' => [ + 'caption' => 'Text', + 'type' => 'richtext', + 'default' => '', + 'theme' => 'mini', + 'options' => [ + 'height' => '300px', + ], + ], + ], + ]; + diff --git a/assets/plugins/pagebuilder/images/2col-photo-text.jpg b/assets/plugins/pagebuilder/images/2col-photo-text.jpg new file mode 100644 index 0000000..e3bde0e Binary files /dev/null and b/assets/plugins/pagebuilder/images/2col-photo-text.jpg differ diff --git a/assets/plugins/pagebuilder/images/2col-text-photo.jpg b/assets/plugins/pagebuilder/images/2col-text-photo.jpg new file mode 100644 index 0000000..752af0a Binary files /dev/null and b/assets/plugins/pagebuilder/images/2col-text-photo.jpg differ diff --git a/assets/plugins/pagebuilder/images/button.jpg b/assets/plugins/pagebuilder/images/button.jpg new file mode 100644 index 0000000..a0fe116 Binary files /dev/null and b/assets/plugins/pagebuilder/images/button.jpg differ diff --git a/assets/plugins/pagebuilder/images/code.jpg b/assets/plugins/pagebuilder/images/code.jpg new file mode 100644 index 0000000..5a8d2ec Binary files /dev/null and b/assets/plugins/pagebuilder/images/code.jpg differ diff --git a/assets/plugins/pagebuilder/images/devider.jpg b/assets/plugins/pagebuilder/images/devider.jpg new file mode 100644 index 0000000..f5266a5 Binary files /dev/null and b/assets/plugins/pagebuilder/images/devider.jpg differ diff --git a/assets/plugins/pagebuilder/images/gallery.jpg b/assets/plugins/pagebuilder/images/gallery.jpg new file mode 100644 index 0000000..8a57296 Binary files /dev/null and b/assets/plugins/pagebuilder/images/gallery.jpg differ diff --git a/assets/plugins/pagebuilder/images/image-title.jpg b/assets/plugins/pagebuilder/images/image-title.jpg new file mode 100644 index 0000000..162e8d2 Binary files /dev/null and b/assets/plugins/pagebuilder/images/image-title.jpg differ diff --git a/assets/plugins/pagebuilder/images/image.jpg b/assets/plugins/pagebuilder/images/image.jpg new file mode 100644 index 0000000..b2a7e34 Binary files /dev/null and b/assets/plugins/pagebuilder/images/image.jpg differ diff --git a/assets/plugins/pagebuilder/images/introtext.jpg b/assets/plugins/pagebuilder/images/introtext.jpg new file mode 100644 index 0000000..a12c5fe Binary files /dev/null and b/assets/plugins/pagebuilder/images/introtext.jpg differ diff --git a/assets/plugins/pagebuilder/images/socialmedia.jpg b/assets/plugins/pagebuilder/images/socialmedia.jpg new file mode 100644 index 0000000..a9e2f41 Binary files /dev/null and b/assets/plugins/pagebuilder/images/socialmedia.jpg differ diff --git a/assets/plugins/pagebuilder/images/text-photo.jpg b/assets/plugins/pagebuilder/images/text-photo.jpg new file mode 100644 index 0000000..bd1db7f Binary files /dev/null and b/assets/plugins/pagebuilder/images/text-photo.jpg differ diff --git a/assets/plugins/pagebuilder/images/text.jpg b/assets/plugins/pagebuilder/images/text.jpg new file mode 100644 index 0000000..7f7ca52 Binary files /dev/null and b/assets/plugins/pagebuilder/images/text.jpg differ diff --git a/assets/plugins/pagebuilder/images/video.jpg b/assets/plugins/pagebuilder/images/video.jpg new file mode 100644 index 0000000..4bf178d Binary files /dev/null and b/assets/plugins/pagebuilder/images/video.jpg differ diff --git a/assets/plugins/pagebuilder/js/interaction.js b/assets/plugins/pagebuilder/js/interaction.js index b0a7a18..a4483fd 100644 --- a/assets/plugins/pagebuilder/js/interaction.js +++ b/assets/plugins/pagebuilder/js/interaction.js @@ -1,114 +1,113 @@ - var initcontentblocks = function( opts ) { - return ( function( $ ) { - - var $container = $(opts.container); + var initcontentblocks = function(opts) { + return (function($) { var ContentBlock = { - initialize: function( blocks ) { - $(blocks).each( function() { + initialize: function(blocks) { + $(blocks).each(function() { var $wrap = $(this), $block = $wrap.children('.block-inner'), - confName = $wrap.attr( 'data-config' ), + confName = $wrap.attr('data-config'), conf = opts.config[ confName ], $list = $block.children('.fields-list'); // set block type - $block.children('.change-type').children('select').val( confName ); + $block.children('.change-type').children('select').val(confName); // add button for mass upload - $block.find('.sortable-list').each( function() { - if ( $(this).children('.sortable-item').eq(0).children('.fields-list').children('.type-image').length ) { - $(this).prev('.group-title').append( '' ); + $block.find('.sortable-list').each(function() { + if ($(this).children('.sortable-item').eq(0).children('.fields-list').children('.type-image').length) { + $(this).prev('.group-title').append(''); } - } ); + }); // add controls handlers - ( function( $wrap ) { + (function($wrap) { $block.children('.controls') - .on( 'click', '.moveup, .movedown', function( e ) { + .on('click', '.moveup, .movedown', function(e) { e.preventDefault(); - ContentBlock.move( $wrap, $(this).hasClass( 'moveup' ) ? 'up' : 'down' ); - } ) + ContentBlock.move($wrap, $(this).hasClass('moveup') ? 'up' : 'down'); + }) - .on( 'click', '.insert', function( e ) { + .on('click', '.insert', function(e) { e.preventDefault(); - ContentBlock.append( $wrap ); - } ) + var config = $(this).closest('.block').attr('data-config'); + ContentBlock.append(config, $wrap); + }) - .on( 'click', '.remove', function( e ) { + .on('click', '.remove', function(e) { e.preventDefault(); - $wrap.slideUp( 200, function() { + $wrap.slideUp(200, function() { $wrap.remove(); - } ); - } ); - } )( $wrap ); + }); + }); + })($wrap); - $block.on( 'click', '.open-browser', function( e ) { + $block.on('click', '.open-browser', function(e) { e.preventDefault(); - ContentBlock.openBrowser( $(this).next('input'), $(this).parent().hasClass( 'type-image' ) ? 'images' : 'files' ); - } ); + ContentBlock.openBrowser($(this).next('input'), $(this).parent().hasClass('type-image') ? 'images' : 'files'); + }); - $block.on( 'click', '.sortable-item > .controls > .insert', function( e ) { + $block.on('click', '.sortable-item > .controls > .insert', function(e) { e.preventDefault(); e.stopPropagation(); - ContentBlock.insertItem( $(this).closest('.sortable-item') ); - } ); + ContentBlock.insertItem($(this).closest('.sortable-item')); + }); - $block.on( 'click', '.sortable-item > .controls > .remove', function( e ) { + $block.on('click', '.sortable-item > .controls > .remove', function(e) { e.preventDefault(); e.stopPropagation(); - $(this).closest('.sortable-item').slideUp( 200, function() { + $(this).closest('.sortable-item').slideUp(200, function() { $(this).remove(); - } ); - } ); + }); + }); - $block.on( 'change', '> .change-type select', function( e ) { - ContentBlock.changeType( $(this).closest('.block'), $(this).val() ); - } ); + $block.on('change', '> .change-type select', function(e) { + ContentBlock.changeType($(this).closest('.block'), $(this).val()); + }); - $block.on( 'click', '.fill-with-images', function( e ) { + $block.on('click', '.fill-with-images', function(e) { e.preventDefault(); var $list = $(this).parent().next('.sortable-list'); - ( function( $list ) { - ContentBlock.openBrowser( $list, 'images', function( files ) { + (function($list) { + ContentBlock.openBrowser($list, 'images', function(files) { var $item = $list.children(':last-child'); - for ( var i = 0; i < files.length; i++ ) { - $item = ContentBlock.insertItem( $item ); + for (var i = 0; i < files.length; i++) { + $item = ContentBlock.insertItem($item); var $input = $item.children('.fields-list').children('.type-image').eq(0).children('input[type="text"]'); - $input.val( files[i] ); - ContentBlock.setThumb( $input.parent() ); + $input.val(files[i]); + ContentBlock.setThumb($input.parent()); } - } ); - } )( $list ); - } ); + }); + })($list); + }); - ContentBlock.initializeFieldsList( conf.fields, $list ); - } ); + ContentBlock.initializeFieldsList(conf.fields, $list); + }); }, - fetch: function( $block, oldValues ) { - if ( $block.hasClass( 'block' ) ) { + fetch: function($block, oldValues) { + if ($block.hasClass('block')) { $block = $block.children('.block-inner'); } var values = oldValues || {}, $list = $block.children('.fields-list'), - conf = $list.data( 'fields' ); + conf = $list.data('fields'); - for ( var field in conf ) { + for (var field in conf) { var $field = $list.children('.field[data-field="' + field + '"]'), fieldConfig = conf[field]; - switch ( conf[field].type ) { + switch (conf[field].type) { case 'richtext': { var f = $field.children('textarea').get(0); - if ( typeof tinymce != 'undefined' && f.id && tinymce.editors[f.id] ) { + if (typeof tinymce != 'undefined' && f.id && tinymce.editors[f.id]) { values[field] = tinymce.editors[f.id].getContent(); } else { values[field] = $(f).val(); @@ -118,29 +117,29 @@ } case 'group': { - if ( typeof values[field] != 'object' ) { + if (typeof values[field] != 'object') { values[field] = []; } - $field.children('.sortable-list').children('.sortable-item:not(.hidden)').each( function( i ) { - values[field][i] = ContentBlock.fetch( $(this) ); - } ); + $field.children('.sortable-list').children('.sortable-item:not(.hidden)').each(function(i) { + values[field][i] = ContentBlock.fetch($(this)); + }); break; } case 'checkbox': { - if ( typeof values[field] != 'object' ) { + if (typeof values[field] != 'object') { values[field] = {}; } - $field.children('.check-list').children('.check-row').each( function( i ) { + $field.children('.check-list').children('.check-row').each(function(i) { var $input = $(this).children('label').children(':checked'); - if ( $input.length ) { + if ($input.length) { values[field][i] = $input.val(); } - } ); + }); break; } @@ -148,7 +147,7 @@ case 'radio': { var $input = $field.children('.check-list').children('.check-row').children('label').children(':checked'); - if ( $input.length ) { + if ($input.length) { values[field] = $input.val(); } @@ -164,22 +163,22 @@ return values; }, - setValues: function( conf, $list, values ) { - for ( var field in conf ) { + setValues: function(conf, $list, values) { + for (var field in conf) { var $field = $list.children('.field[data-field="' + field + '"]'); - switch ( conf[field].type ) { + switch (conf[field].type) { case 'group': { - if ( typeof values[field] === 'object' && values[field].length ) { + if (typeof values[field] === 'object' && values[field].length) { var $sortable = $field.children('.sortable-list'), $element = $sortable.children('.sortable-item.hidden'); - for ( var i = 0; i < values[field].length; i++ ) { - var $clone = ContentBlock.createSortableItem( $sortable ); + for (var i = 0; i < values[field].length; i++) { + var $clone = ContentBlock.createSortableItem($sortable); - $clone.appendTo( $sortable ).show(); + $clone.appendTo($sortable).show(); - ContentBlock.setValues( conf[field].fields, $clone.children('.fields-list'), values[field][i] ); + ContentBlock.setValues(conf[field].fields, $clone.children('.fields-list'), values[field][i]); } } @@ -187,21 +186,21 @@ } case 'checkbox': { - if ( typeof values[field] !== 'undefined' ) { - if ( typeof values[field] != 'object' ) { + if (typeof values[field] !== 'undefined') { + if (typeof values[field] != 'object') { values[field] = [ values[field] ]; } - if ( typeof values[field].length == 'undefined' ) { + if (typeof values[field].length == 'undefined') { values[field] = {}; } - var $inputs = $field.children('.check-list').children('.check-row').children('label').children('input').removeAttr( 'checked' ); + var $inputs = $field.children('.check-list').children('.check-row').children('label').children('input').removeAttr('checked'); - for ( var i = 0; i < values[field].length; i++ ) { + for (var i = 0; i < values[field].length; i++) { var $input = $inputs.filter('[value="' + values[field][i] + '"]'); - if ( $input.length ) { + if ($input.length) { $input.get(0).checked = true; } } @@ -211,10 +210,10 @@ } case 'radio': { - if ( typeof values[field] !== 'undefined' && typeof values[field] != 'object' ) { + if (typeof values[field] !== 'undefined' && typeof values[field] != 'object') { var $input = $field.children('.check-list').children('.check-row').children('label').children('[value="' + values[field] + '"]'); - if ( $input.length ) { + if ($input.length) { $input.get(0).checked = true; } } @@ -223,194 +222,204 @@ } default: { - if ( typeof values[field] !== 'undefined' && typeof values[field] != 'object' ) { - $field.children('input[type="text"], textarea, select').val( values[field] ); + if (typeof values[field] !== 'undefined' && typeof values[field] != 'object') { + $field.children('input[type="text"], textarea, select').val(values[field]); } } } } }, - setThumb: function( $field ) { - var source = $.trim( $field.children('input[type="text"]').val() ); + setThumb: function($field) { + var source = $.trim($field.children('input[type="text"]').val()); $preview = $field.children('.preview'), - thumb = source.replace( 'assets/images/', '../assets/.thumbs/images/' ); + thumb = source.replace('assets/images/', '../assets/.thumbs/images/'); - if ( source == '' ) { - $field.removeClass( 'with-thumb' ); - $field.children('.preview').removeAttr( 'style' ); + if (source == '') { + $field.removeClass('with-thumb'); + $field.children('.preview').removeAttr('style'); } else { - $field.addClass( 'with-thumb' ); + $field.addClass('with-thumb'); - if ( document.images ) { + if (document.images) { var image = new Image(); - ( function( source, thumb, $preview ) { + (function(source, thumb, $preview) { image.onload = function() { - if ( this.width + this.height == 0 ) { + if (this.width + this.height == 0) { return this.onerror(); } - $preview.css( 'background-image', 'url("' + thumb + '")' ); + $preview.css('background-image', 'url("' + thumb + '")'); } image.onerror = function() { - if ( this.thumbChecked == undefined ) { + if (this.thumbChecked == undefined) { this.thumbChecked = true; - this.src = source.replace( 'assets/images', '../assets/images' ); + this.src = source.replace('assets/images', '../assets/images'); } else { - $preview.css( 'background-image', 'url("../assets/images/noimage.jpg")' ); + $preview.css('background-image', 'url("../assets/images/noimage.jpg")'); } } - } )( source, thumb, $preview ); + })(source, thumb, $preview); image.src = thumb; } else { - $preview.css( 'background-image', 'url("' + thumb + '")' ); + $preview.css('background-image', 'url("' + thumb + '")'); } } }, - changeType: function( $block, type ) { - var values = this.fetch( $block, $block.data( 'values' ) ), + changeType: function($block, type) { + var values = this.fetch($block, $block.data('values')), $newblock = $('.content-blocks-configs').children('[data-config="' + type + '"]'); - if ( $newblock.length ) { - $newblock = $newblock.clone().data( 'values', values ); - $block.replaceWith( $newblock ); + if ($newblock.length) { + $newblock = $newblock.clone().data('values', values); + $block.replaceWith($newblock); - ContentBlock.setValues( opts.config[type].fields, $newblock.children('.block-inner').children('.fields-list'), values ); - ContentBlock.initialize( $newblock ); + ContentBlock.setValues(opts.config[type].fields, $newblock.children('.block-inner').children('.fields-list'), values); + ContentBlock.initialize($newblock); } }, - append: function( $after ) { - var $block = $('.content-blocks-configs').children().eq(0); + append: function(config, $after) { + var $block = $('.content-blocks-configs').children('[data-config="' + config + '"]'); - if ( $block.length ) { + if ($block.length) { $block = $block.clone(); - $block.find('.type-radio').each( function() { - $(this).find('[type="radio"]').attr( 'name', 'contentblocks_radio_' + ContentBlock.randomString() ); - } ); + // removing blocks from type-selector that not belongs to this container + var $configs = $after.closest('.content-blocks').children('.change-type').children('select').clone().show(); + $block.children('.block-inner').children('.change-type').children('select').replaceWith($configs); + + // adding add-block-section to the bottom of block + var $add = $after.closest('.content-blocks').children('.add-block').clone(); + $add.removeClass('show'); + $add.children('.add-block-icons').removeAttr('style'); + $block.append($add); - $block.hide().insertAfter( $after ).slideDown( 200 ); - ContentBlock.initialize( $block ); + $block.find('.type-radio').each(function() { + $(this).find('[type="radio"]').attr('name', 'contentblocks_radio_' + ContentBlock.randomString()); + }); + + $block.hide().insertAfter($after).slideDown(200); + ContentBlock.initialize($block); } }, - move: function( $block, direction ) { - if ( direction == 'up' ) { + move: function($block, direction) { + if (direction == 'up') { var $sibling = $block.prev('.block'); - if ( !$sibling.length ) { + if (!$sibling.length) { return; } } else { var $sibling = $block.next('.block'); - if ( $sibling.length ) { - $block.insertAfter( $sibling ); + if ($sibling.length) { + $block.insertAfter($sibling); } } var $rich = $block.find('textarea.richtext'); - $rich.each( function() { - if ( typeof tinymce != 'undefined' && this.id && tinymce.editors[this.id] ) { + $rich.each(function() { + if (typeof tinymce != 'undefined' && this.id && tinymce.editors[this.id]) { tinymce.editors[this.id].destroy(); } - } ); + }); - if ( direction == 'up' ) { - $block.insertBefore( $sibling ); + if (direction == 'up') { + $block.insertBefore($sibling); } else { - $block.insertAfter( $sibling ); + $block.insertAfter($sibling); } - $rich.each( function() { - ContentBlock.initializeRichField( $(this) ); - } ); + $rich.each(function() { + ContentBlock.initializeRichField($(this)); + }); }, - createSortableItem: function( $list ) { - var $clone = $list.children('.hidden').eq(0).clone( true ); + createSortableItem: function($list) { + var $clone = $list.children('.hidden').eq(0).clone(true); - $clone.removeClass( 'hidden' ).hide(); - $clone.children('.fields-list').removeClass( 'hidden' ); + $clone.removeClass('hidden').hide(); + $clone.children('.fields-list').removeClass('hidden'); - $clone.children('.fields-list').children('.type-radio').find('[type="radio"]').attr( 'name', 'contentblocks_radio_' + ContentBlock.randomString() ); + $clone.children('.fields-list').children('.type-radio').find('[type="radio"]').attr('name', 'contentblocks_radio_' + ContentBlock.randomString()); return $clone; }, - insertItem: function( $after ) { + insertItem: function($after) { var $list = $after.parent(), - $clone = ContentBlock.createSortableItem( $list ); + $clone = ContentBlock.createSortableItem($list); - $clone.insertAfter( $after ); + $clone.insertAfter($after); - if ( $after.hasClass( 'hidden' ) ) { - ContentBlock.initializeSortableList( $list ); + if ($after.hasClass('hidden')) { + ContentBlock.initializeSortableList($list); } - ContentBlock.initializeFieldsList( $after.children('.fields-list').data( 'fields' ), $clone.children('.fields-list') ); + ContentBlock.initializeFieldsList($after.children('.fields-list').data('fields'), $clone.children('.fields-list')); - $clone.slideDown( 200 ); + $clone.slideDown(200); return $clone; }, - initializeFieldsList: function( conf, $list ) { - $list.data( 'fields', conf ); + initializeFieldsList: function(conf, $list) { + $list.data('fields', conf); - for ( var field in conf ) { + for (var field in conf) { var $field = $list.children('.field[data-field="' + field + '"]'), fieldConfig = conf[field]; - switch ( fieldConfig.type ) { + switch (fieldConfig.type) { case 'richtext': { var $textarea = $field.children('textarea'); - if ( fieldConfig.options ) { - $textarea.data( 'options', fieldConfig.options ); + if (fieldConfig.options) { + $textarea.data('options', fieldConfig.options); } - if ( fieldConfig.theme ) { - $textarea.data( 'theme', fieldConfig.theme ); + if (fieldConfig.theme) { + $textarea.data('theme', fieldConfig.theme); } - ContentBlock.initializeRichField( $textarea ); + ContentBlock.initializeRichField($textarea); break; } case 'image': { - $field.children('input[type="text"]').on( 'input change', function() { - if ( this.value == '' ) { - ContentBlock.setThumb( $(this).parent() ); + $field.children('input[type="text"]').on('input change', function() { + if (this.value == '') { + ContentBlock.setThumb($(this).parent()); } - } ); + }); - ContentBlock.setThumb( $field ); + ContentBlock.setThumb($field); break; } case 'date': { var $input = $field.children('input'); - $input.data( 'picker', new DatePicker( $input.get(0), opts.picker ) ); + $input.data('picker', new DatePicker($input.get(0), opts.picker)); break; } case 'group': { var $sortable = $field.children('.sortable-list'); - $sortable.children('.sortable-item').each( function() { - ContentBlock.initializeFieldsList( conf[field].fields, $(this).children('.fields-list') ); - } ); + $sortable.children('.sortable-item').each(function() { + ContentBlock.initializeFieldsList(conf[field].fields, $(this).children('.fields-list')); + }); - if ( !$list.parent().hasClass( 'hidden' ) ) { - ContentBlock.initializeSortableList( $sortable ); + if (!$list.parent().hasClass('hidden')) { + ContentBlock.initializeSortableList($sortable); } break; @@ -419,59 +428,59 @@ } }, - initializeSortableList: function( $sortable ) { - $sortable.sortable( { + initializeSortableList: function($sortable) { + $sortable.sortable({ axis: 'y', items: '> .sortable-item:not(.hidden)', handle: '> .handle', - start: function( e, ui ) { - ui.item.find('textarea.richtext').each( function() { - if ( typeof tinymce != 'undefined' && this.id && tinymce.editors[this.id] ) { + start: function(e, ui) { + ui.item.find('textarea.richtext').each(function() { + if (typeof tinymce != 'undefined' && this.id && tinymce.editors[this.id]) { tinymce.editors[this.id].save(); } - } ); + }); }, - stop: function( e, ui ) { - ui.item.find('textarea.richtext').each( function() { - if ( typeof tinymce != 'undefined' && this.id && tinymce.editors[this.id] ) { + stop: function(e, ui) { + ui.item.find('textarea.richtext').each(function() { + if (typeof tinymce != 'undefined' && this.id && tinymce.editors[this.id]) { tinymce.editors[this.id].destroy(); } - ContentBlock.initializeRichField( $(this) ); - } ); + ContentBlock.initializeRichField($(this)); + }); } - } ); + }); }, - initializeRichField: function( $textarea ) { - if ( $textarea.closest('.hidden').length ) { + initializeRichField: function($textarea) { + if ($textarea.closest('.hidden').length) { return; } - var theme = $textarea.data( 'theme' ), - options = $textarea.data( 'options' ); + var theme = $textarea.data('theme'), + options = $textarea.data('options'); $textarea.get(0).id = 'rich' + ContentBlock.randomString(); - if ( typeof tinymce !== 'undefined' ) { + if (typeof tinymce !== 'undefined') { var conf = theme != undefined ? window['config_tinymce4_' + theme] : window[ modxRTEbridge_tinymce4.default ]; // content field configuration for tinymce - if ( options ) { + if (options) { var old = {}; // save all standard options for other fields - for ( option in options ) { + for (option in options) { old[option] = conf[option] ? conf[option] : undefined; conf[option] = options[option]; } } - conf['selector'] = '#' + $textarea.attr( 'id' ); - tinymce.init( conf ); + conf['selector'] = '#' + $textarea.attr('id'); + tinymce.init(conf); - if ( options ) { - for ( option in old ) { - if ( old[option] != undefined ) { + if (options) { + for (option in old) { + if (old[option] != undefined) { conf[option] = old[option]; } else { delete conf[option]; @@ -481,136 +490,134 @@ } }, - openBrowser: function( $element, type, multipleCallback ) { + openBrowser: function($element, type, multipleCallback) { var wnd = window.parent || window, - margin = parseInt( wnd.innerHeight * .1 ), + margin = parseInt(wnd.innerHeight * .1), width = wnd.innerWidth - margin * 2, height = wnd.innerHeight - margin * 2, - params = 'toolbar=no,status=no,resizable=yes,dependent=yes,width=' + width + ',height=' + height + ',left=' + margin + ',top=' + ( margin + ( wnd._startY ? wnd._startY * .5 : 0 ) ); + params = 'toolbar=no,status=no,resizable=yes,dependent=yes,width=' + width + ',height=' + height + ',left=' + margin + ',top=' + (margin + (wnd._startY ? wnd._startY * .5 : 0)); - if ( window['SetUrl'] ) { + if (window['SetUrl']) { window['SetUrl_disabled'] = window['SetUrl']; window['SetUrl'] = null; } window.KCFinder = { - callBack: function( url ) { - if ( window['SetUrl_disabled'] ) { + callBack: function(url) { + if (window['SetUrl_disabled']) { window['SetUrl'] = window['SetUrl_disabled']; } window.KCFinder = null; - $element.val( url ); + $element.val(url); - if ( type == 'images' ) { - ContentBlock.setThumb( $element.parent() ); + if (type == 'images') { + ContentBlock.setThumb($element.parent()); } } }; - if ( multipleCallback !== undefined ) { - window.KCFinder.callBackMultiple = window.KCFinder.callBack = function( files ) { - if ( typeof files !== 'object' ) { + if (multipleCallback !== undefined) { + window.KCFinder.callBackMultiple = window.KCFinder.callBack = function(files) { + if (typeof files !== 'object') { files = [ files ]; } - if ( window['SetUrl_disabled'] ) { + if (window['SetUrl_disabled']) { window['SetUrl'] = window['SetUrl_disabled']; } window.KCFinder = null; - multipleCallback( files ); + multipleCallback(files); }; } - var wnd = window.open( opts.browser + '?type=' + type, 'FileManager', params ); + var wnd = window.open(opts.browser + '?type=' + type, 'FileManager', params); }, randomString: function() { - return ( ( ( 1 + Math.random() ) * 0x100000 ) | 0 ).toString( 16 ); + return (((1 + Math.random()) * 0x100000) | 0).toString(16); } } - ContentBlock.initialize( $container.children('.block') ); - - $container.closest('form').submit( function() { - var $form = $(this), - $blocks = $container.children('.block'); - - $form.children('input[name^="contentblocks"]').remove(); + opts.containers.each(function() { - if ( !$blocks.length ) { - $('').attr( 'name', 'contentblocks' ).val( '0' ).appendTo( $form ); - } + var $container = $(this); - $blocks.each( function( i ) { - var $block = $(this), - $id = $block.children('.block-inner').children('[name="contentblocks_id"]'); + ContentBlock.initialize($container.children('.block')); - $('').attr( 'name', 'contentblocks[' + i + '][config]' ).val( $block.attr( 'data-config' ) ).appendTo( $form ); - $('').attr( 'name', 'contentblocks[' + i + '][values]' ).val( JSON.stringify( ContentBlock.fetch( $block ) ) ).appendTo( $form ); + $container.on('click', '.dropdown-add-block', function(e) { + e.preventDefault(); + var config = $(this).prev('select').val(); - if ( $id.length ) { - $('').attr( 'name', 'contentblocks[' + i + '][id]' ).val( $id.val() ).appendTo( $form ); + if (config != '') { + var $current = $(this).closest('.block, .add-block'); + ContentBlock.append(config, $current); } - } ); - } ); - - $container.on( 'click', '.dropdown-add-block', function( e ) { - e.preventDefault(); + }); - var config = $(this).prev('select').val(); + $container.on('click', '.add-block .trigger a', function(e) { + e.preventDefault(); + $(this).closest('.add-block').toggleClass('show').children('.add-block-icons').slideToggle(200); + }); - if ( config != '' ) { - var $block = $('.content-blocks-configs').children('[data-config="' + config + '"]'); + $container.on('click', '.add-block-icons a', function(e) { + e.preventDefault(); - if ( $block.length ) { - $block = $block.clone(); + $(this).closest('.add-block-icons').prev('.trigger').children('a').click(); - $block.find('.type-radio').each( function() { - $(this).find('[type="radio"]').attr( 'name', 'contentblocks_radio_' + ContentBlock.randomString() ); - } ); + var config = $(this).attr('data-config'); + if (config != '') { var $current = $(this).closest('.block'); - $block.hide().insertAfter( $current.length ? $current : $(this).closest('.add-block') ).slideDown( 200 ); - ContentBlock.initialize( $block ); - } - } - } ); - - $container.on( 'click', '.add-block .trigger a', function( e ) { - e.preventDefault(); - $(this).closest('.add-block').toggleClass( 'show' ).children('.add-block-icons').slideToggle( 200 ); - } ); - - $container.on( 'click', '.add-block-icons a', function( e ) { - e.preventDefault(); + if (!$current.length) { + $current = $(this).closest('.add-block'); + } - $(this).parent().prev('.trigger').children('a').click(); + ContentBlock.append(config, $current); + } + }); + }); - var config = $(this).attr( 'data-config' ); + opts.containers.eq(0).closest('form').submit(function() { + var $form = $(this); - if ( config != '' ) { - var $block = $('.content-blocks-configs').children('[data-config="' + config + '"]'); + $form.children('input[name^="contentblocks"]').remove(); - if ( $block.length ) { - $block = $block.clone(); + $('.content-blocks').each(function() { + var length = 0, + container = $(this).attr('data-container'); + + $(this).children('.block').each(function() { + var $block = $(this), + $inner = $block.children('.block-inner'), + $id = $inner.children('[name="contentblocks_id"]'), + data = { + visible: $inner.children('.change-type').children('.visible').children('input:checked').length, + config: $block.attr('data-config'), + values: JSON.stringify(ContentBlock.fetch($inner)) + }; + + if ($id.length) { + data.id = $id.val(); + } - $block.find('.type-radio').each( function() { - $(this).find('[type="radio"]').attr( 'name', 'contentblocks_radio_' + ContentBlock.randomString() ); - } ); + for (var field in data) { + $('').attr('name', 'contentblocks[' + container + '][' + length + '][' + field + ']').val(data[field]).appendTo($form); + } - var $current = $(this).closest('.block'); + length++; + }); - $block.hide().insertAfter( $current.length ? $current : $(this).closest('.add-block') ).slideDown( 200 ); - ContentBlock.initialize( $block ); + if (!length) { + $('').attr('name', 'contentblocks[' + container + ']').val('0').appendTo($form); } - } - } ); + }); + }); - } )( jQuery ); + })(jQuery); } diff --git a/assets/plugins/pagebuilder/lang/english.php b/assets/plugins/pagebuilder/lang/english.php index 01076f8..ffa2e0c 100644 --- a/assets/plugins/pagebuilder/lang/english.php +++ b/assets/plugins/pagebuilder/lang/english.php @@ -13,5 +13,6 @@ 'Fill with images' => 'Fill with images', 'No variants provided' => 'No variants provided', 'No fields provided in this block' => 'No fields provided in this block', + 'Visible' => 'Visible', ]; diff --git a/assets/plugins/pagebuilder/lang/nederlands-utf8.php b/assets/plugins/pagebuilder/lang/nederlands-utf8.php index 0addcdc..cc86275 100644 --- a/assets/plugins/pagebuilder/lang/nederlands-utf8.php +++ b/assets/plugins/pagebuilder/lang/nederlands-utf8.php @@ -1,4 +1,5 @@ 'Blok toevoegen', 'Choose' => 'Selecteer', @@ -12,4 +13,5 @@ 'Fill with images' => 'Vullen met afbeeldingen', 'No variants provided' => 'Geen opties', 'No fields provided in this block' => 'In deze eenheid, zijn er geen velden om in te vullen', + 'Visible' => 'Toon', ]; diff --git a/assets/plugins/pagebuilder/lang/polish-utf8.php b/assets/plugins/pagebuilder/lang/polish-utf8.php index 91b0223..5ee4ff6 100644 --- a/assets/plugins/pagebuilder/lang/polish-utf8.php +++ b/assets/plugins/pagebuilder/lang/polish-utf8.php @@ -13,5 +13,6 @@ 'Fill with images' => 'Wypełnij obrazami', 'No variants provided' => 'Brak wariantów', 'No fields provided in this block' => 'W tym bloku nie ma pól do wypełnienia', + 'Visible' => 'Pokaż', ]; diff --git a/assets/plugins/pagebuilder/lang/russian-UTF8.php b/assets/plugins/pagebuilder/lang/russian-UTF8.php index 3c9dfed..1524173 100644 --- a/assets/plugins/pagebuilder/lang/russian-UTF8.php +++ b/assets/plugins/pagebuilder/lang/russian-UTF8.php @@ -13,5 +13,6 @@ 'Fill with images' => 'Заполнить изображениями', 'No variants provided' => 'Нет вариантов выбора', 'No fields provided in this block' => 'В этом блоке нет полей для заполнения', + 'Visible' => 'Показывать', ]; diff --git a/assets/plugins/pagebuilder/pagebuilder.php b/assets/plugins/pagebuilder/pagebuilder.php index 52133ca..45addcf 100644 --- a/assets/plugins/pagebuilder/pagebuilder.php +++ b/assets/plugins/pagebuilder/pagebuilder.php @@ -2,30 +2,31 @@ class PageBuilder { - const version = '1.0.0'; + const version = '1.1.0'; private $modx; private $data; private $conf = []; private $themes = []; + private $containers = []; private $path; private $params; private $lang; private $iterations = []; - public function __construct( $modx ) { + public function __construct($modx) { $this->modx = $modx; - $this->richeditor = $modx->getConfig( 'which_editor' ); - $this->browser = $modx->getConfig( 'which_browser' ); - $this->table = $modx->getFullTableName( 'pagebuilder' ); + $this->richeditor = $modx->getConfig('which_editor'); + $this->browser = $modx->getConfig('which_browser'); + $this->table = $modx->getFullTableName('pagebuilder'); $this->path = MODX_BASE_PATH . 'assets/plugins/pagebuilder/config/'; $this->params = $modx->event->params; - $lang = $modx->getConfig( 'manager_language' ); + $lang = $modx->getConfig('manager_language'); $lang = __DIR__ . '/lang/' . $lang . '.php'; - if ( !is_readable( $lang ) ) { + if (!is_readable($lang)) { $lang = __DIR__ . '/lang/english.php'; } @@ -39,66 +40,66 @@ public function __construct( $modx ) { * @param array $data Values * @return string Result of parsing */ - private function parseTemplate( $template, $data ) { - if ( !function_exists( 'ParseCommand' ) ) { - require_once( MODX_MANAGER_PATH . 'includes/tmplvars.commands.inc.php' ); + private function parseTemplate($template, $data) { + if (!function_exists('ParseCommand')) { + require_once(MODX_MANAGER_PATH . 'includes/tmplvars.commands.inc.php'); } - $binding = ParseCommand( $template ); + $binding = ParseCommand($template); - if ( !empty( $binding ) ) { - list( $command, $source ) = $binding; + if (!empty($binding)) { + list($command, $source) = $binding; - switch ( $command ) { + switch ($command) { case 'CHUNK': { - $template = $this->modx->getChunk( trim( $source ) ); + $template = $this->modx->getChunk(trim($source)); break; } case 'FILE': { - $template = $this->modx->atBindFileContent( $template ); + $template = $this->modx->atBindFileContent($template); break; } } } - $template = $this->modx->mergeSettingsContent( $template ); + $template = $this->modx->mergeSettingsContent($template); - return $this->modx->parseText( $template , $data ); + return $this->modx->parseText($template , $data); } - private function renderFieldsList( $templates, $template, $config, $values ) { + private function renderFieldsList($templates, $template, $config, $values) { $out = ''; $data = []; - if ( isset( $config['fields'] ) ) { - foreach ( $config['fields'] as $field => $options ) { - if ( isset( $options['elements'] ) ) { - if ( !isset( $templates[$field] ) ) { + if (isset($config['fields'])) { + foreach ($config['fields'] as $field => $options) { + if (isset($options['elements'])) { + if (!isset($templates[$field])) { $data[$field] = $values[$field]; - if ( is_array( $data[$field] ) ) { - $data[$field] = implode( '||', $data[$field] ); + if (is_array($data[$field])) { + $data[$field] = implode('||', $data[$field]); } } else { $fieldTemplates = $templates[$field]; - if ( !is_array( $fieldTemplates ) ) { + if (!is_array($fieldTemplates)) { $fieldTemplates = [ $fieldTemplates ]; } - foreach ( $fieldTemplates as $name => $tpl ) { - $key = $field . ( !is_numeric( $name ) || $name > 0 ? '.' . $name : '' ); + foreach ($fieldTemplates as $name => $tpl) { + $key = $field . (!is_numeric($name) || $name > 0 ? '.' . $name : ''); $data[$key] = ''; - foreach ( $values[$field] as $index => $value ) { + foreach ($values[$field] as $index => $value) { $this->iterations["{$field}_index"] = $index; $this->iterations["{$field}_iteration"] = $index + 1; - $data[$key] .= $this->parseTemplate( $tpl, array_merge( $this->iterations, [ + $data[$key] .= $this->parseTemplate($tpl, array_merge($this->iterations, [ 'value' => $value, 'title' => $options['elements'][$value], - ] ) ); + ])); } } } @@ -106,37 +107,37 @@ private function renderFieldsList( $templates, $template, $config, $values ) { continue; } - if ( $options['type'] != 'group' ) { + if ($options['type'] != 'group') { $data[$field] = $values[$field]; continue; } - if ( !isset( $templates[$field] ) ) { + if (!isset($templates[$field])) { $data[$field] = "
Template for fieldgroup '$field' not defined
"; continue; } $fieldTemplates = $templates[$field]; - if ( !is_array( $fieldTemplates ) ) { + if (!is_array($fieldTemplates)) { $fieldTemplates = [ $fieldTemplates ]; } - foreach ( $fieldTemplates as $name => $tpl ) { - $key = $field . ( !is_numeric( $name ) || $name > 0 ? '.' . $name : '' ); + foreach ($fieldTemplates as $name => $tpl) { + $key = $field . (!is_numeric($name) || $name > 0 ? '.' . $name : ''); $data[$key] = ''; - foreach ( $values[$field] as $index => $value ) { + foreach ($values[$field] as $index => $value) { $this->iterations["{$field}_index"] = $index; $this->iterations["{$field}_iteration"] = $index + 1; - $data[$key] .= $this->renderFieldsList( $templates, $tpl, $options, $value ); + $data[$key] .= $this->renderFieldsList($templates, $tpl, $options, $value); } } } } - return $this->parseTemplate( $template, array_merge( $this->iterations, $data ) ); + return $this->parseTemplate($template, array_merge($this->iterations, $data)); } /** @@ -145,51 +146,52 @@ private function renderFieldsList( $templates, $template, $config, $values ) { * @param int $params Snippet parameters * @return string Output */ - public function render( $params ) { - $params = array_merge( [ + public function render($params) { + $params = array_merge([ 'docid' => $this->modx->documentIdentifier, + 'container' => 'default', 'blocks' => '*', 'templates' => '', 'offset' => 0, 'limit' => 0, - ], $params ); + ], $params); - if ( $params['blocks'] != '*' ) { - $params['blocks'] = explode( ',', $params['blocks'] ); + if ($params['blocks'] != '*') { + $params['blocks'] = explode(',', $params['blocks']); } $out = ''; $idx = -1; - $this->fetch( $params['docid'], false ); + $this->fetch($params['docid'], $params['container'], false); - foreach ( $this->data as $row ) { + foreach ($this->data as $row) { $idx++; $this->iterations['index'] = $idx; $this->iterations['iteration'] = $idx + 1; - if ( $params['blocks'] != '*' ) { - $config = pathinfo( $row['config'], PATHINFO_FILENAME ); + if ($params['blocks'] != '*') { + $config = pathinfo($row['config'], PATHINFO_FILENAME); - if ( !in_array( $config, $params['blocks'] ) ) { + if (!in_array($config, $params['blocks'])) { continue; } } - if ( $idx < $params['offset'] ) { + if ($idx < $params['offset']) { continue; } - if ( $params['limit'] > 0 && $idx >= $params['limit'] ) { + if ($params['limit'] > 0 && $idx >= $params['limit']) { break; } $conf = $this->conf[ $row['config'] ]; $templates = $conf['templates']; - if ( !empty( $params['templates'] ) ) { - if ( !isset( $templates[ $params['templates'] ] ) ) { + if (!empty($params['templates'])) { + if (!isset($templates[ $params['templates'] ])) { $out .= "
Templates set '" . $params['templates'] . "' not defined
"; continue; } @@ -197,15 +199,27 @@ public function render( $params ) { $templates = $templates[ $params['templates'] ]; } - if ( !isset( $templates['owner'] ) ) { + if (!isset($templates['owner'])) { $out .= "
Template 'owner' not defined
"; continue; } - $out .= $this->renderFieldsList( $templates, $templates['owner'], $conf, $row['values'] ); + $out .= $this->renderFieldsList($templates, $templates['owner'], $conf, $row['values']); } - return $out; + $wrapper = '[+wrap+]'; + + if (isset($params['wrapTpl'])) { + $wrapper = $this->modx->getChunk($params['wrapTpl']); + } else if (isset($this->containers[ $params['container'] ])) { + $container = $this->containers[ $params['container'] ]; + + if (!empty($container['templates']['owner'])) { + $wrapper = $container['templates']['owner']; + } + } + + return $this->parseTemplate($wrapper, ['wrap' => $out]); } /** @@ -215,13 +229,12 @@ public function render( $params ) { * @param array $data Values for binding to template * @return string Output */ - public function renderTpl( $template, $data ) { - $data['instance'] = $this; + public function renderTpl($template, $data) { $data['l'] = $this->lang; - extract( $data ); + extract($data); ob_start(); - include( __DIR__ . '/' . $template ); + include(__DIR__ . '/' . $template); $output = ob_get_contents(); ob_end_clean(); @@ -234,131 +247,193 @@ public function renderTpl( $template, $data ) { * @return string Output */ public function renderForm() { - $this->fetch( $this->params['id'] ); + $this->fetch($this->params['id']); - if ( empty( $this->conf ) ) { + if (empty($this->conf)) { return ''; } // load manager lang file for date settings - include MODX_MANAGER_PATH . 'includes/lang/' . $this->modx->getConfig( 'manager_language' ) . '.inc.php'; - - return $this->renderTpl( 'tpl/form.tpl', [ - 'version' => self::version, - 'tabname' => !empty( $this->params['tabName'] ) ? $this->params['tabName'] : 'Page Builder', - 'addType' => !empty( $this->params['addType'] ) ? $this->params['addType'] : 'dropdown', - 'placement' => !empty( $this->params['placement'] ) ? $this->params['placement'] : 'content', - 'browseurl' => MODX_MANAGER_URL . 'media/browser/' . $this->browser . '/browse.php', - 'configs' => $this->conf, - 'blocks' => $this->data, - 'adminlang' => $_lang, - 'picker' => [ - 'yearOffset' => $this->modx->getConfig( 'datepicker_offset' ), - 'format' => $this->modx->getConfig( 'datetime_format' ) . ' hh:mm:00', + include MODX_MANAGER_PATH . 'includes/lang/' . $this->modx->getConfig('manager_language') . '.inc.php'; + + return $this->renderTpl('tpl/form.tpl', [ + 'version' => self::version, + 'browseurl' => MODX_MANAGER_URL . 'media/browser/' . $this->browser . '/browse.php', + 'containers' => $this->containers, + 'configs' => $this->conf, + 'blocks' => $this->data, + 'adminlang' => $_lang, + 'picker' => [ + 'yearOffset' => $this->modx->getConfig('datepicker_offset'), + 'format' => $this->modx->getConfig('datetime_format') . ' hh:mm:00', ], - ] ); + ]); + } + + /** + * Determines whether a block can be included and shown + * after filtering by parameters + * + * @param array $block Block configuration + * @param integer $docid Curent document identifier + * @return boolean + */ + private function canIncludeBlock($block, $docid) { + $templateid = isset($this->params['template']) ? $this->params['template'] : $this->modx->documentObject['template']; + + foreach ([ 'show_in_templates', 'show_in_docs', 'hide_in_docs' ] as $opt) { + if (isset($block[$opt]) && !is_array($block[$opt])) { + $block[$opt] = [ $block[$opt] ]; + } + } + + if (isset($block['show_in_templates']) && !in_array($templateid, $block['show_in_templates'])) { + return false; + } + + if (isset($block['hide_in_docs']) && in_array($docid, $block['hide_in_docs'])) { + return false; + } + + if (isset($block['show_in_docs'])) { + if (in_array($docid, $block['show_in_docs'])) { + return true; + } else if (!isset($block['show_in_templates'])) { + return false; + } + } + + return true; } /** * Loads saved content blocks and configuration files * * @param int $docid Document identificator + * @param string $container Name of the container * @param boolean $notpl If true, template will be cut from configuration array */ - private function fetch( $docid, $notpl = true ) { - if ( $docid ) { - $query = $this->modx->db->select( '*', $this->table, "`document_id` = '$docid'", "`index` ASC" ); - $data = $this->modx->db->makeArray( $query ); - } else { - $data = []; - } + private function fetch($docid, $containerName = null, $notpl = true) { + $this->containers['default'] = [ + 'title' => !empty($this->params['tabName']) ? $this->params['tabName'] : 'Page Builder', + 'addType' => !empty($this->params['addType']) ? $this->params['addType'] : 'dropdown', + 'placement' => !empty($this->params['placement']) ? $this->params['placement'] : 'content' + ]; $this->conf = []; - $templateid = isset( $this->params['template'] ) ? $this->params['template'] : $this->modx->documentObject['template']; - - foreach ( scandir( $this->path ) as $entry ) { - if ( pathinfo( $entry, PATHINFO_EXTENSION ) == 'php' ) { - $config = include( $this->path . $entry ); + // Loading all config files, that complied with filters + foreach (scandir($this->path) as $entry) { + if (pathinfo($entry, PATHINFO_EXTENSION) == 'php') { + $name = pathinfo($entry, PATHINFO_FILENAME); + $block = include($this->path . $entry); - foreach ( [ 'show_in_templates', 'show_in_docs', 'hide_in_docs' ] as $opt ) { - if ( isset( $config[$opt] ) && !is_array( $config[$opt] ) ) { - $config[$opt] = [ $config[$opt] ]; + if ($this->canIncludeBlock($block, $docid)) { + if ($notpl) { + unset($block['templates']); } - } - $add = true; - - if ( isset( $config['show_in_templates'] ) && !in_array( $templateid, $config['show_in_templates'] ) ) { - $add = false; - } + if (strpos($name, 'container.') === 0) { + $name = str_replace('container.', '', $name); + $block['sections'] = []; + $this->containers[$name] = $block; + } else { + if (!isset($block['container'])) { + $block['container'] = 'default'; + } - if ( $add && isset( $config['hide_in_docs'] ) && in_array( $docid, $config['hide_in_docs'] ) ) { - $add = false; - } + if (!isset($block['order'])) { + $block['order'] = PHP_INT_MAX; + } - if ( isset( $config['show_in_docs'] ) ) { - if ( in_array( $docid, $config['show_in_docs'] ) ) { - $add = true; - } else if ( !isset( $config['show_in_templates'] ) ) { - $add = false; + $block['name'] = $name; + $this->conf[$name] = $block; } } + } + } - if ( $add ) { - $this->conf[$entry] = $config; + foreach ($this->conf as $name => $block) { + $containers = $block['container']; - if ( $notpl ) { - unset( $this->conf[$entry]['templates'] ); - } + if (!is_array($containers)) { + $containers = [$containers]; + } + + foreach ($containers as $container) { + if (!isset($this->containers[$container])) { + $container = 'default'; } + + $this->containers[$container]['sections'][] = $name; } } - foreach ( $data as $i => $row ) { - if ( isset( $this->conf[ $row['config'] ] ) ) { - $data[$i]['values'] = json_decode( $data[$i]['values'], true ); - } else { - unset( $data[$i] ); + uasort($this->conf, function($a, $b) { + if ($a['order'] == $b['order']) { + return $a['title'] < $b['title'] ? -1 : 1; } - } + return ($a['order'] < $b['order']) ? -1 : 1; + }); - $this->data = $data; + $this->containers = array_filter($this->containers, function($container) { + return !empty($container['sections']); + }); + + $this->containers = array_map(function($item) { + $item['sections'] = array_unique($item['sections']); + return $item; + }, $this->containers); + + $this->data = []; + + if ($docid) { + $query = $this->modx->db->select('*', $this->table, "`document_id` = '$docid'" . ($containerName !== null ? " AND `container` = '$containerName'" : '') . (!$notpl ? " AND `visible` = '1'" : ''), "`index` ASC"); + + while ($row = $this->modx->db->getRow($query)) { + $row['config'] = str_replace('.php', '', $row['config']); + + if (isset($this->conf[ $row['config'] ])) { + $row['values'] = json_decode($row['values'], true); + $this->data[] = $row; + } + } + } } /** * Called at OnDocFormSave event for saving content blocks */ public function save() { - if ( isset( $_POST['contentblocks'] ) ) { - if ( is_array( $_POST['contentblocks'] ) ) { - $docid = $this->params['id']; - - $exists = array_map( function( $element ) { - return $element['id']; - }, $_POST['contentblocks'] ); - - $this->modx->db->delete( $this->table, "`document_id` = '$docid' AND `id` NOT IN ('" . implode( "','", $exists ) . "')" ); - - foreach ( $_POST['contentblocks'] as $index => $row ) { - if ( !empty( $row['id'] ) ) { - $this->modx->db->update( [ - 'config' => $this->modx->db->escape( $row['config'] ), - 'values' => $this->modx->db->escape( $row['values'] ), - 'index' => $index, - ], $this->table, "`id` = '{$row[id]}'" ); - } else { - $this->modx->db->insert( [ - 'document_id' => $docid, - 'config' => $this->modx->db->escape( $row['config'] ), - 'values' => $this->modx->db->escape( $row['values'] ), - 'index' => $index, - ], $this->table ); + if (isset($_POST['contentblocks'])) { + foreach ($_POST['contentblocks'] as $container => $blocks) { + if (is_array($blocks)) { + $docid = $this->params['id']; + + $exists = array_map(function($element) { + return $element['id']; + }, $blocks); + + $this->modx->db->delete($this->table, "`document_id` = '$docid' AND `container` = '$container' AND `id` NOT IN ('" . implode("','", $exists) . "')"); + + foreach ($blocks as $index => $row) { + $data = [ + 'container' => $this->modx->db->escape($container), + 'config' => $this->modx->db->escape($row['config']), + 'values' => $this->modx->db->escape($row['values']), + 'visible' => $row['visible'] > 0 ? 1 : 0, + 'index' => $index, + ]; + + if (!empty($row['id'])) { + $this->modx->db->update($data, $this->table, "`id` = '{$row[id]}'"); + } else { + $data['document_id'] = $docid; + $this->modx->db->insert($data, $this->table); + } } - } - } else { - if ( $_POST['contentblocks'] == 0 ) { - $this->modx->db->delete( $this->table, "`document_id` = '" . $this->params['id'] . "'" ); + } else { + $this->modx->db->delete($this->table, "`document_id` = '" . $this->params['id'] . "' AND `container` = '$container'"); } } } @@ -373,30 +448,30 @@ public function save() { * @param mixed $input * @return mixed */ - private function parseValues( $input ) { - if ( !function_exists( 'ParseIntputOptions' ) ) { - require_once( MODX_MANAGER_PATH . 'includes/tmplvars.inc.php' ); + private function parseValues($input) { + if (!function_exists('ParseIntputOptions')) { + require_once(MODX_MANAGER_PATH . 'includes/tmplvars.inc.php'); } - if ( !function_exists( 'ProcessTVCommand' ) ) { - require_once( MODX_MANAGER_PATH . 'includes/tmplvars.commands.inc.php' ); + if (!function_exists('ProcessTVCommand')) { + require_once(MODX_MANAGER_PATH . 'includes/tmplvars.commands.inc.php'); } - if ( !is_string( $input ) ) { + if (!is_string($input)) { return $input; } else { $values = []; - $elements = ParseIntputOptions( ProcessTVCommand( $input, '', '', 'tvform', $tv = [] ) ); + $elements = ParseIntputOptions(ProcessTVCommand($input, '', '', 'tvform', $tv = [])); - if ( !empty( $elements ) ) { - foreach ( $elements as $element ) { - list( $val, $key ) = is_array( $element ) ? $element : explode( '==', $element ); + if (!empty($elements)) { + foreach ($elements as $element) { + list($val, $key) = is_array($element) ? $element : explode('==', $element); - if ( strlen( $val ) == 0 ) { + if (strlen($val) == 0) { $val = $key; } - if ( strlen( $key ) == 0 ) { + if (strlen($key) == 0) { $key = $val; } @@ -416,60 +491,60 @@ private function parseValues( $input ) { * @param mixed $value Value of field * @return string Output */ - public function renderField( $field, $name, $value ) { + public function renderField($field, $name, $value) { $out = ''; $default = ''; - if ( !empty( $field['default'] ) ) { - $default = $this->parseValues( $field['default'] ); + if (!empty($field['default'])) { + $default = $this->parseValues($field['default']); - if ( $field['type'] != 'checkbox' && is_array( $default ) ) { - $default = reset( $default ); + if ($field['type'] != 'checkbox' && is_array($default)) { + $default = reset($default); } } $params = [ 'name' => $name, 'field' => $field, - 'value' => is_null( $value ) ? $default : $value, + 'value' => is_null($value) ? $default : $value, 'elements' => [ '' => $this->lang['No variants provided'], ], ]; - switch ( $field['type'] ) { + switch ($field['type']) { case 'group': { - if ( !is_array( $value ) ) { + if (!is_array($value)) { $value = [ [] ]; } else { - array_unshift( $value, [] ); + array_unshift($value, []); } - return $this->renderTpl( 'tpl/field_group.tpl', array_merge( $params, [ + return $this->renderTpl('tpl/field_group.tpl', array_merge($params, [ 'values' => $value, - ] ) ); + ])); } case 'richtext': { - if ( isset( $field['theme'] ) && !isset( $this->themes[ $field['theme'] ] ) && in_array( $this->richeditor, [ 'TinyMCE4' ] ) ) { - $result = $this->modx->invokeEvent( 'OnRichTextEditorInit', [ + if (isset($field['theme']) && !isset($this->themes[ $field['theme'] ]) && in_array($this->richeditor, [ 'TinyMCE4' ])) { + $result = $this->modx->invokeEvent('OnRichTextEditorInit', [ 'editor' => $this->richeditor, 'options' => [ 'theme' => $field['theme'] ], - ] ); + ]); - if ( is_array( $result ) ) { - $result = implode( '', $result ); + if (is_array($result)) { + $result = implode('', $result); } $this->themes[ $field['theme'] ] = $result; } - return $this->renderTpl( 'tpl/field_richtext.tpl', $params ); + return $this->renderTpl('tpl/field_richtext.tpl', $params); } case 'checkbox': { - if ( !is_array( $value ) ) { + if (!is_array($value)) { $value = [ $value ]; } } @@ -477,19 +552,19 @@ public function renderField( $field, $name, $value ) { case 'radio': { $params['layout'] = 'vertical'; - if ( isset( $field['layout'] ) && in_array( $field['layout'], [ 'horizontal', 'vertical' ] ) ) { + if (isset($field['layout']) && in_array($field['layout'], [ 'horizontal', 'vertical' ])) { $params['layout'] = $field['layout']; } } case 'dropdown': { - if ( !empty( $field['elements'] ) ) { - $params['elements'] = $this->parseValues( $field['elements'] ); + if (!empty($field['elements'])) { + $params['elements'] = $this->parseValues($field['elements']); } } default: { - return $this->renderTpl( 'tpl/field_' . $field['type'] . '.tpl', $params ); + return $this->renderTpl('tpl/field_' . $field['type'] . '.tpl', $params); } } @@ -500,16 +575,18 @@ public function renderField( $field, $name, $value ) { * Called at OnDocDuplicate event */ public function duplicate() { - if ( $this->params['id'] && $this->params['new_id'] ) { - $query = $this->modx->db->select( '*', $this->table, "`document_id` = '" . $this->params['id'] . "'", "`index` ASC" ); + if ($this->params['id'] && $this->params['new_id']) { + $query = $this->modx->db->select('*', $this->table, "`document_id` = '" . $this->params['id'] . "'", "`index` ASC"); - while ( $row = $this->modx->db->getRow( $query ) ) { - $this->modx->db->insert( [ + while ($row = $this->modx->db->getRow($query)) { + $this->modx->db->insert([ 'document_id' => $this->params['new_id'], - 'config' => $this->modx->db->escape( $row['config'] ), - 'values' => $this->modx->db->escape( $row['values'] ), + 'container' => $this->modx->db->escape($row['container']), + 'config' => $this->modx->db->escape($row['config']), + 'values' => $this->modx->db->escape($row['values']), + 'visible' => $row['visible'] > 0 ? 1 : 0, 'index' => $row['index'], - ], $this->table ); + ], $this->table); } } } @@ -518,8 +595,8 @@ public function duplicate() { * Called at OnBeforeEmptyTrash event */ public function delete() { - if ( !empty( $this->params['ids'] ) ) { - $this->modx->db->delete( $this->table, "`document_id` IN ('" . implode( "','", $this->params['ids'] ) . "')" ); + if (!empty($this->params['ids'])) { + $this->modx->db->delete($this->table, "`document_id` IN ('" . implode("','", $this->params['ids']) . "')"); } } diff --git a/assets/plugins/pagebuilder/styles/styles.css b/assets/plugins/pagebuilder/styles/styles.css index fc36469..22d6943 100644 --- a/assets/plugins/pagebuilder/styles/styles.css +++ b/assets/plugins/pagebuilder/styles/styles.css @@ -1,5 +1,6 @@ .content-blocks { margin: 30px 0; } .content-blocks-tab > .content-blocks { margin: 10px 0; } +#tabGeneral .content-blocks-container { margin-top: 30px; } .content-blocks input[type="button"] { border: 1px solid rgba(0,0,0,0.15); } .content-blocks .blocks { padding: 0 0 40px; } .content-blocks .block:last-child { margin-bottom: 0 !important; } @@ -29,6 +30,7 @@ .content-blocks .block .field .check-list.layout-horizontal .check-row label { display: block; } .content-blocks .block .change-type { position: absolute; left: 20px; top: -20px; } .content-blocks .block .change-type select { width: 150px !important; } +.content-blocks .block .change-type .visible { margin: 0 10px; vertical-align: middle; background: #fff; padding: 6px 10px; cursor: pointer; } .content-blocks .block .controls { position: absolute; height: 28px; line-height: 26px; right: 20px; top: -20px; cursor: default; background: #fff; padding: 0 10px; border-radius: 0; border: 1px solid #f8f8f8; font-size: 14px; } .content-blocks .block .controls a { display: inline-block; padding: 0 5px; color: #555; } @@ -69,17 +71,22 @@ .content-blocks .add-block .trigger a:before { vertical-align: top; line-height: 20px; } .content-blocks .add-block.show .trigger a { transform: rotate(45deg); color: #c9302c; } .content-blocks .add-block .add-block-icons { margin: 30px 0; display: none; } -.content-blocks .add-block .add-block-icons a { display: inline-block; margin: 10px 5px 0; border: 2px solid #ccc; padding: 7px; width: 96px; text-decoration: none; color: #333; vertical-align: top; border-radius: 3px; } +.content-blocks .add-block .add-block-icons a { display: inline-block; margin: 10px 5px 0; border: 2px solid #ccc; padding: 7px; width: 96px; text-decoration: none; color: #333; vertical-align: top; border-radius: 3px; font-size: 11px; } .content-blocks .add-block .add-block-icons a:hover { background-color: #fafafa; } .content-blocks .add-block .add-block-icons a > .icon { display: block; width: 80px; height: 60px; line-height: 76px; margin: 0 0 5px; } .content-blocks .add-block .add-block-icons a > .icon i { font-size: 36px; } +.content-blocks .add-block .add-block-icons a > .icon img { vertical-align: top; } -@media ( max-width: 1100px ) { +@supports (display: flex) { + .content-blocks .add-block .add-block-icons .icons-list { display: flex; justify-content: center; flex-wrap: wrap; } +} + +@media (max-width: 1100px) { .content-blocks .block .field.uploadable input[type="text"] { width: 87%; } .content-blocks .block .field.uploadable input[type="button"] { width: 12% !important; } } -@media ( max-width: 850px ) { +@media (max-width: 850px) { .content-blocks .block .field.uploadable input[type="text"] { width: 78%; } .content-blocks .block .field.uploadable input[type="button"] { width: 20% !important; margin-right: 2%; } } diff --git a/assets/plugins/pagebuilder/tpl/add_block.tpl b/assets/plugins/pagebuilder/tpl/add_block.tpl index 5378aff..4236e9a 100644 --- a/assets/plugins/pagebuilder/tpl/add_block.tpl +++ b/assets/plugins/pagebuilder/tpl/add_block.tpl @@ -1,11 +1,11 @@ -
- - renderTpl( 'tpl/add_block_icons.tpl', [ 'configs' => $configs, 'type' => $type ] ); ?> - - renderTpl( 'tpl/add_block_dropdown.tpl', [ 'configs' => $configs ] ); ?> +
+ + renderTpl('tpl/add_block_icons.tpl', ['configs' => $configs, 'type' => $type]); ?> + + renderTpl('tpl/add_block_dropdown.tpl', ['configs' => $configs]); ?> - +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/add_block_dropdown.tpl b/assets/plugins/pagebuilder/tpl/add_block_dropdown.tpl index 0097a97..9d7c555 100644 --- a/assets/plugins/pagebuilder/tpl/add_block_dropdown.tpl +++ b/assets/plugins/pagebuilder/tpl/add_block_dropdown.tpl @@ -1,6 +1,6 @@ diff --git a/assets/plugins/pagebuilder/tpl/add_block_icons.tpl b/assets/plugins/pagebuilder/tpl/add_block_icons.tpl index 6b651c9..5c7cf8d 100644 --- a/assets/plugins/pagebuilder/tpl/add_block_icons.tpl +++ b/assets/plugins/pagebuilder/tpl/add_block_icons.tpl @@ -7,17 +7,19 @@
- $config ) { ?> - - - - - - - - +
+ $config): ?> + + + + + + + + - - - + + + +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/block.tpl b/assets/plugins/pagebuilder/tpl/block.tpl index d9ad75f..7545c52 100644 --- a/assets/plugins/pagebuilder/tpl/block.tpl +++ b/assets/plugins/pagebuilder/tpl/block.tpl @@ -1,12 +1,17 @@
- renderTpl( 'tpl/add_block_dropdown.tpl', [ 'configs' => $configs ] ); ?> + renderTpl('tpl/add_block_dropdown.tpl', ['configs' => $configs]); ?> + +
- + - +
@@ -15,14 +20,14 @@
- -
+ +
- - $field ) { ?> - renderField( $field, $name, isset( $block['values'][$name] ) ? $block['values'][$name] : null ); ?> - - + + $field): ?> + renderField($field, $name, isset($block['values'][$name]) ? $block['values'][$name] : null); ?> + +
@@ -30,9 +35,11 @@
- renderTpl( 'tpl/add_block.tpl', [ - 'configs' => $configs, - 'type' => $type, - ] ) ?> + + renderTpl('tpl/add_block.tpl', [ + 'configs' => $configs, + 'type' => $type, + ]) ?> +
diff --git a/assets/plugins/pagebuilder/tpl/container.tpl b/assets/plugins/pagebuilder/tpl/container.tpl new file mode 100644 index 0000000..821d668 --- /dev/null +++ b/assets/plugins/pagebuilder/tpl/container.tpl @@ -0,0 +1,35 @@ + +
+

+ +
+

+ + +
+ + + renderTpl('tpl/add_block.tpl', [ + 'configs' => $configs, + 'type' => $container['addType'], + ]) ?> + + + + renderTpl('tpl/block.tpl', [ + 'configs' => $configs, + 'block' => $block, + 'addType' => [$container['addType']], + ]); ?> + + +
+
+ + + + diff --git a/assets/plugins/pagebuilder/tpl/field_checkbox.tpl b/assets/plugins/pagebuilder/tpl/field_checkbox.tpl index a66b0df..55e5c5a 100644 --- a/assets/plugins/pagebuilder/tpl/field_checkbox.tpl +++ b/assets/plugins/pagebuilder/tpl/field_checkbox.tpl @@ -1,13 +1,13 @@
- +
- +
- $title ) { ?> + $title): ?>
- +
- +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_date.tpl b/assets/plugins/pagebuilder/tpl/field_date.tpl index c8c5692..dc910d1 100644 --- a/assets/plugins/pagebuilder/tpl/field_date.tpl +++ b/assets/plugins/pagebuilder/tpl/field_date.tpl @@ -1,10 +1,10 @@
- +
- + - + - +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_dropdown.tpl b/assets/plugins/pagebuilder/tpl/field_dropdown.tpl index 8f3c91d..9154c1c 100644 --- a/assets/plugins/pagebuilder/tpl/field_dropdown.tpl +++ b/assets/plugins/pagebuilder/tpl/field_dropdown.tpl @@ -1,11 +1,11 @@
- +
- +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_file.tpl b/assets/plugins/pagebuilder/tpl/field_file.tpl index e965e75..ab65d3c 100644 --- a/assets/plugins/pagebuilder/tpl/field_file.tpl +++ b/assets/plugins/pagebuilder/tpl/field_file.tpl @@ -1,6 +1,6 @@
- +
- - + +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_group.tpl b/assets/plugins/pagebuilder/tpl/field_group.tpl index f6d0add..0dc6c7a 100644 --- a/assets/plugins/pagebuilder/tpl/field_group.tpl +++ b/assets/plugins/pagebuilder/tpl/field_group.tpl @@ -4,14 +4,14 @@
- $value ) { ?> + $value): ?>
- $childfield ) { ?> - renderField( $childfield, $child, isset( $value[$child] ) ? $value[$child] : null ) ?> - + $childfield): ?> + renderField($childfield, $child, isset($value[$child]) ? $value[$child] : null) ?> +
@@ -19,6 +19,6 @@
- +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_image.tpl b/assets/plugins/pagebuilder/tpl/field_image.tpl index 1ccd5d6..0573b47 100644 --- a/assets/plugins/pagebuilder/tpl/field_image.tpl +++ b/assets/plugins/pagebuilder/tpl/field_image.tpl @@ -1,7 +1,7 @@
- +
- +
- +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_radio.tpl b/assets/plugins/pagebuilder/tpl/field_radio.tpl index cf0f27c..ee89d65 100644 --- a/assets/plugins/pagebuilder/tpl/field_radio.tpl +++ b/assets/plugins/pagebuilder/tpl/field_radio.tpl @@ -1,15 +1,15 @@
- +
- + - +
- $title ) { ?> + $title): ?>
- +
- +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_richtext.tpl b/assets/plugins/pagebuilder/tpl/field_richtext.tpl index 8fdf4df..b01c9f4 100644 --- a/assets/plugins/pagebuilder/tpl/field_richtext.tpl +++ b/assets/plugins/pagebuilder/tpl/field_richtext.tpl @@ -1,6 +1,6 @@
- +
- - + +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_text.tpl b/assets/plugins/pagebuilder/tpl/field_text.tpl index 21db148..d0695b7 100644 --- a/assets/plugins/pagebuilder/tpl/field_text.tpl +++ b/assets/plugins/pagebuilder/tpl/field_text.tpl @@ -1,6 +1,6 @@
- -
- - + +
+ +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/field_textarea.tpl b/assets/plugins/pagebuilder/tpl/field_textarea.tpl index 9cc990f..34edead 100644 --- a/assets/plugins/pagebuilder/tpl/field_textarea.tpl +++ b/assets/plugins/pagebuilder/tpl/field_textarea.tpl @@ -1,6 +1,6 @@
- -
- - + +
+ +
\ No newline at end of file diff --git a/assets/plugins/pagebuilder/tpl/form.tpl b/assets/plugins/pagebuilder/tpl/form.tpl index 6b73714..ac6806f 100644 --- a/assets/plugins/pagebuilder/tpl/form.tpl +++ b/assets/plugins/pagebuilder/tpl/form.tpl @@ -2,52 +2,37 @@ - -
-

- +
+ $config): ?> + renderTpl('tpl/block.tpl', [ + 'configs' => $configs, + 'block' => ['config' => $filename], + 'addType' => [], + ]) ?> + +
-
- $config ) { ?> - renderTpl( 'tpl/block.tpl', [ - 'configs' => $configs, - 'block' => [ 'config' => $filename ], - 'type' => $addType, - ] ); ?> - -
- -
- renderTpl( 'tpl/add_block.tpl', [ - 'configs' => $configs, - 'type' => $addType, - ] ) ?> + $container): ?> + renderTpl('tpl/container.tpl', [ + 'name' => $name, + 'container' => $container, + 'blocks' => array_filter($blocks, function($block) use ($container) { + return in_array($block['config'], $container['sections']); + }), + 'configs' => array_filter($configs, function($key) use ($container) { + return in_array($key, $container['sections']); + }, ARRAY_FILTER_USE_KEY), + ]) ?> + - - renderTpl( 'tpl/block.tpl', [ - 'configs' => $configs, - 'block' => $block, - 'type' => $addType, - ] ); ?> - -
- - -
- - -themes as $theme ) { ?> +themes as $theme): ?> - +
Имя параметраЗначение по умолчаниюВозможные значения
docidТекущий документИдентификатор любого существующего документа, целое число
containerdefaultИмя контейнера
blocks*Список блоков через запятую, без пробелов. Берется имя файла конфигурации без расширения (Например, 'all_fields,groups'). Если указать '*', фильтрация по имени произведена не будет
wrapTpl[+wrap+]Имя чанка, содержащего шаблон-обертку для списка блоков выводимого контейнера
templatesИдентификатор группы шаблонов, которые будут использоваться для вывода. Должен быть определен в конфигурации каждого выводимого блока
offset0Число пропускаемых блоков с начала вывода
limit0Число блоков для вывода, либо 0 - для вывода всех