refinerycms 0.9.5.31 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/.gitignore +1 -0
  2. data/VERSION +1 -1
  3. data/bin/refinery +2 -1
  4. data/config/environment.rb +1 -1
  5. data/config/environments/development.rb +3 -0
  6. data/contributors.md +2 -0
  7. data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +13 -0
  8. data/db/migrate/20100204011654_change_part_titles_to_titleized_version_for_new_format.rb +13 -0
  9. data/db/schema.rb +6 -10
  10. data/public/javascripts/admin.js +1 -1
  11. data/public/javascripts/jquery-ui-1.8rc1.min.js +375 -0
  12. data/public/javascripts/jquery.js +4231 -2529
  13. data/public/javascripts/refinery/admin.js +609 -38
  14. data/public/javascripts/refinery/boot_wym.js +3 -3
  15. data/public/javascripts/thickbox.js +116 -129
  16. data/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +3674 -3732
  17. data/public/javascripts/wymeditor/skins/refinery/skin.js +8 -8
  18. data/public/stylesheets/refinery/refinery.css +142 -32
  19. data/public/stylesheets/wymeditor/skins/refinery/skin.css +8 -1
  20. data/readme.md +35 -21
  21. data/test/fixtures/page_parts.yml +9 -0
  22. data/test/fixtures/pages.yml +88 -0
  23. data/test/performance/browsing_test.rb +9 -0
  24. data/test/test_helper.rb +38 -0
  25. data/test/unit/image_test.rb +14 -0
  26. data/test/unit/page_part_test.rb +19 -0
  27. data/test/unit/page_test.rb +130 -0
  28. data/vendor/plugins/authentication/app/controllers/sessions_controller.rb +1 -1
  29. data/vendor/plugins/authentication/app/views/admin/users/index.html.erb +1 -2
  30. data/vendor/plugins/authentication/authentication.md +9 -1
  31. data/vendor/plugins/dashboard/dashboard.md +3 -3
  32. data/vendor/plugins/images/app/controllers/admin/images_controller.rb +17 -13
  33. data/vendor/plugins/images/app/helpers/admin/images_helper.rb +6 -0
  34. data/vendor/plugins/images/app/models/image.rb +24 -39
  35. data/vendor/plugins/images/app/views/admin/images/_form.html.erb +11 -4
  36. data/vendor/plugins/images/app/views/admin/images/_grid_view.html.erb +1 -2
  37. data/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb +1 -2
  38. data/vendor/plugins/images/app/views/admin/images/index.html.erb +1 -1
  39. data/vendor/plugins/images/app/views/admin/images/insert.html.erb +8 -71
  40. data/vendor/plugins/images/images.md +12 -7
  41. data/vendor/plugins/inquiries/app/views/admin/inquiries/_inquiry.html.erb +6 -13
  42. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/index.html.erb +1 -2
  43. data/vendor/plugins/inquiries/inquiries.md +8 -8
  44. data/vendor/plugins/news/app/views/admin/news_items/_news_item.html.erb +1 -2
  45. data/vendor/plugins/news/news.md +4 -4
  46. data/vendor/plugins/pages/app/controllers/admin/page_dialogs_controller.rb +11 -10
  47. data/vendor/plugins/pages/app/controllers/admin/page_parts_controller.rb +5 -1
  48. data/vendor/plugins/pages/app/controllers/admin/pages_controller.rb +2 -2
  49. data/vendor/plugins/pages/app/models/page.rb +75 -29
  50. data/vendor/plugins/pages/app/models/page_part.rb +1 -1
  51. data/vendor/plugins/pages/app/views/admin/page_dialogs/_page_link.html.erb +2 -2
  52. data/vendor/plugins/pages/app/views/admin/page_dialogs/link_to.html.erb +8 -112
  53. data/vendor/plugins/pages/app/views/admin/pages/_form.html.erb +50 -154
  54. data/vendor/plugins/pages/app/views/admin/pages/_list.html.erb +10 -10
  55. data/vendor/plugins/pages/app/views/admin/pages/_page_part_field.html.erb +4 -4
  56. data/vendor/plugins/pages/app/views/admin/pages/_sortable_list.html.erb +1 -1
  57. data/vendor/plugins/pages/pages.md +30 -25
  58. data/vendor/plugins/refinery/app/views/admin/_head.html.erb +5 -14
  59. data/vendor/plugins/refinery/app/views/admin/_menu.html.erb +2 -64
  60. data/vendor/plugins/refinery/app/views/shared/_message.html.erb +0 -6
  61. data/vendor/plugins/refinery/app/views/shared/admin/_error_messages_for.html.erb +1 -6
  62. data/vendor/plugins/refinery/app/views/shared/admin/_form_actions.html.erb +8 -10
  63. data/vendor/plugins/refinery/app/views/shared/admin/_image_picker.html.erb +22 -38
  64. data/vendor/plugins/refinery/app/views/shared/admin/_make_sortable.html.erb +6 -65
  65. data/vendor/plugins/refinery/app/views/shared/admin/_resource_picker.html.erb +16 -16
  66. data/vendor/plugins/refinery/app/views/shared/admin/_sortable_list.html.erb +3 -4
  67. data/vendor/plugins/refinery/lib/crud.rb +1 -1
  68. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_singular_name.html.erb +1 -1
  69. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_sortable_list.html.erb +1 -1
  70. data/vendor/plugins/refinery/plugins.md +19 -12
  71. data/vendor/plugins/refinery_dialogs/app/controllers/admin/dialogs_controller.rb +6 -4
  72. data/vendor/plugins/refinery_dialogs/app/views/admin/dialogs/show.html.erb +3 -3
  73. data/vendor/plugins/refinery_dialogs/app/views/layouts/admin_dialog.html.erb +7 -14
  74. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_refinery_setting.html.erb +1 -1
  75. data/vendor/plugins/refinery_settings/settings.md +51 -1
  76. data/vendor/plugins/resources/app/controllers/admin/resources_controller.rb +16 -11
  77. data/vendor/plugins/resources/app/views/admin/resources/_form.html.erb +9 -2
  78. data/vendor/plugins/resources/app/views/admin/resources/_resource.html.erb +1 -3
  79. data/vendor/plugins/resources/app/views/admin/resources/index.html.erb +2 -2
  80. data/vendor/plugins/resources/app/views/admin/resources/insert.html.erb +14 -60
  81. data/vendor/plugins/resources/resources.md +1 -1
  82. data/vendor/plugins/themes/app/controllers/admin/themes_controller.rb +6 -6
  83. data/vendor/plugins/themes/app/models/theme.rb +3 -3
  84. data/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb +14 -20
  85. data/vendor/plugins/themes/themes.md +21 -19
  86. metadata +18 -19
  87. data/public/javascripts/builder.js +0 -136
  88. data/public/javascripts/controls.js +0 -963
  89. data/public/javascripts/dragdrop.js +0 -973
  90. data/public/javascripts/effects.js +0 -1128
  91. data/public/javascripts/fastinit.js +0 -84
  92. data/public/javascripts/livepipe.js +0 -180
  93. data/public/javascripts/prototype.js +0 -4874
  94. data/public/javascripts/refinery/dialog.js +0 -52
  95. data/public/javascripts/refinery/parse_url.js +0 -38
  96. data/public/javascripts/refinery/prototype.enhancements.js +0 -24
  97. data/public/javascripts/refinery/tooltips.js +0 -173
  98. data/public/javascripts/scriptaculous.js +0 -47
  99. data/public/javascripts/slider.js +0 -275
  100. data/public/javascripts/tabs.js +0 -149
  101. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_make_sortable.html.erb +0 -7
