refinerycms-image_rotators 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/app/controllers/admin/image_rotator_images_controller.rb +26 -0
  2. data/app/controllers/admin/image_rotators_controller.rb +7 -0
  3. data/app/models/image_rotator.rb +13 -0
  4. data/app/models/image_rotator_image.rb +13 -0
  5. data/app/views/admin/image_rotator_images/_form.html.erb +33 -0
  6. data/app/views/admin/image_rotator_images/_image_rotator_image.html.erb +15 -0
  7. data/app/views/admin/image_rotator_images/_sortable_list.html.erb +4 -0
  8. data/app/views/admin/image_rotator_images/edit.html.erb +1 -0
  9. data/app/views/admin/image_rotator_images/new.html.erb +1 -0
  10. data/app/views/admin/image_rotators/_form.html.erb +29 -0
  11. data/app/views/admin/image_rotators/_image_rotator.html.erb +15 -0
  12. data/app/views/admin/image_rotators/_sortable_list.html.erb +4 -0
  13. data/app/views/admin/image_rotators/edit.html.erb +57 -0
  14. data/app/views/admin/image_rotators/index.html.erb +47 -0
  15. data/app/views/admin/image_rotators/new.html.erb +1 -0
  16. data/config/locales/en.yml +34 -0
  17. data/config/locales/nb.yml +19 -0
  18. data/config/locales/nl.yml +19 -0
  19. data/config/routes.rb +11 -0
  20. data/lib/gemspec.rb +27 -0
  21. data/lib/generators/refinerycms_image_rotators_generator.rb +71 -0
  22. data/lib/generators/templates/db/migrate/create_image_rotators.rb +35 -0
  23. data/lib/generators/templates/db/seeds/image_rotators.rb +4 -0
  24. data/lib/generators/templates/public/images/arrows.png +0 -0
  25. data/lib/generators/templates/public/images/bullets.png +0 -0
  26. data/lib/generators/templates/public/images/loading.gif +0 -0
  27. data/lib/generators/templates/public/javascripts/jquery.image-rotators.js +12 -0
  28. data/lib/generators/templates/public/javascripts/refinery/admin.js +1011 -0
  29. data/lib/generators/templates/public/stylesheets/image-rotators.css +138 -0
  30. data/lib/image_rotators.rb +7 -0
  31. data/lib/refinerycms-image_rotators.rb +20 -0
  32. data/lib/tasks/image_rotators.rake +13 -0
  33. data/readme.md +10 -0
  34. metadata +99 -0
