This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from asedano/master
Compatibility with 5.7
- Loading branch information
Showing
7 changed files
with
285 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,164 @@ | ||
|
||
/** | ||
* Clone functionality from standard Image field type | ||
*/ | ||
acf.fields.qtranslate_image = acf.fields.image.extend({ | ||
type: 'qtranslate_image', | ||
focus: function() { | ||
this.$el = this.$field.find('.acf-image-uploader.current-language'); | ||
this.$input = this.$el.find('input[type="hidden"]'); | ||
this.$img = this.$el.find('img'); | ||
|
||
this.o = acf.get_data(this.$el); | ||
acf.registerFieldType(acf.models.ImageField.extend({ | ||
type: 'qtranslate_image', | ||
|
||
$control: function(){ | ||
return this.$('.acf-image-uploader.current-language'); | ||
}, | ||
|
||
$input: function(){ | ||
return this.$('.acf-image-uploader.current-language input[type="hidden"]'); | ||
}, | ||
|
||
render: function( attachment ){ | ||
var control = this.$control(); | ||
|
||
// vars | ||
attachment = this.validateAttachment( attachment ); | ||
|
||
// update image | ||
control.find('img').attr({ | ||
src: attachment.url, | ||
alt: attachment.alt, | ||
title: attachment.title | ||
}); | ||
|
||
// vars | ||
var val = attachment.id || ''; | ||
|
||
// update val | ||
this.val( val ); | ||
|
||
// update class | ||
if( val ) { | ||
control.addClass('has-value'); | ||
} else { | ||
control.removeClass('has-value'); | ||
} | ||
}); | ||
} | ||
})); | ||
|
||
/** | ||
* Clone functionality from standard File field type | ||
*/ | ||
acf.fields.qtranslate_file = acf.fields.file.extend({ | ||
type: 'qtranslate_file', | ||
focus: function() { | ||
this.$el = this.$field.find('.acf-file-uploader.current-language'); | ||
this.$input = this.$el.find('input[type="hidden"]'); | ||
acf.registerFieldType(acf.models.QtranslateImageField.extend({ | ||
type: 'qtranslate_file', | ||
render: function( attachment ){ | ||
var control = this.$control(); | ||
|
||
// vars | ||
attachment = this.validateAttachment( attachment ); | ||
|
||
this.o = acf.get_data(this.$el); | ||
// update image | ||
this.$control().find(' img').attr({ | ||
src: attachment.icon, | ||
alt: attachment.alt, | ||
title: attachment.title | ||
}); | ||
|
||
// update elements | ||
control.find('[data-name="title"]').text( attachment.title ); | ||
control.find('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url ); | ||
control.find('[data-name="filesize"]').text( attachment.filesizeHumanReadable ); | ||
|
||
// vars | ||
var val = attachment.id || ''; | ||
|
||
// update val | ||
acf.val( this.$input(), val ); | ||
|
||
// update class | ||
if( val ) { | ||
control.addClass('has-value'); | ||
} else { | ||
control.removeClass('has-value'); | ||
} | ||
}); | ||
}, | ||
})); | ||
|
||
/** | ||
* Clone functionality from standard WYSIWYG field type | ||
*/ | ||
acf.fields.qtranslate_wysiwyg = acf.fields.wysiwyg.extend({ | ||
type: 'qtranslate_wysiwyg', | ||
focus: function() { | ||
this.$el = this.$field.find('.wp-editor-wrap.current-language').last(); | ||
this.$textarea = this.$el.find('textarea'); | ||
this.o = acf.get_data(this.$el); | ||
this.o.id = this.$textarea.attr('id'); | ||
}, | ||
initialize: function() { | ||
var self = this; | ||
this.$field.find('.wp-editor-wrap').each(function() { | ||
self.$el = jQuery(this); | ||
self.$textarea = self.$el.find('textarea'); | ||
self.o = acf.get_data(self.$el); | ||
self.o.id = self.$textarea.attr('id'); | ||
acf.fields.wysiwyg.initialize.call(self); | ||
}); | ||
this.focus(); | ||
acf.registerFieldType(acf.models.WysiwygField.extend({ | ||
type: 'qtranslate_wysiwyg', | ||
initializeEditor: function() { | ||
var self = this; | ||
this.$('.acf-editor-wrap').each(function() { | ||
var $wrap = $(this); | ||
var $textarea = $wrap.find('textarea'); | ||
var args = { | ||
tinymce: true, | ||
quicktags: true, | ||
toolbar: self.get('toolbar'), | ||
mode: self.getMode(), | ||
field: self | ||
}; | ||
|
||
// generate new id | ||
var oldId = $textarea.attr('id'); | ||
var newId = acf.uniqueId('acf-editor-'); | ||
|
||
// rename | ||
acf.rename({ | ||
target: $wrap, | ||
search: oldId, | ||
replace: newId, | ||
destructive: true | ||
}); | ||
|
||
// update id | ||
self.set('id', newId, true); | ||
|
||
// initialize | ||
acf.tinymce.initialize(newId, args); | ||
}); | ||
} | ||
})); | ||
|
||
acf.registerFieldType(acf.models.UrlField.extend({ | ||
type: 'qtranslate_url', | ||
$control: function(){ | ||
return this.$('.acf-input-wrap.current-language'); | ||
}, | ||
|
||
$input: function(){ | ||
return this.$('.acf-input-wrap.current-language input[type="url"]'); | ||
}, | ||
isValid: function(){ | ||
|
||
// vars | ||
var val = this.val(); | ||
|
||
// bail early if no val | ||
if( !val ) { | ||
return false; | ||
} | ||
|
||
// url | ||
if( val.indexOf('://') !== -1 ) { | ||
return true; | ||
} | ||
|
||
// protocol relative url | ||
if( val.indexOf('//') === 0 ) { | ||
return true; | ||
} | ||
|
||
// relative url | ||
if( val.indexOf('/') === 0 ) { | ||
return true; | ||
} | ||
|
||
// return | ||
return false; | ||
}, | ||
|
||
render: function(){ | ||
|
||
// add class | ||
if( this.isValid() ) { | ||
this.$control().addClass('-valid'); | ||
} else { | ||
this.$control().removeClass('-valid'); | ||
} | ||
}); | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
class acf_qtranslate_acf_5_url extends acf_qtranslate_acf_5_text { | ||
function initialize() { | ||
|
||
// vars | ||
$this->name = 'qtranslate_url'; | ||
$this->label = __("Url",'acf'); | ||
$this->category = __("qTranslate",'acf'); | ||
$this->defaults = array( | ||
'default_value' => '', | ||
'maxlength' => '', | ||
'placeholder' => '', | ||
'prepend' => '', | ||
'append' => '' | ||
); | ||
|
||
} | ||
|
||
/* | ||
* render_field() | ||
* | ||
* Create the HTML interface for your field | ||
* | ||
* @param $field - an array holding all the field's data | ||
* | ||
* @type action | ||
* @since 3.6 | ||
* @date 23/01/13 | ||
*/ | ||
function render_field($field) { | ||
global $q_config; | ||
$languages = qtrans_getSortedLanguages(true); | ||
$values = qtrans_split($field['value'], $quicktags = true); | ||
$currentLanguage = $this->plugin->get_active_language(); | ||
|
||
// vars | ||
$o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); | ||
$s = array( 'readonly', 'disabled' ); | ||
$e = ''; | ||
|
||
// maxlength | ||
if( $field['maxlength'] !== "" ) { | ||
$o[] = 'maxlength'; | ||
} | ||
|
||
// populate atts | ||
$atts = array(); | ||
foreach( $o as $k ) { | ||
$atts[ $k ] = $field[ $k ]; | ||
} | ||
|
||
// special atts | ||
foreach( $s as $k ) { | ||
if( isset($field[ $k ]) && $field[ $k ] ) { | ||
$atts[ $k ] = $k; | ||
} | ||
} | ||
|
||
// render | ||
$e .= '<div class="acf-url-wrap multi-language-field">'; | ||
|
||
foreach ($languages as $language) { | ||
$class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor'; | ||
$e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; | ||
} | ||
|
||
foreach ($languages as $language) { | ||
$atts['class'] = $field['class']; | ||
|
||
$atts['type'] = 'text'; | ||
$atts['name'] = $field['name'] . "[$language]"; | ||
$atts['value'] = $values[$language]; | ||
|
||
$container_class = 'acf-input-wrap acf-url'; | ||
if ($language === $currentLanguage) { | ||
$container_class .= ' current-language'; | ||
} | ||
|
||
$e .= '<div class="' . $container_class . '" data-language="' . $language . '">'; | ||
$e .= '<i class="acf-icon -globe -small"></i>'; | ||
$e .= '<input ' . acf_esc_attr( $atts ) . ' />'; | ||
$e .= '</div>'; | ||
|
||
} | ||
|
||
$e .= '</div>'; | ||
|
||
// return | ||
echo $e; | ||
} | ||
|
||
function validate_value( $valid, $value, $field, $input ){ | ||
foreach ($value as $valor) { | ||
// bail early if empty | ||
if ( empty( $valor ) ) { | ||
|
||
continue; | ||
|
||
} | ||
|
||
if ( strpos( $valor, '://' ) !== false ) { | ||
|
||
// url | ||
|
||
} elseif ( strpos( $valor, '//' ) === 0 ) { | ||
|
||
// protocol relative url | ||
|
||
} elseif ( strpos( $valor, '/' ) === 0 ) { | ||
|
||
// relative url | ||
|
||
} else { | ||
|
||
$valid = __( 'Value must be a valid URL', 'acf' ); | ||
|
||
} | ||
} | ||
|
||
// return | ||
return $valid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters