Gravity Forms CSS Ready Class Selector - Version 1.0

Version Description

  • Initial Relase. First version.

=

Download this release

Release Info

Developer bradvin
Plugin Icon wp plugin Gravity Forms CSS Ready Class Selector
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (6) hide show
  1. btn.png +0 -0
  2. gf-readyclasses-addon.php +246 -0
  3. gfaddoncommon.php +96 -0
  4. readme.txt +50 -0
  5. screenshot-1.png +0 -0
  6. screenshot-2.png +0 -0
btn.png ADDED
Binary file
gf-readyclasses-addon.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Gravity Forms CSS Ready Class Selector
4
+ Plugin URI: http://themergency.com/plugins/gravity-forms-custom-post-types/
5
+ Description: Easily select a CSS "Ready Class" for your fields within Gravity Forms
6
+ Version: 1.0
7
+ Author: Brad Vincent
8
+ Author URI: http://themergency.com/
9
+ License: GPL2
10
+
11
+ ------------------------------------------------------------------------
12
+ Copyright 2011 Themergency
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+ // Include Gravity Forms
30
+ if (!class_exists('RGForms'))
31
+ @include_once(WP_PLUGIN_DIR . '/gravityforms/gravityforms.php');
32
+ if (!class_exists('RGFormsModel'))
33
+ @include_once(WP_PLUGIN_DIR . '/gravityforms/forms_model.php');
34
+ if (!class_exists('GFCommon'))
35
+ @include_once(WP_PLUGIN_DIR . '/gravityforms/common.php');
36
+
37
+ @include_once "GFAddonCommon.php";
38
+
39
+ add_action('init', array('GFReadyClassesAddon', 'init'));
40
+ add_action('admin_notices', array('GFReadyClassesAddon', 'admin_warnings'));
41
+
42
+ if (!class_exists('GFReadyClassesAddon')) {
43
+
44
+ class GFReadyClassesAddon {
45
+
46
+ public static function init() {
47
+ add_action('gform_editor_js', array('GFReadyClassesAddon', 'render_editor_js'));
48
+ }
49
+
50
+ public static function admin_warnings() {
51
+ return GFAddonCommon::admin_warnings('Gravity Forms Ready Classes Addon', 'GFReadyClassesAddon', '1.5');
52
+ }
53
+
54
+ /*
55
+ * render some custom JS to get the settings to work
56
+ */
57
+ function render_editor_js(){
58
+
59
+ $btn_url = GFAddonCommon::get_base_url() . '/btn.png';
60
+
61
+ $modal_html = "
62
+ <div id='css_ready_modal'>
63
+ <style>
64
+ #css_ready_modal h4 { margin-bottom:2px; }
65
+ .cssr_accordian { display:none; }
66
+ a.cssr_acc_link { font-weight:bold; display:block; padding:5px; text-decoration:none; text-align:left; background:#888; border:solid 1px #ddd; color:#fff; }
67
+ a.cssr_link { text-decoration:none; margin:2px; text-align:center; padding:3px; border:solid 1px #aaa; background:#eee; display:inline-block; }
68
+ a.cssr_link:hover { background:#ddd; }
69
+ ul.cssr_ul { margin:0; padding: 0; }
70
+ ul.cssr_ul li { margin:2px; padding: 0; }
71
+ </style>
72
+ <strong>Select a CSS ready class</strong>
73
+ <ul class='cssr_ul'>
74
+
75
+ <li>
76
+ <a class='cssr_acc_link' href='#'>2 Columns</a>
77
+ <div class='cssr_accordian'>
78
+ <a class='cssr_link' style='width:180px' href='#' rel='gf_left_half' title='gf_left_half'>Left Half</a>
79
+ <a class='cssr_link' style='width:180px' href='#' rel='gf_right_half' title='gf_right_half'>Right Half</a>
80
+ </div>
81
+ </li>
82
+
83
+ <li>
84
+ <a class='cssr_acc_link' href='#'>3 Columns</a>
85
+ <div class='cssr_accordian'>
86
+ <a class='cssr_link' style='width:115px' href='#' rel='gf_left_third' title='gf_left_third'>Left Third</a>
87
+ <a class='cssr_link' style='width:115px' href='#' rel='gf_middle_third' title='gf_middle_third'>Middle Third</a>
88
+ <a class='cssr_link' style='width:115px' href='#' rel='gf_right_third' title='gf_right_third'>Right Third</a>
89
+ </div>
90
+ </li>
91
+
92
+ <li>
93
+ <a class='cssr_acc_link' href='#'>List Layout</a>
94
+ <div class='cssr_accordian'>
95
+ <a class='cssr_link' style='width:115px' rel='gf_list_2col' title='gf_list_2col' href='#'>2 Column List</a>
96
+ <a class='cssr_link' style='width:115px' rel='gf_list_3col' title='gf_list_3col' href='#'>3 Column List</a>
97
+ <a class='cssr_link' style='width:115px' rel='gf_list_4col' title='gf_list_4col' href='#'>4 Column List</a>
98
+ <a class='cssr_link' style='width:115px' rel='gf_list_5col' title='gf_list_5col' href='#'>5 Column List</a>
99
+ <a class='cssr_link' style='width:115px' rel='gf_list_inline' title='gf_list_inline' href='#'>Inline List</a>
100
+ </div>
101
+ </li>
102
+
103
+ <li>
104
+ <a class='cssr_acc_link' href='#'>List Heights</a>
105
+ <div class='cssr_accordian'>
106
+ <a class='cssr_link' style='width:115px' rel='gf_list_height_25' title='gf_list_height_25' href='#'>25px Height</a>
107
+ <a class='cssr_link' style='width:115px' rel='gf_list_height_50' title='gf_list_height_50' href='#'>50px Height</a>
108
+ <a class='cssr_link' style='width:115px' rel='gf_list_height_75' title='gf_list_height_75' href='#'>75px Height</a>
109
+ <a class='cssr_link' style='width:115px' rel='gf_list_height_100' title='gf_list_height_100' href='#'>100px Height</a>
110
+ <a class='cssr_link' style='width:115px' rel='gf_list_height_125' title='gf_list_height_125' href='#'>125px Height</a>
111
+ <a class='cssr_link' style='width:115px' rel='gf_list_height_150' title='gf_list_height_150' href='#'>150px Height</a>
112
+ </div>
113
+ </li>
114
+
115
+ <li>
116
+ <a class='cssr_acc_link' href='#'>Others</a>
117
+ <div class='cssr_accordian'>
118
+ <a class='cssr_link' style='width:180px' rel='gf_scroll_text' title='gf_scroll_text' href='#'>Scrolling Paragraph Text</a>
119
+ <a class='cssr_link' style='width:180px' rel='gf_hide_ampm' title='gf_hide_ampm' href='#'>Hide Time am/pm</a>
120
+ <a class='cssr_link' style='width:180px' rel='gf_hide_charleft' title='gf_hide_charleft' href='#'>Hide Character Counter</a>
121
+ </div>
122
+ </li>
123
+ </ul>
124
+ Click on one or more CSS ready classes to add them.<br />
125
+ Double-clicking adds the class and closes this popup.<br />
126
+ For more help with CSS ready classes, refer to <a href='http://www.gravityhelp.com/css-ready-classes-for-gravity-forms/' target='_blank'>this documentation</a>.
127
+ ";
128
+
129
+ ?>
130
+ <script type='text/javascript'>
131
+
132
+ function removeTokenFromInput(input, tokenPos,seperator) {
133
+ var text = input.val();
134
+
135
+ var tokens = text.split(seperator);
136
+ var newText = '';
137
+ for(i = 0; i < tokens.length; i++)
138
+ {
139
+ if (tokens[i].replace(' ','').replace(seperator,'') == '')
140
+ { continue; }
141
+ if (i != tokenPos) {
142
+ newText += (tokens[i].trim()+seperator);
143
+ }
144
+ }
145
+ input.val(fixTokens(newText, seperator));
146
+ }
147
+
148
+ function addTokenToInput(input, tokenToAdd, seperator) {
149
+ var text = input.val().trim();
150
+ if (text == '') {
151
+ input.val(tokenToAdd);
152
+ }
153
+ else {
154
+ if (!tokenExists(input, tokenToAdd, seperator))
155
+ { input.val(fixTokens(text + seperator + tokenToAdd, seperator)); }
156
+ }
157
+ }
158
+
159
+ function fixTokens(tokens, seperator) {
160
+ var text = tokens.trim();
161
+ var tokens = text.split(seperator);
162
+ var newTokens = '';
163
+ for(i = 0; i < tokens.length; i++)
164
+ {
165
+ var token = tokens[i].trim().replace(seperator,'');
166
+ if (token == '') { continue; }
167
+ newTokens += (token + seperator);
168
+ }
169
+ return newTokens;
170
+ }
171
+
172
+ function tokenExists(input, tokenToCheck, seperator) {
173
+ var text = input.val().trim();
174
+ if (text == '') return false;
175
+ var tokens = text.split(seperator);
176
+ for(i = 0; i < tokens.length; i++)
177
+ {
178
+ var token = tokens[i].trim().replace(seperator,'');
179
+ if (token == '') { continue; }
180
+ if (token == tokenToCheck) {
181
+ return true;
182
+ }
183
+ }
184
+ return false;
185
+ }
186
+
187
+ jQuery(document).bind("gform_load_field_settings", function(event, field, form){
188
+
189
+ if (jQuery("#css_ready_selector").length == 0) {
190
+ //jQuery("#css_ready_selector").remove();
191
+ //jQuery("#css_ready_modal").remove();
192
+
193
+ //add some html after the CSS Class Name input
194
+ var $select_link = jQuery("<a id='css_ready_selector' href='#'><img src='<?php echo $btn_url; ?>' /></a>");
195
+
196
+ var $modal = jQuery("<?php echo preg_replace( '/\s*[\r\n\t]+\s*/', '', $modal_html ); ?>").hide();
197
+
198
+ jQuery(".css_class_setting").append($select_link).append($modal);
199
+
200
+ $select_link.click(function(e) {
201
+ e.preventDefault();
202
+ var $m = jQuery("#css_ready_modal");
203
+
204
+ $m.find(".cssr_acc_link").unbind("click").click(function(e) {
205
+ e.preventDefault();
206
+ jQuery('.cssr_accordian:visible').slideUp();
207
+ jQuery(this).parent("li:first").find(".cssr_accordian").slideDown();
208
+ });
209
+
210
+ var $links = $m.find(".cssr_link");
211
+
212
+ $links.unbind("click").click(function(e) {
213
+ e.preventDefault();
214
+ var css = jQuery(this).attr("rel");
215
+ addTokenToInput(jQuery("#field_css_class"), css, ' ');
216
+ });
217
+
218
+ $links.unbind("dblclick").dblclick(function(e) {
219
+ e.preventDefault();
220
+ var css = jQuery(this).attr("rel");
221
+ addTokenToInput(jQuery("#field_css_class"), css, ' ');
222
+ jQuery.modal.close();
223
+ });
224
+
225
+ $m.modal({
226
+ onOpen: function (dialog) {
227
+ dialog.overlay.fadeIn(function () {
228
+ dialog.container.slideDown(function () {
229
+ dialog.data.fadeIn('slow');
230
+ });
231
+ });
232
+ }
233
+ });
234
+ });
235
+
236
+ }
237
+
238
+ });
239
+
240
+ </script>
241
+ <?php
242
+ }
243
+ }
244
+
245
+ }
246
+ ?>
gfaddoncommon.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!class_exists('GFAddonCommon')) {
4
+
5
+ class GFAddonCommon {
6
+
7
+ //display admin warnings if GF is not the correct version or GF is not installed
8
+ public static function admin_warnings($plugin, $textdomain, $min_gf_version) {
9
+ if ( !self::is_gravityforms_installed() ) {
10
+ $message = __('requires Gravity Forms to be installed.', $textdomain);
11
+ } else if ( !self::is_gravityforms_supported($min_gf_version) ) {
12
+ $message = __('requires a minimum Gravity Forms version of ', $textdomain) . $min_gf_version;
13
+ }
14
+
15
+ if (empty($message)) {
16
+ return;
17
+ }
18
+ ?>
19
+ <div class="error">
20
+ <p>
21
+ <?php _e('The plugin ', $textdomain); ?><strong><?php echo $plugin; ?></strong> <?php echo $message; ?><br />
22
+ <?php _e('Please ', $textdomain); ?><a href="http://bit.ly/getgravityforms"><?php _e(' download the latest version ',$textdomain); ?></a><?php _e(' of Gravity Forms and try again.',$textdomain) ?>
23
+ </p>
24
+ </div>
25
+ <?php
26
+ }
27
+
28
+ /*
29
+ * Check if GF is installed
30
+ */
31
+ public static function is_gravityforms_installed(){
32
+ return class_exists( 'RGForms' );
33
+ }
34
+
35
+ /*
36
+ * Check if the installed version of GF is supported
37
+ */
38
+ public static function is_gravityforms_supported($min_gf_version = '1.5'){
39
+ return self::check_gravityforms_version( $min_gf_version,'>=' );
40
+ }
41
+
42
+ /*
43
+ * Do a GF version compare
44
+ */
45
+ public static function check_gravityforms_version($version, $operator){
46
+ if(class_exists('GFCommon')){
47
+ return version_compare( GFCommon::$version, $version, $operator );
48
+ }
49
+ return false;
50
+ }
51
+
52
+ /*
53
+ * Returns the url of the plugin's root folder
54
+ */
55
+ public function get_base_url(){
56
+ return plugins_url(null, __FILE__);
57
+ }
58
+
59
+ /*
60
+ * Returns the physical path of the plugin's root folder
61
+ */
62
+ public function get_base_path(){
63
+ $folder = basename(dirname(__FILE__));
64
+ return WP_PLUGIN_DIR . '/' . $folder;
65
+ }
66
+
67
+ /**
68
+ * starts_with
69
+ * Tests if a text starts with an given string.
70
+ *
71
+ * @param string
72
+ * @param string
73
+ * @return bool
74
+ */
75
+ public static function starts_with($haystack, $needle){
76
+ return strpos($haystack, $needle) === 0;
77
+ }
78
+
79
+ /*
80
+ * returns true if a needle can be found in a haystack
81
+ */
82
+ public static function str_contains($haystack, $needle) {
83
+ if (empty($haystack) || empty($needle))
84
+ return false;
85
+
86
+ $pos = strpos(strtolower($haystack), strtolower($needle));
87
+
88
+ if ($pos === false)
89
+ return false;
90
+ else
91
+ return true;
92
+ }
93
+ }
94
+
95
+ }
96
+ ?>
readme.txt ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Gravity Forms CSS Ready Class Selector ===
2
+ Contributors: bradvin
3
+ Donate link: http://themergency.com/donate/
4
+ Tags: form,forms,gravity,gravity form,gravity forms,ready classes,CSS Ready,CSS,class
5
+ Requires at least: 3.0
6
+ Tested up to: 3.2
7
+ Stable tag: 1.0
8
+
9
+ Easily select a CSS "Ready Class" for your fields within Gravity Forms
10
+
11
+ == Description ==
12
+
13
+ > This plugin is an add-on for the [Gravity Forms Plugin](http://bit.ly/getgravityforms "visit the Gravity Forms website").
14
+ > If you don't yet own a license of the best forms plugin for WordPress, go and [buy one now!](http://bit.ly/getgravityforms "purchase Gravity Forms!")
15
+
16
+ **Requires at least v1.5 of Gravity Forms**
17
+
18
+ "Ready Classes" were introduced in Gravity Forms 1.5. Using these new classes, you can easily create more advanced alternative layouts for the fields in your forms. Excellent idea, however, the problem is you always need to remember what the exact class name is. Now with the CSS Ready class selector, you don't need to remember. Simply click on a button to lauch the popup and choose the class you want to add from the list.
19
+
20
+ **features**
21
+
22
+ * Convenient button added under the advanced tab next to the "CSS Class Name" field
23
+ * Clean and simple popup that lists all the "Ready Classes"
24
+ * Add more than one "Ready Class"
25
+ * Double click a "Ready Class" to add it and auto-close the popup
26
+
27
+ == Installation ==
28
+
29
+ 1. Upload the plugin folder to your `/wp-content/plugins/` folder
30
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
31
+ 3. Make sure you also have Gravity Forms 1.5 activated.
32
+
33
+ == Screenshots ==
34
+
35
+ 1. The button that gets added in the advanced tab
36
+ 2. The popup that is displayed
37
+
38
+ == Changelog ==
39
+
40
+ = 1.0 =
41
+ * Initial Relase. First version.
42
+
43
+ == Frequently Asked Questions ==
44
+
45
+ = Does this plugin rely on anything? =
46
+ Yes, you need to install the [Gravity Forms Plugin](http://bit.ly/getgravityforms "visit the Gravity Forms website") for this plugin to work. And it needs to be at leat v1.5
47
+
48
+ == Upgrade Notice ==
49
+
50
+ Please upgrade to the latest version
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file