Skip to content

Commit

Permalink
Merge pull request #17 from ZNick1982/wp-4.7.1
Browse files Browse the repository at this point in the history
fixes for wp 7.4.1
  • Loading branch information
dmitry-mukhin committed Mar 2, 2017
2 parents 184ee1d + 4d5eacb commit 1967fa4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Changelog
**2.4.1** ([Download](http://downloads.wordpress.org/plugin/uploadcare.2.4.1.zip))
* Minor bug fix for usage jQuery.
* Test up to Wordpress 4.7.2

**2.4.0** ([Download](http://downloads.wordpress.org/plugin/uploadcare.2.4.0.zip))
* Uploadcare widget updated to version 2.6.0
Expand Down
70 changes: 45 additions & 25 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

function ucEditFile(file_id) {
try {
tb_remove();
Expand All @@ -15,7 +17,7 @@ function ucStoreImg(fileInfo, callback) {
'action': 'uploadcare_handle',
'file_id': fileInfo.uuid
};
jQuery.post(ajaxurl, data, function(response) {
uploadcare.jQuery.post(ajaxurl, data, function(response) {
if (callback) {
callback(response);
}
Expand All @@ -25,21 +27,21 @@ function ucStoreImg(fileInfo, callback) {
function ucAddImg(fileInfo) {
ucStoreImg(fileInfo, function(response) {
if (fileInfo.isImage) {
var $img = '<img src="' + fileInfo.cdnUrl + '\" alt="' + fileInfo.name + '"/>';
var $img = '<img src="' + fileInfo.cdnUrl + '" alt="' + fileInfo.name + '"/>';
if(UPLOADCARE_CONF.original) {
window.send_to_editor('<a href="' + UPLOADCARE_CDN_BASE + fileInfo.uuid + '/">' + $img + '</a>');
window.send_to_editor('<a href="' + fileInfo.cdnUrl + '">' + $img + '</a>');
} else {
window.send_to_editor($img);
}
} else {
window.send_to_editor('<a href="' + fileInfo.cdnUrl + '\">' + fileInfo.name + '</a>');
window.send_to_editor('<a href="' + fileInfo.cdnUrl + '">' + fileInfo.name + '</a>');
}
window.send_to_editor('\n');
});
}

function ucFileDone(data) {
jQuery('#content').prop('disabled', true);
uploadcare.jQuery('#content').prop('disabled', true);
if(UPLOADCARE_MULTIPLE) {
data.promise().done(function(fileGroupInfo) {
var files = data.files();
Expand All @@ -50,13 +52,13 @@ function ucFileDone(data) {
});
}
}).always(function() {
jQuery('#content').prop('disabled', false);
uploadcare.jQuery('#content').prop('disabled', false);
});
} else {
var file = data;
file.done(ucAddImg)
.always(function() {
jQuery('#content').prop('disabled', false);
uploadcare.jQuery('#content').prop('disabled', false);
});
}
}
Expand All @@ -82,12 +84,26 @@ function ucPostUploadUiBtn() {
}
}
if(wp.media) {
// select attachment
var obj = jQuery.parseJSON(response);
var selection = wp.media.frame.state().get('selection'),
attachment = wp.media.attachment(obj.attach_id);
var obj = uploadcare.jQuery.parseJSON(response);
var attachment = wp.media.attachment(obj.attach_id);
attachment.fetch();
selection.add(attachment);
var library = null;
switch(wp.media.frame._state) {
case 'insert':
case 'gallery':
case 'featured-image':
case 'library':
wp.media.frame.content.mode('browse');
library = wp.media.frame.content.mode('library').get().collection;
break;
case 'edit-attachment':
library = wp.media.frame.content.mode('library').view.library;
break;
}

if(library) {
library.add(attachment);
}
}
stored++;
if(stored == files.length) {
Expand All @@ -97,8 +113,12 @@ function ucPostUploadUiBtn() {
if(wp.media) {
// switch to attachment browser
wp.media.frame.content.mode('browse');

// refresh attachment collection
updateAttachments();
// no need for WP 4.7.2 but kept for older WP versions
try {
updateAttachments();
} catch(ex) {}
} else if (adminpage == 'media-new-php') {
location = 'upload.php';
}
Expand All @@ -110,19 +130,19 @@ function ucPostUploadUiBtn() {
});
}

jQuery(function() {
uploadcare.jQuery(function() {
// add button to all inputs with .uploadcare-url-field
jQuery('input.uploadcare-url-field').each(function() {
var input = jQuery(this);
var img = jQuery('<img />');
uploadcare.jQuery('input.uploadcare-url-field').each(function() {
var input = uploadcare.jQuery(this);
var img = uploadcare.jQuery('<img />');
var preview = function() {
if(input.val().length > 0) {
img.attr('src', input.val() + '-/preview/300x300/');
}
};
input.before(img);
preview();
input.after(jQuery('<a class="button"><span>uc</span></a>').on('click', function() {
input.after(uploadcare.jQuery('<a class="button"><span>uc</span></a>').on('click', function() {
uploadcare.openDialog(null, {multiple: false}).done(function(data) {
data.done(function(fileInfo) {
ucStoreImg(fileInfo, function() {
Expand All @@ -135,8 +155,8 @@ jQuery(function() {
});

// featured image stuff
var addLink = jQuery('#uc-set-featured-img');
var removeLink = jQuery('#uc-remove-featured-img');
var addLink = uploadcare.jQuery('#uc-set-featured-img');
var removeLink = uploadcare.jQuery('#uc-remove-featured-img');

function setImg() {
var url = addLink.data('uc-url');
Expand All @@ -160,25 +180,25 @@ jQuery(function() {
data.done(function(fileInfo) {
ucStoreImg(fileInfo, function() {
addLink.data('uc-url', fileInfo.cdnUrl);
jQuery('#uc-featured-image-input').val(fileInfo.cdnUrl);
uploadcare.jQuery('#uc-featured-image-input').val(fileInfo.cdnUrl);
setImg();
});
});
});
});

removeLink.click(function() {
jQuery('#uc-featured-image-input').val('');
uploadcare.jQuery('#uc-featured-image-input').val('');
addLink.data('uc-url', '');
setImg();
});

setImg();

// media tab
jQuery('#uploadcare-more').on('click', function() {
jQuery('#uploadcare-more-container').hide();
jQuery('#uploadcare-lib-container').hide();
uploadcare.jQuery('#uploadcare-more').on('click', function() {
uploadcare.jQuery('#uploadcare-more-container').hide();
uploadcare.jQuery('#uploadcare-lib-container').hide();
uploadcare.openPanel('#uploadcare-panel-container', [], {
multiple: true,
autostore: true
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Contributors: grayhound1, dmitry-mukhin
Tags: media upload, file handling, cdn, storage, facebook, dropbox, instagram, google drive, vk, evernote, box, images, flickr
Requires at least: 3.5+
Tested up to: 4.4.2
Stable tag: 2.4.0
Tested up to: 4.7.2
Stable tag: 2.4.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Donate link: https://uploadcare.com/pricing/
Expand Down Expand Up @@ -115,6 +115,10 @@ Access all files in your Uploadcare account via Media Library.

== Changelog ==

= 2.4.1 =
* Minor bug fix for usage jQuery.
* Test up to Wordpress 4.7.2

= 2.4.0 =
* Uploadcare widget updated to version 2.6.0
* Test up to Wordpress 4.4.2
Expand Down
4 changes: 2 additions & 2 deletions uploadcare.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Uploadcare
Plugin URI: http://github.com/uploadcare/uploadcare-wordpress
Description: Uploadcare let's you upload anything from anywhere (Instagram, Facebook, Dropbox, etc.)
Version: 2.5.1
Version: 2.4.1
Author: Uploadcare
Author URI: https://uploadcare.com/
License: GPL2
Expand All @@ -14,7 +14,7 @@
exit("Uploadcare plugin requires PHP version <b>5.3+</b>, you've got <b>" . PHP_VERSION . "</b>");
}

define('UPLOADCARE_PLUGIN_VERSION', '2.5.1');
define('UPLOADCARE_PLUGIN_VERSION', '2.4.1');
define('UPLOADCARE_WIDGET_VERSION', '2.x');

define('UPLOADCARE_PLUGIN_URL', plugin_dir_url(__FILE__));
Expand Down

0 comments on commit 1967fa4

Please sign in to comment.