Skip to content

Commit

Permalink
Change coding standard to PSR2
Browse files Browse the repository at this point in the history
  • Loading branch information
puleeno committed Jan 27, 2023
1 parent c6e3fa1 commit 0fb18f9
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 166 deletions.
222 changes: 112 additions & 110 deletions assets/js/wallery.js
Original file line number Diff line number Diff line change
@@ -1,117 +1,119 @@
jQuery(
function ($) {
var file_frame;
$( document ).on(
'click',
'.select-image-box',
function (e) {
var wallery_element = $( this ).parent( '.wallery' );
var wallery_id = $( wallery_element ).attr( 'id' );
e.preventDefault();
if (file_frame) {
file_frame.close();
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: $( this ).data( 'uploader-title' ),
button: {
text: $( this ).data( 'uploader-button-text' ),
},
multiple: true
}
);
file_frame.on(
'select',
function () {
var listIndex = $( wallery_element ).find( '.images-list .image' ).index( $( wallery_element ).find( '.images-list .image:last' ) ),
selection = file_frame.state().get( 'selection' );
selection.map(
function (attachment, i) {
attachment = attachment.toJSON();
index = listIndex + (i + 1);
firstImage = attachment.sizes.thumbnail ? attachment.sizes.thumbnail : _.head( Object.values( attachment.sizes ) );
$( wallery_element ).find( '.images-list' ).append(
'<div class="wallery-image image"><div class="image-inner"><input type="hidden" name="' + wallery_id + '[' + index + ']" value="' + attachment.id + '"><img class="image-preview" src="' + firstImage.url + '"><a class="wallary-action change-image" href="#" data-uploader-title="Change image" data-uploader-button-text="Change image"><span class="wallery-retweet"></span></a><br><a class="wallary-action remove-image" href="#"><span class="wallery-trash"></span></a></div></div>'
);
}
);
}
);
makeSortable();
file_frame.open();
}
);
function ($) {
var file_frame;
$(document).on(
'click',
'.select-image-box',
function (e) {
var wallery_element = $(this).parent('.wallery');
var wallery_id = $(wallery_element).attr('id');
e.preventDefault();
if (file_frame) {
file_frame.close();
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: $(this).data('uploader-title'),
button: {
text: $(this).data('uploader-button-text'),
},
multiple: true
}
);
file_frame.on(
'select',
function () {
var listIndex = $(wallery_element).find('.images-list .image').index($(wallery_element).find('.images-list .image:last')),
selection = file_frame.state().get('selection');
selection.map(
function (attachment, i) {
attachment = attachment.toJSON();
index = listIndex + (i + 1);
firstImage = attachment.sizes.thumbnail ? attachment.sizes.thumbnail : _.head(Object.values(attachment.sizes));
$(wallery_element).find('.images-list').append(
'<div class="wallery-image image"><div class="image-inner"><input type="hidden" name="' + wallery_id + '[' + index + ']" value="' + attachment.id + '"><img class="image-preview" src="' + firstImage.url + '"><a class="wallary-action change-image" href="#" data-uploader-title="Change image" data-uploader-button-text="Change image"><span class="wallery-retweet"></span></a><br><a class="wallary-action remove-image" href="#"><span class="wallery-trash"></span></a></div></div>'
);
}
);
}
);
makeSortable();
file_frame.open();
}
);

$( document ).on(
'click',
'.images-list a.change-image',
function (e) {
$(document).on(
'click',
'.images-list a.change-image',
function (e) {

e.preventDefault();
var that = $( this );
if (file_frame) {
file_frame.close();
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: $( this ).data( 'uploader-title' ),
button: {
text: $( this ).data( 'uploader-button-text' ),
},
multiple: false
}
);
file_frame.on(
'select',
function () {
attachment = file_frame.state().get( 'selection' ).first().toJSON();
firstImage = attachment.sizes.thumbnail ? attachment.sizes.thumbnail : _.head( Object.values( attachment.sizes ) );
that.parent().find( 'input:hidden' ).attr( 'value', attachment.id );
that.parent().find( 'img.image-preview' ).attr( 'src', firstImage.url );
}
);
file_frame.open();
}
);
e.preventDefault();
var that = $(this);
if (file_frame) {
file_frame.close();
}
file_frame = wp.media.frames.file_frame = wp.media(
{
title: $(this).data('uploader-title'),
button: {
text: $(this).data('uploader-button-text'),
},
multiple: false
}
);
file_frame.on(
'select',
function () {
attachment = file_frame.state().get('selection').first().toJSON();
firstImage = attachment.sizes.thumbnail ? attachment.sizes.thumbnail : _.head(Object.values(attachment.sizes));
that.parent().find('input:hidden').attr('value', attachment.id);
that.parent().find('img.image-preview').attr('src', firstImage.url);
}
);
file_frame.open();
}
);

function resetIndex() {
$( '.images-list .image' ).each(
function (i) {
var wallery_id = $( this ).parents( '.images-list' ).parent().attr( 'id' );
$( this ).find( 'input:hidden' ).attr( 'name', wallery_id + '[' + i + ']' );
}
);
}
function resetIndex()
{
$('.images-list .image').each(
function (i) {
var wallery_id = $(this).parents('.images-list').parent().attr('id');
$(this).find('input:hidden').attr('name', wallery_id + '[' + i + ']');
}
);
}

