dust-generators 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/lib/dust/version.rb +1 -1
  2. data/lib/generators/dust/albums/albums_generator.rb +129 -34
  3. data/lib/generators/dust/albums/templates/app/controllers/albums_controller.rb +24 -18
  4. data/lib/generators/dust/albums/templates/app/controllers/photos_controller.rb +37 -40
  5. data/lib/generators/dust/albums/templates/app/controllers/view_albums_controller.rb +6 -7
  6. data/lib/generators/dust/albums/templates/app/helpers/albums_helper.rb +1 -1
  7. data/lib/generators/dust/albums/templates/app/helpers/photos_helper.rb +1 -1
  8. data/lib/generators/dust/albums/templates/app/helpers/view_albums_helper.rb +1 -1
  9. data/lib/generators/dust/albums/templates/app/models/album.rb +8 -4
  10. data/lib/generators/dust/albums/templates/app/models/photo.rb +11 -4
  11. data/lib/generators/dust/albums/templates/app/views/albums/_form.html.erb +48 -18
  12. data/lib/generators/dust/albums/templates/app/views/albums/_search.html.erb +4 -4
  13. data/lib/generators/dust/albums/templates/app/views/albums/_upload_script.html.erb +11 -11
  14. data/lib/generators/dust/albums/templates/app/views/albums/edit.html.erb +3 -3
  15. data/lib/generators/dust/albums/templates/app/views/albums/index.html.erb +23 -23
  16. data/lib/generators/dust/albums/templates/app/views/albums/manage.html.erb +65 -0
  17. data/lib/generators/dust/albums/templates/app/views/albums/new.html.erb +3 -3
  18. data/lib/generators/dust/albums/templates/app/views/albums/show.html.erb +33 -21
  19. data/lib/generators/dust/albums/templates/app/views/albums/show.js.erb +1 -0
  20. data/lib/generators/dust/albums/templates/app/views/photos/_form.html.erb +20 -19
  21. data/lib/generators/dust/albums/templates/app/views/photos/_photo.html.erb +25 -23
  22. data/lib/generators/dust/albums/templates/app/views/photos/_search.html.erb +6 -0
  23. data/lib/generators/dust/albums/templates/app/views/photos/array.js.erb +3 -0
  24. data/lib/generators/dust/albums/templates/app/views/photos/edit.html.erb +6 -6
  25. data/lib/generators/dust/albums/templates/app/views/photos/index.html.erb +28 -23
  26. data/lib/generators/dust/albums/templates/app/views/photos/new.html.erb +4 -4
  27. data/lib/generators/dust/albums/templates/app/views/photos/show.html.erb +9 -9
  28. data/lib/generators/dust/albums/templates/app/views/photos/show.js.erb +2 -2
  29. data/lib/generators/dust/albums/templates/app/views/view_albums/index.html.erb +25 -14
  30. data/lib/generators/dust/albums/templates/app/views/view_albums/show.html.erb +23 -12
  31. data/lib/generators/dust/albums/templates/images/save_position.png +0 -0
  32. data/lib/generators/dust/albums/templates/javascripts/dragsort.js +288 -0
  33. data/lib/generators/dust/albums/templates/javascripts/dust_album.js +28 -0
  34. data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/jquery.uploadify.v2.1.0.js +0 -0
  35. data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/swfobject.js +0 -0
  36. data/lib/generators/dust/albums/templates/{uploadify → javascripts/uploadify}/uploadify.swf +0 -0
  37. data/lib/generators/dust/albums/templates/migration/albums_migration.rb +39 -0
  38. data/lib/generators/dust/albums/templates/stylesheets/dust_album.css +16 -0
  39. data/lib/generators/dust/albums/templates/stylesheets/dust_album_app.css +15 -0
  40. data/lib/generators/dust/albums/templates/{uploadify.css → stylesheets/uploadify.css} +1 -1
  41. data/rails_generators/dust_albums/templates/app/controllers/view_albums_controller.rb +1 -1
  42. data/rails_generators/dust_albums/templates/app/views/albums/show.html.erb +1 -1
  43. metadata +17 -12
  44. data/lib/generators/dust/albums/templates/albums_migration.rb +0 -18
  45. data/lib/generators/dust/albums/templates/dust_album.css +0 -11
  46. data/lib/generators/dust/albums/templates/jquery-1.4.2.js +0 -6240
  47. data/lib/generators/dust/albums/templates/photos_migration.rb +0 -20
