PluginProbe
Smart Forms – when you need more than just a contact form / trunk
Smart Forms – when you need more than just a contact form vtrunk
trunk 0.5 0.5.5 0.6 0.7 0.8 0.8.5 0.9.1
smart-forms / js / shortcode / smartFormsShortCodeButton.js

smartFormsShortCodeButton.js in Smart Forms – when you need more than just a contact form trunk, at js/shortcode/smartFormsShortCodeButton.js

108 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 javascriptUrl='';
3 tinymce.create('tinymce.plugins.rednao_smart_forms', {
4 init : function(ed, url) {
5 javascriptUrl=url.substring(0,url.length-13);
6 // Register command for when button is clicked
7 ed.addCommand('rednao_smart_forms_short_code_clicked', function(a,donationId) {
8
9 var shortCode=rnJQuery('#smartFormShortCodeSelect').val();
10 if(shortCode==null)
11 return;
12 tinymce.execCommand('mceInsertContent', false,shortCode);
13
14 rnJQuery("#smartformsShortCodeDialog").dialog('close');
15 rnJQuery("#smartformsShortCodeDialog").remove();
16 }),
17
18 // Register buttons - trigger above command when clicked
19 ed.addButton('rednao_smart_forms_button', {title : 'Smart Forms', image: javascriptUrl + '/images/smartFormsIcon.png',
20 onclick:function()
21 {
22 var data={
23 action:"rednao_smart_form_short_code_setup",
24 nonce:smartformsvars.nonce
25 };
26
27 rnJQuery.post(ajaxurl,data,smartFormsAjaxCompleted);
28
29 }});
30 }
31 });
32
33
34 tinymce.PluginManager.add('rednao_smart_forms_button', tinymce.plugins.rednao_smart_forms);
35 })();
36 var smartFormsShortCodeDialog;
37 function smartFormsAjaxCompleted(result,status)
38 {
39 var shortCodeOptions=rnJQuery.parseJSON(result);
40
41
42 if(smartFormsShortCodeDialog==null)
43 {
44 var $optionsSelect=rnJQuery('<select style="display: block;width:100%;margin-bottom: 10px;" ></select>');
45 var $elementsSelect=rnJQuery('<select id="smartFormShortCodeSelect" style="display: block;width:100%;"></select>');
46 var smartFormsPopUpForm='<div style=""><div id="smartformsShortCodeDialog" title="Basic modal dialog">';
47 smartFormsPopUpForm+='</div></div>';
48 var dialog=rnJQuery(smartFormsPopUpForm);
49 dialog.find('#smartformsShortCodeDialog').append($optionsSelect).append($elementsSelect);
50
51 ConfigureDialogs(shortCodeOptions,$optionsSelect,$elementsSelect);
52
53 smartFormsShortCodeDialog=dialog.dialog({
54 modal:true,
55 draggable:false,
56 title:'Select a Form ',
57 resizable:false,
58 buttons:[
59 {text: "Apply", click: function() {tinymce.execCommand('rednao_smart_forms_short_code_clicked', false, rnJQuery('#smartFormList').val())}},
60 {text: "Cancel", click: function() {rnJQuery(this).dialog("close")}}
61 ],
62 create: function(event, ui){
63 rnJQuery('.ui-dialog').wrap('<div class="smartFormsSlider" />');
64 },
65 open: function(event, ui){
66 rnJQuery('.ui-widget-overlay').wrap('<div class="smartFormsSlider" />');
67 rnJQuery(".smartFormsConfigurationFields").val('');
68 }
69 });
70 }else{
71 smartFormsShortCodeDialog.dialog('open');
72 rnJQuery('#redNaoSelection').val('button');
73 }
74
75 function ConfigureDialogs(shortCodeOptions,$optionsSelect,$elementsSelect)
76 {
77 var isFirst=true;
78 for(var i=0;i<shortCodeOptions.length;i++)
79 {
80 $optionsSelect.append('<option '+(isFirst?'selected="selected"':'')+'>'+RedNaoEscapeHtml(shortCodeOptions[i].Name)+'</option>');
81 isFirst=false;
82 }
83
84 $optionsSelect.change(function ()
85 {
86 $elementsSelect.empty();
87 var index=rnJQuery(this).find('option:selected').index();
88 if(index<0)
89 return;
90
91
92 var selectedOption=shortCodeOptions[index];
93 var isFirst=true;
94 for(var i=0;i<selectedOption.Elements.length;i++)
95 {
96 $elementsSelect.append('<option value="['+selectedOption.ShortCode+']'+selectedOption.Elements[i].Id+'[/'+selectedOption.ShortCode+']" '+(isFirst?'selected="selected"':'')+'>'+RedNaoEscapeHtml(selectedOption.Elements[i].Name)+'</option>');
97 isFirst=false;
98 }
99 }).change();
100
101 }
102
103
104
105 }
106
107
108