function makeSortable() {
$( '.images-list' ).sortable(
{
opacity: 0.6,
float: 'left',
stop: function () {
resetIndex();
}
}
);
}
$( document ).on(
'click',
'.images-list a.remove-image',
function (e) {
e.preventDefault();
$( this ).parents( '.image' ).animate(
{
opacity: 0
},
200,
function () {
$( this ).remove();
resetIndex();
}
);
}
);
function makeSortable()
{
$('.images-list').sortable(
{
opacity: 0.6,
float: 'left',
stop: function () {
resetIndex();
}
}
);
}
$(document).on(
'click',
'.images-list a.remove-image',
function (e) {
e.preventDefault();
$(this).parents('.image').animate(
{
opacity: 0
},
200,
function () {
$(this).remove();
resetIndex();
}
);
}
);

makeSortable();
}
makeSortable();
}
);
26 changes: 13 additions & 13 deletions templates/image-content.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="wallery-image image">
<div class="image-inner">
<input type="hidden" name="<?php echo $wallery_id; ?>[<?php echo $index; ?>]" value="<?php echo $image['id']; ?>">
<img class="image-preview" src="<?php echo $image['src']; ?>">
<a
class="wallary-action change-image"
href="#"
data-uploader-title="<?php _e( 'Change Images', 'wallery' ); ?>"
data-uploader-button-text="<?php _e( 'Change Images', 'wallery' ); ?>"
>
<span class="wallery-retweet"></span>
</a>
<a class="wallary-action remove-image" href="#"><span class="wallery-trash"></span></a>
</div>
<div class="image-inner">
<input type="hidden" name="<?php echo $wallery_id; ?>[<?php echo $index; ?>]" value="<?php echo $image['id']; ?>">
<img class="image-preview" src="<?php echo $image['src']; ?>">
<a
class="wallary-action change-image"
href="#"
data-uploader-title="<?php _e('Change Images', 'wallery'); ?>"
data-uploader-button-text="<?php _e('Change Images', 'wallery'); ?>"
>
<span class="wallery-retweet"></span>
</a>
<a class="wallary-action remove-image" href="#"><span class="wallery-trash"></span></a>
</div>
</div>
28 changes: 14 additions & 14 deletions templates/image-list-styles.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div class="toolbar image-layouts">
<h2 class="heading-images">
<?php echo esc_html($heading_text); ?>
</h2>
<div class="layouts">
<div class="layout layout-list">
<span class="wallery-list"></span>
</div>
<div class="layout layout-thumbnail">
<span class="wallery-layout"></span>
</div>
<?php do_action( 'wallery_layouts' ); ?>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<h2 class="heading-images">
<?php echo esc_html($heading_text); ?>
</h2>
<div class="layouts">
<div class="layout layout-list">
<span class="wallery-list"></span>
</div>
<div class="layout layout-thumbnail">
<span class="wallery-layout"></span>
</div>
<?php do_action('wallery_layouts'); ?>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
58 changes: 29 additions & 29 deletions templates/select-box.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<div id="<?php echo $wallery_id; ?>" class="wallery">
<div class="select-image-box">
<div class="wrapper">
<div class="outline">
<i class="wallery-upload"></i>
</div>
</div>
</div>
<div class="wallery-toolbars">
<?php if ( has_action( 'wallery_left_toolbars' ) || has_action( 'wallery_right_toolbars' ) ) : ?>
<div class="wallery-toolbar-inner">
<div class="wallery-left-toolbar">
<?php do_action( 'wallery_left_toolbars' ); ?>
</div>
<div class="wallery-right-toolbar">
<?php do_action( 'wallery_right_toolbars' ); ?>
</div>
</div>
<?php endif; ?>
<div class="wallery-toolbar-inner">
<?php do_action( 'wallery_toolbars' ); ?>
</div>
</div>
<div class="images-list">
<?php
foreach ( $images as $index => $image ) {
wallery_load_template( 'image-content', compact( 'index', 'image', 'wallery_id' ) );
}
?>
</div>
<div class="select-image-box">
<div class="wrapper">
<div class="outline">
<i class="wallery-upload"></i>
</div>
</div>
</div>
<div class="wallery-toolbars">
<?php if (has_action('wallery_left_toolbars') || has_action('wallery_right_toolbars')) : ?>
<div class="wallery-toolbar-inner">
<div class="wallery-left-toolbar">
<?php do_action('wallery_left_toolbars'); ?>
</div>
<div class="wallery-right-toolbar">
<?php do_action('wallery_right_toolbars'); ?>
</div>
</div>
<?php endif; ?>
<div class="wallery-toolbar-inner">
<?php do_action('wallery_toolbars'); ?>
</div>
</div>
<div class="images-list">
<?php
foreach ($images as $index => $image) {
wallery_load_template('image-content', compact('index', 'image', 'wallery_id'));
}
?>
</div>
</div>

0 comments on commit 0fb18f9

Please sign in to comment.