@@ -0,0 +1,35 @@
1
+ class CreateImageRotators < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :image_rotators do |t|
5
+ t.string :title
6
+ t.string :height
7
+ t.string :width
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :image_rotators, :id
13
+
14
+ load(Rails.root.join('db', 'seeds', 'refinerycms-image_rotators.rb'))
15
+
16
+ create_table :image_rotator_images do |t|
17
+ t.integer :image_rotator_id
18
+ t.integer :image_id
19
+ t.text :url
20
+ t.integer :position
21
+
22
+ t.timestamps
23
+ end
24
+
25
+ add_index :image_rotator_images, :id
26
+ end
27
+
28
+ def self.down
29
+ UserPlugin.destroy_all({:name => "image_rotators"})
30
+
31
+ drop_table :image_rotator_images
32
+ drop_table :image_rotators
33
+ end
34
+
35
+ end
@@ -0,0 +1,4 @@
1
+ User.find(:all).each do |user|
2
+ user.plugins.create(:name => "image_rotators",
3
+ :position => (user.plugins.maximum(:position) || -1) +1)
4
+ end
@@ -0,0 +1,12 @@
1
+ /*
2
+ * jQuery Nivo Slider v2.3
3
+ * http://nivo.dev7studios.com
4
+ *
5
+ * Copyright 2010, Gilbert Pellegrom
6
+ * Free to use and abuse under the MIT license.
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ */
9
+
10
+ (function(b){var a=function(j,q){var g=b.extend({},b.fn.nivoSlider.defaults,q);var m={currentSlide:0,currentImage:"",totalSlides:0,randAnim:"",running:false,paused:false,stop:false};var d=b(j);d.data("nivo:vars",m);d.css("position","relative");d.addClass("nivoSlider");var e=d.children();e.each(function(){var t=b(this);var s="";if(!t.is("img")){if(t.is("a")){t.addClass("nivo-imageLink");s=t}t=t.find("img:first")}var r=t.width();if(r==0){r=t.attr("width")}var i=t.height();if(i==0){i=t.attr("height")}if(r>d.width()){d.width(r)}if(i>d.height()){d.height(i)}if(s!=""){s.css("display","none")}t.css("display","none");m.totalSlides++});if(g.startSlide>0){if(g.startSlide>=m.totalSlides){g.startSlide=m.totalSlides-1}m.currentSlide=g.startSlide}if(b(e[m.currentSlide]).is("img")){m.currentImage=b(e[m.currentSlide])}else{m.currentImage=b(e[m.currentSlide]).find("img:first")}if(b(e[m.currentSlide]).is("a")){b(e[m.currentSlide]).css("display","block")}d.css("background","url("+m.currentImage.attr("src")+") no-repeat");for(var k=0;k<g.slices;k++){var o=Math.round(d.width()/g.slices);if(k==g.slices-1){d.append(b('<div class="nivo-slice"></div>').css({left:(o*k)+"px",width:(d.width()-(o*k))+"px"}))}else{d.append(b('<div class="nivo-slice"></div>').css({left:(o*k)+"px",width:o+"px"}))}}d.append(b('<div class="nivo-caption"><p></p></div>').css({display:"none",opacity:g.captionOpacity}));if(m.currentImage.attr("title")!=""){var n=m.currentImage.attr("title");if(n.substr(0,1)=="#"){n=b(n).html()}b(".nivo-caption p",d).html(n);b(".nivo-caption",d).fadeIn(g.animSpeed)}var c=0;if(!g.manualAdvance&&e.length>1){c=setInterval(function(){p(d,e,g,false)},g.pauseTime)}if(g.directionNav){d.append('<div class="nivo-directionNav"><a class="nivo-prevNav">Prev</a><a class="nivo-nextNav">Next</a></div>');if(g.directionNavHide){b(".nivo-directionNav",d).hide();d.hover(function(){b(".nivo-directionNav",d).show()},function(){b(".nivo-directionNav",d).hide()})}b("a.nivo-prevNav",d).live("click",function(){if(m.running){return false}clearInterval(c);c="";m.currentSlide-=2;p(d,e,g,"prev")});b("a.nivo-nextNav",d).live("click",function(){if(m.running){return false}clearInterval(c);c="";p(d,e,g,"next")})}if(g.controlNav){var l=b('<div class="nivo-controlNav"></div>');d.append(l);for(var k=0;k<e.length;k++){if(g.controlNavThumbs){var f=e.eq(k);if(!f.is("img")){f=f.find("img:first")}if(g.controlNavThumbsFromRel){l.append('<a class="nivo-control" rel="'+k+'"><img src="'+f.attr("rel")+'" alt="" /></a>')}else{l.append('<a class="nivo-control" rel="'+k+'"><img src="'+f.attr("src").replace(g.controlNavThumbsSearch,g.controlNavThumbsReplace)+'" alt="" /></a>')}}else{l.append('<a class="nivo-control" rel="'+k+'">'+(k+1)+"</a>")}}b(".nivo-controlNav a:eq("+m.currentSlide+")",d).addClass("active");b(".nivo-controlNav a",d).live("click",function(){if(m.running){return false}if(b(this).hasClass("active")){return false}clearInterval(c);c="";d.css("background","url("+m.currentImage.attr("src")+") no-repeat");m.currentSlide=b(this).attr("rel")-1;p(d,e,g,"control")})}if(g.keyboardNav){b(window).keypress(function(i){if(i.keyCode=="37"){if(m.running){return false}clearInterval(c);c="";m.currentSlide-=2;p(d,e,g,"prev")}if(i.keyCode=="39"){if(m.running){return false}clearInterval(c);c="";p(d,e,g,"next")}})}if(g.pauseOnHover){d.hover(function(){m.paused=true;clearInterval(c);c=""},function(){m.paused=false;if(c==""&&!g.manualAdvance){c=setInterval(function(){p(d,e,g,false)},g.pauseTime)}})}d.bind("nivo:animFinished",function(){m.running=false;b(e).each(function(){if(b(this).is("a")){b(this).css("display","none")}});if(b(e[m.currentSlide]).is("a")){b(e[m.currentSlide]).css("display","block")}if(c==""&&!m.paused&&!g.manualAdvance){c=setInterval(function(){p(d,e,g,false)},g.pauseTime)}g.afterChange.call(this)});var p=function(r,s,u,x){var y=r.data("nivo:vars");if(y&&(y.currentSlide==y.totalSlides-1)){u.lastSlide.call(this)}if((!y||y.stop)&&!x){return false}u.beforeChange.call(this);if(!x){r.css("background","url("+y.currentImage.attr("src")+") no-repeat")}else{if(x=="prev"){r.css("background","url("+y.currentImage.attr("src")+") no-repeat")}if(x=="next"){r.css("background","url("+y.currentImage.attr("src")+") no-repeat")}}y.currentSlide++;if(y.currentSlide==y.totalSlides){y.currentSlide=0;u.slideshowEnd.call(this)}if(y.currentSlide<0){y.currentSlide=(y.totalSlides-1)}if(b(s[y.currentSlide]).is("img")){y.currentImage=b(s[y.currentSlide])}else{y.currentImage=b(s[y.currentSlide]).find("img:first")}if(u.controlNav){b(".nivo-controlNav a",r).removeClass("active");b(".nivo-controlNav a:eq("+y.currentSlide+")",r).addClass("active")}if(y.currentImage.attr("title")!=""){var z=y.currentImage.attr("title");if(z.substr(0,1)=="#"){z=b(z).html()}if(b(".nivo-caption",r).css("display")=="block"){b(".nivo-caption p",r).fadeOut(u.animSpeed,function(){b(this).html(z);b(this).fadeIn(u.animSpeed)})}else{b(".nivo-caption p",r).html(z)}b(".nivo-caption",r).fadeIn(u.animSpeed)}else{b(".nivo-caption",r).fadeOut(u.animSpeed)}var w=0;b(".nivo-slice",r).each(function(){var i=Math.round(r.width()/u.slices);b(this).css({height:"0px",opacity:"0",background:"url("+y.currentImage.attr("src")+") no-repeat -"+((i+(w*i))-i)+"px 0%"});w++});if(u.effect=="random"){var A=new Array("sliceDownRight","sliceDownLeft","sliceUpRight","sliceUpLeft","sliceUpDown","sliceUpDownLeft","fold","fade");y.randAnim=A[Math.floor(Math.random()*(A.length+1))];if(y.randAnim==undefined){y.randAnim="fade"}}if(u.effect.indexOf(",")!=-1){var A=u.effect.split(",");y.randAnim=b.trim(A[Math.floor(Math.random()*A.length)])}y.running=true;if(u.effect=="sliceDown"||u.effect=="sliceDownRight"||y.randAnim=="sliceDownRight"||u.effect=="sliceDownLeft"||y.randAnim=="sliceDownLeft"){var t=0;var w=0;var C=b(".nivo-slice",r);if(u.effect=="sliceDownLeft"||y.randAnim=="sliceDownLeft"){C=b(".nivo-slice",r)._reverse()}C.each(function(){var i=b(this);i.css("top","0px");if(w==u.slices-1){setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},u.animSpeed,"",function(){r.trigger("nivo:animFinished")})},(100+t))}else{setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},u.animSpeed)},(100+t))}t+=50;w++})}else{if(u.effect=="sliceUp"||u.effect=="sliceUpRight"||y.randAnim=="sliceUpRight"||u.effect=="sliceUpLeft"||y.randAnim=="sliceUpLeft"){var t=0;var w=0;var C=b(".nivo-slice",r);if(u.effect=="sliceUpLeft"||y.randAnim=="sliceUpLeft"){C=b(".nivo-slice",r)._reverse()}C.each(function(){var i=b(this);i.css("bottom","0px");if(w==u.slices-1){setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},u.animSpeed,"",function(){r.trigger("nivo:animFinished")})},(100+t))}else{setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},u.animSpeed)},(100+t))}t+=50;w++})}else{if(u.effect=="sliceUpDown"||u.effect=="sliceUpDownRight"||y.randAnim=="sliceUpDown"||u.effect=="sliceUpDownLeft"||y.randAnim=="sliceUpDownLeft"){var t=0;var w=0;var B=0;var C=b(".nivo-slice",r);if(u.effect=="sliceUpDownLeft"||y.randAnim=="sliceUpDownLeft"){C=b(".nivo-slice",r)._reverse()}C.each(function(){var i=b(this);if(w==0){i.css("top","0px");w++}else{i.css("bottom","0px");w=0}if(B==u.slices-1){setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},u.animSpeed,"",function(){r.trigger("nivo:animFinished")})},(100+t))}else{setTimeout(function(){i.animate({height:"100%",opacity:"1.0"},u.animSpeed)},(100+t))}t+=50;B++})}else{if(u.effect=="fold"||y.randAnim=="fold"){var t=0;var w=0;b(".nivo-slice",r).each(function(){var i=b(this);var v=i.width();i.css({top:"0px",height:"100%",width:"0px"});if(w==u.slices-1){setTimeout(function(){i.animate({width:v,opacity:"1.0"},u.animSpeed,"",function(){r.trigger("nivo:animFinished")})},(100+t))}else{setTimeout(function(){i.animate({width:v,opacity:"1.0"},u.animSpeed)},(100+t))}t+=50;w++})}else{if(u.effect=="fade"||y.randAnim=="fade"){var w=0;b(".nivo-slice",r).each(function(){b(this).css("height","100%");if(w==u.slices-1){b(this).animate({opacity:"1.0"},(u.animSpeed*2),"",function(){r.trigger("nivo:animFinished")})}else{b(this).animate({opacity:"1.0"},(u.animSpeed*2))}w++})}}}}}};var h=function(i){if(this.console&&typeof console.log!="undefined"){console.log(i)}};this.stop=function(){if(!b(j).data("nivo:vars").stop){b(j).data("nivo:vars").stop=true;h("Stop Slider")}};this.start=function(){if(b(j).data("nivo:vars").stop){b(j).data("nivo:vars").stop=false;h("Start Slider")}};g.afterLoad.call(this)};b.fn.nivoSlider=function(c){return this.each(function(){var d=b(this);if(d.data("nivoslider")){return}var e=new a(this,c);d.data("nivoslider",e)})};b.fn.nivoSlider.defaults={effect:"random",slices:15,animSpeed:500,pauseTime:3000,startSlide:0,directionNav:true,directionNavHide:true,controlNav:true,controlNavThumbs:false,controlNavThumbsFromRel:false,controlNavThumbsSearch:".jpg",controlNavThumbsReplace:"_thumb.jpg",keyboardNav:true,pauseOnHover:true,manualAdvance:false,captionOpacity:0.8,beforeChange:function(){},afterChange:function(){},slideshowEnd:function(){},lastSlide:function(){},afterLoad:function(){}};b.fn._reverse=[].reverse})(jQuery);
11
+
12
+ jQuery(function($){ $('.image-rotator').nivoSlider(); });
@@ -0,0 +1,1011 @@
1
+ var shiftHeld = false;
2
+ $(document).ready(function(){
3
+ init_interface();
4
+ init_sortable_menu();
5
+ init_submit_continue();
6
+ init_modal_dialogs();
7
+ init_tooltips();
8
+ });
9
+
10
+ init_interface = function() {
11
+ if (parent && parent.document.location.href != document.location.href) {
12
+ $('body#dialog_container.dialog').addClass('iframed');
13
+ }
14
+ $('input:submit:not(.button)').addClass('button');
15
+
16
+ $('.button, #editor_switch a').corner('6px');
17
+ $('#editor_switch a').appendTo($('<span></span>').prependTo('#editor_switch').corner('6px'));
18
+ $('#page_container, .wym_box').corner('5px bottom');
19
+ $('.wym_box').corner('5px tr');
20
+ $('.field > .wym_box').corner('5px tl');
21
+ $('.wym_iframe iframe').corner('2px');
22
+ $('.form-actions:not(".form-actions-dialog")').corner('5px');
23
+ $('#recent_activity li a, #recent_inquiries li a').each(function(i, a) {
24
+ $(this).textTruncate({
25
+ width: $(this).width()
26
+ , tooltip: false
27
+ });
28
+ });
29
+
30
+ // make sure that users can tab to wymeditor fields and add an overlay while loading.
31
+ $('textarea.wymeditor').each(function() {
32
+ textarea = $(this);
33
+ if ((instance = WYMeditor.INSTANCES[$((textarea.next('.wym_box').find('iframe').attr('id')||'').split('_')).last().get(0)]) != null) {
34
+ if ((next = textarea.parent().next()) != null && next.length > 0) {
35
+ next.find('input, textarea').keydown($.proxy(function(e) {
36
+ shiftHeld = e.shiftKey;
37
+ if (shiftHeld && e.keyCode == $.ui.keyCode.TAB) {
38
+ this._iframe.contentWindow.focus();
39
+ e.preventDefault();
40
+ }
41
+ }, instance)).keyup(function(e) {
42
+ shiftHeld = false;
43
+ });
44
+ }
45
+ if ((prev = textarea.parent().prev()) != null && prev.length > 0) {
46
+ prev.find('input, textarea').keydown($.proxy(function(e) {
47
+ if (e.keyCode == $.ui.keyCode.TAB) {
48
+ this._iframe.contentWindow.focus();
49
+ e.preventDefault();
50
+ }
51
+ }, instance));
52
+ }
53
+ }
54
+ });
55
+
56
+ // ensure that the menu isn't wider than the page_container or else it looks silly to round that corner.
57
+ if (($menu = $('#menu')).length > 0) {
58
+ $menu.jcarousel({
59
+ vertical: false
60
+ , scroll: 1
61
+ , buttonNextHTML: "<img src='/images/refinery/carousel-right.png' alt='down' height='15' width='10' />"
62
+ , buttonPrevHTML: "<img src='/images/refinery/carousel-left.png' alt='up' height='15' width='10' />"
63
+ , listTag: $menu.get(0).tagName.toLowerCase()
64
+ , itemTag: $menu.children(':first').get(0).tagName.toLowerCase()
65
+ });
66
+
67
+ if ($menu.outerWidth() < $('#page_container').outerWidth()) {
68
+ $("#page_container:not('.login #page_container')").corner('5px tr');
69
+ } else {
70
+ $("#page_container:not('.login #page_container')").uncorner();
71
+ }
72
+ }
73
+
74
+ $('#current_locale li a').click(function(e) {
75
+ $('#current_locale li a span').each(function(span){
76
+ $(this).css('display', $(this).css('display') == 'none' ? '' : 'none');
77
+ });
78
+ $('#other_locales').animate({opacity: 'toggle', height: 'toggle'}, 250);
79
+ e.preventDefault();
80
+ });
81
+
82
+ $('#existing_image img').load(function(){
83
+ $('form.edit_image .form-actions').css({
84
+ 'margin-top': ($('#existing_image').height() - $('form.edit_image').height() + 8)
85
+ });
86
+ });
87
+
88
+ $('.form-actions .form-actions-left input:submit#submit_button').click(function(e) {
89
+ $("<img src='/images/refinery/icons/ajax-loader.gif' width='16' height='16' class='save-loader' />").appendTo($(this).parent());
90
+ });
91
+ }
92
+
93
+ init_modal_dialogs = function(){
94
+ $('a[href*="dialog=true"]').not('#dialog_container a').each(function(i, anchor) {
95
+ $(anchor).data({
96
+ 'dialog-width': parseInt($($(anchor).attr('href').match("width=([0-9]*)")).last().get(0))||928
97
+ , 'dialog-height': parseInt($($(anchor).attr('href').match("height=([0-9]*)")).last().get(0))||473
98
+ , 'dialog-title': ($(anchor).attr('title') || $(anchor).attr('name') || $(anchor).html() || null)
99
+ }).attr('href', $(anchor).attr('href').replace(/(\&(amp\;)?)?dialog\=true/, '')
100
+ .replace(/(\&(amp\;)?)?width\=\d+/, '')
101
+ .replace(/(\&(amp\;)?)?height\=\d+/, '')
102
+ .replace(/(\?&(amp\;)?)/, '?')
103
+ .replace(/\?$/, ''))
104
+ .click(function(e){
105
+ $anchor = $(this);
106
+ iframe_src = (iframe_src = $anchor.attr('href'))
107
+ + (iframe_src.indexOf('?') > -1 ? '&amp;' : '?')
108
+ + 'app_dialog=true&amp;dialog=true';
109
+
110
+ iframe = $("<iframe id='dialog_iframe' src='" + iframe_src + "'></iframe>").corner('8px');
111
+ iframe.dialog({
112
+ title: $anchor.data('dialog-title')
113
+ , modal: true
114
+ , resizable: false
115
+ , autoOpen: true
116
+ , width: $anchor.data('dialog-width')
117
+ , height: $anchor.data('dialog-height')
118
+ , open: onOpenDialog
119
+ , close: onCloseDialog
120
+ });
121
+ if ($.browser.msie) {
122
+ iframe.css({'margin':'-2px 2px 2px -2px'});
123
+ }
124
+ if(parseInt($anchor.data('dialog-height')) < $(window).height()) {
125
+ $(document.body).addClass('hide-overflow');
126
+ }
127
+ e.preventDefault();
128
+ });
129
+ });
130
+ }
131
+
132
+ init_sortable_menu = function(){
133
+ var $menu = $('#menu');
134
+
135
+ if($menu.length == 0){return}
136
+
137
+ $menu.sortable({
138
+ axis: 'x',
139
+ cursor: 'crosshair',
140
+ connectWith: '.nested',
141
+ update: function(){
142
+ $.post('/refinery/update_menu_positions', $menu.sortable('serialize', {
143
+ key: 'menu[]'
144
+ , expression: /plugin_([\w]*)$/
145
+ }));
146
+ }
147
+ }).tabs();
148
+ //Initial status disabled
149
+ $menu.sortable('disable');
150
+
151
+ $menu.find('#menu_reorder').click(function(e){
152
+ trigger_reordering(e, true);
153
+ });
154
+
155
+ $menu.find('#menu_reorder_done').click(function(e){
156
+ trigger_reordering(e, false);
157
+ });
158
+
159
+ $menu.find('> a').corner('top 5px');
160
+ }
161
+
162
+ trigger_reordering = function(e, enable) {
163
+ e.preventDefault();
164
+ $('#menu_reorder, #menu_reorder_done').toggle();
165
+ $('#site_bar, #content').fadeTo(500, enable ? 0.35 : 1);
166
+
167
+ if(enable) {
168
+ $menu.find('.tab a').click(function(ev){
169
+ ev.preventDefault();
170
+ });
171
+ } else {
172
+ $menu.find('.tab a').unbind('click');
173
+ }
174
+
175
+ $menu.sortable(enable ? 'enable' : 'disable');
176
+ }
177
+
178
+ init_submit_continue = function(){
179
+ $('#submit_continue_button').click(submit_and_continue);
180
+
181
+ $('form').change(function(e) {
182
+ $(this).attr('data-changes-made', true);
183
+ });
184
+
185
+ if ((continue_editing_button = $('#continue_editing')).length > 0 && continue_editing_button.attr('rel') != 'no-prompt') {
186
+ $('#editor_switch a').click(function(e) {
187
+ if ($('form[data-changes-made]').length > 0) {
188
+ if (!confirm("Any changes you've made will be lost. Are you sure you want to continue without saving?")) {
189
+ e.preventDefault();
190
+ }
191
+ }
192
+ });
193
+ }
194
+ }
195
+
196
+ submit_and_continue = function(e, redirect_to) {
197
+ // ensure wymeditors are up to date.
198
+ if ($(this).hasClass('wymupdate')) {
199
+ $.each(WYMeditor.INSTANCES, function(index, wym)
200
+ {
201
+ wym.update();
202
+ });
203
+ }
204
+
205
+ $('#continue_editing').val(true);
206
+ $('#flash').fadeOut(250)
207
+
208
+ $('.fieldWithErrors').removeClass('fieldWithErrors').addClass('field');
209
+ $('#flash_container .errorExplanation').remove();
210
+
211
+ $.post($('#continue_editing').get(0).form.action, $($('#continue_editing').get(0).form).serialize(), function(data) {
212
+ if (($flash_container = $('#flash_container')).length > 0) {
213
+ $flash_container.html(data);
214
+
215
+ $('#flash').css('width', 'auto').fadeIn(550);
216
+
217
+ $('.errorExplanation').not($('#flash_container .errorExplanation')).remove();
218
+
219
+ if ((error_fields = $('#fieldsWithErrors').val()) != null) {
220
+ $.each(error_fields.split(','), function() {
221
+ $("#" + this).wrap("<div class='fieldWithErrors' />");
222
+ });
223
+ } else if (redirect_to) {
224
+ window.location = redirect_to;
225
+ }
226
+
227
+ $('.fieldWithErrors:first :input:first').focus();
228
+
229
+ $('#continue_editing').val(false);
230
+
231
+ init_flash_messages();
232
+ }
233
+ });
234
+
235
+ e.preventDefault();
236
+ }
237
+
238
+ init_tooltips = function(args){
239
+ $($(args != null ? args : 'a[title], span[title], #image_grid img[title], *[tooltip]')).not('.no-tooltip').each(function(index, element)
240
+ {
241
+ // create tooltip on hover and destroy it on hoveroff.
242
+ $(element).hover(function(e) {
243
+ $(this).oneTime(350, 'tooltip', $.proxy(function() {
244
+ $('.tooltip').remove();
245
+ tooltip = $("<div class='tooltip'><div><span></span></div></div>").corner('6px').appendTo('#tooltip_container');
246
+ tooltip.find("span").html($(this).attr('tooltip')).corner('6px');
247
+
248
+ nib = $("<img src='/images/refinery/tooltip-nib.png' class='tooltip-nib'/>").appendTo('#tooltip_container');
249
+
250
+ tooltip.css({
251
+ 'opacity': 0
252
+ , 'maxWidth': '300px'
253
+ });
254
+ required_left_offset = $(this).offset().left - (tooltip.outerWidth() / 2) + ($(this).outerWidth() / 2);
255
+ tooltip.css('left', (required_left_offset > 0 ? required_left_offset : 0));
256
+
257
+ var tooltip_offset = tooltip.offset();
258
+ var tooltip_outer_width = tooltip.outerWidth();
259
+ if (tooltip_offset && (tooltip_offset.left + tooltip_outer_width) > (window_width = $(window).width())) {
260
+ tooltip.css('left', window_width - tooltip_outer_width);
261
+ }
262
+
263
+ tooltip.css({
264
+ 'top': $(this).offset().top - tooltip.outerHeight() - 2
265
+ })
266
+
267
+ nib.css({
268
+ 'opacity': 0
269
+ });
270
+
271
+ if (tooltip_offset = tooltip.offset()) {
272
+ nib.css({
273
+ 'left': $(this).offset().left + ($(this).outerWidth() / 2) - 5
274
+ , 'top': tooltip_offset.top + tooltip.height()
275
+ });
276
+ }
277
+
278
+ try {
279
+ tooltip.animate({
280
+ top: tooltip_offset.top - 10
281
+ , opacity: 1
282
+ }, 200, 'swing');
283
+ nib.animate({
284
+ top: nib.offset().top - 10
285
+ , opacity: 1
286
+ }, 200);
287
+ } catch(e) {
288
+ tooltip.show();
289
+ nib.show();
290
+ }
291
+ }, $(this)));
292
+
293
+ }, function(e) {
294
+ $(this).stopTime('tooltip');
295
+ if ((tt_offset = (tooltip = $('.tooltip')).css('z-index', '-1').offset()) == null) {
296
+ tt_offset = {'top':0,'left':0};
297
+ }
298
+ tooltip.animate({
299
+ top: tt_offset.top - 20
300
+ , opacity: 0
301
+ }, 125, 'swing', function(){
302
+ $(this).remove();
303
+ });
304
+ if ((nib_offset = (nib = $('.tooltip-nib')).offset()) == null) {
305
+ nib_offset = {'top':0,'left':0};
306
+ }
307
+ nib.animate({
308
+ top: nib_offset.top - 20
309
+ , opacity: 0
310
+ }, 125, 'swing', function(){
311
+ $(this).remove();
312
+ });
313
+ }).click(function(e) {
314
+ $(this).stopTime('tooltip');
315
+ });
316
+ if ($(element).attr('tooltip') == null) {
317
+ $(element).attr('tooltip', $(element).attr('title'));
318
+ }
319
+ // wipe clean the title on any children too.
320
+ $(element).add($(element).children('img')).removeAttr('title');
321
+ });
322
+ }
323
+
324
+ var link_dialog = {
325
+ init: function(test_url, test_email){
326
+ this.test_url = test_url;
327
+ this.test_email = test_email;
328
+ this.init_tabs();
329
+ this.init_resources_submit();
330
+ this.init_close();
331
+ this.page_tab();
332
+ this.web_tab();
333
+ this.email_tab();
334
+ },
335
+
336
+ init_tabs: function(){
337
+ var radios = $('#dialog_menu_left input:radio');
338
+ var selected = radios.parent().filter(".selected_radio").find('input:radio').first() || radios.first();
339
+
340
+ radios.click(function(){
341
+ link_dialog.switch_area($(this));
342
+ });
343
+
344
+ selected.attr('checked', 'true');
345
+ link_dialog.switch_area(selected);
346
+ },
347
+
348
+ init_resources_submit: function(){
349
+ $('#existing_resource_area .form-actions-dialog #submit_button').click(function(e){
350
+ e.preventDefault();
351
+ if((resource_selected = $('#existing_resource_area_content ul li.linked a')).length > 0) {
352
+ resourceUrl = parseURL(resource_selected.attr('href'));
353
+ relevant_href = resourceUrl.pathname;
354
+
355
+ // Add any alternate resource stores that need a absolute URL in the regex below
356
+ if(resourceUrl.hostname.match(/s3.amazonaws.com/)) {
357
+ relevant_href = resourceUrl.protocol + '//' + resourceUrl.host + relevant_href;
358
+ }
359
+
360
+ if (typeof(resource_picker.callback) == "function") {
361
+ resource_picker.callback({
362
+ id: resource_selected.attr('id').replace("resource_", "")
363
+ , href: relevant_href
364
+ , html: resource_selected.html()
365
+ });
366
+ }
367
+ }
368
+ });
369
+
370
+ $('.form-actions-dialog #cancel_button').trigger('click');
371
+ },
372
+
373
+ init_close: function(){
374
+ $('.form-actions-dialog #cancel_button').click(close_dialog);
375
+
376
+ if (parent
377
+ && parent.document.location.href != document.location.href
378
+ && parent.document.getElementById('wym_dialog_submit') != null) {
379
+ $('#dialog_container .form-actions input#submit_button').click(function(e) {
380
+ e.preventDefault();
381
+ $(parent.document.getElementById('wym_dialog_submit')).click();
382
+ });
383
+ $('#dialog_container .form-actions a.close_dialog').click(close_dialog);
384
+ }
385
+ },
386
+
387
+ switch_area: function(area){
388
+ $('#dialog_menu_left .selected_radio').removeClass('selected_radio');
389
+ $(area).parent().addClass('selected_radio');
390
+ $('#dialog_main .dialog_area').hide();
391
+ $('#' + $(area).val() + '_area').show();
392
+ },
393
+
394
+ //Same for resources tab
395
+ page_tab: function(){
396
+ $('.link_list li').click(function(e){
397
+ e.preventDefault();
398
+
399
+ $('.link_list li.linked').removeClass('linked');
400
+ $(this).addClass('linked');
401
+
402
+ var link = $(this).children('a.page_link').get(0);
403
+ var port = (window.location.port.length > 0 ? (":" + window.location.port) : "");
404
+ var url = link.href.replace(window.location.protocol + "//" + window.location.hostname + port, "");
405
+
406
+ link_dialog.update_parent(url, link.rel.replace(/\ ?<em>.+?<\/em>/, ''));
407
+ });
408
+ },
409
+
410
+ web_tab: function(){
411
+ $('#web_address_text').bind('paste change',function(){
412
+ var prefix = '#web_address_',
413
+ icon = '';
414
+
415
+ $(prefix + 'test_loader').show();
416
+ $(prefix + 'test_result').hide();
417
+ $(prefix + 'test_result').removeClass('success_icon').removeClass('failure_icon');
418
+
419
+ $.getJSON(link_dialog.test_url, {url: this.value}, function(data){
420
+ if(data.result == 'success'){
421
+ icon = 'success_icon';
422
+ }else{
423
+ icon = 'failure_icon';
424
+ }
425
+
426
+ $(prefix + 'test_result').addClass(icon).show();
427
+ $(prefix + 'test_loader').hide();
428
+ });
429
+
430
+ link_dialog.update_parent( $(prefix + 'text').val(),
431
+ $(prefix + 'text').val(),
432
+ ($(prefix + 'target_blank').checked ? "_blank" : "")
433
+ );
434
+ });
435
+
436
+ $('#web_address_target_blank').click(function(){
437
+ parent.document.getElementById('wym_target').value = this.checked ? "_blank" : "";
438
+ });
439
+
440
+ },
441
+
442
+ email_tab: function() {
443
+ $('#email_address_text, #email_default_subject_text, #email_default_body_text').change(function(e){
444
+ var default_subject = $('#email_default_subject_text').val(),
445
+ default_body = $('#email_default_body_text').val(),
446
+ mailto = "mailto:" + $('#email_address_text').val(),
447
+ modifier = "?",
448
+ icon = '';
449
+
450
+ $('#email_address_test_loader').show();
451
+ $('#email_address_test_result').hide();
452
+ $('#email_address_test_result').removeClass('success_icon').removeClass('failure_icon');
453
+
454
+ $.getJSON(link_dialog.test_email, {email: mailto}, function(data){
455
+ if(data.result == 'success'){
456
+ icon = 'success_icon';
457
+ }else{
458
+ icon = 'failure_icon';
459
+ }
460
+
461
+ $('#email_address_test_result').addClass(icon).show();
462
+ $('#email_address_test_loader').hide();
463
+ });
464
+
465
+ if(default_subject.length > 0){
466
+ mailto += modifier + "subject=" + default_subject;
467
+ modifier = "&";
468
+ }
469
+
470
+ if(default_body.length > 0){
471
+ mailto += modifier + "body=" + default_body;
472
+ modifier = "&";
473
+ }
474
+
475
+ link_dialog.update_parent(mailto, mailto.replace('mailto:', ''));
476
+ });
477
+ },
478
+
479
+ update_parent: function(url, title, target) {
480
+ if (parent != null) {
481
+ if ((wym_href = parent.document.getElementById('wym_href')) != null) {
482
+ wym_href.value = url;
483
+ }
484
+ if ((wym_title = parent.document.getElementById('wym_title')) != null) {
485
+ wym_title.value = title;
486
+ }
487
+ if ((wym_target = parent.document.getElementById('wym_target')) != null) {
488
+ wym_target.value = target || "";
489
+ }
490
+ }
491
+ }
492
+ }
493
+
494
+ var page_options = {
495
+ init: function(enable_parts, new_part_url, del_part_url){
496
+ // set the page tabs up, but ensure that all tabs are shown so that when wymeditor loads it has a proper height.
497
+ // also disable page overflow so that scrollbars don't appear while the page is loading.
498
+ $(document.body).addClass('hide-overflow');
499
+ page_options.tabs = $('#page-tabs');
500
+ page_options.tabs.tabs({tabTemplate: '<li><a href="#{href}">#{label}</a></li>'})
501
+ page_options.tabs.find(' > ul li a').corner('top 5px');
502
+
503
+ part_shown = $('#page-tabs .page_part.field').not('.ui-tabs-hide');
504
+ $('#page-tabs .page_part.field').removeClass('ui-tabs-hide');
505
+
506
+ this.enable_parts = enable_parts;
507
+ this.new_part_url = new_part_url;
508
+ this.del_part_url = del_part_url;
509
+ this.show_options();
510
+ this.title_type();
511
+
512
+ // Hook into the loaded function. This will be called when WYMeditor has done its thing.
513
+ WYMeditor.loaded = function(){
514
+ // hide the tabs that are supposed to be hidden and re-enable overflow.
515
+ $(document.body).removeClass('hide-overflow');
516
+ $('#page-tabs .page_part.field').not(part_shown).addClass('ui-tabs-hide');
517
+ $('#page-tabs > ul li a').corner('top 5px');
518
+ }
519
+
520
+ if(this.enable_parts){
521
+ this.page_part_dialog();
522
+ }
523
+ },
524
+
525
+ show_options: function(){
526
+ $('#toggle_advanced_options').click(function(e){
527
+ e.preventDefault();
528
+ $('#more_options').animate({opacity: 'toggle', height: 'toggle'}, 250);
529
+
530
+ $('html,body').animate({
531
+ scrollTop: $('#toggle_advanced_options').parent().offset().top
532
+ }, 250);
533
+ });
534
+ },
535
+
536
+ title_type: function(){
537
+ $("input[name=page\[custom_title_type\]]").change(function(){
538
+ $('#custom_title_text, #custom_title_image').hide();
539
+ $('#custom_title_' + this.value).show();
540
+ });
541
+ },
542
+
543
+ page_part_dialog: function(){
544
+ $('#new_page_part_dialog').dialog({
545
+ title: 'Create Content Section',
546
+ modal: true,
547
+ resizable: false,
548
+ autoOpen: false,
549
+ width: 600,
550
+ height: 200
551
+ });
552
+
553
+ $('#add_page_part').click(function(e){
554
+ e.preventDefault();
555
+ $('#new_page_part_dialog').dialog('open');
556
+ });
557
+
558
+ $('#new_page_part_save').click(function(e){
559
+ e.preventDefault();
560
+
561
+ var part_title = $('#new_page_part_title').val();
562
+
563
+ if(part_title.length > 0){
564
+ var tab_title = part_title.toLowerCase().replace(" ", "_");
565
+
566
+ if ($('#part_' + tab_title).size() == 0) {
567
+ $.get(page_options.new_part_url,
568
+ {
569
+ title: part_title
570
+ , part_index: $('#new_page_part_index').val()
571
+ , body: ''
572
+ }
573
+ , function(data, status){
574
+ $('#submit_continue_button').remove();
575
+ // Add a new tab for the new content section.
576
+ $(data).appendTo('#page_part_editors');
577
+ page_options.tabs.tabs('add', '#page_part_new_' + $('#new_page_part_index').val(), part_title);
578
+ page_options.tabs.tabs('select', $('#new_page_part_index').val());
579
+
580
+ // turn the new textarea into a wymeditor.
581
+ $('#page_parts_attributes_' + $('#new_page_part_index').val() + "_body").wymeditor(wymeditor_boot_options);
582
+
583
+ // hook into wymedtior to instruct it to select this new tab again once it has loaded.
584
+ WYMeditor.loaded = function() {
585
+ page_options.tabs.tabs('select', $('#new_page_part_index').val());
586
+ WYMeditor.loaded = function(){}; // kill it again.
587
+ }
588
+
589
+ // Wipe the title and increment the index counter by one.
590
+ $('#new_page_part_index').val(parseInt($('#new_page_part_index').val()) + 1);
591
+ $('#new_page_part_title').val('');
592
+
593
+ page_options.tabs.find('> ul li a').corner('top 5px');
594
+
595
+ $('#new_page_part_dialog').dialog('close');
596
+ }
597
+ );
598
+ }else{
599
+ alert("A content section with that title already exists, please choose another.");
600
+ }
601
+ }else{
602
+ alert("You have not entered a title for the content section, please enter one.");
603
+ }
604
+ });
605
+
606
+ $('#new_page_part_cancel').click(function(e){
607
+ e.preventDefault();
608
+ $('#new_page_part_dialog').dialog('close');
609
+ $('#new_page_part_title').val('');
610
+ });
611
+
612
+ $('#delete_page_part').click(function(e){
613
+ e.preventDefault();
614
+
615
+ if(confirm("This will remove the content section '" + $('#page_parts .ui-tabs-selected a').html() + "' immediately even if you don't save this page, are you sure?")) {
616
+ var tabId = page_options.tabs.tabs('option', 'selected');
617
+ $.ajax({
618
+ url: page_options.del_part_url + '/' + $('#page_parts_attributes_' + tabId + '_id').val(),
619
+ type: 'DELETE'
620
+ });
621
+ page_options.tabs.tabs('remove', tabId);
622
+ $('#page_parts_attributes_' + tabId + '_id').remove();
623
+ $('#submit_continue_button').remove();
624
+ }
625
+
626
+ });
627
+
628
+ }
629
+
630
+ }
631
+
632
+ var image_dialog = {
633
+ callback: null
634
+
635
+ , init: function(callback){
636
+ this.callback = callback;
637
+ this.init_tabs();
638
+ this.init_select();
639
+ this.init_actions();
640
+ return this;
641
+ }
642
+
643
+ , init_tabs: function(){
644
+ var radios = $('#dialog_menu_left input:radio');
645
+ var selected = radios.parent().filter(".selected_radio").find('input:radio').first() || radios.first();
646
+
647
+ radios.click(function(){
648
+ link_dialog.switch_area($(this));
649
+ });
650
+
651
+ selected.attr('checked', 'true');
652
+ link_dialog.switch_area(selected);
653
+ }
654
+
655
+ , switch_area: function(radio){
656
+ $('#dialog_menu_left .selected_radio').removeClass('selected_radio');
657
+ $(radio).parent().addClass('selected_radio');
658
+ $('#dialog_main .dialog_area').hide();
659
+ $('#' + radio.value + '_area').show();
660
+ }
661
+
662
+ , init_select: function(){
663
+ $('#existing_image_area_content ul li img').click(function(){
664
+ image_dialog.set_image(this);
665
+ });
666
+ //Select any currently selected, just uploaded...
667
+ if ((selected_img = $('#existing_image_area_content ul li.selected img')).length > 0) {
668
+ image_dialog.set_image(selected_img.first());
669
+ }
670
+ }
671
+
672
+ , set_image: function(img){
673
+ if ($(img).length > 0) {
674
+ $('#existing_image_area_content ul li.selected').removeClass('selected');
675
+
676
+ $(img).parent().addClass('selected');
677
+ var imageId = $(img).attr('data-id');
678
+ var imageThumbnailSize = $('#existing_image_size_area li.selected a').attr('data-size');
679
+ var resize = $("#wants_to_resize_image").is(':checked');
680
+
681
+ var url = '/refinery/images/'+imageId+'/url';
682
+ if (resize) {
683
+ url += '?size='+imageThumbnailSize;
684
+ }
685
+
686
+ var data;
687
+ $.ajax({
688
+ async: false,
689
+ url: url,
690
+ success: function (result, status, xhr) {
691
+ if (result.error) {
692
+ if (console && console.log) {
693
+ console.log("Something went wrong with the image insertion!");
694
+ console.log(result);
695
+ }
696
+ } else {
697
+ data = result;
698
+ }
699
+ },
700
+ error: function(xhr, txt, status) {
701
+ if (console && console.log) {
702
+ console.log("Something went wrong with the image insertion!");
703
+ console.log(xhr);
704
+ console.log(txt);
705
+ console.log(status);
706
+ }
707
+ }
708
+ });
709
+
710
+ if (parent) {
711
+ if ((wym_src = parent.document.getElementById('wym_src')) != null) {
712
+ wym_src.value = data.url
713
+ }
714
+ if ((wym_title = parent.document.getElementById('wym_title')) != null) {
715
+ wym_title.value = $(img).attr('title');
716
+ }
717
+ if ((wym_alt = parent.document.getElementById('wym_alt')) != null) {
718
+ wym_alt.value = $(img).attr('alt');
719
+ }
720
+ if ((wym_size = parent.document.getElementById('wym_size')) != null) {
721
+ wym_size.value = imageThumbnailSize.replace(/[<>=]/g, '');
722
+ }
723
+ }
724
+ }
725
+ }
726
+
727
+ , submit_image_choice: function(e) {
728
+ e.preventDefault();
729
+ if((img_selected = $('#existing_image_area_content ul li.selected img').get(0)) && $.isFunction(this.callback))
730
+ {
731
+ this.callback(img_selected);
732
+ }
733
+
734
+ close_dialog(e);
735
+ }
736
+
737
+ , init_actions: function(){
738
+ var _this = this;
739
+ $('#existing_image_area .form-actions-dialog #submit_button').click($.proxy(_this.submit_image_choice, _this));
740
+ $('.form-actions-dialog #cancel_button').not('body.wym_iframe_body .form-actions-dialog #cancel_button').click($.proxy(close_dialog, _this));
741
+ $('#existing_image_size_area ul li a').click(function(e) {
742
+ $('#existing_image_size_area ul li').removeClass('selected');
743
+ $(this).parent().addClass('selected');
744
+ $('#existing_image_size_area #wants_to_resize_image').attr('checked', 'checked');
745
+ image_dialog.set_image($('#existing_image_area_content ul li.selected img'));
746
+ e.preventDefault();
747
+ });
748
+ $('#existing_image_size_area #wants_to_resize_image').change(function(){
749
+ if($(this).is(":checked")) {
750
+ $('#existing_image_size_area ul li:first a').click();
751
+ } else {
752
+ $('#existing_image_size_area ul li').removeClass('selected');
753
+ image_dialog.set_image($('#existing_image_area_content ul li.selected img'));
754
+ }
755
+ });
756
+
757
+ if (parent && parent.document.location.href != document.location.href
758
+ && parent.document.getElementById('wym_dialog_submit') != null) {
759
+ $('#existing_image_area .form-actions input#submit_button').click($.proxy(function(e) {
760
+ e.preventDefault();
761
+ $(this.document.getElementById('wym_dialog_submit')).click();
762
+ }, parent));
763
+ $('#existing_image_area .form-actions a.close_dialog').click(close_dialog);
764
+ }
765
+ }
766
+ }
767
+
768
+ var list_reorder = {
769
+ init: function() {
770
+ $('#reorder_action').click(list_reorder.enable_reordering);
771
+ $('#reorder_action_done').click(list_reorder.disable_reordering);
772
+ if (list_reorder.tree) {
773
+ list_reorder.sortable_list.nestedSortable({
774
+ disableNesting: 'no-nest',
775
+ forcePlaceholderSize: true,
776
+ handle: 'div',
777
+ items: 'li',
778
+ opacity: .6,
779
+ placeholder: 'placeholder',
780
+ tabSize: 25,
781
+ tolerance: 'pointer',
782
+ toleranceElement: '> div',
783
+ disabled: true,
784
+ start: function () {
785
+ },
786
+ change: function () {
787
+ list_reorder.reset_branch_classes(this);
788
+ },
789
+ stop: function () {
790
+ list_reorder.reset_branch_classes(this);
791
+ }
792
+ });
793
+ list_reorder.reset_branch_classes(list_reorder.sortable_list);
794
+ } else {
795
+ list_reorder.sortable_list.sortable({
796
+ axis: 'y',
797
+ cursor: 'crosshair',
798
+ connectWith: '.nested',
799
+ handle: 'img',
800
+ });
801
+ }
802
+ }
803
+
804
+ ,reset_branch_classes: function (ul) {
805
+ $("li.ui-sortable-helper", this).removeClass("record").removeClass("branch_start").removeClass("branch_end");
806
+ $("li", ul).removeClass("branch_start").removeClass("branch_end");
807
+
808
+ $("> li:first", ul).addClass("branch_start")
809
+ $("> li:last", ul).addClass("branch_end")
810
+
811
+ var nested_ul = $("ul", ul);
812
+ $("> li:last", nested_ul).addClass("branch_end");
813
+ }
814
+
815
+ ,enable_reordering: function(e) {
816
+ if(e) { e.preventDefault(); }
817
+ $('#sortable_list').addClass("reordering");
818
+
819
+ $('#sortable_list .actions, #site_bar, header > *:not(script)').fadeTo(500, 0.3);
820
+ $('#actions *:not("#reorder_action_done, #reorder_action")').not($('#reorder_action_done').parents('li, ul')).fadeTo(500, 0.55);
821
+
822
+ if (list_reorder.tree) {
823
+ list_reorder.sortable_list.nestedSortable("enable");
824
+ } else {
825
+ list_reorder.sortable_list.sortable("enable");
826
+ }
827
+ $('#reorder_action').hide();
828
+ $('#reorder_action_done').show();
829
+ }
830
+
831
+ , disable_reordering: function(e) {
832
+ if($('#reorder_action_done').hasClass('loading')){
833
+ return false;
834
+ }
835
+ if(e) { e.preventDefault(); }
836
+ $('#reorder_action_done').addClass('loading');
837
+ if (list_reorder.tree) {
838
+ list_reorder.sortable_list.nestedSortable("disable");
839
+ } else {
840
+ list_reorder.sortable_list.sortable("disable");
841
+ }
842
+
843
+ $('#sortable_list').removeClass("reordering");
844
+
845
+ if (list_reorder.update_url != null) {
846
+
847
+ var serialized = list_reorder.sortable_list.serializelist();
848
+
849
+ $.post(list_reorder.update_url, serialized, function(data) {
850
+ list_reorder.restore_controls(e);
851
+ });
852
+ } else {
853
+ list_reorder.restore_controls(e);
854
+ }
855
+ }
856
+
857
+ , restore_controls: function(e) {
858
+ if (list_reorder.tree && !$.browser.msie) {
859
+ list_reorder.sortable_list.add(list_reorder.sortable_list.find('ul, li')).draggable('destroy');
860
+ } else {
861
+ $(list_reorder.sortable_list).sortable('destroy');
862
+ }
863
+ $(list_reorder.sortable_list).removeClass('reordering, ui-sortable');
864
+
865
+ $('#sortable_list .actions, #site_bar, header > *:not(script)').fadeTo(250, 1);
866
+ $('#actions *:not("#reorder_action_done, #reorder_action")').not($('#reorder_action_done').parents('li, ul')).fadeTo(250, 1, function() {
867
+ $('#reorder_action_done').hide().removeClass('loading');
868
+ $('#reorder_action').show();
869
+ });
870
+ }
871
+ }
872
+
873
+ var image_picker = {
874
+ options: {
875
+ selected: '',
876
+ thumbnail: 'dialog_thumb',
877
+ field: '#image',
878
+ image_display: '#current_picked_image',
879
+ no_image_message: '#no_picked_image_selected',
880
+ image_container: '#current_image_container',
881
+ remove_image_button: '#remove_picked_image',
882
+ image_toggler: null
883
+ }
884
+
885
+ , init: function(new_options){
886
+ this.options = $.extend(this.options, new_options);
887
+ $(this.options.remove_image_button).click($.proxy(this.remove_image, this));
888
+ $(this.options.image_toggler).click($.proxy(this.toggle_image, this));
889
+ }
890
+
891
+ , remove_image: function(e) {
892
+ e.preventDefault();
893
+ $(this.options.image_display).removeClass('brown_border')
894
+ .attr({'src': '', 'width': '', 'height': ''})
895
+ .css({'width': 'auto', 'height': 'auto'})
896
+ .hide();
897
+ $(this.options.field).val('');
898
+ $(this.options.no_image_message).show();
899
+ $(this.options.remove_image_button).hide();
900
+ $(this).hide();
901
+ }
902
+
903
+ , toggle_image: function(e) {
904
+ $(this.options.image_toggler).html(($(this.options.image_toggler).html() == 'Show' ? 'Hide' : 'Show'));
905
+ $(this.options.image_container).toggle();
906
+ e.preventDefault();
907
+ }
908
+
909
+ , changed: function(image) {
910
+ $(this.options.field).val(image.id.replace("image_", ""));
911
+
912
+ $.ajax({
913
+ async: false,
914
+ url: '/refinery/images/'+$(image).attr('data-id')+'/url?size='+this.options.thumbnail,
915
+ success: function (result, status, xhr) {
916
+ if (result.error) {
917
+ if (console && console.log) {
918
+ console.log("Something went wrong with the image insertion!");
919
+ console.log(result);
920
+ }
921
+ } else {
922
+ image.src = result.url;
923
+ }
924
+ },
925
+ error: function(xhr, txt, status) {
926
+ if (console && console.log) {
927
+ console.log("Something went wrong with the image insertion!");
928
+ console.log(xhr);
929
+ console.log(txt);
930
+ console.log(status);
931
+ }
932
+ }
933
+ });
934
+
935
+ current_image = $(this.options.image_display);
936
+ current_image.replaceWith($("<img src='"+image.src+"?"+Math.floor(Math.random() * 1000000000)+"' id='"+current_image.attr('id')+"' class='brown_border' />"));
937
+
938
+ $(this.options.remove_image_button).show();
939
+ $(this.options.no_image_message).hide();
940
+ }
941
+ }
942
+
943
+ var resource_picker = {
944
+ callback: null
945
+
946
+ , init: function(callback) {
947
+ this.callback = callback;
948
+ }
949
+ }
950
+
951
+ close_dialog = function(e) {
952
+ if (parent && parent.document.location.href != document.location.href && $.isFunction(parent.$))
953
+ {
954
+ the_body = $(parent.document.body)
955
+ the_dialog = parent.$('.ui-dialog');
956
+ } else {
957
+ the_body = $(document.body).removeClass('hide-overflow');
958
+ the_dialog = $('.ui-dialog').dialog('close').remove();
959
+ }
960
+ // if there's a wymeditor involved then let it do its thing without blocking first.
961
+ if (!($(document.body).hasClass('wym_iframe_body'))) {
962
+ the_body.removeClass('hide-overflow');
963
+ the_dialog.dialog('close').remove();
964
+
965
+ e.preventDefault();
966
+ }
967
+ }
968
+
969
+ //parse a URL to form an object of properties
970
+ parseURL = function(url)
971
+ {
972
+ //save the unmodified url to href property
973
+ //so that the object we get back contains
974
+ //all the same properties as the built-in location object
975
+ var loc = { 'href' : url };
976
+
977
+ //split the URL by single-slashes to get the component parts
978
+ var parts = url.replace('//', '/').split('/');
979
+
980
+ //store the protocol and host
981
+ loc.protocol = parts[0];
982
+ loc.host = parts[1];
983
+
984
+ //extract any port number from the host
985
+ //from which we derive the port and hostname
986
+ parts[1] = parts[1].split(':');
987
+ loc.hostname = parts[1][0];
988
+ loc.port = parts[1].length > 1 ? parts[1][1] : '';
989
+
990
+ //splice and join the remainder to get the pathname
991
+ parts.splice(0, 2);
992
+ // ensure we don't destroy absolute urls like /system/images/whatever.jpg
993
+ loc.pathname = (loc.href[0] == '/' ? ("/" + loc.host) : '');
994
+ loc.pathname += '/' + parts.join('/');
995
+
996
+ //extract any hash and remove from the pathname
997
+ loc.pathname = loc.pathname.split('#');
998
+ loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
999
+ loc.pathname = loc.pathname[0];
1000
+
1001
+ //extract any search query and remove from the pathname
1002
+ loc.pathname = loc.pathname.split('?');
1003
+ loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
1004
+ loc.pathname = loc.pathname[0];
1005
+
1006
+ var options = url.split('?')[1];
1007
+ loc.options = options;
1008
+
1009
+ //return the final object
1010
+ return loc;
1011
+ }