@@ -1,65 +1,636 @@
1
- init_tooltips = function(args){
2
- jQuery(jQuery(args != null ? args : 'a[title], #image_grid img[title]')).each(function(index, element)
3
- {
4
- new Tooltip(element, {mouseFollow:false, delay: 0, opacity: 1, appearDuration:0, hideDuration: 0, rounded: false});
5
- });
6
- };
1
+ $(document).ready(function(){
7
2
 
8
- FastInit.addOnLoad(function()
9
- {
3
+ init_flash_messages();
4
+ init_delete_confirmations();
5
+ init_sortable_menu();
6
+ init_submit_continue();
7
+ init_modal_dialogs();
10
8
  init_tooltips();
9
+
11
10
  // focus first field in an admin form.
12
- jQuery('form input[type=text]:first').focus();
11
+ $('form input[type=text]:first').focus();
12
+ });
13
+
14
+ init_delete_confirmations = function() {
15
+ $('a.confirm-delete').click(function(e) {
16
+ if (confirm("Are you sure you want to " + (t=$(this).attr('title'))[0].toLowerCase() + t.substring(1) + "?")) {
17
+ $("<form method='POST' action='" + $(this).attr('href') + "'></form>")
18
+ .append("<input type='hidden' name='_method' value='delete' />")
19
+ .append("<input type='hidden' name='authenticity_token' value='" + $('#admin_authenticity_token').val() + "'/>")
20
+ .appendTo('body').submit();
21
+ }
22
+ e.preventDefault();
23
+ });
24
+ }
25
+
26
+ init_flash_messages = function(){
27
+ $('#flash').fadeIn(550);
28
+ $('#flash_close').click(function(e) {
29
+ $('#flash').fadeOut({duration: 330});
30
+ e.preventDefault();
31
+ });
32
+ }
13
33
 
14
- jQuery('a[href*="dialog=true"]').each(function(i, anchor)
34
+ init_modal_dialogs = function(){
35
+ $('a[href*="dialog=true"]').each(function(i, anchor)
15
36
  {
16
- ['modal=true', 'width=928', 'height=473', 'titlebar=true', 'draggable=true'].each(function(feature)
17
- {
18
- if (anchor.href.indexOf(feature.split('=')[0] + '=') == -1)
19
- {
20
- anchor.href += "&" + feature;
21
- }
37
+ $(anchor).click(function(e){
38
+ iframe = $("<iframe id='dialog_iframe' src='" + $(this).attr('href') + "'></iframe>");
39
+ iframe.dialog({
40
+ title: $(anchor).attr('title') || $(anchor).attr('name') || $(anchor).html() || null,
41
+ modal: true,
42
+ resizable: false,
43
+ autoOpen: true,
44
+ width: (parseInt($(anchor.href.match("width=([0-9]*)")).last().get(0))||928),
45
+ height: (parseInt($(anchor.href.match("height=([0-9]*)")).last().get(0))||473)
46
+ });
47
+ e.preventDefault();
48
+ });
49
+ });
50
+ }
51
+
52
+ init_sortable_menu = function(){
53
+ var $menu = $('#menu');
54
+
55
+ if($menu.length == 0){return}
56
+
57
+ $menu.sortable({
58
+ axis: 'x',
59
+ cursor: 'crosshair',
60
+ items: '.tab',
61
+ update: function(){
62
+ var ser = $menu.sortable('serialize', {key: 'menu[]'}),
63
+ token = escape($('#admin_authenticity_token').val());
64
+
65
+ $.get('/admin/update_menu_positions?' + ser, {authenticity_token: token});
66
+ }
67
+ });
68
+ //Initial status disabled
69
+ $menu.sortable('disable');
70
+
71
+ $menu.find('#menu_reorder').click(function(e){
72
+ e.preventDefault();
73
+ $('#menu_reorder, #menu_reorder_done').toggle();
74
+ $('#header >*:not(#menu, script), #content, #logout').fadeTo(500, 0.2);
75
+ $menu.find('.tab a').click(function(ev){
76
+ ev.preventDefault();
22
77
  });
23
78
 
24
- tb_init(anchor);
79
+ $menu.sortable('enable');
25
80
  });
26
81
 
27
- jQuery('#submit_continue_button').bind('click', function(e) {
82
+ $menu.find('#menu_reorder_done').click(function(e){
83
+ e.preventDefault();
84
+ $('#menu_reorder, #menu_reorder_done').toggle();
85
+ $('#header >*:not(#menu, script), #content, #logout').fadeTo(500, 1);
86
+ $menu.find('.tab a').unbind('click');
87
+
88
+ $menu.sortable('disable');
89
+ });
90
+ }
91
+
92
+ init_submit_continue = function(){
93
+ $('#submit_continue_button').click(function(e) {
28
94
  // ensure wymeditors are up to date.
29
- if (jQuery(this).hasClass('wymupdate')) {
30
- WYMeditor.INSTANCES.each(function(wym)
95
+ if ($(this).hasClass('wymupdate')) {
96
+ $.each(WYMeditor.INSTANCES, function(index, wym)
31
97
  {
32
98
  wym.update();
33
99
  });
34
100
  }
35
101
 
36
- jQuery('#continue_editing').val(true);
37
- jQuery('#flash').fadeOut(250)
102
+ $('#continue_editing').val(true);
103
+ $('#flash').fadeOut(250)
38
104
 
39
- jQuery.post(this.form.action, this.form.serialize(), function(data) {
40
- if ((flash_container = $('flash_container')) != null) {
41
- flash_container.update(data);
105
+ $('.fieldWithErrors').removeClass('fieldWithErrors').addClass('field');
106
+ $('#flash_container .errorExplanation').remove();
42
107
 
43
- jQuery('#flash').css('width', 'auto').fadeIn(550);
108
+ $.post(this.form.action, $(this.form).serialize(), function(data) {
109
+ if ((flash_container = $('#flash_container')).length > 0) {
110
+ flash_container.html(data);
44
111
 
45
- jQuery('.errorExplanation').each(function(i, node) {
46
- if (node.parentNode.id != 'flash_container') {
47
- node.remove();
48
- }
49
- });
112
+ $('#flash').css('width', 'auto').fadeIn(550);
50
113
 
51
- jQuery('.fieldWithErrors').each(function(i, field) {
52
- field.removeClassName('fieldWithErrors').addClassName('field');
53
- });
114
+ $('.errorExplanation').not($('#flash_container .errorExplanation')).remove();
54
115
 
55
- $('flash_container').scrollTo();
116
+ if ((error_fields = $('#fieldsWithErrors').val()) != null) {
117
+ $.each(error_fields.split(','), function() {
118
+ $("#" + this).wrap("<div class='fieldWithErrors' />");
119
+ });
120
+ }
56
121
 
57
- jQuery('#continue_editing').val(false);
122
+ $('.fieldWithErrors:first :input:first').focus();
58
123
 
59
- jQuery('.fieldWithErrors:first :input:first').focus();
124
+ $('#continue_editing').val(false);
60
125
  }
61
126
  });
62
127
 
63
128
  e.preventDefault();
64
129
  });
65
- });
130
+ }
131
+
132
+ init_tooltips = function(args){
133
+ if (typeof(Tooltip) != "undefined") {
134
+ $($(args != null ? args : 'a[title], #image_grid img[title]')).each(function(index, element)
135
+ {
136
+ new Tooltip(element, {mouseFollow:false, delay: 0, opacity: 1, appearDuration:0, hideDuration: 0, rounded: false});
137
+ });
138
+ }
139
+ }
140
+
141
+ var link_dialog = {
142
+ init: function(test_url, test_email){
143
+ this.test_url = test_url;
144
+ this.test_email = test_email;
145
+ this.init_tabs();
146
+ this.init_close();
147
+ this.page_tab();
148
+ this.web_tab();
149
+ this.email_tab();
150
+ },
151
+
152
+ init_tabs: function(){
153
+ var radios = $('#dialog_menu_left input:radio');
154
+ var selected = radios.parent().filter(".selected_radio").find('input:radio').first() || radios.first();
155
+
156
+ radios.click(function(){
157
+ link_dialog.switch_area($(this));
158
+ });
159
+
160
+ selected.attr('checked', 'true');
161
+ link_dialog.switch_area(selected);
162
+ },
163
+
164
+ init_close: function(){
165
+ $('#TB_title .close_dialog, #dialog_container .close_dialog').click(function(e) {
166
+ e.preventDefault();
167
+
168
+ // if we're in a frame
169
+ if(parent && typeof(parent.tb_remove) == "function"){
170
+ parent.tb_remove();
171
+
172
+ } // if we're not in a frame
173
+ else if(typeof(tb_remove) == 'function'){
174
+ tb_remove();
175
+ }
176
+ });
177
+ },
178
+
179
+ switch_area: function(area){
180
+ $('#dialog_menu_left .selected_radio').removeClass('selected_radio');
181
+ $(area).parent().addClass('selected_radio');
182
+ $('#dialog_main .dialog_area').hide();
183
+ $('#' + $(area).val() + '_area').show();
184
+ },
185
+
186
+ //Same for resources tab
187
+ page_tab: function(){
188
+ $('.link_list li').click(function(e){
189
+ e.preventDefault();
190
+
191
+ remove_linked_class();
192
+ $(this).addClass('linked');
193
+
194
+ function remove_linked_class(){
195
+ $('.link_list li.linked').removeClass('linked');
196
+ }
197
+
198
+ var link = $(this).children('a.page_link').get(0);
199
+ var port = (window.location.port.length > 0 ? (":" + window.location.port) : "");
200
+ var url = link.href.replace(window.location.protocol + "//" + window.location.hostname + port, "");
201
+
202
+ link_dialog.update_parent(url, link.rel);
203
+ });
204
+ },
205
+
206
+ web_tab: function(){
207
+ $('#web_address_text').change(function(){
208
+ var prefix = '#web_address_',
209
+ icon = '';
210
+
211
+ $(prefix + 'test_loader').show();
212
+ $(prefix + 'test_result').hide();
213
+ $(prefix + 'test_result').removeClass('success_icon').removeClass('failure_icon');
214
+
215
+ $.getJSON(link_dialog.test_url, {url: this.value}, function(data){
216
+ if(data.result == 'success'){
217
+ icon = 'success_icon';
218
+ }else{
219
+ icon = 'failure_icon';
220
+ }
221
+
222
+ $(prefix + 'test_result').addClass(icon).show();
223
+ $(prefix + 'test_loader').hide();
224
+ });
225
+
226
+ link_dialog.update_parent( $(prefix + 'text').val(),
227
+ $(prefix + 'text').val(),
228
+ ($(prefix + 'target_blank').checked ? "_blank" : "")
229
+ );
230
+ });
231
+
232
+ $('#web_address_target_blank').click(function(){
233
+ parent.document.getElementById('wym_target').value = this.checked ? "_blank" : "";
234
+ });
235
+
236
+ },
237
+
238
+ email_tab: function(){
239
+ $('#email_address_text, #email_default_subject_text, #email_default_body_text').change(function(e){
240
+ var default_subject = $('#email_default_subject_text').val(),
241
+ default_body = $('#email_default_body_text').val(),
242
+ mailto = "mailto:" + $('#email_address_text').val(),
243
+ modifier = "?",
244
+ icon = '';
245
+
246
+ $('#email_address_test_loader').show();
247
+ $('#email_address_test_result').hide();
248
+ $('#email_address_test_result').removeClass('success_icon').removeClass('failure_icon');
249
+
250
+ $.getJSON(link_dialog.test_email, {email: mailto}, function(data){
251
+ if(data.result == 'success'){
252
+ icon = 'success_icon';
253
+ }else{
254
+ icon = 'failure_icon';
255
+ }
256
+
257
+ $('#email_address_test_result').addClass(icon).show();
258
+ $('#email_address_test_loader').hide();
259
+ });
260
+
261
+ if(default_subject.length > 0){
262
+ mailto += modifier + "subject=" + default_subject;
263
+ modifier = "&";
264
+ }
265
+
266
+ if(default_body.length > 0){
267
+ mailto += modifier + "body=" + default_body;
268
+ modifier = "&";
269
+ }
270
+
271
+ link_dialog.update_parent(mailto, mailto.replace('mailto:', ''));
272
+ });
273
+ },
274
+
275
+ update_parent: function(url, title, target){
276
+ parent.document.getElementById('wym_href').value = url;
277
+ parent.document.getElementById('wym_title').value = title;
278
+ parent.document.getElementById('wym_target').value = target || '';
279
+ }
280
+ }
281
+
282
+
283
+ var page_options = {
284
+ init: function(enable_parts, new_part_url, del_part_url){
285
+ this.enable_parts = enable_parts;
286
+ this.new_part_url = new_part_url;
287
+ this.del_part_url = del_part_url;
288
+ this.show_options();
289
+ this.title_type();
290
+
291
+ // Hook into the loaded function. This will be called when WYMeditor has done its thing.
292
+ WYMeditor.loaded = function(){
293
+ page_options.tabs = $('#page-tabs').tabs({tabTemplate: '<li><a href="#{href}">#{label}</a></li>'});
294
+ }
295
+
296
+ if(this.enable_parts){
297
+ this.page_part_dialog();
298
+ }
299
+ },
300
+
301
+ show_options: function(){
302
+ $('#toggle_advanced_options').click(function(e){
303
+ e.preventDefault();
304
+ $('#more_options').toggle();
305
+ });
306
+ },
307
+
308
+ title_type: function(){
309
+ $("input[name=page\[custom_title_type\]]").change(function(){
310
+ $('#custom_title_text, #custom_title_image').hide();
311
+ $('#custom_title_' + this.value).show();
312
+ });
313
+ },
314
+
315
+ page_part_dialog: function(){
316
+ $('#new_page_part_dialog').dialog({
317
+ title: 'Create Content Section',
318
+ modal: true,
319
+ resizable: false,
320
+ autoOpen: false,
321
+ width: 600
322
+ });
323
+
324
+ $('#add_page_part').click(function(e){
325
+ e.preventDefault();
326
+ $('#new_page_part_dialog').dialog('open');
327
+ });
328
+
329
+ $('#new_page_part_save').click(function(e){
330
+ e.preventDefault();
331
+
332
+ var part_title = $('#new_page_part_title').val();
333
+
334
+ if(part_title.length > 0){
335
+ var tab_title = part_title.toLowerCase().replace(" ", "_");
336
+
337
+ if ($('#part_' + tab_title).size() == 0) {
338
+ $.get(page_options.new_part_url,
339
+ {
340
+ title: part_title
341
+ , part_index: $('#new_page_part_index').val()
342
+ , body: ''
343
+ }
344
+ , function(data, status){
345
+ // Add a new tab for the new content section.
346
+ $('#page_part_editors').append(data);
347
+ page_options.tabs.tabs('add', '#page_part_new_' + $('#new_page_part_index').val(), part_title);
348
+ page_options.tabs.tabs('select', '#page_part_new_' + $('#new_page_part_index').val());
349
+
350
+ // turn the new textarea into a wymeditor.
351
+ $('#page_parts_attributes_' + $('#new_page_part_index').val() + "_body").wymeditor(wymeditor_boot_options);
352
+
353
+ // Wipe the title and increment the index counter by one.
354
+ $('#new_page_part_index').val(parseInt($('#new_page_part_index').val()) + 1);
355
+ $('#new_page_part_title').val('');
356
+
357
+ $('#page-tabs').tabs();
358
+ }
359
+ );
360
+ }else{
361
+ alert("A content section with that title already exists, please choose another.");
362
+ }
363
+ }else{
364
+ alert("You have not entered a title for the content section, please enter one.");
365
+ }
366
+
367
+
368
+ $('#new_page_part_dialog').dialog('close');
369
+ });
370
+
371
+ $('#new_page_part_cancel').click(function(e){
372
+ e.preventDefault();
373
+ $('#new_page_part_dialog').dialog('close');
374
+ $('#new_page_part_title').val('');
375
+ });
376
+
377
+ $('#delete_page_part').click(function(e){
378
+ e.preventDefault();
379
+ var stab_id = page_options.tabs.tabs('option', 'selected');
380
+ var part_id = $('#page_parts_attributes_' + stab_id + '_id').val();
381
+ //console.log('stab_id: ' + stab_id + ' part_id: ' + part_id);
382
+
383
+ var result = confirm("This will remove the content section '" + $('#page_parts .ui-tabs-selected a').html() + "' when the page is saved and erase all content that has been entered into it, Are you sure?");
384
+ if(part_id && result){
385
+ $.ajax({
386
+ url: page_options.del_part_url + '/' + part_id,
387
+ type: 'DELETE'
388
+ });
389
+ page_options.tabs.tabs('remove', stab_id);
390
+ //WYMeditor.loaded();
391
+ }
392
+
393
+ });
394
+
395
+ }
396
+
397
+ }
398
+
399
+ var image_dialog = {
400
+ init: function(){
401
+ this.init_tabs();
402
+ this.init_select();
403
+ this.init_submit();
404
+ this.init_close();
405
+ },
406
+
407
+ init_tabs: function(){
408
+ var radios = $('#dialog_menu_left input:radio');
409
+ var selected = radios.parent().filter(".selected_radio").find('input:radio').first() || radios.first();
410
+
411
+ radios.click(function(){
412
+ link_dialog.switch_area($(this));
413
+ });
414
+
415
+ selected.attr('checked', 'true');
416
+ link_dialog.switch_area(selected);
417
+ },
418
+
419
+ switch_area: function(radio){
420
+ $('#dialog_menu_left .selected_radio').removeClass('selected_radio');
421
+ $(radio).parent().addClass('selected_radio');
422
+ $('#dialog_main .dialog_area').hide();
423
+ $('#' + radio.value + '_area').show();
424
+ },
425
+
426
+ init_select: function(){
427
+ $('#existing_image_area_content ul li img').click(function(){
428
+ image_dialog.set_image(this);
429
+ });
430
+ //Select any currently selected, just uploaded...
431
+ if ((selected_image = $('#existing_image_area_content ul li.selected img')).length > 0) {
432
+ image_dialog.set_image(selected_image.first());
433
+ }
434
+ },
435
+
436
+ set_image: function(img){
437
+ if ($(img).length > 0) {
438
+ $('#existing_image_area_content ul li.selected').removeClass('selected');
439
+
440
+ $(img).parent().addClass('selected');
441
+ var imageUrl = parseURL($(img).attr('src'));
442
+ var relevant_src = imageUrl.pathname.replace('_dialog_thumb', '');
443
+ if (imageUrl.protocol == "" && imageUrl.hostname == "system") {
444
+ relevant_src = "/system" + relevant_src;
445
+ }
446
+
447
+ if(imageUrl.hostname.match(/s3.amazonaws.com/)){
448
+ relevant_src = imageUrl.protocol + '//' + imageUrl.host + relevant_src;
449
+ }
450
+
451
+ try {
452
+ parent.document.getElementById('wym_src').value = relevant_src;
453
+ parent.document.getElementById('wym_title').value = img.title;
454
+ parent.document.getElementById('wym_alt').value = img.alt;
455
+ }
456
+ catch(e){}
457
+ }
458
+ },
459
+
460
+ init_submit: function(){
461
+ $('#dialog-form-actions #submit_button').click(function(e){
462
+ e.preventDefault();
463
+ if(img_selected = $('#existing_image_area_content ul li.selected img').get(0)) {
464
+ parent.image_picker.changed(img_selected);
465
+ }
466
+
467
+ if(parent && typeof(parent.tb_remove) == "function"){
468
+ parent.tb_remove();
469
+ }
470
+ });
471
+
472
+ $('#dialog-form-actions #cancel_button').click(function(e){
473
+ e.preventDefault();
474
+ parent.tb_remove();
475
+ });
476
+ },
477
+
478
+ init_close: function(){
479
+ $('#TB_title .close_dialog, #dialog_container .close_dialog').click(function(e) {
480
+ e.preventDefault();
481
+
482
+ // if we're in a frame
483
+ if(parent && typeof(parent.tb_remove) == "function"){
484
+ parent.tb_remove();
485
+
486
+ } // if we're not in a frame
487
+ else if(typeof(tb_remove) == 'function'){
488
+ tb_remove();
489
+ }
490
+ });
491
+ }
492
+ }
493
+
494
+ var list_reorder = {
495
+ init: function() {
496
+ $('#reorder_action').click(list_reorder.enable_reordering);
497
+ $('#reorder_action_done').click(list_reorder.disable_reordering);
498
+ }
499
+
500
+ , enable_reordering: function(e) {
501
+ if(e) { e.preventDefault(); }
502
+
503
+ list_reorder.sortable_list.find('li').each(function(index, li) {
504
+ if ($('ul', li).length) { return; }
505
+ $("<ul></ul>").appendTo(li);
506
+ });
507
+
508
+ list_reorder.sortable_list.add(list_reorder.sortable_list.find('ul')).sortable({
509
+ 'connectWith': $(list_reorder.sortable_list.find('ul'))
510
+ , 'tolerance': 'pointer'
511
+ , 'placeholder': 'placeholder'
512
+ , 'cursor': 'drag'
513
+ , 'items': 'li'
514
+ , 'axis': 'y'
515
+ });
516
+
517
+ $('#reorder_action').hide();
518
+ $('#reorder_action_done').show();
519
+ }
520
+
521
+ , parse_branch: function(indexes, li) {
522
+ branch = "&sortable_list";
523
+ $.each(indexes, function(i, index) {
524
+ branch += "[" + index + "]";
525
+ });
526
+ branch += "[id]=" + $($(li).attr('id').split('_')).last().get(0);
527
+
528
+ // parse any children branches too.
529
+ $(li).find('> li[id], > ul li[id]').each(function(i, child) {
530
+ branch += list_reorder.parse_branch(indexes + [i], child);
531
+ });
532
+
533
+ return branch;
534
+ }
535
+
536
+ , disable_reordering: function(e) {
537
+ if(e) { e.preventDefault(); }
538
+
539
+ serialized = "";
540
+ list_reorder.sortable_list.find('> li[id]').each(function(index, li) {
541
+ serialized += list_reorder.parse_branch([index], li);
542
+ });
543
+ serialized += "&tree=" + list_reorder.tree + "&authenticity_token=" + encodeURIComponent($('#reorder_authenticity_token').val() + "&continue_reordering=false");
544
+
545
+ $.post(list_reorder.update_url, serialized, function(data) {
546
+ $(list_reorder.sortable_list.get(0)).html(data);
547
+
548
+ $(list_reorder.sortable_list).removeClass('reordering').sortable('destroy');
549
+
550
+ $('#reorder_action_done').hide();
551
+ $('#reorder_action').show();
552
+ });
553
+ }
554
+ }
555
+
556
+ var image_picker = {
557
+ options: {
558
+ selected: '',
559
+ thumbnail: '',
560
+ toggle_image_display: false
561
+ }
562
+
563
+ , init: function(new_options){
564
+ this.options = $.extend(this.options, new_options);
565
+ $('#remove_picked_image').click(function(e){
566
+ e.preventDefault();
567
+ $('#current_picked_image').removeClass('brown_border')
568
+ .attr({'src': '', 'width': '', 'height': ''})
569
+ .css({'width': 'auto', 'height': 'auto'})
570
+ .hide();
571
+ $('#custom_title_field').val('');
572
+ $('#no_picked_image_selected').show();
573
+ $(this).hide();
574
+ });
575
+
576
+ if(this.options.toggle_image_display){
577
+ $('#current_image_toggler').click(function(e){
578
+ $(this).html(($(this).html() == 'Show' ? 'Hide' : 'Show'));
579
+ $("#current_image_container").toggle();
580
+ e.preventDefault();
581
+ });
582
+ }
583
+
584
+ }
585
+
586
+ , changed: function(image){
587
+ var current_img = $('#current_picked_image');
588
+ $('#custom_title_field').val(image.id.replace("image_", ""));
589
+
590
+ if(this.options.thumbnail != ''){
591
+ image.src = image.src.replace('_dialog_thumb', '_' + this.options.thumbnail);
592
+ }
593
+ current_img.attr('src', image.src).addClass('brown_border').show();
594
+ $('#remove_picked_image').show();
595
+ $('#no_picked_image_selected').hide();
596
+ }
597
+ }
598
+
599
+ //parse a URL to form an object of properties
600
+ parseURL = function(url)
601
+ {
602
+ //save the unmodified url to href property
603
+ //so that the object we get back contains
604
+ //all the same properties as the built-in location object
605
+ var loc = { 'href' : url };
606
+
607
+ //split the URL by single-slashes to get the component parts
608
+ var parts = url.replace('//', '/').split('/');
609
+
610
+ //store the protocol and host
611
+ loc.protocol = parts[0];
612
+ loc.host = parts[1];
613
+
614
+ //extract any port number from the host
615
+ //from which we derive the port and hostname
616
+ parts[1] = parts[1].split(':');
617
+ loc.hostname = parts[1][0];
618
+ loc.port = parts[1].length > 1 ? parts[1][1] : '';
619
+
620
+ //splice and join the remainder to get the pathname
621
+ parts.splice(0, 2);
622
+ loc.pathname = '/' + parts.join('/');
623
+
624
+ //extract any hash and remove from the pathname
625
+ loc.pathname = loc.pathname.split('#');
626
+ loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
627
+ loc.pathname = loc.pathname[0];
628
+
629
+ //extract any search query and remove from the pathname
630
+ loc.pathname = loc.pathname.split('?');
631
+ loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
632
+ loc.pathname = loc.pathname[0];
633
+
634
+ //return the final object
635
+ return loc;
636
+ }