Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
someguy9 committed May 22, 2022
1 parent c528875 commit 3a86761
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 66 deletions.
23 changes: 15 additions & 8 deletions inc/admin/assets/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ function toggleApiKeyFieldMask(field) {
const selectedField = document.querySelector(field);
selectedField.type = this.event.target.checked ? "text" : "password";
}
function renderMightyShareTemplatePreview(){
const result = document.querySelector(".mightyshare-image-preview");
const templateSelected = document.querySelector(".default_template_field").value;
if( templateSelected != "screenshot-self" ){
function renderMightyShareTemplatePreview(event){
const result = event.closest("td").querySelector(".mightyshare-image-preview");
const templateSelected = event.value;
if( templateSelected && templateSelected != "screenshot-self" ){
result.innerHTML = `<img src="https://api.mightyshare.io/template/preview/${templateSelected}.png">`;
}else{
result.innerHTML = ``;
}
}

const selectElement = document.querySelector(".default_template_field");
selectElement.addEventListener("change", (event) => {
renderMightyShareTemplatePreview();
}); document.addEventListener("DOMContentLoaded",renderMightyShareTemplatePreview);
document.querySelectorAll(".mightyshare_template_field").forEach(item => {
item.addEventListener('change', event => {
renderMightyShareTemplatePreview(event.target);
})
});

document.addEventListener("DOMContentLoaded", event => {
document.querySelectorAll(".mightyshare_template_field").forEach(item => {
renderMightyShareTemplatePreview(item);
})
});

jQuery(document).ready(function(){
jQuery(function() {
Expand Down
25 changes: 22 additions & 3 deletions inc/admin/mightyshare-metaboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,41 @@ function render_mightyshare_select_field( $param, $value = '', $prefix = '' ) {
<?php
}

function render_mightyshare_text_field( $param, $value = '', $prefix = '' ) {

$value = $value ? $value : ( isset( $param['default'] ) ? $param['default'] : '' );

?>
<input type="text" value="<?php echo esc_attr( $value ); ?>" id="<?php echo esc_attr( $prefix . $param['id'] ); ?>" name="<?php echo esc_attr( $param['id'] ); ?>" class="<?php echo esc_attr( ( ! empty( $param['classes'] ) ? ' ' . $param['classes'] : '' ) ); ?>" value="<?php echo esc_attr( $value ); ?>">
<?php
}

function render_mightyshare_color_field( $param, $value = '', $prefix = '' ) {

$value = $value ? $value : ( isset( $param['default'] ) ? $param['default'] : '' );

?>
<input type="text" value="<?php echo esc_attr( $value ); ?>" id="<?php echo esc_attr( $prefix . $param['id'] ); ?>" name="<?php echo esc_attr( $param['id'] ); ?>" class="mightyshare_color_field<?php echo esc_attr( ( ! empty( $param['classes'] ) ? ' ' . $param['classes'] : '' ) ); ?>" value="<?php echo esc_attr( $value ); ?>">
<?php
}

function render_mightyshare_checkbox_field( $param, $value = '', $prefix = '' ) {

$value = ( 'yes' === $value || ( ! $value && isset( $param['default'] ) && 'yes' === $param['default'] ) ) ? 'yes' : 'no';
$label = ! empty( $param['short_description'] ) ? $param['short_description'] : '';
$id = ! empty( $param['id'] ) ? $param['id'] : uniqid();
?>
<input type="checkbox"
id="<?php echo esc_attr( $prefix . $param['id'] ); ?>"
name="<?php echo esc_attr( $param['id'] ); ?>"
id="<?php echo esc_attr( $prefix . $id ); ?>"
name="<?php echo ! empty( $param['name'] ) ? esc_attr( $param['name'] ) : esc_attr( $param['id'] ); ?>"
<?php if ( ! empty( $param['set_value'] ) ) { ?>
value="<?php echo esc_attr( $param['set_value'] ); ?>"
<?php }; ?>
<?php echo checked( 'yes', $value, false ); ?> />
<?php
if ( ! empty( $param['label'] ) ) {
?>
<label for="<?php echo esc_attr( $prefix . $param['id'] ); ?>" class="mightyshare-label checkbox"> <?php echo esc_attr( $label ); ?></label>
<label for="<?php echo esc_attr( $prefix . $id ); ?>" class="mightyshare-label checkbox"> <?php echo esc_attr( $label ); ?></label>
<?php
}
}
Expand Down
Loading

0 comments on commit 3a86761

Please sign in to comment.