@@ -1,23 +1,25 @@
1
- <div class="photo">
2
- <script type="text/javascript" charset="utf-8">
3
- $("a.settings").fancybox({
4
- 'showCloseButton' : false,
5
- 'transitionIn' : 'elastic',
6
- 'transitionOut' : 'elastic',
7
- 'speedIn' : 400,
8
- 'speedOut' : 200,
9
- 'hideOnContentClick': false,
10
- 'overlayOpacity' : 0.6,
11
- 'overlayColor' : '#000',
12
- 'opacity' : 'true'
13
- });
14
- </script>
15
- <%= image_tag photo.file.url(:thumb), :height => '50' %>
16
- <p>
17
- <%= photo.title %> <br />
18
- <% unless photo.date_shot.blank? %>
19
- (<%= photo.date_shot %>)
20
- <% end -%>
21
- <%= link_to "Edit Photo", edit_photo_path(photo, :format => :html, :edit => 'photo'), :class => "settings", :title => "Photo Settings" %>
22
- </p>
23
- </div>
1
+ <li id="<%%= "<%=child_singular_name%>_#{<%=child_singular_name%>.id}" %>">
2
+ <div class="<%=child_singular_name%> <%%= "<%=child_singular_name%>_#{<%=child_singular_name%>.id}" %>">
3
+ <script type="text/javascript" charset="utf-8">
4
+ $("a.settings").fancybox({
5
+ 'showCloseButton' : false,
6
+ 'transitionIn' : 'elastic',
7
+ 'transitionOut' : 'elastic',
8
+ 'speedIn' : 400,
9
+ 'speedOut' : 200,
10
+ 'hideOnContentClick': false,
11
+ 'overlayOpacity' : 0.6,
12
+ 'overlayColor' : '#000',
13
+ 'opacity' : 'true'
14
+ });
15
+ </script>
16
+ <%%= image_tag <%=child_singular_name%>.file.url(:thumb), :height => '50' %>
17
+ <p>
18
+ <%%= truncate <%=child_singular_name%>.title, :length => 23 %> <br />
19
+ <%% unless <%=child_singular_name%>.date_shot.blank? %>
20
+ (<%%= <%=child_singular_name%>.date_shot %>)
21
+ <%% end -%>
22
+ <%%= link_to "Edit <%=child_class_name%>", edit_<%=child_singular_name%>_path(<%=child_singular_name%>.id, :format => 'html', :edit => "<%=child_singular_name%>"), :class => "settings", :title => "<%=child_class_name%> Settings" %>
23
+ </p>
24
+ </div>
25
+ </li>
@@ -0,0 +1,6 @@
1
+ <div id="searchbox">
2
+ <%% form_tag <%=child_plural_name%>_path, :method => 'get' do %>
3
+ <%%= text_field_tag :search, params[:search], :class => "input-text", :placeholder => 'Search <%=child_plural_class_name%>' %>
4
+ <%%= image_submit_tag "admin/blank.png", :class => "image-submit"%>
5
+ <%% end %>
6
+ </div>
@@ -0,0 +1,3 @@
1
+ $('#status').html('<%%= escape_javascript(flash.delete(:notice)) %>');
2
+ $('#status').fadeIn().delay(2000).slideUp('4000', 'easeInOutBack');
3
+ $.fancybox.hideActivity();
@@ -1,6 +1,6 @@
1
- <% title "Edit Photo" %>
1
+ <%%title "Edit <%=child_class_name%>" %>
2
2
 
3
- <% if params[:edit] == 'photo' %>
3
+ <%%if params[:edit] == '<%=child_singular_name%>' %>
4
4
  <script type="text/javascript" charset="utf-8">
5
5
 
6
6
  var options = {
@@ -9,9 +9,9 @@
9
9
  clearForm: true
10
10
  };
11
11
 
