/**
* AdSimple-Vote — Let the users to vote with just one simple click. Create a question and get deep insights in the process. Listen your audience.
* @encoding UTF-8
* @version 1.0.0
* @copyright Copyright (C) 2018 AdSimple (https://www.adsimple.at). All rights reserved.
* @license GPLv2 or later; See http://www.gnu.org/licenses/gpl-2.0.html
* @author Alexander Khmelnitskiy (hi@alexander.khmelnitskiy.ua)
* @support support@adsimple.at
*/
(function() {
tinymce.create('tinymce.plugins.adsimplevote_plugin', {
// URL argument holds the absolute url of our plugin directory.
init : function(editor, url) {
var html = ''
+ '
'
+ '
Your shortcode is: [adsimplevote id=""]
'
+ '
Select one of the existing votes.
'
+ '
'
+ ''
+ '
'
+ '
'
+ '
'
+ '
'
+ '
'
+ '
';
// Add new button.
editor.addButton('adsimplevote', {
title: 'Insert AdSimple Vote',
image: url + '/../images/icon.svg',
onclick: function () {
// Open window
editor.windowManager.open({
title: 'Insert Vote',
width: 500,
height: 400,
body: [
{type: 'container', html: html }
],
buttons: [{
text: 'Insert Vote',
classes: 'btn primary',
id: 'insert-vote-btn',
onclick: function (e) {
var selected = editor.selection.getContent();
var shorcode = jQuery("#insert-adsimplevote .shortcode").text();
var content = "";
if( selected ){
//If text is selected when button is clicked
content = selected + shorcode;
}else{
content = shorcode;
}
editor.execCommand("mceInsertContent", 0, content);
editor.windowManager.close();
}
}, {
text: 'Close',
id: 'close-vote-btn',
onclick: 'close'
}],
onOpen: function (e) {
// Get Votes
// TODO: Add pagination or ajax load more
jQuery("#adsimplevote-search-results").addClass("loader"); // Show loader
jQuery.ajax({
url: adsimple_data['rest_url'] + "wp/v2/adsimplevote/?filter[posts_per_page]=42",
dataType: 'json'
}).done(function(data) {
jQuery("#adsimplevote-search-results ul").empty();
jQuery.each(data, function(index, element) {
jQuery("#adsimplevote-search-results ul").append(''
+ '