Skip to content

Commit

Permalink
General improvments and adjusts preparing the release of 1.0
Browse files Browse the repository at this point in the history
- Fixed autoload
- Fixed Odin Framework 2.0 classes incorporation
- Fixed shortcode creation
- Fixed get_template_directory calls
- Inserted and fixed the load of JavaScritps
- Inserted meta box placeholder images
  • Loading branch information
allysonsouza committed Sep 30, 2018
1 parent e99db91 commit e2b95c8
Show file tree
Hide file tree
Showing 24 changed files with 1,622 additions and 292 deletions.
20 changes: 0 additions & 20 deletions .editorconfig

This file was deleted.

24 changes: 0 additions & 24 deletions .jshintrc

This file was deleted.

Empty file added assets/css/admin.css
Empty file.
Binary file added assets/images/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions assets/js/admin-custom-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function ( $ ) {
'use strict';

/**
* Custom post status
*/
$(function() {
var html = '';
var label = false;
var $body = $( document.body );
var $odinMeta = document.querySelectorAll( 'meta.odin-custom-status-meta' );

Array.prototype.forEach.call( $odinMeta, function( item ) {
var $meta = $( item );
var args = $.parseJSON( $meta.attr( 'value' ) );

if( $body.hasClass( 'post-php' ) || $body.hasClass( 'post-new-php' ) ) {
var select = '';
if( args.select ) {
select = 'selected="selected"';
label = '<span id="post-status-display">&nbsp;' + $.trim( args.appliedLabel ) + '</span>';
}
html += '<option value="' + $.trim( args.slug ) + '" ' + $.trim( select ) + '>' + $.trim( args.appliedLabel ) + '</option>';
}
if( $body.hasClass( 'edit-php' ) ) {
html += '<option value="' + $.trim( args.slug ) + '">' + $.trim( args.appliedLabel ) + '</option>';
}
});
if( $body.hasClass( 'post-php' ) || $body.hasClass( 'post-new-php' ) ) {
$( '#post_status ').append( html );
if( label ) {
$( 'label[for="post_status"]' ).append( label );
}
}
if( $body.hasClass( 'edit-php' ) ) {
var $inlineStatus = document.querySelectorAll( '.inline-edit-status select' );
Array.prototype.forEach.call( $inlineStatus, function( item ) {
$( item ).append( html );
});
}
});
}( jQuery ));
219 changes: 219 additions & 0 deletions assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/* global odinAdminParams */
(function ( $ ) {
'use strict';

/**
* Theme Options and Metaboxes.
*/
$( function () {

/**
* Image field.
*/
$( '.odin-upload-image .button' ).on( 'click', function ( e ) {
e.preventDefault();

var uploadFrame,
uploadInput = $(this).siblings( '.image' ),
uploadPreview = $(this).siblings( '.preview' );

// If the media frame already exists, reopen it.
if ( uploadFrame ) {
uploadFrame.open();

return;
}

// Create the media frame.
uploadFrame = wp.media.frames.downloadable_file = wp.media({
title: odinAdminParams.uploadTitle,
button: {
text: odinAdminParams.uploadButton
},
multiple: false,
library: {
type: 'image'
}
});

uploadFrame.on( 'select', function () {
var attachment = uploadFrame.state().get( 'selection' ).first().toJSON();
uploadPreview.attr( 'src', attachment.url );
uploadInput.val( attachment.id );
});

// Finally, open the modal.
uploadFrame.open();
});

$( '.odin-upload-image .delete' ).click( function ( e ) {
e.preventDefault();

var wrapper = $( this ).parents( '.odin-upload-image' ),
defaultImage = $( '.default-image', wrapper ).text();

$( '.image', wrapper ).val( '' );
$( '.preview', wrapper ).attr( 'src', defaultImage );
});

/**
* Upload.
*/
$( '.odin-upload-button' ).on( 'click', function ( e ) {
e.preventDefault();

var uploadFrame,
uploadInput = $( this ).prev( 'input' );

// If the media frame already exists, reopen it.
if ( uploadFrame ) {
uploadFrame.open();

return;
}

// Create the media frame.
uploadFrame = wp.media.frames.downloadable_file = wp.media({
title: odinAdminParams.uploadTitle,
button: {
text: odinAdminParams.uploadButton
},
multiple: false
});

uploadFrame.on( 'select', function () {
var attachment = uploadFrame.state().get( 'selection').first().toJSON();
uploadInput.val( attachment.url );
});

// Finally, open the modal.
uploadFrame.open();
});

/**
* Color Picker.
*/
$( '.odin-color-field' ).wpColorPicker();

/**
* Image plupload adds.
*/
$( '.odin-gallery-container' ).on( 'click', '.odin-gallery-add', function ( e ) {
e.preventDefault();

var galleryFrame,
galleryWrap = $( this ).parent( '.odin-gallery-container' ),
imageGalleryIds = $( '.odin-gallery-field', galleryWrap ),
images = $( 'ul.odin-gallery-images', galleryWrap ),
attachmentIds = imageGalleryIds.val();

// If the media frame already exists, reopen it.
if ( galleryFrame ) {
galleryFrame.open();

return;
}

// Create the media frame.
galleryFrame = wp.media.frames.downloadable_file = wp.media({
title: odinAdminParams.galleryTitle,
button: {
text: odinAdminParams.galleryButton
},
multiple: true,
library: {
type: 'image'
}
});

// When an image is selected, run a callback.
galleryFrame.on( 'select', function () {

var selection = galleryFrame.state().get( 'selection' );

selection.map( function ( attachment ) {

attachment = attachment.toJSON();

if ( attachment.id ) {
attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id;

images.append( '<li class="image" data-attachment_id="' + attachment.id + '"><img src="' + attachment.url + '" /><ul class="actions"><li><a href="#" class="delete" title="' + odinAdminParams.galleryRemove + '">X</a></li></ul></li>' );
}

});

imageGalleryIds.val( attachmentIds );
});

// Finally, open the modal.
galleryFrame.open();
});

/**
* Image plupload ordering.
*/
$( '.odin-gallery-container' ).on( 'mouseover', 'ul.odin-gallery-images', function () {
var galleryWrap = $( this ).parent( '.odin-gallery-container' ),
imageGalleryIds = $( '.odin-gallery-field', galleryWrap );

// Call the sortable action.
$( this ).sortable({
items: 'li.image',
cursor: 'move',
scrollSensitivity: 40,
forcePlaceholderSize: true,
forceHelperSize: false,
helper: 'clone',
opacity: 0.65,
placeholder: 'wc-metabox-sortable-placeholder',
start: function ( event, ui ) {
ui.item.css('background-color', '#f6f6f6');
}, stop: function ( event, ui ) {
ui.item.removeAttr( 'style' );
}, update: function () {
var attachmentIds = '';

// Gets the current ids.
$( 'li.image', $( this ) ).css( 'cursor', 'default' ).each( function () {
var attachmentId = $( this ).attr( 'data-attachment_id' );
attachmentIds = attachmentIds + attachmentId + ',';
});

// Return the new value.
imageGalleryIds.val( attachmentIds );
}
});
});

/**
* Image plupload remove link.
*/
$( '.odin-gallery-container' ).on( 'click', 'a.delete', function ( e ) {
e.preventDefault();

var galleryWrap = $( this ).parents( '.odin-gallery-container' ),
imageGalleryIds = $( '.odin-gallery-field', galleryWrap ),
attachmentIds = '';

// Remove the item.
$( this ).closest( 'li.image' ).remove();

// Gets the current ids.
$( 'ul li.image', galleryWrap ).css( 'cursor', 'default' ).each( function () {
var attachmentId = $( this ).attr( 'data-attachment_id' );
attachmentIds = attachmentIds ? attachmentIds + ',' + attachmentId : attachmentId;
});

// Return the new value.
imageGalleryIds.val( attachmentIds );
});
/**
* Save editor field in add term screen
*/
$( 'body.edit-tags-php .wp-editor-wrap' ).on( 'mouseover mouseout', function( e ) {
tinyMCE.triggerSave();
});

});
}( jQuery ));
Loading

0 comments on commit e2b95c8

Please sign in to comment.