Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
funkjedi authored Oct 25, 2018
2 parents 2b4bf09 + 117c808 commit 1c9db9a
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 163 deletions.
2 changes: 1 addition & 1 deletion acf-qtranslate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Advanced Custom Fields: qTranslate
Plugin URI: http://github.com/funkjedi/acf-qtranslate
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
Version: 1.7.23
Version: 1.7.25
Author: funkjedi
Author URI: http://funkjedi.com
License: GPLv2 or later
Expand Down
127 changes: 49 additions & 78 deletions assets/acf_5/main.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,104 @@
/**
* Clone functionality from standard Image field type
*/
acf.registerFieldType(acf.models.ImageField.extend({
type: 'qtranslate_image',


acf.registerFieldType(acf.models.FileField.extend({
type: 'qtranslate_file',

$control: function(){
return this.$('.acf-image-uploader.current-language');
return this.$('.acf-file-uploader.current-language');
},

$input: function(){
return this.$('.acf-image-uploader.current-language input[type="hidden"]');
return this.$('.acf-file-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,
this.$control().find('img').attr({
src: attachment.icon,
alt: attachment.alt,
title: attachment.title
});

// update elements
this.$control().find('[data-name="title"]').text( attachment.title );
this.$control().find('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url );
this.$control().find('[data-name="filesize"]').text( attachment.filesizeHumanReadable );

// vars
var val = attachment.id || '';

// update val
this.val( val );
acf.val( this.$input(), val );

// update class
if( val ) {
control.addClass('has-value');
this.$control().addClass('has-value');
} else {
control.removeClass('has-value');
this.$control().removeClass('has-value');
}
}
}));

/**
* Clone functionality from standard File field type
*/
acf.registerFieldType(acf.models.QtranslateImageField.extend({
type: 'qtranslate_file',

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
this.$control().find(' img').attr({
src: attachment.icon,
this.$control().find('img').attr({
src: attachment.url,
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 );
this.val( val );

// update class
if( val ) {
control.addClass('has-value');
this.$control().addClass('has-value');
} else {
control.removeClass('has-value');
this.$control().removeClass('has-value');
}
}
}));


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"]');
}
}));


acf.registerFieldType(acf.models.WysiwygField.extend({
type: 'qtranslate_wysiwyg',

initializeEditor: function() {
var self = this;
this.$('.acf-editor-wrap').each(function() {
Expand Down Expand Up @@ -114,51 +133,3 @@ acf.registerFieldType(acf.models.WysiwygField.extend({
}
}));

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');
}
},
}));
14 changes: 9 additions & 5 deletions assets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
z-index: 100;
border: 1px solid #ededed;
margin-left: -1px;
padding: 6px 7px;
text-transform: uppercase;
cursor: pointer
}

.multi-language-field > .wp-switch-editor:last-of-type {
margin-left: 5px;
}

.multi-language-field input,
.multi-language-field input:focus,
.multi-language-field textarea,
Expand Down Expand Up @@ -67,11 +70,11 @@
.multi-language-field > textarea,
.multi-language-field > fieldset,
.multi-language-field .acf_wysiwyg,
.multi-language-field .acf-url,
.multi-language-field .acf-post-object,
.multi-language-field .acf-editor-wrap,
.multi-language-field .acf-file-uploader,
.multi-language-field .acf-image-uploader { display: none }
.multi-language-field .acf-image-uploader,
.multi-language-field .acf-url > input { display: none }

.multi-language-field .acf_input input,
.multi-language-field .acf_input textarea,
Expand All @@ -81,8 +84,9 @@
margin-top: 0;
}

.acf-input .acf-url input[type="text"] {
padding-left: 25px;
.multi-language-field .acf-url {
position: relative;
clear: both;
}

.multi-language-field .acf-file-uploader,
Expand Down
22 changes: 16 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: funkjedi
Tags: acf, advanced custom fields, qtranslate, add-on, admin
Requires at least: 3.5.0
Tested up to: 4.7.2
Version: 1.7.23
Stable tag: 1.7.23
Tested up to: 4.9.8
Version: 1.7.25
Stable tag: 1.7.25
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -21,6 +21,7 @@ This plugin provides qTranslate-X compatible ACF4 and ACF5PRO field types for Te
* qTranslate WYSIWYG (a wordpress wysiwyg editor, api returns html)
* qTranslate Image (upload an image, api returns the url)
* qTranslate File (upload a file, api returns the url)
* qTranslate URL (type text, api returns text)

The standard Text, Text Area and WYSIWYG field types can also be enabled for translation.

Expand All @@ -33,9 +34,9 @@ https://github.com/funkjedi/acf-qtranslate/issues/
1. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress

= Requires ACF4 or ACF5PRO =
= Requires ACF or ACFPRO =
* [ACF](https://wordpress.org/plugins/advanced-custom-fields/)
* [ACF5PRO](http://www.advancedcustomfields.com/pro/)
* [ACFPRO](http://www.advancedcustomfields.com/pro/)

= Requires qTranslate-X Plugin =
* [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
Expand All @@ -54,6 +55,15 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Changelog ==

= 1.7.25 =
* Core: Added qTranslate suffix to field labels
* Bug Fix: Fixed issue with File fields

= 1.7.24 =
* Core: (asedano) Added ACF5 support for URL field
* Bug Fix: (asedano) Added ACF 5.7 compatibility
* Bug Fix: (asedano) Prevent PHP warnings about non-existent indexes

= 1.7.23 =
* Bug Fix: Added ACF 5.6 compatibility

Expand Down Expand Up @@ -182,4 +192,4 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac

== Upgrade Notice ==

Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade
Bug Fix: Fixed issue with File fields
2 changes: 1 addition & 1 deletion src/acf_5/fields/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function initialize() {

// vars
$this->name = 'qtranslate_file';
$this->label = __("File",'acf');
$this->label = __("File (qTranslate)",'acf');
$this->category = __("qTranslate", 'acf');
$this->defaults = array(
'return_format' => 'array',
Expand Down
2 changes: 1 addition & 1 deletion src/acf_5/fields/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function initialize() {

// vars
$this->name = 'qtranslate_image';
$this->label = __("Image",'acf');
$this->label = __("Image (qTranslate)",'acf');
$this->category = __("qTranslate", 'acf');
$this->defaults = array(
'return_format' => 'array',
Expand Down
2 changes: 1 addition & 1 deletion src/acf_5/fields/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function initialize() {

// vars
$this->name = 'qtranslate_text';
$this->label = __("Text",'acf');
$this->label = __("Text (qTranslate)",'acf');
$this->category = __("qTranslate",'acf');
$this->defaults = array(
'default_value' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/acf_5/fields/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function initialize() {

// vars
$this->name = 'qtranslate_textarea';
$this->label = __("Text Area",'acf');
$this->label = __("Text Area (qTranslate)",'acf');
$this->category = __("qTranslate",'acf');
$this->defaults = array(
'default_value' => '',
Expand Down
Loading

0 comments on commit 1c9db9a

Please sign in to comment.