1
|
|
|
/** |
2
|
|
|
* Rich Variables plugin for Craft CMS |
3
|
|
|
* |
4
|
|
|
* Rich Variables JS |
5
|
|
|
* |
6
|
|
|
* @author nystudio107 |
7
|
|
|
* @copyright Copyright (c) 2017 nystudio107 |
8
|
|
|
* @link https://nystudio107.com |
9
|
|
|
* @package RichVariables |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
View Code Duplication |
if (!RedactorPlugins) var RedactorPlugins = {}; |
|
|
|
|
14
|
|
|
|
15
|
|
|
// Grab the globals set Reference Tags from our controller |
16
|
|
|
var request = new XMLHttpRequest(); |
|
|
|
|
17
|
|
|
request.open('GET', Craft.getActionUrl('rich-variables'), false); |
|
|
|
|
18
|
|
|
request.onload = function() { |
19
|
|
|
if (request.status >= 200 && request.status < 400) { |
|
|
|
|
20
|
|
|
} else { |
|
|
|
|
21
|
|
|
} |
22
|
|
|
}; |
23
|
|
|
request.send(); |
24
|
|
|
|
25
|
|
|
// Add our Redactor plugin |
26
|
|
|
RedactorPlugins.richvariables = function() { |
27
|
|
|
return { |
28
|
|
|
init: function() { |
29
|
|
|
var dropdown = {}; |
30
|
|
|
var responseVars = JSON.parse(request.responseText); |
31
|
|
|
var _this = this; |
|
|
|
|
32
|
|
|
|
33
|
|
|
// Iterate through each menu item, adding them to our dropdown |
34
|
|
|
responseVars.variablesList.forEach(function(menuItem, index) { |
35
|
|
|
var key = 'point' + (index + 1); |
36
|
|
|
dropdown[key] = { |
37
|
|
|
title: menuItem.title, |
38
|
|
|
func: function(buttonName) { |
|
|
|
|
39
|
|
|
this.insert.raw('<ins>' + menuItem.text + '</ins>'); |
40
|
|
|
}, |
41
|
|
|
}; |
42
|
|
|
}); |
43
|
|
|
// Handle empty menu items |
44
|
|
|
if (responseVars.variablesList.length === 0) { |
45
|
|
|
dropdown.point1 = { |
46
|
|
|
title: "No Globals Found", |
47
|
|
|
func: function(buttonName) { |
|
|
|
|
48
|
|
|
// NOP |
49
|
|
|
}, |
50
|
|
|
}; |
51
|
|
|
} |
52
|
|
|
// Add the button and dropdown |
53
|
|
|
var button = this.button.add('variables', 'Variables'); |
54
|
|
|
this.button.addDropdown(button, dropdown); |
55
|
|
|
if (responseVars.useIconForMenu) |
56
|
|
|
this.button.setIcon(button, '<img src="' + responseVars.menuIconUrl + '" height="16" width="16" style="margin-top: -2px;">'); |
|
|
|
|
57
|
|
|
}, |
58
|
|
|
}; |
59
|
|
|
}; |