<?php
.sceditor-button-imgur div {
background-image:url(imgur.png);
}
.sceditor-button-imgur div.imgurup {
background-image:url(spinner.gif) !important;
}
<?php
tooltip: 'Insert a video'
});
<?php
/*********************
* Add imgur command *
*********************/
$.sceditor.command.set("imgur", {
_imgur: function () {
document.querySelector('textarea').insertAdjacentHTML( 'afterEnd', '<input class="imgur" style="visibility:hidden;position:absolute;top:0;" type="file" onchange="upload(this.files[0])" accept="image/*">' );
document.querySelector('input.imgur').click();
},
exec: function ()
{
$.sceditor.command.get('imgur')._imgur();
},
txtExec: function()
{
$.sceditor.command.get('imgur')._imgur();
},
tooltip: 'Subir a Imgur'
});
<?php
/*****************************
* Add imgur upload function *
*****************************/
function upload(file) {
/* Is the file an image? */
if (!file || !file.type.match(/image.*/)) return;
/* It is! */
document.body.className = "uploading";
var d = document.querySelector(".sceditor-button-imgur div");
d.className = d.className + " imgurup";
/* Lets build a FormData object*/
var fd = new FormData(); // I wrote about it: https://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/
fd.append("image", file); // Append the file
var xhr = new XMLHttpRequest(); // Create the XHR (Cross-Domain XHR FTW!!!) Thank you sooooo much imgur.com
xhr.open("POST", "https://api.imgur.com/3/image.json"); // Boooom!
xhr.onload = function() {
var code = '[img]' + JSON.parse(xhr.responseText).data.link + '[/img]';
$('#message, #signature, textarea[name*="value"]').data('sceditor').insert(code);
var d = document.querySelector(".sceditor-button-imgur div.imgurup");
d.className = d.className - " imgurup";
document.querySelector('input.imgur').remove();
}
// Ok, I don't handle the errors. An exercice for the reader.
xhr.setRequestHeader('Authorization', 'Client-ID your-key');
/* And now, we send the formdata */
xhr.send(fd);
};
<?php
{$basic2}image,{$email}
<?php
{$basic2}image,imgur,{$email}
(4 Oct, 2014, 12:57 am)XEDE escribió: Yo todavía no lo probé, pero creo que la Key la creas aca https://api.imgur.com/oauth2/addclient completas con tus datos y te da tu Api Key
(4 Oct, 2014, 12:14 pm)XEDE escribió: Osea en las opciones que tenes aca https://api.imgur.com/oauth2/addclient te referís? tendrías que poner:
Application name: MI APP o lo que te guste mas
Authorization type: Anonymous
Authorization callback URL: Seria la url de tu web aunque no estoy seguro si solo con el www funciona en todo caso lo configuras en "Account Settings" una vez lo creas
Application website (optional): esto es opcional
Email: tu e-mail
Description: Lo que quieras
<?php
// Ok, I don't handle the errors. An exercice for the reader.
xhr.setRequestHeader('Authorization', 'Client-ID your-key');