chef-server-webui 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +135 -0
  3. data/Rakefile +62 -0
  4. data/app/controllers/application.rb +281 -0
  5. data/app/controllers/clients.rb +120 -0
  6. data/app/controllers/cookbook_attributes.rb +41 -0
  7. data/app/controllers/cookbook_definitions.rb +41 -0
  8. data/app/controllers/cookbook_files.rb +39 -0
  9. data/app/controllers/cookbook_libraries.rb +41 -0
  10. data/app/controllers/cookbook_recipes.rb +40 -0
  11. data/app/controllers/cookbook_templates.rb +57 -0
  12. data/app/controllers/cookbooks.rb +78 -0
  13. data/app/controllers/databag_items.rb +102 -0
  14. data/app/controllers/databags.rb +83 -0
  15. data/app/controllers/exceptions.rb +19 -0
  16. data/app/controllers/main.rb +7 -0
  17. data/app/controllers/nodes.rb +138 -0
  18. data/app/controllers/openid_consumer.rb +154 -0
  19. data/app/controllers/roles.rb +144 -0
  20. data/app/controllers/search.rb +62 -0
  21. data/app/controllers/search_entries.rb +64 -0
  22. data/app/controllers/status.rb +39 -0
  23. data/app/controllers/users.rb +186 -0
  24. data/app/helpers/application_helper.rb +171 -0
  25. data/app/helpers/cookbook_attributes_helper.rb +7 -0
  26. data/app/helpers/cookbook_definitions_helper.rb +8 -0
  27. data/app/helpers/cookbook_files_helper.rb +8 -0
  28. data/app/helpers/cookbook_libraries_helper.rb +7 -0
  29. data/app/helpers/cookbook_recipes_helper.rb +8 -0
  30. data/app/helpers/cookbook_templates_helper.rb +8 -0
  31. data/app/helpers/exceptions_helper.rb +6 -0
  32. data/app/helpers/global_helpers.rb +35 -0
  33. data/app/helpers/nodes_helper.rb +41 -0
  34. data/app/helpers/openid_consumer_helper.rb +8 -0
  35. data/app/helpers/openid_register_helper.rb +8 -0
  36. data/app/helpers/openid_server_helper.rb +6 -0
  37. data/app/helpers/openid_server_helpers.rb +29 -0
  38. data/app/helpers/roles_helper.rb +5 -0
  39. data/app/helpers/search_entries_helper.rb +8 -0
  40. data/app/helpers/search_helper.rb +38 -0
  41. data/app/helpers/status_helper.rb +26 -0
  42. data/app/views/clients/_form.html.haml +22 -0
  43. data/app/views/clients/_navigation.html.haml +9 -0
  44. data/app/views/clients/edit.html.haml +6 -0
  45. data/app/views/clients/index.html.haml +21 -0
  46. data/app/views/clients/new.html.haml +6 -0
  47. data/app/views/clients/show.html.haml +20 -0
  48. data/app/views/cookbooks/index.html.haml +10 -0
  49. data/app/views/cookbooks/show.html.haml +40 -0
  50. data/app/views/databag_items/_form.html.haml +14 -0
  51. data/app/views/databag_items/_navigation.html.haml +9 -0
  52. data/app/views/databag_items/edit.html.haml +6 -0
  53. data/app/views/databag_items/index.html.haml +0 -0
  54. data/app/views/databag_items/new.html.haml +6 -0
  55. data/app/views/databag_items/show.html.haml +9 -0
  56. data/app/views/databags/_form.html.haml +12 -0
  57. data/app/views/databags/_item_navigation.html.haml +8 -0
  58. data/app/views/databags/_navigation.html.haml +9 -0
  59. data/app/views/databags/edit.html.haml +6 -0
  60. data/app/views/databags/index.html.haml +19 -0
  61. data/app/views/databags/new.html.haml +6 -0
  62. data/app/views/databags/show.html.haml +19 -0
  63. data/app/views/exceptions/bad_request.json.erb +1 -0
  64. data/app/views/exceptions/internal_server_error.html.erb +216 -0
  65. data/app/views/exceptions/not_acceptable.html.erb +63 -0
  66. data/app/views/exceptions/not_found.html.erb +47 -0
  67. data/app/views/exceptions/standard_error.html.erb +217 -0
  68. data/app/views/layout/_jsonedit.html.haml +82 -0
  69. data/app/views/layout/chef_server_webui.html.haml +56 -0
  70. data/app/views/layout/login.html.haml +36 -0
  71. data/app/views/main/index.html.erb +1 -0
  72. data/app/views/nodes/_action.html.haml +13 -0
  73. data/app/views/nodes/_form.html.haml +53 -0
  74. data/app/views/nodes/_navigation.html.haml +9 -0
  75. data/app/views/nodes/_resource.html.haml +22 -0
  76. data/app/views/nodes/edit.html.haml +7 -0
  77. data/app/views/nodes/index.html.haml +25 -0
  78. data/app/views/nodes/new.html.haml +6 -0
  79. data/app/views/nodes/show.html.haml +60 -0
  80. data/app/views/openid_consumer/index.html.haml +28 -0
  81. data/app/views/openid_consumer/start.html.haml +4 -0
  82. data/app/views/openid_login/index.html.haml +5 -0
  83. data/app/views/openid_register/index.html.haml +19 -0
  84. data/app/views/openid_register/show.html.haml +7 -0
  85. data/app/views/roles/_form.html.haml +53 -0
  86. data/app/views/roles/_navigation.html.haml +9 -0
  87. data/app/views/roles/edit.html.haml +6 -0
  88. data/app/views/roles/index.html.haml +21 -0
  89. data/app/views/roles/new.html.haml +6 -0
  90. data/app/views/roles/show.html.haml +54 -0
  91. data/app/views/search/_search_form.html.haml +6 -0
  92. data/app/views/search/index.html.haml +8 -0
  93. data/app/views/search/show.html.haml +13 -0
  94. data/app/views/search_entries/index.html.haml +8 -0
  95. data/app/views/search_entries/show.html.haml +7 -0
  96. data/app/views/status/index.html.haml +90 -0
  97. data/app/views/users/_form.html.haml +39 -0
  98. data/app/views/users/_navigation.html.haml +9 -0
  99. data/app/views/users/edit.html.haml +6 -0
  100. data/app/views/users/index.html.haml +20 -0
  101. data/app/views/users/login.html.haml +16 -0
  102. data/app/views/users/new.html.haml +27 -0
  103. data/app/views/users/show.html.haml +13 -0
  104. data/app/views/users/start.html.haml +4 -0
  105. data/config.ru +84 -0
  106. data/config/init.rb +49 -0
  107. data/config/router.rb +6 -0
  108. data/lib/chef-server-webui.rb +155 -0
  109. data/lib/chef-server-webui/merbtasks.rb +103 -0
  110. data/lib/chef-server-webui/slicetasks.rb +20 -0
  111. data/lib/chef-server-webui/spectasks.rb +53 -0
  112. data/public/facebox/README.txt +4 -0
  113. data/public/facebox/b.png +0 -0
  114. data/public/facebox/bl.png +0 -0
  115. data/public/facebox/br.png +0 -0
  116. data/public/facebox/closelabel.gif +0 -0
  117. data/public/facebox/facebox.css +95 -0
  118. data/public/facebox/facebox.js +319 -0
  119. data/public/facebox/loading.gif +0 -0
  120. data/public/facebox/tl.png +0 -0
  121. data/public/facebox/tr.png +0 -0
  122. data/public/images/avatar.png +0 -0
  123. data/public/images/black_big.png +0 -0
  124. data/public/images/indicator.gif +0 -0
  125. data/public/images/jsonedit/add2.png +0 -0
  126. data/public/images/jsonedit/build-button.png +0 -0
  127. data/public/images/jsonedit/bullet.gif +0 -0
  128. data/public/images/jsonedit/bullet_orange.png +0 -0
  129. data/public/images/jsonedit/cross.png +0 -0
  130. data/public/images/jsonedit/delete.png +0 -0
  131. data/public/images/jsonedit/deleted.png +0 -0
  132. data/public/images/jsonedit/json.jpg +0 -0
  133. data/public/images/jsonedit/label.gif +0 -0
  134. data/public/images/jsonedit/minus.gif +0 -0
  135. data/public/images/jsonedit/pixel.gif +0 -0
  136. data/public/images/jsonedit/plus.gif +0 -0
  137. data/public/images/jsonedit/saved.png +0 -0
  138. data/public/images/jsonedit/table_refresh.png +0 -0
  139. data/public/images/jsonedit/value.gif +0 -0
  140. data/public/images/merb.jpg +0 -0
  141. data/public/images/toggle-collapse-dark.png +0 -0
  142. data/public/images/toggle-collapse-light.png +0 -0
  143. data/public/images/toggle-collapse.gif +0 -0
  144. data/public/images/toggle-expand-dark.png +0 -0
  145. data/public/images/toggle-expand-light.png +0 -0
  146. data/public/images/toggle-expand.gif +0 -0
  147. data/public/images/treeBuilderImages/Thumbs.db +0 -0
  148. data/public/images/treeBuilderImages/doc.gif +0 -0
  149. data/public/images/treeBuilderImages/docNode.gif +0 -0
  150. data/public/images/treeBuilderImages/docNodeLast.gif +0 -0
  151. data/public/images/treeBuilderImages/docNodeLastFirst.gif +0 -0
  152. data/public/images/treeBuilderImages/folder.gif +0 -0
  153. data/public/images/treeBuilderImages/folderNode.gif +0 -0
  154. data/public/images/treeBuilderImages/folderNodeFirst.gif +0 -0
  155. data/public/images/treeBuilderImages/folderNodeLast.gif +0 -0
  156. data/public/images/treeBuilderImages/folderNodeLastFirst.gif +0 -0
  157. data/public/images/treeBuilderImages/folderNodeOpen.gif +0 -0
  158. data/public/images/treeBuilderImages/folderNodeOpenFirst.gif +0 -0
  159. data/public/images/treeBuilderImages/folderNodeOpenLast.gif +0 -0
  160. data/public/images/treeBuilderImages/folderNodeOpenLastFirst.gif +0 -0
  161. data/public/images/treeBuilderImages/folderOpen.gif +0 -0
  162. data/public/images/treeBuilderImages/vertLine.gif +0 -0
  163. data/public/javascripts/chef.js +160 -0
  164. data/public/javascripts/jquery-1.3.2.min.js +19 -0
  165. data/public/javascripts/jquery-ui-1.7.1.custom.min.js +65 -0
  166. data/public/javascripts/jquery.editinline.js +108 -0
  167. data/public/javascripts/jquery.jeditable.mini.js +30 -0
  168. data/public/javascripts/jquery.livequery.js +250 -0
  169. data/public/javascripts/jquery.localscroll.js +104 -0
  170. data/public/javascripts/jquery.scrollTo.js +150 -0
  171. data/public/javascripts/jquery.tools.min.js +17 -0
  172. data/public/javascripts/jquery.treeTable.min.js +165 -0
  173. data/public/javascripts/json.js +153 -0
  174. data/public/javascripts/jsonedit_main.js +675 -0
  175. data/public/javascripts/yetii-min.js +1 -0
  176. data/public/stylesheets/base.css +336 -0
  177. data/public/stylesheets/chef.css +157 -0
  178. data/public/stylesheets/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png +0 -0
  179. data/public/stylesheets/images/ui-bg_diagonals-thick_15_444444_40x40.png +0 -0
  180. data/public/stylesheets/images/ui-bg_glass_100_f0f0f0_1x400.png +0 -0
  181. data/public/stylesheets/images/ui-bg_glass_50_99c2ff_1x400.png +0 -0
  182. data/public/stylesheets/images/ui-bg_glass_55_fbf5d0_1x400.png +0 -0
  183. data/public/stylesheets/images/ui-bg_glass_80_e6e6e6_1x400.png +0 -0
  184. data/public/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  185. data/public/stylesheets/images/ui-bg_highlight-hard_100_f9f9f9_1x100.png +0 -0
  186. data/public/stylesheets/images/ui-bg_highlight-soft_100_e7eef3_1x100.png +0 -0
  187. data/public/stylesheets/images/ui-icons_222222_256x240.png +0 -0
  188. data/public/stylesheets/images/ui-icons_2694e8_256x240.png +0 -0
  189. data/public/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
  190. data/public/stylesheets/images/ui-icons_72a7cf_256x240.png +0 -0
  191. data/public/stylesheets/images/ui-icons_888888_256x240.png +0 -0
  192. data/public/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
  193. data/public/stylesheets/images/ui-icons_ffffff_256x240.png +0 -0
  194. data/public/stylesheets/jquery-ui-1.7.1.custom.css +404 -0
  195. data/public/stylesheets/jquery.treeTable.css +43 -0
  196. data/public/stylesheets/jsonedit_main.css +280 -0
  197. data/public/stylesheets/themes/bec-green/style.css +290 -0
  198. data/public/stylesheets/themes/bec/style.css +301 -0
  199. data/public/stylesheets/themes/blue/style.css +280 -0
  200. data/public/stylesheets/themes/default/style.css +267 -0
  201. data/public/stylesheets/themes/djime-cerulean/style.css +298 -0
  202. data/public/stylesheets/themes/kathleene/style.css +272 -0
  203. data/public/stylesheets/themes/orange/style.css +263 -0
  204. data/public/stylesheets/themes/reidb-greenish/style.css +301 -0
  205. data/stubs/app/controllers/application.rb +2 -0
  206. data/stubs/app/controllers/main.rb +2 -0
  207. metadata +399 -0
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :chefserverslice do
3
+
4
+ desc "Install Chefserver"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ ChefServerWebui.mirrored_components.each do |type|
15
+ if File.directory?(ChefServerWebui.dir_for(type))
16
+ if !File.directory?(dst_path = ChefServerWebui.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # desc "Copy stub files to host application"
26
+ # task :stubs do
27
+ # puts "Copying stubs for ChefServerWebui - resolves any collisions"
28
+ # copied, preserved = ChefServerWebui.mirror_stubs!
29
+ # puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ # copied.each { |f| puts "- copied #{f}" }
31
+ # preserved.each { |f| puts "! preserved override as #{f}" }
32
+ # end
33
+
34
+ # desc "Copy stub files and views to host application"
35
+ # task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for ChefServerWebui - resolves any collisions"
40
+ copied, preserved = ChefServerWebui.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze ChefServerWebui into your app (only chefserverslice/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ # desc "Freezes ChefServerWebui by installing the gem into application/gems"
56
+ # task :gem do
57
+ # ENV["GEM"] ||= "chefserverslice"
58
+ # Rake::Task['slices:install_as_gem'].invoke
59
+ # end
60
+
61
+ desc "Freezes ChefServerWebui by copying all files from chefserverslice/app to your application"
62
+ task :app do
63
+ puts "Copying all chefserverslice/app files to your application - resolves any collisions"
64
+ copied, preserved = ChefServerWebui.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = ChefServerWebui.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = ChefServerWebui.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes ChefServerWebui as a gem and copies over chefserver/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes ChefServerWebui by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking ChefServerWebui files to your application - resolves any collisions"
94
+ copied, preserved = ChefServerWebui.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,20 @@
1
+ namespace :slices do
2
+ namespace :chefserverslice do
3
+
4
+ # add your own chefserver tasks here
5
+
6
+ # # Uncomment the following lines and edit the pre defined tasks
7
+ #
8
+ # # implement this to test for structural/code dependencies
9
+ # # like certain directories or availability of other files
10
+ # desc "Test for any dependencies"
11
+ # task :preflight do
12
+ # end
13
+ #
14
+ # # implement this to perform any database related setup steps
15
+ # desc "Migrate the database"
16
+ # task :migrate do
17
+ # end
18
+
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ namespace :slices do
2
+ namespace :chefserverslice do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running ChefServerWebui specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all request specs, run a spec for a specific request with REQUEST=MyRequest"
34
+ Spec::Rake::SpecTask.new('request') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['REQUEST'])
37
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/#{ENV['REQUEST']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all specs and output the result in html"
44
+ Spec::Rake::SpecTask.new('html') do |t|
45
+ t.spec_opts = ["--format", "html"]
46
+ t.libs = ['lib', 'server/lib' ]
47
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ Please visit http://famspam.com/facebox/ or open index.html in your favorite browser.
2
+
3
+ Need help? Join our Google Groups mailing list:
4
+ http://groups.google.com/group/facebox/
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,95 @@
1
+ #facebox .b {
2
+ background:url(/facebox/b.png);
3
+ }
4
+
5
+ #facebox .tl {
6
+ background:url(/facebox/tl.png);
7
+ }
8
+
9
+ #facebox .tr {
10
+ background:url(/facebox/tr.png);
11
+ }
12
+
13
+ #facebox .bl {
14
+ background:url(/facebox/bl.png);
15
+ }
16
+
17
+ #facebox .br {
18
+ background:url(/facebox/br.png);
19
+ }
20
+
21
+ #facebox {
22
+ position: absolute;
23
+ top: 0;
24
+ left: 0;
25
+ z-index: 100;
26
+ text-align: left;
27
+ }
28
+
29
+ #facebox .popup {
30
+ position: relative;
31
+ }
32
+
33
+ #facebox table {
34
+ border-collapse: collapse;
35
+ }
36
+
37
+ #facebox td {
38
+ border-bottom: 0;
39
+ padding: 0;
40
+ }
41
+
42
+ #facebox .body {
43
+ padding: 10px;
44
+ background: #fff;
45
+ width: 370px;
46
+ }
47
+
48
+ #facebox .loading {
49
+ text-align: center;
50
+ }
51
+
52
+ #facebox .image {
53
+ text-align: center;
54
+ }
55
+
56
+ #facebox img {
57
+ border: 0;
58
+ margin: 0;
59
+ }
60
+
61
+ #facebox .footer {
62
+ border-top: 1px solid #DDDDDD;
63
+ padding-top: 5px;
64
+ margin-top: 10px;
65
+ text-align: right;
66
+ }
67
+
68
+ #facebox .tl, #facebox .tr, #facebox .bl, #facebox .br {
69
+ height: 10px;
70
+ width: 10px;
71
+ overflow: hidden;
72
+ padding: 0;
73
+ }
74
+
75
+ #facebox_overlay {
76
+ position: fixed;
77
+ top: 0px;
78
+ left: 0px;
79
+ height:100%;
80
+ width:100%;
81
+ }
82
+
83
+ .facebox_hide {
84
+ z-index:-100;
85
+ }
86
+
87
+ .facebox_overlayBG {
88
+ background-color: #000;
89
+ z-index: 99;
90
+ }
91
+
92
+ * html #facebox_overlay { /* ie6 hack */
93
+ position: absolute;
94
+ height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
95
+ }
@@ -0,0 +1,319 @@
1
+ /*
2
+ * Facebox (for jQuery)
3
+ * version: 1.2 (05/05/2008)
4
+ * @requires jQuery v1.2 or later
5
+ *
6
+ * Examples at http://famspam.com/facebox/
7
+ *
8
+ * Licensed under the MIT:
9
+ * http://www.opensource.org/licenses/mit-license.php
10
+ *
11
+ * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
12
+ *
13
+ * Usage:
14
+ *
15
+ * jQuery(document).ready(function() {
16
+ * jQuery('a[rel*=facebox]').facebox()
17
+ * })
18
+ *
19
+ * <a href="#terms" rel="facebox">Terms</a>
20
+ * Loads the #terms div in the box
21
+ *
22
+ * <a href="terms.html" rel="facebox">Terms</a>
23
+ * Loads the terms.html page in the box
24
+ *
25
+ * <a href="terms.png" rel="facebox">Terms</a>
26
+ * Loads the terms.png image in the box
27
+ *
28
+ *
29
+ * You can also use it programmatically:
30
+ *
31
+ * jQuery.facebox('some html')
32
+ *
33
+ * The above will open a facebox with "some html" as the content.
34
+ *
35
+ * jQuery.facebox(function($) {
36
+ * $.get('blah.html', function(data) { $.facebox(data) })
37
+ * })
38
+ *
39
+ * The above will show a loading screen before the passed function is called,
40
+ * allowing for a better ajaxy experience.
41
+ *
42
+ * The facebox function can also display an ajax page or image:
43
+ *
44
+ * jQuery.facebox({ ajax: 'remote.html' })
45
+ * jQuery.facebox({ image: 'dude.jpg' })
46
+ *
47
+ * Want to close the facebox? Trigger the 'close.facebox' document event:
48
+ *
49
+ * jQuery(document).trigger('close.facebox')
50
+ *
51
+ * Facebox also has a bunch of other hooks:
52
+ *
53
+ * loading.facebox
54
+ * beforeReveal.facebox
55
+ * reveal.facebox (aliased as 'afterReveal.facebox')
56
+ * init.facebox
57
+ *
58
+ * Simply bind a function to any of these hooks:
59
+ *
60
+ * $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
61
+ *
62
+ */
63
+ (function($) {
64
+ $.facebox = function(data, klass) {
65
+ $.facebox.loading()
66
+
67
+ if (data.ajax) fillFaceboxFromAjax(data.ajax)
68
+ else if (data.image) fillFaceboxFromImage(data.image)
69
+ else if (data.div) fillFaceboxFromHref(data.div)
70
+ else if ($.isFunction(data)) data.call($)
71
+ else $.facebox.reveal(data, klass)
72
+ }
73
+
74
+ /*
75
+ * Public, $.facebox methods
76
+ */
77
+
78
+ $.extend($.facebox, {
79
+ settings: {
80
+ opacity : 0,
81
+ overlay : true,
82
+ loadingImage : '/facebox/loading.gif',
83
+ closeImage : '/facebox/closelabel.gif',
84
+ imageTypes : [ 'png', 'jpg', 'jpeg', 'gif' ],
85
+ faceboxHtml : '\
86
+ <div id="facebox" style="display:none;"> \
87
+ <div class="popup"> \
88
+ <table> \
89
+ <tbody> \
90
+ <tr> \
91
+ <td class="tl"/><td class="b"/><td class="tr"/> \
92
+ </tr> \
93
+ <tr> \
94
+ <td class="b"/> \
95
+ <td class="body"> \
96
+ <div class="content"> \
97
+ </div> \
98
+ <div class="footer"> \
99
+ <a href="#" class="close"> \
100
+ <img src="/facebox/closelabel.gif" title="close" class="close_image" /> \
101
+ </a> \
102
+ </div> \
103
+ </td> \
104
+ <td class="b"/> \
105
+ </tr> \
106
+ <tr> \
107
+ <td class="bl"/><td class="b"/><td class="br"/> \
108
+ </tr> \
109
+ </tbody> \
110
+ </table> \
111
+ </div> \
112
+ </div>'
113
+ },
114
+
115
+ loading: function() {
116
+ init()
117
+ if ($('#facebox .loading').length == 1) return true
118
+ showOverlay()
119
+
120
+ $('#facebox .content').empty()
121
+ $('#facebox .body').children().hide().end().
122
+ append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')
123
+
124
+ $('#facebox').css({
125
+ top: getPageScroll()[1] + (getPageHeight() / 10),
126
+ left: 385.5
127
+ }).show()
128
+
129
+ $(document).bind('keydown.facebox', function(e) {
130
+ if (e.keyCode == 27) $.facebox.close()
131
+ return true
132
+ })
133
+ $(document).trigger('loading.facebox')
134
+ },
135
+
136
+ reveal: function(data, klass) {
137
+ $(document).trigger('beforeReveal.facebox')
138
+ if (klass) $('#facebox .content').addClass(klass)
139
+ $('#facebox .content').append(data)
140
+ $('#facebox .loading').remove()
141
+ $('#facebox .body').children().fadeIn('normal')
142
+ $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
143
+ $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
144
+ },
145
+
146
+ close: function() {
147
+ $(document).trigger('close.facebox')
148
+ return false
149
+ }
150
+ })
151
+
152
+ /*
153
+ * Public, $.fn methods
154
+ */
155
+
156
+ $.fn.facebox = function(settings) {
157
+ init(settings)
158
+
159
+ function clickHandler() {
160
+ $.facebox.loading(true)
161
+
162
+ // support for rel="facebox.inline_popup" syntax, to add a class
163
+ // also supports deprecated "facebox[.inline_popup]" syntax
164
+ var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
165
+ if (klass) klass = klass[1]
166
+
167
+ fillFaceboxFromHref(this.href, klass)
168
+ return false
169
+ }
170
+
171
+ return this.click(clickHandler)
172
+ }
173
+
174
+ /*
175
+ * Private methods
176
+ */
177
+
178
+ // called one time to setup facebox on this page
179
+ function init(settings) {
180
+ if ($.facebox.settings.inited) return true
181
+ else $.facebox.settings.inited = true
182
+
183
+ $(document).trigger('init.facebox')
184
+ makeCompatible()
185
+
186
+ var imageTypes = $.facebox.settings.imageTypes.join('|')
187
+ $.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')
188
+
189
+ if (settings) $.extend($.facebox.settings, settings)
190
+ $('body').append($.facebox.settings.faceboxHtml)
191
+
192
+ var preload = [ new Image(), new Image() ]
193
+ preload[0].src = $.facebox.settings.closeImage
194
+ preload[1].src = $.facebox.settings.loadingImage
195
+
196
+ $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
197
+ preload.push(new Image())
198
+ preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
199
+ })
200
+
201
+ $('#facebox .close').click($.facebox.close)
202
+ $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
203
+ }
204
+
205
+ // getPageScroll() by quirksmode.com
206
+ function getPageScroll() {
207
+ var xScroll, yScroll;
208
+ if (self.pageYOffset) {
209
+ yScroll = self.pageYOffset;
210
+ xScroll = self.pageXOffset;
211
+ } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
212
+ yScroll = document.documentElement.scrollTop;
213
+ xScroll = document.documentElement.scrollLeft;
214
+ } else if (document.body) {// all other Explorers
215
+ yScroll = document.body.scrollTop;
216
+ xScroll = document.body.scrollLeft;
217
+ }
218
+ return new Array(xScroll,yScroll)
219
+ }
220
+
221
+ // Adapted from getPageSize() by quirksmode.com
222
+ function getPageHeight() {
223
+ var windowHeight
224
+ if (self.innerHeight) { // all except Explorer
225
+ windowHeight = self.innerHeight;
226
+ } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
227
+ windowHeight = document.documentElement.clientHeight;
228
+ } else if (document.body) { // other Explorers
229
+ windowHeight = document.body.clientHeight;
230
+ }
231
+ return windowHeight
232
+ }
233
+
234
+ // Backwards compatibility
235
+ function makeCompatible() {
236
+ var $s = $.facebox.settings
237
+
238
+ $s.loadingImage = $s.loading_image || $s.loadingImage
239
+ $s.closeImage = $s.close_image || $s.closeImage
240
+ $s.imageTypes = $s.image_types || $s.imageTypes
241
+ $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
242
+ }
243
+
244
+ // Figures out what you want to display and displays it
245
+ // formats are:
246
+ // div: #id
247
+ // image: blah.extension
248
+ // ajax: anything else
249
+ function fillFaceboxFromHref(href, klass) {
250
+ // div
251
+ if (href.match(/#/)) {
252
+ var url = window.location.href.split('#')[0]
253
+ var target = href.replace(url,'')
254
+ $.facebox.reveal($(target).clone().show(), klass)
255
+
256
+ // image
257
+ } else if (href.match($.facebox.settings.imageTypesRegexp)) {
258
+ fillFaceboxFromImage(href, klass)
259
+ // ajax
260
+ } else {
261
+ fillFaceboxFromAjax(href, klass)
262
+ }
263
+ }
264
+
265
+ function fillFaceboxFromImage(href, klass) {
266
+ var image = new Image()
267
+ image.onload = function() {
268
+ $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
269
+ }
270
+ image.src = href
271
+ }
272
+
273
+ function fillFaceboxFromAjax(href, klass) {
274
+ $.get(href, function(data) { $.facebox.reveal(data, klass) })
275
+ }
276
+
277
+ function skipOverlay() {
278
+ return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
279
+ }
280
+
281
+ function showOverlay() {
282
+ if (skipOverlay()) return
283
+
284
+ if ($('facebox_overlay').length == 0)
285
+ $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')
286
+
287
+ $('#facebox_overlay').hide().addClass("facebox_overlayBG")
288
+ .css('opacity', $.facebox.settings.opacity)
289
+ .click(function() { $(document).trigger('close.facebox') })
290
+ .fadeIn(200)
291
+ return false
292
+ }
293
+
294
+ function hideOverlay() {
295
+ if (skipOverlay()) return
296
+
297
+ $('#facebox_overlay').fadeOut(200, function(){
298
+ $("#facebox_overlay").removeClass("facebox_overlayBG")
299
+ $("#facebox_overlay").addClass("facebox_hide")
300
+ $("#facebox_overlay").remove()
301
+ })
302
+
303
+ return false
304
+ }
305
+
306
+ /*
307
+ * Bindings
308
+ */
309
+
310
+ $(document).bind('close.facebox', function() {
311
+ $(document).unbind('keydown.facebox')
312
+ $('#facebox').fadeOut(function() {
313
+ $('#facebox .content').removeClass().addClass('content')
314
+ hideOverlay()
315
+ $('#facebox .loading').remove()
316
+ })
317
+ })
318
+
319
+ })(jQuery);