typus 3.1.0.rc18 → 3.1.0.rc19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/.gitignore +14 -11
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG +253 -0
  4. data/Gemfile +69 -0
  5. data/Guardfile +11 -0
  6. data/README.md +14 -26
  7. data/Rakefile +24 -100
  8. data/app/assets/javascripts/typus/application.js +8 -2
  9. data/app/assets/javascripts/typus/custom.js +2 -0
  10. data/app/assets/javascripts/typus/jquery.application.js +14 -0
  11. data/app/assets/stylesheets/typus/application.css +18 -10
  12. data/app/assets/stylesheets/typus/content.css +0 -1
  13. data/app/assets/stylesheets/typus/custom.css +11 -0
  14. data/app/assets/stylesheets/typus/errors.css +1 -1
  15. data/app/assets/stylesheets/typus/forms.css +17 -5
  16. data/app/assets/stylesheets/typus/hacks.css +4 -0
  17. data/app/assets/stylesheets/typus/header.css +8 -2
  18. data/app/assets/stylesheets/typus/pagination.css +3 -3
  19. data/app/assets/stylesheets/typus/sidebar.css +4 -0
  20. data/app/assets/stylesheets/typus/tables.css +0 -1
  21. data/app/controllers/admin/account_controller.rb +1 -2
  22. data/app/controllers/admin/base_controller.rb +5 -2
  23. data/app/controllers/admin/dashboard_controller.rb +5 -0
  24. data/app/controllers/admin/resource_controller.rb +1 -2
  25. data/app/controllers/admin/resources_controller.rb +36 -51
  26. data/app/controllers/admin/session_controller.rb +2 -3
  27. data/app/helpers/admin/base_helper.rb +2 -5
  28. data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +35 -27
  29. data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +16 -3
  30. data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +45 -13
  31. data/app/helpers/admin/resources/data_types/has_many_helper.rb +27 -19
  32. data/app/helpers/admin/resources/data_types/has_one_helper.rb +24 -11
  33. data/app/helpers/admin/resources/data_types/paperclip_helper.rb +1 -1
  34. data/app/helpers/admin/resources/data_types/string_helper.rb +1 -1
  35. data/app/helpers/admin/resources/data_types/text_helper.rb +1 -1
  36. data/app/helpers/admin/resources/data_types/transversal_helper.rb +1 -1
  37. data/app/helpers/admin/resources/data_types/tree_helper.rb +1 -1
  38. data/app/helpers/admin/resources/display_helper.rb +10 -9
  39. data/app/helpers/admin/resources/filters_helper.rb +3 -10
  40. data/app/helpers/admin/resources/form_helper.rb +12 -2
  41. data/app/helpers/admin/resources/list_helper.rb +13 -5
  42. data/app/helpers/admin/resources/relationships_helper.rb +0 -21
  43. data/app/helpers/admin/resources_helper.rb +3 -3
  44. data/app/mailers/admin/mailer.rb +9 -4
  45. data/app/views/admin/base/user_guide.html.erb +1 -1
  46. data/app/views/admin/dashboard/{show.html.erb → index.html.erb} +0 -0
  47. data/app/views/admin/dashboard/widgets/_applications.html.erb +32 -10
  48. data/app/views/admin/mailer/reset_password_instructions.html.erb +9 -0
  49. data/app/views/admin/mailer/reset_password_instructions.text.erb +9 -0
  50. data/app/views/admin/resources/edit.html.erb +3 -13
  51. data/app/views/admin/resources/index.html.erb +11 -4
  52. data/app/views/admin/resources/new.html.erb +2 -2
  53. data/app/views/admin/resources/show.html.erb +1 -1
  54. data/app/views/admin/shared/_head.html.erb +2 -2
  55. data/app/views/admin/templates/_belongs_to.html.erb +6 -9
  56. data/app/views/admin/templates/_dragonfly.html.erb +1 -1
  57. data/app/views/admin/templates/_dragonfly_form_preview.html.erb +21 -0
  58. data/app/views/admin/templates/_dragonfly_preview.html.erb +1 -1
  59. data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +15 -0
  60. data/app/views/admin/templates/{_has_n.html.erb → _has_many.html.erb} +0 -0
  61. data/app/views/admin/templates/_password.html.erb +1 -1
  62. data/app/views/admin/templates/_selector.html.erb +1 -11
  63. data/app/views/admin/templates/_string.html.erb +2 -20
  64. data/app/views/admin/templates/_string_with_preview.html.erb +2 -3
  65. data/app/views/admin/templates/_text.html.erb +1 -8
  66. data/app/views/admin/templates/_text_with_ckeditor.html.erb +1 -1
  67. data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +12 -9
  68. data/app/views/helpers/admin/base/_apps.html.erb +12 -4
  69. data/app/views/helpers/admin/base/_login_info.html.erb +1 -1
  70. data/app/views/helpers/admin/resources/_filters.html.erb +2 -1
  71. data/app/views/helpers/admin/resources/_sidebar.html.erb +25 -41
  72. data/app/views/layouts/admin/base.html.erb +1 -1
  73. data/config/locales/typus.ca.yml +1 -1
  74. data/config/locales/typus.de.yml +40 -35
  75. data/config/locales/typus.el.yml +1 -1
  76. data/config/locales/typus.es.yml +1 -1
  77. data/config/locales/typus.fr.yml +1 -1
  78. data/config/locales/typus.hu.yml +1 -1
  79. data/config/locales/typus.it.yml +1 -1
  80. data/config/locales/typus.locale.models.yml.template +17 -0
  81. data/config/locales/typus.locale.yml.template +80 -0
  82. data/config/locales/typus.pt-BR.yml +1 -1
  83. data/config/locales/typus.pt-PT.yml +2 -2
  84. data/config/locales/typus.ru.yml +1 -1
  85. data/config/locales/typus.zh-CN.yml +1 -1
  86. data/config/routes.rb +5 -1
  87. data/lib/generators/templates/config/initializers/typus.rb +9 -0
  88. data/lib/generators/templates/config/typus/README +0 -6
  89. data/lib/support/active_record.rb +2 -10
  90. data/lib/support/string.rb +6 -1
  91. data/lib/typus.rb +49 -10
  92. data/lib/typus/authentication/base.rb +0 -4
  93. data/lib/typus/authentication/none_with_role.rb +15 -0
  94. data/lib/typus/configuration.rb +3 -7
  95. data/lib/typus/controller/ancestry.rb +1 -1
  96. data/lib/typus/controller/bulk.rb +6 -2
  97. data/lib/typus/controller/format.rb +38 -25
  98. data/lib/typus/orm/active_record/class_methods.rb +0 -1
  99. data/lib/typus/orm/active_record/search.rb +6 -2
  100. data/lib/typus/orm/base.rb +4 -3
  101. data/lib/typus/orm/mongoid.rb +4 -0
  102. data/lib/typus/orm/{mongo → mongoid}/class_methods.rb +4 -3
  103. data/lib/typus/resources.rb +9 -0
  104. data/lib/typus/version.rb +1 -1
  105. data/typus.gemspec +13 -13
  106. data/vendor/assets/chosen/chosen-sprite.png +0 -0
  107. data/vendor/assets/chosen/chosen.css +334 -0
  108. data/vendor/assets/chosen/chosen.jquery.min.js +10 -0
  109. data/vendor/assets/fancybox/jquery.fancybox-1.3.4.css +17 -17
  110. metadata +57 -131
  111. data/.gitmodules +0 -6
  112. data/app/assets/javascripts/typus.js +0 -8
  113. data/app/assets/stylesheets/typus.css +0 -20
  114. data/app/assets/stylesheets/typus/actions.css +0 -11
  115. data/app/views/admin/mailer/reset_password_link.text.erb +0 -9
  116. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +0 -26
  117. data/lib/typus/controller/associations.rb +0 -146
  118. data/lib/typus/controller/autocomplete.rb +0 -16
  119. data/vendor/assets/fancybox/jquery.easing-1.3.pack.js +0 -72
  120. data/vendor/assets/fancybox/jquery.fancybox-1.3.4.js +0 -1156
  121. data/vendor/assets/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
  122. data/vendor/assets/formalize/css/_formalize.sass +0 -332
  123. data/vendor/assets/formalize/css/demo.css +0 -47
  124. data/vendor/assets/formalize/css/reset.css +0 -202
  125. data/vendor/assets/formalize/css/text.css +0 -81
  126. data/vendor/assets/formalize/js/dojo.formalize.js +0 -166
  127. data/vendor/assets/formalize/js/dojo.formalize.min.js +0 -1
  128. data/vendor/assets/formalize/js/extjs.formalize.js +0 -163
  129. data/vendor/assets/formalize/js/extjs.formalize.min.js +0 -1
  130. data/vendor/assets/formalize/js/jquery.formalize.js +0 -150
  131. data/vendor/assets/formalize/js/mootools.formalize.js +0 -155
  132. data/vendor/assets/formalize/js/mootools.formalize.min.js +0 -1
  133. data/vendor/assets/formalize/js/prototype.formalize.js +0 -163
  134. data/vendor/assets/formalize/js/prototype.formalize.min.js +0 -1
  135. data/vendor/assets/formalize/js/yui.formalize.js +0 -152
  136. data/vendor/assets/formalize/js/yui.formalize.min.js +0 -1
  137. data/vendor/assets/jquery-tokeninput/jquery.tokeninput.js +0 -736
  138. data/vendor/assets/jquery-tokeninput/token-input.css +0 -120