12
- $('.edit_photo').ajaxForm(options);
12
+ $('.edit_<%=child_singular_name%>').ajaxForm(options);
13
13
 
14
- $("#photo_submit").click(function () {
14
+ $("#<%=child_singular_name%>_submit").click(function () {
15
15
  $("#fancybox-inner").fadeTo("slow", 0.1);
16
16
  $.fancybox.showActivity();
17
17
  });
@@ -23,6 +23,6 @@
23
23
  $("#fancybox-inner").fadeTo("slow", 1);
24
24
  }
25
25
  </script>
26
- <% end -%>
26
+ <%%end -%>
27
27
 
28
- <%= render :partial => 'form' %>
28
+ <%%= render :partial => 'form' %>
@@ -1,7 +1,7 @@
1
- <% title "Photos" %>
1
+ <%% title "<%=child_plural_class_name%>" %>
2
2
 
3
- <%= stylesheet( 'dust_album','uploadify') %>
4
- <%= javascript( 'uploadify/jquery.uploadify.v2.1.0' ) %>
3
+ <%%= stylesheet( 'dust_<%=parent_singular_name%>','<%=parent_singular_name%>_uploadify') %>
4
+ <%%= javascript( 'uploadify/jquery.uploadify.v2.1.0' ) %>
5
5
 
6
6
  <script type="text/javascript" charset="utf-8">
7
7
  $(document).ready(function() {
@@ -13,15 +13,20 @@
13
13
  });
14
14
  </script>
15
15
 
16
- <%= will_paginate @photos %>
16
+ <div class="button_bar">
17
+ <%%= render :partial => 'search' %>
18
+ </div>
17
19
 
18
- <% @photo_albums.sort.each do |title, photos| %>
19
- <div class='photolist'>
20
- <h1><%= link_to title, album_path(photos.first.album) %></h1>
20
+
21
+ <%%= will_paginate @<%=child_plural_name%> %>
22
+
23
+ <%% @<%=child_singular_name%>_<%=parent_plural_name%>.sort.each do |title, <%=child_plural_name%>| %>
24
+ <div class='<%=child_singular_name%>list'>
25
+ <h1><%%= link_to title, <%=parent_singular_name%>_path(<%=child_plural_name%>.first.<%=parent_singular_name%>) %></h1>
21
26
 
22
- <%= form_for(:photo, :url => delete_photos_path) do %>
27
+ <%% form_for :<%=child_singular_name%>, :url => {:action => 'destroy'} do %>
23
28
 
24
- <table class='photos'>
29
+ <table class='<%=child_plural_name%>'>
25
30
  <tr style='color:#222;'>
26
31
  <th>
27
32
 
@@ -37,44 +42,44 @@
37
42
  Created At
38
43
  </th>
39
44
  </tr>
40
- <% for photo in photos %>
41
- <%= hidden_field_tag :album_id, photo.album.id %>
42
- <tr class='<%= cycle('odd', 'even')%>'>
45
+ <%% for <%=child_singular_name%> in <%=child_plural_name%> %>
46
+ <%%= hidden_field_tag :<%=parent_singular_name%>_id, <%=child_singular_name%>.<%=parent_singular_name%>.id %>
47
+ <tr class='<%%= cycle('odd', 'even')%>'>
43
48
  <td>
44
- <%= check_box_tag "photo_ids[]", photo.id %>
49
+ <%%= check_box_tag "<%=child_singular_name%>_ids[]", <%=child_singular_name%>.id %>
45
50
  </td>
46
51
  <td>
47
- <%= link_to image_tag(photo.file.url(:thumb), :height => "30"), photo.file.url(:original), :rel => title, :id => 'single_image' %>
52
+ <%%= link_to image_tag(<%=child_singular_name%>.file.url(:thumb), :height => "30"), <%=child_singular_name%>.file.url(:original), :rel => title, :id => 'single_image' %>
48
53
 
49
- <div style="display:none"><div id="<%=photo.id%>"><%= image_tag(photo.file.url(:original)) %></div></div>
54
+ <div style="display:none"><div id="<%%=<%=child_singular_name%>.id%>"><%%= image_tag(<%=child_singular_name%>.file.url(:original)) %></div></div>
50
55
  </td>
51
56
  <td>
52
- <%= photo.file_file_name %>
57
+ <%%= <%=child_singular_name%>.file_file_name %>
53
58
  </td>
54
59
  <td>
55
- <%= number_to_human_size(photo.file_file_size) %>
60
+ <%%= number_to_human_size(<%=child_singular_name%>.file_file_size) %>
56
61
  </td>
57
62
  <td>
58
- <%= photo.created_at.to_s(:m_d_y) %>
63
+ <%%= <%=child_singular_name%>.created_at.to_s(:m_d_y) %>
59
64
  </td>
60
65
  </tr>
61
- <% end %>
66
+ <%% end %>
62
67
  <tr class='odd'>
63
68
  <td colspan='5'>
64
69
  <input type="checkbox" class="checkall"> Check all
65
- <%= submit_tag "Delete checked" %>
70
+ <%%= submit_tag "Delete checked" %>
66
71
  </td>
67
72
  </tr>
68
73
  </table>
69
74
 
70
75
 
71
- <% end -%>
76
+ <%% end -%>
72
77
 
73
78
  </div>
74
79
 
75
80
 
76
81
 
77
- <% end %>
82
+ <%% end %>
78
83
 
79
- <%= will_paginate @photos %>
84
+ <%%= will_paginate @<%=child_plural_name%> %>
80
85
 
@@ -1,7 +1,7 @@
1
- <% title "New Photo" %>
1
+ <%% title "New <%=child_class_name%>" %>
2
2
 
3
- <%= stylesheet( 'dust_album','uploadify') %>
3
+ <%%= stylesheet( 'dust_<%=parent_singular_name%>','<%=parent_singular_name%>_uploadify') %>
4
4
 
5
- <%= render :partial => 'form' %>
5
+ <%%= render :partial => 'form' %>
6
6
 
7
- <p><%= link_to "Back to List", photos_path %></p>
7
+ <p><%%= link_to "Back to List", <%=child_plural_name%>_path %></p>
@@ -1,26 +1,26 @@
1
- <% title "Photo" %>
1
+ <%% title "<%=child_class_name%>" %>
2
2
 
3
- <%= stylesheet( 'dust_album','uploadify') %>
3
+ <%%= stylesheet( 'dust_<%=parent_singular_name%>','<%=parent_singular_name%>_uploadify') %>
4
4
 
5
5
  <p>
6
6
  <strong>Title:</strong>
7
- <%=h @photo.title %>
7
+ <%%=h @<%=child_singular_name%>.title %>
8
8
  </p>
9
9
  <p>
10
10
  <strong>Desc:</strong>
11
- <%=h @photo.desc %>
11
+ <%%=h @<%=child_singular_name%>.desc %>
12
12
  </p>
13
13
  <p>
14
14
  <strong>Date Shot:</strong>
15
- <%=h @photo.date_shot %>
15
+ <%%=h @<%=child_singular_name%>.date_shot %>
16
16
  </p>
17
17
  <p>
18
18
  <strong>Location:</strong>
19
- <%=h @photo.location %>
19
+ <%%=h @<%=child_singular_name%>.location %>
20
20
  </p>
21
21
 
22
22
  <p>
23
- <%= link_to "Edit", edit_photo_path(@photo) %> |
24
- <%= link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete %> |
25
- <%= link_to "View All", photos_path %>
23
+ <%%= link_to "Edit", edit_<%=child_singular_name%>_path(@<%=child_singular_name%>) %> |
24
+ <%%= link_to "Destroy", @<%=child_singular_name%>, :confirm => 'Are you sure?', :method => :delete %> |
25
+ <%%= link_to "View All", <%=child_plural_name%>_path %>
26
26
  </p>
@@ -1,5 +1,5 @@
1
- $('#photos_count').html('<%= pluralize(@total_uploads.count, "Photo") %> | <%= link_to "Manage Photos", photos_path %>');
2
- $('#uploads').append("<%= escape_javascript(render(:partial => "photos/photo", :locals => {:photo => @photo})) %>");
1
+ $('#<%=child_plural_name%>_count').html('<%%= pluralize(@<%=parent_singular_name%>.<%=child_plural_name%>.size, "<%=child_class_name%>")%> | <%%= link_to "Select <%=child_plural_class_name%> For Deletion", manage_<%=child_plural_name%>_path(@<%=parent_singular_name%>), :class => 'settings' %> ');
2
+ $('#uploads').append("<%%= escape_javascript(render(:partial => "<%=child_plural_name%>/<%=child_singular_name%>", :locals => {:<%=child_singular_name%> => @<%=child_singular_name%>})) %>");
3
3
  $("a#inline").fancybox({
4
4
  'transitionIn' : 'elastic',
5
5
  'transitionOut' : 'elastic',
@@ -1,20 +1,31 @@
1
- <% title "All Albums" %>
2
- <% heading "All Albums" %>
1
+ <%% title "All <%=parent_plural_class_name%>" %>
2
+ <%% heading "All <%=parent_plural_class_name%>" %>
3
3
 
4
- <% content_for :head do -%>
5
- <%= stylesheet_link_tag 'dust_album' %>
6
- <% end -%>
4
+ <%% content_for :head do %>
5
+ <%%= stylesheet_link_tag 'dust_<%=parent_singular_name%>_app' %>
6
+ <%% end -%>
7
7
 
8
- <%= will_paginate @albums %>
8
+ <%%= will_paginate @<%=parent_plural_name%> %>
9
9
 
10
- <% @albums.each do |album| %>
11
- <div class="photo">
12
- <% unless album.photos.empty? %>
13
- <% @photo = album.photos.find(:first) %>
14
- <%= link_to image_tag(@photo.file.url(:thumb)), view_album_path(album.filename) %>
15
- <% end -%>
10
+ <%% @<%=parent_plural_name%>.each do |<%=parent_singular_name%>| %>
11
+ <div class="<%=parent_singular_name%>_thumb">
12
+ <%% unless <%=parent_singular_name%>.<%=child_plural_name%>.empty? %>
13
+
14
+ <%% @<%=child_singular_name%> = <%=parent_singular_name%>.<%=child_plural_name%>.find(:first) %>
15
+
16
+ <%% link_to view_<%=parent_singular_name%>_path(<%=parent_singular_name%>.filename), :style => 'float:left; ' do %>
17
+ <%%= image_tag @<%=child_singular_name%>.file.url(:thumb), :alt => <%=parent_singular_name%>.heading %>
18
+ <%% end %>
19
+
20
+ <p>
21
+ <%%= link_to <%=parent_singular_name%>.title, view_<%=parent_singular_name%>_path(<%=parent_singular_name%>.filename) %><br />
22
+ <%%= truncate(<%=parent_singular_name%>.desc, :length => 100) %>
23
+ <%%= link_to "Read More", view_<%=parent_singular_name%>_path(<%=parent_singular_name%>.filename) unless <%=parent_singular_name%>.desc.blank? %>
24
+ </p>
25
+
26
+ <%% end -%>
16
27
  </div>
17
- <% end -%>
28
+ <%% end -%>
18
29
  <div class="clear"></div>
19
30
 
20
- <%= will_paginate @albums %>
31
+ <%%= will_paginate @<%=parent_plural_name%> %>
@@ -1,20 +1,31 @@
1
- <% title @album.title %>
2
- <% heading @album.title %>
3
- <%= @album.desc %>
1
+ <%% title @<%=parent_singular_name%>.title %>
2
+ <%% heading @<%=parent_singular_name%>.heading %>
4
3
 
5
- <% content_for :head do -%>
6
- <%= stylesheet_link_tag 'dust_album' %>
7
- <% end -%>
4
+ <%% content_for :head do %>
5
+ <%%= stylesheet_link_tag 'dust_<%=parent_singular_name%>_app' %>
6
+ <%% end -%>
8
7
 
9
- <%= will_paginate @photos %>
8
+ <%%= @<%=parent_singular_name%>.desc %>
9
+
10
+ <%%= will_paginate @<%=child_plural_name%> %>
10
11
 
11
12
  <div id="uploads">
12
- <% @photos.each do |photo| %>
13
- <div class="photo">
14
- <%= link_to image_tag(photo.file.url(:thumb), :alt => photo.title), photo.file.url(:original), :id => 'single_image' %>
13
+ <%% @<%=child_plural_name%>.each do |<%=child_singular_name%>| %>
14
+ <div class="<%=child_singular_name%>">
15
+ <%%= link_to image_tag(<%=child_singular_name%>.file.url(:thumb), :alt => <%=child_singular_name%>.desc), <%=child_singular_name%>.file.url(:large), :class => 'group', :rel => "#{@<%=parent_singular_name%>.title}" %><br />
16
+ <%%= truncate <%=child_singular_name%>.title, :length => 23 %>
15
17
  </div>
16
- <% end -%>
18
+ <%% end -%>
17
19
  </div>
18
20
  <div class="clear"></div>
19
21
 
20
- <%= will_paginate @photos %>
22
+ <%%= will_paginate @<%=child_plural_name%> %>
23
+
24
+ <%% if permitted_to? :manage, :<%=parent_plural_name%> %>
25
+ <p>
26
+ <%%= link_to "Manage <%=child_plural_class_name%>", @<%=parent_singular_name%> %> |
27
+ <%%= link_to "Edit", edit_<%=parent_singular_name%>_path(@<%=parent_singular_name%>) %> |
28
+ <%%= link_to "Destroy", @<%=parent_singular_name%>, :confirm => 'Are you sure?', :method => :delete %> |
29
+ <%%= link_to "View All", <%=parent_plural_name%>_path %>
30
+ </p>
31
+ <%% end %>
@@ -0,0 +1,288 @@
1
+ // jQuery List DragSort v0.4
2
+ // Website: http://dragsort.codeplex.com/
3
+ // License: http://dragsort.codeplex.com/license
4
+
5
+ (function($) {
6
+
7
+ $.fn.dragsort = function(options) {
8
+ var opts = $.extend({}, $.fn.dragsort.defaults, options);
9
+ var lists = [];
10
+ var list = null, lastPos = null;
11
+ if (this.selector)
12
+ $("head").append("<style type='text/css'>" + (this.selector.split(",").join(" " + opts.dragSelector + ",") + " " + opts.dragSelector) + " { cursor: pointer; }</style>");
13
+
14
+ this.each(function(i, cont) {
15
+
16
+ if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
17
+ cont = $(cont).children().get(0);
18
+
19
+ var newList = {
20
+ draggedItem: null,
21
+ placeHolderItem: null,
22
+ pos: null,
23
+ offset: null,
24
+ offsetLimit: null,
25
+ scroll: null,
26
+ container: cont,
27
+
28
+ init: function() {
29
+ $(this.container).attr("data-listIdx", i).mousedown(this.grabItem).find(opts.dragSelector).css("cursor", "pointer");
30
+ $(this.container).children(opts.itemSelector).each(function(j) { $(this).attr("data-itemIdx", j); });
31
+ },
32
+
33
+ grabItem: function(e) {
34
+ if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude))
35
+ return;
36
+
37
+ var elm = e.target;
38
+ while (!$(elm).is("[data-listIdx='" + $(this).attr("data-listIdx") + "'] " + opts.dragSelector)) {
39
+ if (elm == this) return;
40
+ elm = elm.parentNode;
41
+ }
42
+
43
+ if (list != null && list.draggedItem != null)
44
+ list.dropItem();
45
+
46
+ $(e.target).css("cursor", "move");
47
+
48
+ list = lists[$(this).attr("data-listIdx")];
49
+ list.draggedItem = $(elm).closest(opts.itemSelector);
50
+ var mt = parseInt(list.draggedItem.css("marginTop"));
51
+ var ml = parseInt(list.draggedItem.css("marginLeft"));
52
+ list.offset = list.draggedItem.offset();
53
+ list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
54
+ list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
55
+
56
+ if (!opts.dragBetween) {
57
+ var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + $(list.container).children(opts.itemSelector).size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
58
+ list.offsetLimit = $(list.container).offset();
59
+ list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
60
+ list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
61
+ }
62
+
63
+ var h = list.draggedItem.height();
64
+ var w = list.draggedItem.width();
65
+ var orig = list.draggedItem.attr("style");
66
+ list.draggedItem.attr("data-origStyle", orig ? orig : "");
67
+ if (opts.itemSelector == "tr") {
68
+ list.draggedItem.children().each(function() { $(this).width($(this).width()); });
69
+ list.placeHolderItem = list.draggedItem.clone().attr("data-placeHolder", true);
70
+ list.draggedItem.after(list.placeHolderItem);
71
+ list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html("&nbsp;"); });
72
+ } else {
73
+ list.draggedItem.after(opts.placeHolderTemplate);
74
+ list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeHolder", true);
75
+ }
76
+ list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
77
+
78
+ $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
79
+
80
+ list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
81
+ list.scroll.scrollY = window.setInterval(function() {
82
+ if (opts.scrollContainer != window) {
83
+ $(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
84
+ return;
85
+ }
86
+ var t = $(opts.scrollContainer).scrollTop();
87
+ if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
88
+ $(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
89
+ list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
90
+ }
91
+ }, 10);
92
+ list.scroll.scrollX = window.setInterval(function() {
93
+ if (opts.scrollContainer != window) {
94
+ $(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
95
+ return;
96
+ }
97
+ var l = $(opts.scrollContainer).scrollLeft();
98
+ if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
99
+ $(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
100
+ list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
101
+ }
102
+ }, 10);
103
+
104
+ list.setPos(e.pageX, e.pageY);
105
+ $(document).bind("selectstart", list.stopBubble); //stop ie text selection
106
+ $(document).bind("mousemove", list.swapItems);
107
+ $(document).bind("mouseup", list.dropItem);
108
+ if (opts.scrollContainer != window)
109
+ $(window).bind("DOMMouseScroll mousewheel", list.wheel);
110
+ return false; //stop moz text selection
111
+ },
112
+
113
+ setPos: function(x, y) {
114
+ var top = y - this.offset.top;
115
+ var left = x - this.offset.left;
116
+
117
+ if (!opts.dragBetween) {
118
+ top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
119
+ left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
120
+ }
121
+
122
+ this.draggedItem.parents().each(function() {
123
+ if ($(this).css("position") != "static" && (!$.browser.mozilla || $(this).css("display") != "table")) {
124
+ var offset = $(this).offset();
125
+ top -= offset.top;
126
+ left -= offset.left;
127
+ return false;
128
+ }
129
+ });
130
+
131
+ if (opts.scrollContainer == window) {
132
+ y -= $(window).scrollTop();
133
+ x -= $(window).scrollLeft();
134
+ y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
135
+ x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
136
+ } else {
137
+ var cont = $(opts.scrollContainer);
138
+ var offset = cont.offset();
139
+ y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
140
+ x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
141
+ }
142
+
143
+ list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
144
+ list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
145
+
146
+ this.draggedItem.css({ top: top, left: left });
147
+ },
148
+
149
+ wheel: function(e) {
150
+ if (($.browser.safari || $.browser.mozilla) && list && opts.scrollContainer != window) {
151
+ var cont = $(opts.scrollContainer);
152
+ var offset = cont.offset();
153
+ if (e.pageX > offset.left && e.pageX < offset.left + cont.width() && e.pageY > offset.top && e.pageY < offset.top + cont.height()) {
154
+ var delta = e.detail ? e.detail * 5 : e.wheelDelta / -2;
155
+ cont.scrollTop(cont.scrollTop() + delta);
156
+ e.preventDefault();
157
+ }
158
+ }
159
+ },
160
+
161
+ buildPositionTable: function() {
162
+ var item = this.draggedItem == null ? null : this.draggedItem.get(0);
163
+ var pos = [];
164
+ $(this.container).children(opts.itemSelector).each(function(i, elm) {
165
+ if (elm != item) {
166
+ var loc = $(elm).offset();
167
+ loc.right = loc.left + $(elm).width();
168
+ loc.bottom = loc.top + $(elm).height();
169
+ loc.elm = elm;
170
+ pos.push(loc);
171
+ }
172
+ });
173
+ this.pos = pos;
174
+ },
175
+
176
+ dropItem: function() {
177
+ if (list.draggedItem == null)
178
+ return;
179
+
180
+ $(list.container).find(opts.dragSelector).css("cursor", "pointer");
181
+ list.placeHolderItem.before(list.draggedItem);
182
+
183
+ var orig = list.draggedItem.attr("data-origStyle");
184
+ if (orig == "")
185
+ list.draggedItem.removeAttr("style");
186
+ else
187
+ list.draggedItem.attr("style", orig);
188
+ list.draggedItem.removeAttr("data-origStyle");
189
+ list.placeHolderItem.remove();
190
+
191
+ $("[data-dropTarget]").remove();
192
+
193
+ window.clearInterval(list.scroll.scrollY);
194
+ window.clearInterval(list.scroll.scrollX);
195
+
196
+ var changed = false;
197
+ $(lists).each(function() {
198
+ $(this.container).children(opts.itemSelector).each(function(j) {
199
+ if (parseInt($(this).attr("data-itemIdx")) != j) {
200
+ changed = true;
201
+ $(this).attr("data-itemIdx", j);
202
+ }
203
+ });
204
+ });
205
+ if (changed)
206
+ opts.dragEnd.apply(list.draggedItem);
207
+ list.draggedItem = null;
208
+ $(document).unbind("selectstart", list.stopBubble);
209
+ $(document).unbind("mousemove", list.swapItems);
210
+ $(document).unbind("mouseup", list.dropItem);
211
+ if (opts.scrollContainer != window)
212
+ $(window).unbind("DOMMouseScroll mousewheel", list.wheel);
213
+ return false;
214
+ },
215
+
216
+ stopBubble: function() { return false; },
217
+
218
+ swapItems: function(e) {
219
+ if (list.draggedItem == null)
220
+ return false;
221
+
222
+ list.setPos(e.pageX, e.pageY);
223
+
224
+ var ei = list.findPos(e.pageX, e.pageY);
225
+ var nlist = list;
226
+ for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
227
+ ei = lists[i].findPos(e.pageX, e.pageY);
228
+ nlist = lists[i];
229
+ }
230
+
231
+ if (ei == -1 || $(nlist.pos[ei].elm).attr("data-placeHolder"))
232
+ return false;
233
+
234
+ if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
235
+ $(nlist.pos[ei].elm).before(list.placeHolderItem);
236
+ else
237
+ $(nlist.pos[ei].elm).after(list.placeHolderItem);
238
+
239
+ $(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
240
+ lastPos = list.draggedItem.offset();
241
+ return false;
242
+ },
243
+
244
+ findPos: function(x, y) {
245
+ for (var i = 0; i < this.pos.length; i++) {
246
+ if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
247
+ return i;
248
+ }
249
+ return -1;
250
+ },
251
+
252
+ createDropTargets: function() {
253
+ if (!opts.dragBetween)
254
+ return;
255
+
256
+ $(lists).each(function() {
257
+ var ph = $(this.container).find("[data-placeHolder]");
258
+ var dt = $(this.container).find("[data-dropTarget]");
259
+ if (ph.size() > 0 && dt.size() > 0)
260
+ dt.remove();
261
+ else if (ph.size() == 0 && dt.size() == 0) {
262
+ //list.placeHolderItem.clone().removeAttr("data-placeHolder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
263
+ $(this.container).append(list.placeHolderItem.removeAttr("data-placeHolder").clone().attr("data-dropTarget", true));
264
+ list.placeHolderItem.attr("data-placeHolder", true);
265
+ }
266
+ });
267
+ }
268
+ };
269
+
270
+ newList.init();
271
+ lists.push(newList);
272
+ });
273
+
274
+ return this;
275
+ };
276
+
277
+ $.fn.dragsort.defaults = {
278
+ itemSelector: "li",
279
+ dragSelector: "li",
280
+ dragSelectorExclude: "input, textarea, a[href]",
281
+ dragEnd: function() { },
282
+ dragBetween: false,
283
+ placeHolderTemplate: "<li>&nbsp;</li>",
284
+ scrollContainer: window,
285
+ scrollSpeed: 5
286
+ };
287
+
288
+ })(jQuery);