@@ -1,155 +0,0 @@
1
- /*
2
- Formalize - version 1.1
3
-
4
- Note: This file depends on the MooTools library.
5
- */
6
-
7
- // Module pattern:
8
- // http://yuiblog.com/blog/2007/06/12/module-pattern
9
- var FORMALIZE = (function(window, document, undefined) {
10
- // Private constants.
11
- var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
12
- var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input');
13
- var IE6 = Browser.ie6;
14
- var IE7 = Browser.ie7;
15
-
16
- // Expose innards of FORMALIZE.
17
- return {
18
- // FORMALIZE.go
19
- go: function() {
20
- for (var i in FORMALIZE.init) {
21
- FORMALIZE.init[i]();
22
- }
23
- },
24
- // FORMALIZE.init
25
- init: {
26
- // FORMALIZE.init.full_input_size
27
- full_input_size: function() {
28
- if (!IE7 || !$$('textarea, input.input_full').length) {
29
- return;
30
- }
31
-
32
- // This fixes width: 100% on <textarea> and class="input_full".
33
- // It ensures that form elements don't go wider than container.
34
- $$('textarea, input.input_full').each(function(el) {
35
- new Element('span.input_full_wrap').wraps(el);
36
- });
37
-
38
- },
39
- // FORMALIZE.init.ie6_skin_inputs
40
- ie6_skin_inputs: function() {
41
- // Test for Internet Explorer 6.
42
- if (!IE6 || !$$('input, select, textarea').length) {
43
- // Exit if the browser is not IE6,
44
- // or if no form elements exist.
45
- return;
46
- }
47
-
48
- // For <input type="submit" />, etc.
49
- var button_regex = /button|submit|reset/;
50
-
51
- // For <input type="text" />, etc.
52
- var type_regex = /date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;
53
-
54
- $$('input').each(function(el) {
55
- // Is it a button?
56
- if (el.getAttribute('type').match(button_regex)) {
57
- el.addClass('ie6_button');
58
-
59
- /* Is it disabled? */
60
- if (el.disabled) {
61
- el.addClass('ie6_button_disabled');
62
- }
63
- }
64
- // Or is it a textual input?
65
- else if (el.getAttribute('type').match(type_regex)) {
66
- el.addClass('ie6_input');
67
-
68
- /* Is it disabled? */
69
- if (el.disabled) {
70
- el.addClass('ie6_input_disabled');
71
- }
72
- }
73
- });
74
-
75
- $$('textarea, select').each(function(el) {
76
- /* Is it disabled? */
77
- if (el.disabled) {
78
- el.addClass('ie6_input_disabled');
79
- }
80
- });
81
- },
82
- // FORMALIZE.init.autofocus
83
- autofocus: function() {
84
- if (AUTOFOCUS_SUPPORTED || !$$('[autofocus]').length) {
85
- return;
86
- }
87
-
88
- $$('[autofocus]')[0].focus();
89
- },
90
- // FORMALIZE.init.placeholder
91
- placeholder: function() {
92
- if (PLACEHOLDER_SUPPORTED || !$$('[placeholder]').length) {
93
- // Exit if placeholder is supported natively,
94
- // or if page does not have any placeholder.
95
- return;
96
- }
97
-
98
- FORMALIZE.misc.add_placeholder();
99
-
100
- $$('[placeholder]').each(function(el) {
101
- var text = el.get('placeholder');
102
-
103
- el.addEvents({
104
- focus: function() {
105
- if (el.value === text) {
106
- el.set('value', '').removeClass('placeholder_text');
107
- }
108
- },
109
- blur: function() {
110
- FORMALIZE.misc.add_placeholder();
111
- }
112
- });
113
-
114
- // Prevent <form> from accidentally
115
- // submitting the placeholder text.
116
- el.getParent('form').addEvents({
117
- 'submit': function() {
118
- if (el.value === text) {
119
- el.set('value', '').removeClass('placeholder_text');
120
- }
121
- },
122
- 'reset': function() {
123
- setTimeout(FORMALIZE.misc.add_placeholder, 50);
124
- }
125
- });
126
- });
127
- }
128
- },
129
- // FORMALIZE.misc
130
- misc: {
131
- // FORMALIZE.misc.add_placeholder
132
- add_placeholder: function() {
133
- if (PLACEHOLDER_SUPPORTED || !$$('[placeholder]').length) {
134
- // Exit if placeholder is supported natively,
135
- // or if page does not have any placeholder.
136
- return;
137
- }
138
-
139
- $$('[placeholder]').each(function(el) {
140
- var text = el.get('placeholder');
141
-
142
- if (!el.value || el.value === text) {
143
- el.set('value', text).addClass('placeholder_text');
144
- }
145
- });
146
- }
147
- }
148
- };
149
- // Alias window, document.
150
- })(this, this.document);
151
-
152
- // Automatically calls all functions in FORMALIZE.init
153
- $(document).addEvent('domready', function() {
154
- FORMALIZE.go();
155
- });
@@ -1 +0,0 @@
1
- var FORMALIZE=function(a,b,c){var d="placeholder"in b.createElement("input"),e="autofocus"in b.createElement("input"),f=Browser.ie6,g=Browser.ie7;return{go:function(){for(var a in FORMALIZE.init)FORMALIZE.init[a]()},init:{full_input_size:function(){!!g&&!!$$("textarea, input.input_full").length&&$$("textarea, input.input_full").each(function(a){(new Element("span.input_full_wrap")).wraps(a)})},ie6_skin_inputs:function(){if(!!f&&!!$$("input, select, textarea").length){var a=/button|submit|reset/,b=/date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;$$("input").each(function(c){c.getAttribute("type").match(a)?(c.addClass("ie6_button"),c.disabled&&c.addClass("ie6_button_disabled")):c.getAttribute("type").match(b)&&(c.addClass("ie6_input"),c.disabled&&c.addClass("ie6_input_disabled"))}),$$("textarea, select").each(function(a){a.disabled&&a.addClass("ie6_input_disabled")})}},autofocus:function(){!e&&!!$$("[autofocus]").length&&$$("[autofocus]")[0].focus()},placeholder:function(){!d&&!!$$("[placeholder]").length&&(FORMALIZE.misc.add_placeholder(),$$("[placeholder]").each(function(a){var b=a.get("placeholder");a.addEvents({focus:function(){a.value===b&&a.set("value","").removeClass("placeholder_text")},blur:function(){FORMALIZE.misc.add_placeholder()}}),a.getParent("form").addEvents({submit:function(){a.value===b&&a.set("value","").removeClass("placeholder_text")},reset:function(){setTimeout(FORMALIZE.misc.add_placeholder,50)}})}))}},misc:{add_placeholder:function(){!d&&!!$$("[placeholder]").length&&$$("[placeholder]").each(function(a){var b=a.get("placeholder");(!a.value||a.value===b)&&a.set("value",b).addClass("placeholder_text")})}}}}(this,this.document);$(document).addEvent("domready",function(){FORMALIZE.go()})
@@ -1,163 +0,0 @@
1
- /*
2
- Formalize - version 1.1
3
-
4
- Note: This file depends on the Prototype library.
5
- */
6
-
7
- // Module pattern:
8
- // http://yuiblog.com/blog/2007/06/12/module-pattern
9
- var FORMALIZE = (function(window, document, undefined) {
10
- // Private constants.
11
- var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
12
- var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input');
13
- var IE6 = IE(6);
14
- var IE7 = IE(7);
15
-
16
- // Internet Explorer detection.
17
- function IE(version) {
18
- var b = document.createElement('b');
19
- b.innerHTML = '<!--[if IE ' + version + ']><br><![endif]-->';
20
- return !!b.getElementsByTagName('br').length;
21
- }
22
-
23
- // Expose innards of FORMALIZE.
24
- return {
25
- // FORMALIZE.go
26
- go: function() {
27
- for (var i in FORMALIZE.init) {
28
- FORMALIZE.init[i]();
29
- }
30
- },
31
- // FORMALIZE.init
32
- init: {
33
- // FORMALIZE.init.full_input_size
34
- full_input_size: function() {
35
- if (!IE7 || !$$('textarea, input.input_full').length) {
36
- return;
37
- }
38
-
39
- // This fixes width: 100% on <textarea> and class="input_full".
40
- // It ensures that form elements don't go wider than container.
41
- $$('textarea, input.input_full').each(function(el) {
42
- Element.wrap(el, 'span', {'class': 'input_full_wrap'});
43
- });
44
- },
45
- // FORMALIZE.init.ie6_skin_inputs
46
- ie6_skin_inputs: function() {
47
- // Test for Internet Explorer 6.
48
- if (!IE6 || !$$('input, select, textarea').length) {
49
- // Exit if the browser is not IE6,
50
- // or if no form elements exist.
51
- return;
52
- }
53
-
54
- // For <input type="submit" />, etc.
55
- var button_regex = /button|submit|reset/;
56
-
57
- // For <input type="text" />, etc.
58
- var type_regex = /date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;
59
-
60
- $$('input').each(function(el) {
61
- // Is it a button?
62
- if (el.getAttribute('type').match(button_regex)) {
63
- el.addClassName('ie6_button');
64
-
65
- /* Is it disabled? */
66
- if (el.disabled) {
67
- el.addClassName('ie6_button_disabled');
68
- }
69
- }
70
- // Or is it a textual input?
71
- else if (el.getAttribute('type').match(type_regex)) {
72
- el.addClassName('ie6_input');
73
-
74
- /* Is it disabled? */
75
- if (el.disabled) {
76
- el.addClassName('ie6_input_disabled');
77
- }
78
- }
79
- });
80
-
81
- $$('textarea, select').each(function(el) {
82
- /* Is it disabled? */
83
- if (el.disabled) {
84
- el.addClassName('ie6_input_disabled');
85
- }
86
- });
87
- },
88
- // FORMALIZE.init.autofocus
89
- autofocus: function() {
90
- if (AUTOFOCUS_SUPPORTED || !$$('[autofocus]').length) {
91
- return;
92
- }
93
-
94
- $$('[autofocus]')[0].focus();
95
- },
96
- // FORMALIZE.init.placeholder
97
- placeholder: function() {
98
- if (PLACEHOLDER_SUPPORTED || !$$('[placeholder]').length) {
99
- // Exit if placeholder is supported natively,
100
- // or if page does not have any placeholder.
101
- return;
102
- }
103
-
104
- FORMALIZE.misc.add_placeholder();
105
-
106
- $$('[placeholder]').each(function(el) {
107
- var text = el.getAttribute('placeholder');
108
- var form = el.up('form');
109
-
110
- el.observe('focus', function() {
111
- if (el.value === text) {
112
- el.value = '';
113
- el.removeClassName('placeholder_text');
114
- }
115
- });
116
-
117
- el.observe('blur', function() {
118
- FORMALIZE.misc.add_placeholder();
119
- });
120
-
121
- // Prevent <form> from accidentally
122
- // submitting the placeholder text.
123
- form.observe('submit', function() {
124
- if (el.value === text) {
125
- el.value = '';
126
- el.removeClassName('placeholder_text');
127
- }
128
- });
129
-
130
- form.observe('reset', function() {
131
- setTimeout(FORMALIZE.misc.add_placeholder, 50);
132
- });
133
- });
134
- }
135
- },
136
- // FORMALIZE.misc
137
- misc: {
138
- // FORMALIZE.misc.add_placeholder
139
- add_placeholder: function() {
140
- if (PLACEHOLDER_SUPPORTED || !$$('[placeholder]').length) {
141
- // Exit if placeholder is supported natively,
142
- // or if page does not have any placeholder.
143
- return;
144
- }
145
-
146
- $$('[placeholder]').each(function(el) {
147
- var text = el.getAttribute('placeholder');
148
-
149
- if (!el.value || el.value === text) {
150
- el.value = text;
151
- el.addClassName('placeholder_text');
152
- }
153
- });
154
- }
155
- }
156
- };
157
- // Alias window, document.
158
- })(this, this.document);
159
-
160
- // Automatically calls all functions in FORMALIZE.init
161
- $(document).observe('dom:loaded', function() {
162
- FORMALIZE.go();
163
- });
@@ -1 +0,0 @@
1
- var FORMALIZE=function(a,b,c){function h(a){var c=b.createElement("b");c.innerHTML="<!--[if IE "+a+"]><br><![endif]-->";return!!c.getElementsByTagName("br").length}var d="placeholder"in b.createElement("input"),e="autofocus"in b.createElement("input"),f=h(6),g=h(7);return{go:function(){for(var a in FORMALIZE.init)FORMALIZE.init[a]()},init:{full_input_size:function(){!!g&&!!$$("textarea, input.input_full").length&&$$("textarea, input.input_full").each(function(a){Element.wrap(a,"span",{"class":"input_full_wrap"})})},ie6_skin_inputs:function(){if(!!f&&!!$$("input, select, textarea").length){var a=/button|submit|reset/,b=/date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;$$("input").each(function(c){c.getAttribute("type").match(a)?(c.addClassName("ie6_button"),c.disabled&&c.addClassName("ie6_button_disabled")):c.getAttribute("type").match(b)&&(c.addClassName("ie6_input"),c.disabled&&c.addClassName("ie6_input_disabled"))}),$$("textarea, select").each(function(a){a.disabled&&a.addClassName("ie6_input_disabled")})}},autofocus:function(){!e&&!!$$("[autofocus]").length&&$$("[autofocus]")[0].focus()},placeholder:function(){!d&&!!$$("[placeholder]").length&&(FORMALIZE.misc.add_placeholder(),$$("[placeholder]").each(function(a){var b=a.getAttribute("placeholder"),c=a.up("form");a.observe("focus",function(){a.value===b&&(a.value="",a.removeClassName("placeholder_text"))}),a.observe("blur",function(){FORMALIZE.misc.add_placeholder()}),c.observe("submit",function(){a.value===b&&(a.value="",a.removeClassName("placeholder_text"))}),c.observe("reset",function(){setTimeout(FORMALIZE.misc.add_placeholder,50)})}))}},misc:{add_placeholder:function(){!d&&!!$$("[placeholder]").length&&$$("[placeholder]").each(function(a){var b=a.getAttribute("placeholder");if(!a.value||a.value===b)a.value=b,a.addClassName("placeholder_text")})}}}}(this,this.document);$(document).observe("dom:loaded",function(){FORMALIZE.go()})
@@ -1,152 +0,0 @@
1
- /*
2
- Formalize - version 1.1
3
-
4
- Note: This file depends on the YUI library.
5
- */
6
-
7
- YUI.add('formalize', function(Y) {
8
- // Private constants.
9
- var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
10
- var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input');
11
- var IE6 = parseInt(Y.UA.ie, 10) === 6;
12
- var IE7 = parseInt(Y.UA.ie, 10) === 7;
13
-
14
- // Expose innards of Formalize.
15
- Y.formalize = {
16
- // Y.formalize.go
17
- go: function() {
18
- for (var i in Y.formalize.init) {
19
- Y.formalize.init[i]();
20
- }
21
- },
22
- // Y.formalize.init
23
- init: {
24
- // Y.formalize.init.full_input_size
25
- full_input_size: function() {
26
- if (!IE7 || !Y.all('textarea, input.input_full')) {
27
- return;
28
- }
29
-
30
- // This fixes width: 100% on <textarea> and class="input_full".
31
- // It ensures that form elements don't go wider than container.
32
- Y.all('textarea, input.input_full').each(function(el) {
33
- var wrapper = Y.Node.create('<span class="input_full_wrap"></span>');
34
- wrapper.append(el.replace(wrapper));
35
- });
36
- },
37
- // Y.formalize.init.ie6_skin_inputs
38
- ie6_skin_inputs: function() {
39
- // Test for Internet Explorer 6.
40
- if (!IE6 || !Y.all('input, select, textarea')) {
41
- // Exit if the browser is not IE6,
42
- // or if no form elements exist.
43
- return;
44
- }
45
-
46
- // For <input type="submit" />, etc.
47
- var button_regex = /button|submit|reset/;
48
-
49
- // For <input type="text" />, etc.
50
- var type_regex = /date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;
51
-
52
- Y.all('input').each(function(el) {
53
- // Is it a button?
54
- if (el.getAttribute('type').match(button_regex)) {
55
- el.addClass('ie6_button');
56
-
57
- /* Is it disabled? */
58
- if (el.disabled) {
59
- el.addClass('ie6_button_disabled');
60
- }
61
- }
62
- // Or is it a textual input?
63
- else if (el.getAttribute('type').match(type_regex)) {
64
- el.addClass('ie6_input');
65
-
66
- /* Is it disabled? */
67
- if (el.disabled) {
68
- el.addClass('ie6_input_disabled');
69
- }
70
- }
71
- });
72
-
73
- Y.all('textarea, select').each(function(el) {
74
- /* Is it disabled? */
75
- if (el.disabled) {
76
- el.addClass('ie6_input_disabled');
77
- }
78
- });
79
- },
80
- // Y.formalize.init.autofocus
81
- autofocus: function() {
82
- if (AUTOFOCUS_SUPPORTED || !Y.one('[autofocus]')) {
83
- return;
84
- }
85
-
86
- Y.one('[autofocus]').focus();
87
- },
88
- // Y.formalize.init.placeholder
89
- placeholder: function() {
90
- if (PLACEHOLDER_SUPPORTED || !Y.one('[placeholder]')) {
91
- // Exit if placeholder is supported natively,
92
- // or if page does not have any placeholder.
93
- return;
94
- }
95
-
96
- Y.formalize.misc.add_placeholder();
97
-
98
- Y.all('[placeholder]').each(function(el) {
99
- var text = el.getAttribute('placeholder');
100
- var form = el.ancestor('form');
101
-
102
- function add_placeholder() {
103
- if (!el.get('value') || el.get('value') === text) {
104
- el.set('value', text).addClass('placeholder_text');
105
- }
106
- }
107
-
108
- el.on('focus', function() {
109
- if (el.get('value') === text) {
110
- el.set('value', '').removeClass('placeholder_text');
111
- }
112
- });
113
-
114
- el.on('blur', function() {
115
- Y.formalize.misc.add_placeholder();
116
- });
117
-
118
- // Prevent <form> from accidentally
119
- // submitting the placeholder text.
120
- form.on('submit', function() {
121
- if (el.get('value') === text) {
122
- el.set('value', '').removeClass('placeholder_text');
123
- }
124
- });
125
-
126
- form.on('reset', function() {
127
- setTimeout(Y.formalize.misc.add_placeholder, 50);
128
- });
129
- });
130
- }
131
- },
132
- // Y.formalize.misc
133
- misc: {
134
- // Y.formalize.misc.add_placeholder
135
- add_placeholder: function() {
136
- if (PLACEHOLDER_SUPPORTED || !Y.one('[placeholder]')) {
137
- // Exit if placeholder is supported natively,
138
- // or if page does not have any placeholder.
139
- return;
140
- }
141
-
142
- Y.all('[placeholder]').each(function(el) {
143
- var text = el.getAttribute('placeholder');
144
-
145
- if (!el.get('value') || el.get('value') === text) {
146
- el.set('value', text).addClass('placeholder_text');
147
- }
148
- });
149
- }
150
- }
151
- };
152
- }, '1.1', {requires: ['yui', 'dom', 'event']});