backlog 0.34.2 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/#SearchRequest.xml# +3443 -0
  2. data/History.txt +24 -1
  3. data/Rakefile +1 -1
  4. data/app/controllers/application.rb +13 -44
  5. data/app/controllers/works_controller.rb +7 -3
  6. data/app/models/absence.rb +1 -1
  7. data/app/models/sidebar.rb +40 -0
  8. data/app/views/layouts/mwrt002.rhtml +2 -1
  9. data/app/views/periods/_sidebar_block.rhtml +11 -0
  10. data/app/views/tasks/_task.rhtml +4 -2
  11. data/app/views/works/list_excel.rhtml +3 -1
  12. data/etc/backlog.conf +7 -0
  13. data/jira.log +28423 -0
  14. data/public/images/ajax-loading.gif +0 -0
  15. data/public/images/arrow-down.gif +0 -0
  16. data/public/images/arrow-up.gif +0 -0
  17. data/public/images/black-70.png +0 -0
  18. data/public/images/black.png +0 -0
  19. data/public/images/nextlabel.gif +0 -0
  20. data/public/images/prevlabel.gif +0 -0
  21. data/public/javascripts/lightwindow.js +1921 -0
  22. data/public/stylesheets/lightwindow.css +376 -0
  23. data/vendor/plugins/backlog_jira/README +4 -0
  24. data/vendor/plugins/backlog_jira/Rakefile +22 -0
  25. data/vendor/plugins/backlog_jira/generators/backlog_jira/backlog_jira_generator.rb +13 -0
  26. data/vendor/plugins/backlog_jira/generators/backlog_jira/templates/migration.rb +10 -0
  27. data/vendor/plugins/backlog_jira/generators/history_model/history_model_generator.rb +39 -0
  28. data/vendor/plugins/backlog_jira/generators/history_model/templates/fixtures.yml +17 -0
  29. data/vendor/plugins/backlog_jira/generators/history_model/templates/functional_test.rb +129 -0
  30. data/vendor/plugins/backlog_jira/generators/history_model/templates/model.rb +4 -0
  31. data/vendor/plugins/backlog_jira/generators/history_model/templates/unit_test.rb +75 -0
  32. data/vendor/plugins/backlog_jira/init.rb +59 -0
  33. data/vendor/plugins/backlog_jira/install.rb +1 -0
  34. data/vendor/plugins/backlog_jira/lib/backlog_jira.rb +1 -0
  35. data/vendor/plugins/backlog_jira/tasks/backlog_jira_tasks.rake +4 -0
  36. data/vendor/plugins/backlog_jira/test/backlog_jira_test.rb +8 -0
  37. data/vendor/plugins/backlog_jira/uninstall.rb +1 -0
  38. data/vendor/plugins/lightwindow_helper/README +33 -0
  39. data/vendor/plugins/lightwindow_helper/assets/images/ajax-loading.gif +0 -0
  40. data/vendor/plugins/lightwindow_helper/assets/images/arrow-down.gif +0 -0
  41. data/vendor/plugins/lightwindow_helper/assets/images/arrow-up.gif +0 -0
  42. data/vendor/plugins/lightwindow_helper/assets/images/black-70.png +0 -0
  43. data/vendor/plugins/lightwindow_helper/assets/images/black.png +0 -0
  44. data/vendor/plugins/lightwindow_helper/assets/images/nextlabel.gif +0 -0
  45. data/vendor/plugins/lightwindow_helper/assets/images/prevlabel.gif +0 -0
  46. data/vendor/plugins/lightwindow_helper/assets/javascripts/lightwindow.js +1921 -0
  47. data/vendor/plugins/lightwindow_helper/assets/stylesheets/lightwindow.css +376 -0
  48. data/vendor/plugins/lightwindow_helper/init.rb +1 -0
  49. data/vendor/plugins/lightwindow_helper/install.rb +7 -0
  50. data/vendor/plugins/lightwindow_helper/lib/lightwindow_helper.rb +31 -0
  51. metadata +70 -3
@@ -0,0 +1,17 @@
1
+ quentin:
2
+ id: 1
3
+ login: quentin
4
+ email: quentin@example.com
5
+ salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
6
+ crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
7
+ #crypted_password: "ce2/iFrNtQ8=\n" # quentin, use only if you're using 2-way encryption
8
+ created_at: <%%= 5.days.ago.to_s :db %>
9
+ # activated_at: <%%= 5.days.ago.to_s :db %> # only if you're activating new signups
10
+ aaron:
11
+ id: 2
12
+ login: aaron
13
+ email: aaron@example.com
14
+ salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
15
+ crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
16
+ # activation_code: aaronscode # only if you're activating new signups
17
+ created_at: <%%= 1.days.ago.to_s :db %>
@@ -0,0 +1,129 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require '<%= controller_file_name %>_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
6
+
7
+ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
8
+ # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
9
+ # Then, you can remove it from this and the units test.
10
+ include AuthenticatedTestHelper
11
+
12
+ fixtures :<%= table_name %>
13
+
14
+ def setup
15
+ @controller = <%= controller_class_name %>Controller.new
16
+ @request = ActionController::TestRequest.new
17
+ @response = ActionController::TestResponse.new
18
+ end
19
+
20
+ def test_should_login_and_redirect
21
+ post :login, :login => 'quentin', :password => 'test'
22
+ assert session[:<%= file_name %>]
23
+ assert_response :redirect
24
+ end
25
+
26
+ def test_should_fail_login_and_not_redirect
27
+ post :login, :login => 'quentin', :password => 'bad password'
28
+ assert_nil session[:<%= file_name %>]
29
+ assert_response :success
30
+ end
31
+
32
+ def test_should_allow_signup
33
+ assert_difference <%= class_name %>, :count do
34
+ create_<%= file_name %>
35
+ assert_response :redirect
36
+ end
37
+ end
38
+
39
+ def test_should_require_login_on_signup
40
+ assert_no_difference <%= class_name %>, :count do
41
+ create_<%= file_name %>(:login => nil)
42
+ assert assigns(:<%= file_name %>).errors.on(:login)
43
+ assert_response :success
44
+ end
45
+ end
46
+
47
+ def test_should_require_password_on_signup
48
+ assert_no_difference <%= class_name %>, :count do
49
+ create_<%= file_name %>(:password => nil)
50
+ assert assigns(:<%= file_name %>).errors.on(:password)
51
+ assert_response :success
52
+ end
53
+ end
54
+
55
+ def test_should_require_password_confirmation_on_signup
56
+ assert_no_difference <%= class_name %>, :count do
57
+ create_<%= file_name %>(:password_confirmation => nil)
58
+ assert assigns(:<%= file_name %>).errors.on(:password_confirmation)
59
+ assert_response :success
60
+ end
61
+ end
62
+
63
+ def test_should_require_email_on_signup
64
+ assert_no_difference <%= class_name %>, :count do
65
+ create_<%= file_name %>(:email => nil)
66
+ assert assigns(:<%= file_name %>).errors.on(:email)
67
+ assert_response :success
68
+ end
69
+ end
70
+
71
+ def test_should_logout
72
+ login_as :quentin
73
+ get :logout
74
+ assert_nil session[:<%= file_name %>]
75
+ assert_response :redirect
76
+ end
77
+
78
+ def test_should_remember_me
79
+ post :login, :login => 'quentin', :password => 'test', :remember_me => "1"
80
+ assert_not_nil @response.cookies["auth_token"]
81
+ end
82
+
83
+ def test_should_not_remember_me
84
+ post :login, :login => 'quentin', :password => 'test', :remember_me => "0"
85
+ assert_nil @response.cookies["auth_token"]
86
+ end
87
+
88
+ def test_should_delete_token_on_logout
89
+ login_as :quentin
90
+ get :logout
91
+ assert_equal @response.cookies["auth_token"], []
92
+ end
93
+
94
+ def test_should_login_with_cookie
95
+ <%= table_name %>(:quentin).remember_me
96
+ @request.cookies["auth_token"] = cookie_for(:quentin)
97
+ get :index
98
+ assert @controller.send(:logged_in?)
99
+ end
100
+
101
+ def test_should_fail_expired_cookie_login
102
+ <%= table_name %>(:quentin).remember_me
103
+ users(:quentin).update_attribute :remember_token_expires_at, 5.minutes.ago
104
+ @request.cookies["auth_token"] = cookie_for(:quentin)
105
+ get :index
106
+ assert !@controller.send(:logged_in?)
107
+ end
108
+
109
+ def test_should_fail_cookie_login
110
+ <%= table_name %>(:quentin).remember_me
111
+ @request.cookies["auth_token"] = auth_token('invalid_auth_token')
112
+ get :index
113
+ assert !@controller.send(:logged_in?)
114
+ end
115
+
116
+ protected
117
+ def create_<%= file_name %>(options = {})
118
+ post :signup, :<%= file_name %> => { :login => 'quire', :email => 'quire@example.com',
119
+ :password => 'quire', :password_confirmation => 'quire' }.merge(options)
120
+ end
121
+
122
+ def auth_token(token)
123
+ CGI::Cookie.new('name' => 'auth_token', 'value' => token)
124
+ end
125
+
126
+ def cookie_for(<%= file_name %>)
127
+ auth_token <%= table_name %>(<%= file_name %>).remember_token
128
+ end
129
+ end
@@ -0,0 +1,4 @@
1
+ require 'digest/sha1'
2
+ class <%="#{class_name}History" %> < ActiveRecord::Base
3
+ acts_as_history
4
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class <%= class_name %>Test < Test::Unit::TestCase
4
+ # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead.
5
+ # Then, you can remove it from this and the functional test.
6
+ include AuthenticatedTestHelper
7
+ fixtures :<%= table_name %>
8
+
9
+ def test_should_create_<%= file_name %>
10
+ assert_difference <%= class_name %>, :count do
11
+ <%= file_name %> = create_<%= file_name %>
12
+ assert !<%= file_name %>.new_record?, "#{<%= file_name %>.errors.full_messages.to_sentence}"
13
+ end
14
+ end
15
+
16
+ def test_should_require_login
17
+ assert_no_difference <%= class_name %>, :count do
18
+ u = create_<%= file_name %>(:login => nil)
19
+ assert u.errors.on(:login)
20
+ end
21
+ end
22
+
23
+ def test_should_require_password
24
+ assert_no_difference <%= class_name %>, :count do
25
+ u = create_<%= file_name %>(:password => nil)
26
+ assert u.errors.on(:password)
27
+ end
28
+ end
29
+
30
+ def test_should_require_password_confirmation
31
+ assert_no_difference <%= class_name %>, :count do
32
+ u = create_<%= file_name %>(:password_confirmation => nil)
33
+ assert u.errors.on(:password_confirmation)
34
+ end
35
+ end
36
+
37
+ def test_should_require_email
38
+ assert_no_difference <%= class_name %>, :count do
39
+ u = create_<%= file_name %>(:email => nil)
40
+ assert u.errors.on(:email)
41
+ end
42
+ end
43
+
44
+ def test_should_reset_password
45
+ <%= table_name %>(:quentin).update_attributes(:password => 'new password', :password_confirmation => 'new password')
46
+ assert_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin', 'new password')
47
+ end
48
+
49
+ def test_should_not_rehash_password
50
+ <%= table_name %>(:quentin).update_attributes(:login => 'quentin2')
51
+ assert_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin2', 'test')
52
+ end
53
+
54
+ def test_should_authenticate_<%= file_name %>
55
+ assert_equal <%= table_name %>(:quentin), <%= class_name %>.authenticate('quentin', 'test')
56
+ end
57
+
58
+ def test_should_set_remember_token
59
+ <%= table_name %>(:quentin).remember_me
60
+ assert_not_nil <%= table_name %>(:quentin).remember_token
61
+ assert_not_nil <%= table_name %>(:quentin).remember_token_expires_at
62
+ end
63
+
64
+ def test_should_unset_remember_token
65
+ <%= table_name %>(:quentin).remember_me
66
+ assert_not_nil <%= table_name %>(:quentin).remember_token
67
+ <%= table_name %>(:quentin).forget_me
68
+ assert_nil <%= table_name %>(:quentin).remember_token
69
+ end
70
+
71
+ protected
72
+ def create_<%= file_name %>(options = {})
73
+ <%= class_name %>.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
74
+ end
75
+ end
@@ -0,0 +1,59 @@
1
+ require 'sidebar'
2
+ require 'mechanize'
3
+
4
+ class ::Sidebar
5
+ def blocks_with_jira_issues(*args)
6
+ blocks = blocks_without_jira_issues(*args)
7
+
8
+ app_conf = YAML::load(ERB.new(IO.read(APP_CONFIG_FILE)).result) || {}
9
+ if jira_conf = app_conf['jira']
10
+ jira_url = jira_conf['url'].chomp('/')
11
+ jira_user = jira_conf['user']
12
+ jira_password = jira_conf['password']
13
+ jira_pids = jira_conf['pids'].to_s.split(',').map{|p| "&pid=#{p.strip}"}
14
+ fix_version = jira_conf['fix_version'].to_s
15
+ limit = 20
16
+ assignee = '' # "&assigneeSelect=specificuser&assignee=#{jira_user}"
17
+ sorting = '&sorter/field=priority&sorter/order=DESC'
18
+ resolution = 'resolution=-1'
19
+
20
+ agent = WWW::Mechanize.new { |a| a.log = Logger.new("jira.log") }
21
+ agent.user_agent_alias = 'Mechanize'
22
+
23
+ login_url = "#{jira_url}/login.jsp?os_username=#{jira_user}&os_password=#{jira_password}"
24
+ login_page = agent.get(login_url)
25
+ login_form = login_page.forms.name("loginform").first
26
+ login_form.fields.name("os_username").value = jira_user
27
+ login_form.fields.name("os_username").value = jira_user
28
+ agent.submit(login_form)
29
+
30
+ search_path = 'sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml'
31
+ url = "#{jira_url}/#{search_path}?#{resolution}#{jira_pids}#{assignee}#{sorting}&tempMax=#{limit}&fixfor=#{fix_version}"
32
+ search_results = agent.get(url)
33
+
34
+ xml_search_doc = Hpricot.XML(search_results.body)
35
+ items = (xml_search_doc/"item")
36
+ issues = items.map do |item|
37
+ title = (item/'title').inner_html
38
+ link = (item/'link').first.inner_html
39
+ [title, link]
40
+ end
41
+
42
+ list = "<ul>\n"
43
+ issues.each do |issue|
44
+ list << "<li>\n"
45
+ list << link_to(issue[0], issue[1])
46
+ list << " [" + link_to('Add', :controller => :tasks, :action => :new, :task => {:backlog_id => 1, :period_id => @period, :description => issue[0]})
47
+ list << "]</li>\n"
48
+ end
49
+ list << "</ul>\n"
50
+ blocks << {
51
+ :id => 1,
52
+ :title => "JIRA Issues",
53
+ :options => jira_url,
54
+ :content => list
55
+ }
56
+ end
57
+ end
58
+ alias_method_chain :blocks, :jira_issues
59
+ end
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1 @@
1
+ # BacklogJira
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :backlog_jira do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class BacklogJiraTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
@@ -0,0 +1,33 @@
1
+ LightWindowHelper v.1.0
2
+ ====================
3
+
4
+ # Author:: Carlo Bertini (WaYdotNET)
5
+ # WebSite:: http://blogs.ugidotnet.org/carlitoway
6
+ # Based on LightBoxHelper
7
+ # Many thx to Davide D'Agostino (DAddYE)
8
+
9
+ This LightBox Helper is based on the lastest javascript http://www.stickmanlabs.com/lightwindow/
10
+
11
+ note: this js use Prototype JavaScript framework, version 1.6.0
12
+
13
+ It's only make an helper, copy the lastest javascripts, css, and images on your public/javascript directory
14
+ and register the javascript in the AssetTagHelper of rails,
15
+ so for include the javascript in your page you only can add this (if you havn't yet):
16
+
17
+ <%= javascript_include_tag :defaults %>
18
+
19
+ You must add also the stylesheet so add this on your page head:
20
+
21
+ <%= stylesheet_link_tag 'lightwindow' %>
22
+
23
+ The is very simple for add a LightWindow in your page add this:
24
+ <%= lightwindow_link_to(name, options = {}, html_options = {}, *parameters_for_method_reference) %>
25
+ es:
26
+ <%= lightwindow_link_to(
27
+ "Click me !", {:action => 'edit', :id => "12/"}, :title => "This is a test!",
28
+ :author=>"Carlo Bertini",
29
+ :caption=>"Ruby on rails is beautyfull :D"
30
+ ) %>
31
+
32
+
33
+ Vist my website: http://blogs.ugidotnet.org/carlitoway
@@ -0,0 +1,1921 @@
1
+ // lightwindow.js v2.0
2
+ //
3
+ // Copyright (c) 2007 stickmanlabs
4
+ // Author: Kevin P Miller | http://www.stickmanlabs.com
5
+ //
6
+ // LightWindow is freely distributable under the terms of an MIT-style license.
7
+ //
8
+ // I don't care what you think about the file size...
9
+ // Be a pro:
10
+ // http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
11
+ // http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
12
+ //
13
+
14
+ /*-----------------------------------------------------------------------------------------------*/
15
+
16
+ if(typeof Effect == 'undefined')
17
+ throw("lightwindow.js requires including script.aculo.us' effects.js library!");
18
+
19
+ // This will stop image flickering in IE6 when elements with images are moved
20
+ try {
21
+ document.execCommand("BackgroundImageCache", false, true);
22
+ } catch(e) {}
23
+
24
+ var lightwindow = Class.create();
25
+ lightwindow.prototype = {
26
+ //
27
+ // Setup Variables
28
+ //
29
+ element : null,
30
+ contentToFetch : null,
31
+ windowActive : false,
32
+ dataEffects : [],
33
+ dimensions : {
34
+ cruft : null,
35
+ container : null,
36
+ viewport : {
37
+ height : null,
38
+ width : null,
39
+ offsetTop : null,
40
+ offsetLeft : null
41
+ }
42
+ },
43
+ pagePosition : {
44
+ x : 0,
45
+ y : 0
46
+ },
47
+ pageDimensions : {
48
+ width : null,
49
+ height : null
50
+ },
51
+ preloadImage : [],
52
+ preloadedImage : [],
53
+ galleries : [],
54
+ resizeTo : {
55
+ height : null,
56
+ heightPercent : null,
57
+ width : null,
58
+ widthPercent : null,
59
+ fixedTop : null,
60
+ fixedLeft : null
61
+ },
62
+ scrollbarOffset : 18,
63
+ navigationObservers : {
64
+ previous : null,
65
+ next : null
66
+ },
67
+ containerChange : {
68
+ height : 0,
69
+ width : 0
70
+ },
71
+ activeGallery : false,
72
+ galleryLocation : {
73
+ current : 0,
74
+ total : 0
75
+ },
76
+ //
77
+ // Initialize the lightwindow.
78
+ //
79
+ initialize : function(options) {
80
+ this.options = Object.extend({
81
+ resizeSpeed : 8,
82
+ contentOffset : {
83
+ height : 20,
84
+ width : 20
85
+ },
86
+ dimensions : {
87
+ image : {height : 250, width : 250},
88
+ page : {height : 250, width : 250},
89
+ inline : {height : 250, width : 250},
90
+ media : {height : 250, width : 250},
91
+ external : {height : 250, width : 250},
92
+ titleHeight : 25
93
+ },
94
+ classNames : {
95
+ standard : 'lightwindow',
96
+ action : 'lightwindow_action'
97
+ },
98
+ fileTypes : {
99
+ page : ['asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php4', 'php3', 'php', 'php5', 'phtml', 'rhtml', 'shtml', 'txt', 'vbs', 'rb'],
100
+ media : ['aif', 'aiff', 'asf', 'avi', 'divx', 'm1v', 'm2a', 'm2v', 'm3u', 'mid', 'midi', 'mov', 'moov', 'movie', 'mp2', 'mp3', 'mpa', 'mpa', 'mpe', 'mpeg', 'mpg', 'mpg', 'mpga', 'pps', 'qt', 'rm', 'ram', 'swf', 'viv', 'vivo', 'wav'],
101
+ image : ['bmp', 'gif', 'jpg', 'png', 'tiff']
102
+ },
103
+ mimeTypes : {
104
+ avi : 'video/avi',
105
+ aif : 'audio/aiff',
106
+ aiff : 'audio/aiff',
107
+ gif : 'image/gif',
108
+ bmp : 'image/bmp',
109
+ jpeg : 'image/jpeg',
110
+ m1v : 'video/mpeg',
111
+ m2a : 'audio/mpeg',
112
+ m2v : 'video/mpeg',
113
+ m3u : 'audio/x-mpequrl',
114
+ mid : 'audio/x-midi',
115
+ midi : 'audio/x-midi',
116
+ mjpg : 'video/x-motion-jpeg',
117
+ moov : 'video/quicktime',
118
+ mov : 'video/quicktime',
119
+ movie : 'video/x-sgi-movie',
120
+ mp2 : 'audio/mpeg',
121
+ mp3 : 'audio/mpeg3',
122
+ mpa : 'audio/mpeg',
123
+ mpa : 'video/mpeg',
124
+ mpe : 'video/mpeg',
125
+ mpeg : 'video/mpeg',
126
+ mpg : 'audio/mpeg',
127
+ mpg : 'video/mpeg',
128
+ mpga : 'audio/mpeg',
129
+ pdf : 'application/pdf',
130
+ png : 'image/png',
131
+ pps : 'application/mspowerpoint',
132
+ qt : 'video/quicktime',
133
+ ram : 'audio/x-pn-realaudio-plugin',
134
+ rm : 'application/vnd.rn-realmedia',
135
+ swf : 'application/x-shockwave-flash',
136
+ tiff : 'image/tiff',
137
+ viv : 'video/vivo',
138
+ vivo : 'video/vivo',
139
+ wav : 'audio/wav',
140
+ wmv : 'application/x-mplayer2'
141
+ },
142
+ classids : {
143
+ mov : 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
144
+ swf : 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000',
145
+ wmv : 'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6'
146
+ },
147
+ codebases : {
148
+ mov : 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
149
+ swf : 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0',
150
+ wmv : 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715'
151
+ },
152
+ viewportPadding : 10,
153
+ EOLASFix : 'swf,wmv,fla,flv',
154
+ overlay : {
155
+ opacity : 0.7,
156
+ image : 'images/black.png',
157
+ presetImage : 'images/black-70.png'
158
+ },
159
+ skin : {
160
+ main : '<div id="lightwindow_container" >'+
161
+ '<div id="lightwindow_title_bar" >'+
162
+ '<div id="lightwindow_title_bar_inner" >'+
163
+ '<span id="lightwindow_title_bar_title"></span>'+
164
+ '<a id="lightwindow_title_bar_close_link" >close</a>'+
165
+ '</div>'+
166
+ '</div>'+
167
+ '<div id="lightwindow_stage" >'+
168
+ '<div id="lightwindow_contents" >'+
169
+ '</div>'+
170
+ '<div id="lightwindow_navigation" >'+
171
+ '<a href="#" id="lightwindow_previous" >'+
172
+ '<span id="lightwindow_previous_title"></span>'+
173
+ '</a>'+
174
+ '<a href="#" id="lightwindow_next" >'+
175
+ '<span id="lightwindow_next_title"></span>'+
176
+ '</a>'+
177
+ '<iframe name="lightwindow_navigation_shim" id="lightwindow_navigation_shim" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>'+
178
+ '</div>'+
179
+ '<div id="lightwindow_galleries">'+
180
+ '<div id="lightwindow_galleries_tab_container" >'+
181
+ '<a href="#" id="lightwindow_galleries_tab" >'+
182
+ '<span id="lightwindow_galleries_tab_span" class="up" >Galleries</span>'+
183
+ '</a>'+
184
+ '</div>'+
185
+ '<div id="lightwindow_galleries_list" >'+
186
+ '</div>'+
187
+ '</div>'+
188
+ '</div>'+
189
+ '<div id="lightwindow_data_slide" >'+
190
+ '<div id="lightwindow_data_slide_inner" >'+
191
+ '<div id="lightwindow_data_details" >'+
192
+ '<div id="lightwindow_data_gallery_container" >'+
193
+ '<span id="lightwindow_data_gallery_current"></span>'+
194
+ ' of '+
195
+ '<span id="lightwindow_data_gallery_total"></span>'+
196
+ '</div>'+
197
+ '<div id="lightwindow_data_author_container" >'+
198
+ 'by <span id="lightwindow_data_author"></span>'+
199
+ '</div>'+
200
+ '</div>'+
201
+ '<div id="lightwindow_data_caption" >'+
202
+ '</div>'+
203
+ '</div>'+
204
+ '</div>'+
205
+ '</div>',
206
+ loading : '<div id="lightwindow_loading" >'+
207
+ '<img src="images/ajax-loading.gif" alt="loading" />'+
208
+ '<span>Loading or <a href="javascript: myLightWindow.deactivate();">Cancel</a></span>'+
209
+ '<iframe name="lightwindow_loading_shim" id="lightwindow_loading_shim" src="javascript:false;" frameBorder="0" scrolling="no"></iframe>'+
210
+ '</div>',
211
+ iframe : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+
212
+ '<html xmlns="http://www.w3.org/1999/xhtml">'+
213
+ '<body>'+
214
+ '{body_replace}'+
215
+ '</body>'+
216
+ '</html>',
217
+ gallery : {
218
+ top : '<div class="lightwindow_galleries_list">'+
219
+ '<h1>{gallery_title_replace}</h1>'+
220
+ '<ul>',
221
+ middle : '<li>'+
222
+ '{gallery_link_replace}'+
223
+ '</li>',
224
+ bottom : '</ul>'+
225
+ '</div>'
226
+ }
227
+ },
228
+ formMethod : 'get',
229
+ hideFlash : false,
230
+ hideGalleryTab : false,
231
+ showTitleBar : true,
232
+ animationHandler : false,
233
+ navigationHandler : false,
234
+ transitionHandler : false,
235
+ finalAnimationHandler : false,
236
+ formHandler : false,
237
+ galleryAnimationHandler : false,
238
+ showGalleryCount : true
239
+ }, options || {});
240
+ this.duration = ((11-this.options.resizeSpeed)*0.15);
241
+ this._setupLinks();
242
+ this._getScroll();
243
+ this._getPageDimensions();
244
+ this._browserDimensions();
245
+ this._addLightWindowMarkup(false);
246
+ this._setupDimensions();
247
+ this.buildGalleryList();
248
+ },
249
+ //
250
+ // Activate the lightwindow.
251
+ //
252
+ activate : function(e, link){
253
+ // Clear out the window Contents
254
+ this._clearWindowContents(true);
255
+
256
+ // Add back in out loading panel
257
+ this._addLoadingWindowMarkup();
258
+
259
+ // Setup the element properties
260
+ this._setupWindowElements(link);
261
+
262
+ // Setup everything
263
+ this._getScroll();
264
+ this._browserDimensions();
265
+ this._setupDimensions();
266
+ this._toggleTroubleElements('hidden', false);
267
+ this._displayLightWindow('block', 'hidden');
268
+ this._setStatus(true);
269
+ this._monitorKeyboard(true);
270
+ this._prepareIE(true);
271
+ this._loadWindow();
272
+ },
273
+ //
274
+ // Turn off the window
275
+ //
276
+ deactivate : function(){
277
+ // The window is not active
278
+ this.windowActive = false;
279
+
280
+ // There is no longer a gallery active
281
+ this.activeGallery = false;
282
+ if (!this.options.hideGalleryTab) {
283
+ this._handleGalleryAnimation(false);
284
+ }
285
+
286
+ // Kill the animation
287
+ this.animating = false;
288
+
289
+ // Clear our element
290
+ this.element = null;
291
+
292
+ // hide the window.
293
+ this._displayLightWindow('none', 'visible');
294
+
295
+ // Clear out the window Contents
296
+ this._clearWindowContents(false);
297
+
298
+ // Stop all animation
299
+ var queue = Effect.Queues.get('lightwindowAnimation').each(function(e){e.cancel();});
300
+
301
+ // Undo the setup
302
+ this._prepareIE(false);
303
+ this._setupDimensions();
304
+ this._toggleTroubleElements('visible', false);
305
+ this._monitorKeyboard(false);
306
+ },
307
+ //
308
+ // Initialize specific window
309
+ //
310
+ createWindow : function(element, attributes) {
311
+ this._processLink($(element));
312
+ },
313
+ //
314
+ // Open a Window from a hash of attributes
315
+ //
316
+ activateWindow : function(options) {
317
+ this.element = Object.extend({
318
+ href : null,
319
+ title : null,
320
+ author : null,
321
+ caption : null,
322
+ rel : null,
323
+ top : null,
324
+ left : null,
325
+ type : null,
326
+ showImages : null,
327
+ height : null,
328
+ width : null,
329
+ loadingAnimation : null,
330
+ iframeEmbed : null,
331
+ form : null
332
+ }, options || {});
333
+
334
+ // Set the window type
335
+ this.contentToFetch = this.element.href;
336
+ this.windowType = this.element.type ? this.element.type : this._fileType(this.element.href);
337
+
338
+ // Clear out the window Contents
339
+ this._clearWindowContents(true);
340
+
341
+ // Add back in out loading panel
342
+ this._addLoadingWindowMarkup();
343
+
344
+ // Setup everything
345
+ this._getScroll();
346
+ this._browserDimensions();
347
+ this._setupDimensions();
348
+ this._toggleTroubleElements('hidden', false);
349
+ this._displayLightWindow('block', 'hidden');
350
+ this._setStatus(true);
351
+ this._monitorKeyboard(true);
352
+ this._prepareIE(true);
353
+ this._loadWindow();
354
+ },
355
+ //
356
+ // Fire off our Form handler
357
+ //
358
+ submitForm : function(e) {
359
+ if (this.options.formHandler) {
360
+ this.options.formHandler(e);
361
+ } else {
362
+ this._defaultFormHandler(e);
363
+ }
364
+ },
365
+ //
366
+ // Reload the window with another location
367
+ //
368
+ openWindow : function(element) {
369
+ var element = $(element);
370
+
371
+ // The window is active
372
+ this.windowActive = true;
373
+
374
+ // Clear out the window Contents
375
+ this._clearWindowContents(true);
376
+
377
+ // Add back in out loading panel
378
+ this._addLoadingWindowMarkup();
379
+
380
+ // Setup the element properties
381
+ this._setupWindowElements(element);
382
+
383
+ this._setStatus(true);
384
+ this._handleTransition();
385
+ },
386
+ //
387
+ // Navigate the window
388
+ //
389
+ navigateWindow : function(direction) {
390
+ this._handleNavigation(false);
391
+ if (direction == 'previous') {
392
+ this.openWindow(this.navigationObservers.previous);
393
+ } else if (direction == 'next'){
394
+ this.openWindow(this.navigationObservers.next);
395
+ }
396
+ },
397
+ //
398
+ // Build the Gallery List and Load it
399
+ //
400
+ buildGalleryList : function() {
401
+ var output = '';
402
+ var galleryLink;
403
+ for (i in this.galleries) {
404
+ if (typeof this.galleries[i] == 'object') {
405
+ output += (this.options.skin.gallery.top).replace('{gallery_title_replace}', unescape(i));
406
+ for (j in this.galleries[i]) {
407
+ if (typeof this.galleries[i][j] == 'object') {
408
+ galleryLink = '<a href="#" id="lightwindow_gallery_'+i+'_'+j+'" >'+unescape(j)+'</a>';
409
+ output += (this.options.skin.gallery.middle).replace('{gallery_link_replace}', galleryLink);
410
+ }
411
+ }
412
+ output += this.options.skin.gallery.bottom;
413
+ }
414
+ }
415
+ new Insertion.Top('lightwindow_galleries_list', output);
416
+
417
+ // Attach Events
418
+ for (i in this.galleries) {
419
+ if (typeof this.galleries[i] == 'object') {
420
+ for (j in this.galleries[i]) {
421
+ if (typeof this.galleries[i][j] == 'object') {
422
+ Event.observe($('lightwindow_gallery_'+i+'_'+j), 'click', this.openWindow.bind(this, this.galleries[i][j][0]), false);
423
+ $('lightwindow_gallery_'+i+'_'+j).onclick = function() {return false;};
424
+ }
425
+ }
426
+ }
427
+ }
428
+ },
429
+ //
430
+ // Set Links Up
431
+ //
432
+ _setupLinks : function() {
433
+ var links = $$('.'+this.options.classNames.standard);
434
+ links.each(function(link) {
435
+ this._processLink(link);
436
+ }.bind(this));
437
+ },
438
+ //
439
+ // Process a Link
440
+ //
441
+ _processLink : function(link) {
442
+ if ((this._fileType(link.getAttribute('href')) == 'image' || this._fileType(link.getAttribute('href')) == 'media')) {
443
+ if (gallery = this._getGalleryInfo(link.rel)) {
444
+ if (!this.galleries[gallery[0]]) {
445
+ this.galleries[gallery[0]] = new Array();
446
+ }
447
+ if (!this.galleries[gallery[0]][gallery[1]]) {
448
+ this.galleries[gallery[0]][gallery[1]] = new Array();
449
+ }
450
+ this.galleries[gallery[0]][gallery[1]].push(link);
451
+ }
452
+ }
453
+
454
+ // Take care of our inline content
455
+ var url = link.getAttribute('href');
456
+ if (url.indexOf('?') > -1) {
457
+ url = url.substring(0, url.indexOf('?'));
458
+ }
459
+
460
+ var container = url.substring(url.indexOf('#')+1);
461
+ if($(container)) {
462
+ $(container).setStyle({
463
+ display : 'none'
464
+ });
465
+ }
466
+
467
+ Event.observe(link, 'click', this.activate.bindAsEventListener(this, link), false);
468
+ link.onclick = function() {return false;};
469
+ },
470
+ //
471
+ // Setup our actions
472
+ //
473
+ _setupActions : function() {
474
+ var links = $$('#lightwindow_container .'+this.options.classNames.action);
475
+ links.each(function(link) {
476
+ Event.observe(link, 'click', this[link.getAttribute('rel')].bindAsEventListener(this, link), false);
477
+ link.onclick = function() {return false;};
478
+ }.bind(this));
479
+ },
480
+ //
481
+ // Add the markup to the page.
482
+ //
483
+ _addLightWindowMarkup : function(rebuild) {
484
+ var overlay = Element.extend(document.createElement('div'));
485
+ overlay.setAttribute('id', 'lightwindow_overlay');
486
+ // FF Mac has a problem with putting Flash above a layer without a 100% opacity background, so we need to use a pre-made
487
+ if (Prototype.Browser.Gecko) {
488
+ overlay.setStyle({
489
+ backgroundImage: 'url('+this.options.overlay.presetImage+')',
490
+ backgroundRepeat: 'repeat',
491
+ height: this.pageDimensions.height+'px'
492
+ });
493
+ } else {
494
+ overlay.setStyle({
495
+ opacity: this.options.overlay.opacity,
496
+ backgroundImage: 'url('+this.options.overlay.image+')',
497
+ backgroundRepeat: 'repeat',
498
+ height: this.pageDimensions.height+'px'
499
+ });
500
+ }
501
+
502
+ var lw = document.createElement('div');
503
+ lw.setAttribute('id', 'lightwindow');
504
+ lw.innerHTML = this.options.skin.main;
505
+
506
+ var body = document.getElementsByTagName('body')[0];
507
+ body.appendChild(overlay);
508
+ body.appendChild(lw);
509
+
510
+ if ($('lightwindow_title_bar_close_link')) {
511
+ Event.observe('lightwindow_title_bar_close_link', 'click', this.deactivate.bindAsEventListener(this));
512
+ $('lightwindow_title_bar_close_link').onclick = function() {return false;};
513
+ }
514
+
515
+ Event.observe($('lightwindow_previous'), 'click', this.navigateWindow.bind(this, 'previous'), false);
516
+ $('lightwindow_previous').onclick = function() {return false;};
517
+ Event.observe($('lightwindow_next'), 'click', this.navigateWindow.bind(this, 'next'), false);
518
+ $('lightwindow_next').onclick = function() {return false;};
519
+
520
+ if (!this.options.hideGalleryTab) {
521
+ Event.observe($('lightwindow_galleries_tab'), 'click', this._handleGalleryAnimation.bind(this, true), false);
522
+ $('lightwindow_galleries_tab').onclick = function() {return false;};
523
+ }
524
+
525
+ // Because we use position absolute, kill the scroll Wheel on animations
526
+ if (Prototype.Browser.IE) {
527
+ Event.observe(document, 'mousewheel', this._stopScrolling.bindAsEventListener(this), false);
528
+ } else {
529
+ Event.observe(window, 'DOMMouseScroll', this._stopScrolling.bindAsEventListener(this), false);
530
+ }
531
+
532
+ Event.observe(overlay, 'click', this.deactivate.bindAsEventListener(this), false);
533
+ overlay.onclick = function() {return false;};
534
+ },
535
+ //
536
+ // Add loading window markup
537
+ //
538
+ _addLoadingWindowMarkup : function() {
539
+ $('lightwindow_contents').innerHTML += this.options.skin.loading;
540
+ },
541
+ //
542
+ // Setup the window elements
543
+ //
544
+ _setupWindowElements : function(link) {
545
+ this.element = link;
546
+ this.element.title = null ? '' : link.getAttribute('title');
547
+ this.element.author = null ? '' : link.getAttribute('author');
548
+ this.element.caption = null ? '' : link.getAttribute('caption');
549
+ this.element.rel = null ? '' : link.getAttribute('rel');
550
+ this.element.params = null ? '' : link.getAttribute('params');
551
+
552
+ // Set the window type
553
+ this.contentToFetch = this.element.href;
554
+ this.windowType = this._getParameter('lightwindow_type') ? this._getParameter('lightwindow_type') : this._fileType(this.contentToFetch);
555
+ },
556
+ //
557
+ // Clear the window contents out
558
+ //
559
+ _clearWindowContents : function(contents) {
560
+ // If there is an iframe, its got to go
561
+ if ($('lightwindow_iframe')) {
562
+ Element.remove($('lightwindow_iframe'));
563
+ }
564
+
565
+ // Stop playing an object if its still around
566
+ if ($('lightwindow_media_primary')) {
567
+ try {
568
+ $('lightwindow_media_primary').Stop();
569
+ } catch(e) {}
570
+ Element.remove($('lightwindow_media_primary'));
571
+ }
572
+
573
+ // Stop playing an object if its still around
574
+ if ($('lightwindow_media_secondary')) {
575
+ try {
576
+ $('lightwindow_media_secondary').Stop();
577
+ } catch(e) {}
578
+ Element.remove($('lightwindow_media_secondary'));
579
+ }
580
+
581
+ this.activeGallery = false;
582
+ this._handleNavigation(this.activeGallery);
583
+
584
+ if (contents) {
585
+ // Empty the contents
586
+ $('lightwindow_contents').innerHTML = '';
587
+
588
+ // Reset the scroll bars
589
+ $('lightwindow_contents').setStyle({
590
+ overflow: 'hidden'
591
+ });
592
+
593
+ if (!this.windowActive) {
594
+ $('lightwindow_data_slide_inner').setStyle({
595
+ display: 'none'
596
+ });
597
+
598
+ $('lightwindow_title_bar_title').innerHTML = '';
599
+ }
600
+
601
+ // Because of browser differences and to maintain flexible captions we need to reset this height at close
602
+ $('lightwindow_data_slide').setStyle({
603
+ height: 'auto'
604
+ });
605
+ }
606
+
607
+ this.resizeTo.height = null;
608
+ this.resizeTo.width = null;
609
+ },
610
+ //
611
+ // Set the status of our animation to keep things from getting clunky
612
+ //
613
+ _setStatus : function(status) {
614
+ this.animating = status;
615
+ if (status) {
616
+ Element.show('lightwindow_loading');
617
+ }
618
+ if (!(/MSIE 6./i.test(navigator.userAgent))) {
619
+ this._fixedWindow(status);
620
+ }
621
+ },
622
+ //
623
+ // Make this window Fixed
624
+ //
625
+ _fixedWindow : function(status) {
626
+ if (status) {
627
+ if (this.windowActive) {
628
+ this._getScroll();
629
+ $('lightwindow').setStyle({
630
+ position: 'absolute',
631
+ top: parseFloat($('lightwindow').getStyle('top'))+this.pagePosition.y+'px',
632
+ left: parseFloat($('lightwindow').getStyle('left'))+this.pagePosition.x+'px'
633
+ });
634
+ } else {
635
+ $('lightwindow').setStyle({
636
+ position: 'absolute'
637
+ });
638
+ }
639
+ } else {
640
+ if (this.windowActive) {
641
+ this._getScroll();
642
+ $('lightwindow').setStyle({
643
+ position: 'fixed',
644
+ top: parseFloat($('lightwindow').getStyle('top'))-this.pagePosition.y+'px',
645
+ left: parseFloat($('lightwindow').getStyle('left'))-this.pagePosition.x+'px'
646
+ });
647
+ } else {
648
+ if ($('lightwindow_iframe')) {
649
+ // Ideally here we would set a 50% value for top and left, but Safari rears it ugly head again and we need to do it by pixels
650
+ this._browserDimensions();
651
+ }
652
+ $('lightwindow').setStyle({
653
+ position: 'fixed',
654
+ top: (parseFloat(this._getParameter('lightwindow_top')) ? parseFloat(this._getParameter('lightwindow_top'))+'px' : this.dimensions.viewport.height/2+'px'),
655
+ left: (parseFloat(this._getParameter('lightwindow_left')) ? parseFloat(this._getParameter('lightwindow_left'))+'px' : this.dimensions.viewport.width/2+'px')
656
+ });
657
+ }
658
+ }
659
+ },
660
+ //
661
+ // Prepare the window for IE.
662
+ //
663
+ _prepareIE : function(setup) {
664
+ if (Prototype.Browser.IE) {
665
+ var height, overflowX, overflowY;
666
+ if (setup) {
667
+ var height = '100%';
668
+ } else {
669
+ var height = 'auto';
670
+ }
671
+ var body = document.getElementsByTagName('body')[0];
672
+ var html = document.getElementsByTagName('html')[0];
673
+ html.style.height = body.style.height = height;
674
+ }
675
+ },
676
+ _stopScrolling : function(e) {
677
+ if (this.animating) {
678
+ if (e.preventDefault) {
679
+ e.preventDefault();
680
+ }
681
+ e.returnValue = false;
682
+ }
683
+ },
684
+ //
685
+ // Get the scroll for the page.
686
+ //
687
+ _getScroll : function(){
688
+ if(typeof(window.pageYOffset) == 'number') {
689
+ this.pagePosition.x = window.pageXOffset;
690
+ this.pagePosition.y = window.pageYOffset;
691
+ } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
692
+ this.pagePosition.x = document.body.scrollLeft;
693
+ this.pagePosition.y = document.body.scrollTop;
694
+ } else if(document.documentElement) {
695
+ this.pagePosition.x = document.documentElement.scrollLeft;
696
+ this.pagePosition.y = document.documentElement.scrollTop;
697
+ }
698
+ },
699
+ //
700
+ // Reset the scroll.
701
+ //
702
+ _setScroll : function(x, y) {
703
+ document.documentElement.scrollLeft = x;
704
+ document.documentElement.scrollTop = y;
705
+ },
706
+ //
707
+ // Hide Selects from the page because of IE.
708
+ // We could use iframe shims instead here but why add all the extra markup for one browser when this is much easier and cleaner
709
+ //
710
+ _toggleTroubleElements : function(visibility, content){
711
+
712
+ if (content) {
713
+ var selects = $('lightwindow_contents').getElementsByTagName('select');
714
+ } else {
715
+ var selects = document.getElementsByTagName('select');
716
+ }
717
+
718
+ for(var i = 0; i < selects.length; i++) {
719
+ selects[i].style.visibility = visibility;
720
+ }
721
+
722
+ if (!content) {
723
+ if (this.options.hideFlash){
724
+ var objects = document.getElementsByTagName('object');
725
+ for (i = 0; i != objects.length; i++) {
726
+ objects[i].style.visibility = visibility;
727
+ }
728
+ var embeds = document.getElementsByTagName('embed');
729
+ for (i = 0; i != embeds.length; i++) {
730
+ embeds[i].style.visibility = visibility;
731
+ }
732
+ }
733
+ var iframes = document.getElementsByTagName('iframe');
734
+ for (i = 0; i != iframes.length; i++) {
735
+ iframes[i].style.visibility = visibility;
736
+ }
737
+ }
738
+ },
739
+ //
740
+ // Get the actual page size
741
+ //
742
+ _getPageDimensions : function() {
743
+ var xScroll, yScroll;
744
+ if (window.innerHeight && window.scrollMaxY) {
745
+ xScroll = document.body.scrollWidth;
746
+ yScroll = window.innerHeight + window.scrollMaxY;
747
+ } else if (document.body.scrollHeight > document.body.offsetHeight){
748
+ xScroll = document.body.scrollWidth;
749
+ yScroll = document.body.scrollHeight;
750
+ } else {
751
+ xScroll = document.body.offsetWidth;
752
+ yScroll = document.body.offsetHeight;
753
+ }
754
+
755
+ var windowWidth, windowHeight;
756
+ if (self.innerHeight) {
757
+ windowWidth = self.innerWidth;
758
+ windowHeight = self.innerHeight;
759
+ } else if (document.documentElement && document.documentElement.clientHeight) {
760
+ windowWidth = document.documentElement.clientWidth;
761
+ windowHeight = document.documentElement.clientHeight;
762
+ } else if (document.body) {
763
+ windowWidth = document.body.clientWidth;
764
+ windowHeight = document.body.clientHeight;
765
+ }
766
+
767
+ if(yScroll < windowHeight){
768
+ this.pageDimensions.height = windowHeight;
769
+ } else {
770
+ this.pageDimensions.height = yScroll;
771
+ }
772
+
773
+ if(xScroll < windowWidth){
774
+ this.pageDimensions.width = windowWidth;
775
+ } else {
776
+ this.pageDimensions.width = xScroll;
777
+ }
778
+ },
779
+ //
780
+ // Display the lightWindow.
781
+ //
782
+ _displayLightWindow : function(display, visibility) {
783
+ $('lightwindow_overlay').style.display = $('lightwindow').style.display = $('lightwindow_container').style.display = display;
784
+ $('lightwindow_overlay').style.visibility = $('lightwindow').style.visibility = $('lightwindow_container').style.visibility = visibility;
785
+ },
786
+ //
787
+ // Setup Dimensions of lightwindow.
788
+
789
+ //
790
+ _setupDimensions : function() {
791
+
792
+ var originalHeight, originalWidth;
793
+ switch (this.windowType) {
794
+ case 'page' :
795
+ originalHeight = this.options.dimensions.page.height;
796
+ originalWidth = this.options.dimensions.page.width;
797
+ break;
798
+
799
+ case 'image' :
800
+ originalHeight = this.options.dimensions.image.height;
801
+ originalWidth = this.options.dimensions.image.width;
802
+ break;
803
+
804
+ case 'media' :
805
+ originalHeight = this.options.dimensions.media.height;
806
+ originalWidth = this.options.dimensions.media.width;
807
+ break;
808
+
809
+ case 'external' :
810
+ originalHeight = this.options.dimensions.external.height;
811
+ originalWidth = this.options.dimensions.external.width;
812
+ break;
813
+
814
+ case 'inline' :
815
+ originalHeight = this.options.dimensions.inline.height;
816
+ originalWidth = this.options.dimensions.inline.width;
817
+ break;
818
+
819
+ default :
820
+ originalHeight = this.options.dimensions.page.height;
821
+ originalWidth = this.options.dimensions.page.width;
822
+ break;
823
+
824
+ }
825
+
826
+ var offsetHeight = this._getParameter('lightwindow_top') ? parseFloat(this._getParameter('lightwindow_top'))+this.pagePosition.y : this.dimensions.viewport.height/2+this.pagePosition.y;
827
+ var offsetWidth = this._getParameter('lightwindow_left') ? parseFloat(this._getParameter('lightwindow_left'))+this.pagePosition.x : this.dimensions.viewport.width/2+this.pagePosition.x;
828
+
829
+ // So if a theme has say shadowed edges, they should be consistant and take care of in the contentOffset
830
+ $('lightwindow').setStyle({
831
+ top: offsetHeight+'px',
832
+ left: offsetWidth+'px'
833
+ });
834
+
835
+ $('lightwindow_container').setStyle({
836
+ height: originalHeight+'px',
837
+ width: originalWidth+'px',
838
+ left: -(originalWidth/2)+'px',
839
+ top: -(originalHeight/2)+'px'
840
+ });
841
+
842
+ $('lightwindow_contents').setStyle({
843
+ height: originalHeight+'px',
844
+ width: originalWidth+'px'
845
+ });
846
+ },
847
+ //
848
+ // Get the type of file.
849
+ //
850
+ _fileType : function(url) {
851
+ var image = new RegExp("[^\.]\.("+this.options.fileTypes.image.join('|')+")\s*$", "i");
852
+ if (image.test(url)) return 'image';
853
+ if (url.indexOf('#') > -1 && (document.domain == this._getDomain(url))) return 'inline';
854
+ if (url.indexOf('?') > -1) url = url.substring(0, url.indexOf('?'));
855
+ var type = 'unknown';
856
+ var page = new RegExp("[^\.]\.("+this.options.fileTypes.page.join('|')+")\s*$", "i");
857
+ var media = new RegExp("[^\.]\.("+this.options.fileTypes.media.join('|')+")\s*$", "i");
858
+ if (document.domain != this._getDomain(url)) type = 'external';
859
+ if (media.test(url)) type = 'media';
860
+ if (type == 'external' || type == 'media') return type;
861
+ if (page.test(url) || url.substr((url.length-1), url.length) == '/') type = 'page';
862
+ return type;
863
+ },
864
+ //
865
+ // Get file Extension
866
+ //
867
+ _fileExtension : function(url) {
868
+ if (url.indexOf('?') > -1) {
869
+ url = url.substring(0, url.indexOf('?'));
870
+ }
871
+ var extenstion = '';
872
+ for (var x = (url.length-1); x > -1; x--) {
873
+ if (url.charAt(x) == '.') {
874
+ return extenstion;
875
+ }
876
+ extenstion = url.charAt(x)+extenstion;
877
+ }
878
+ },
879
+ //
880
+ // Monitor the keyboard while this lightwindow is up
881
+ //
882
+ _monitorKeyboard : function(status) {
883
+ if (status) document.onkeydown = this._eventKeypress.bind(this);
884
+ else document.onkeydown = '';
885
+ },
886
+ //
887
+ // Perform keyboard actions
888
+ //
889
+ _eventKeypress : function(e) {
890
+ if (e == null) {
891
+ var keycode = event.keyCode;
892
+ } else {
893
+ var keycode = e.which;
894
+ }
895
+
896
+ switch (keycode) {
897
+ case 27:
898
+ this.deactivate();
899
+ break;
900
+
901
+ case 13:
902
+ return;
903
+
904
+ default:
905
+ break;
906
+ }
907
+
908
+ // Gotta stop those quick fingers
909
+ if (this.animating) {
910
+ return false;
911
+ }
912
+
913
+ switch (String.fromCharCode(keycode).toLowerCase()) {
914
+ case 'p':
915
+ if (this.navigationObservers.previous) {
916
+ this.navigateWindow('previous');
917
+ }
918
+ break;
919
+
920
+ case 'n':
921
+ if (this.navigationObservers.next) {
922
+ this.navigateWindow('next');
923
+ }
924
+ break;
925
+
926
+ default:
927
+ break;
928
+ }
929
+ },
930
+ //
931
+ // Get Gallery Information
932
+ //
933
+ _getGalleryInfo : function(rel) {
934
+ if (!rel) return false;
935
+ if (rel.indexOf('[') > -1) {
936
+ return new Array(escape(rel.substring(0, rel.indexOf('['))), escape(rel.substring(rel.indexOf('[')+1, rel.indexOf(']'))));
937
+ } else {
938
+ return false;
939
+ }
940
+ },
941
+ //
942
+ // Get the domain from a string.
943
+ //
944
+ _getDomain : function(url) {
945
+ var leadSlashes = url.indexOf('//');
946
+ var domainStart = leadSlashes+2;
947
+ var withoutResource = url.substring(domainStart, url.length);
948
+ var nextSlash = withoutResource.indexOf('/');
949
+ var domain = withoutResource.substring(0, nextSlash);
950
+ if (domain.indexOf(':') > -1){
951
+ var portColon = domain.indexOf(':');
952
+ domain = domain.substring(0, portColon);
953
+ }
954
+ return domain;
955
+ },
956
+ //
957
+ // Get the value from the params attribute string.
958
+ //
959
+ _getParameter : function(parameter, parameters) {
960
+ if (!this.element) return false;
961
+ if (parameter == 'lightwindow_top' && this.element.top) {
962
+ return unescape(this.element.top);
963
+ } else if (parameter == 'lightwindow_left' && this.element.left) {
964
+ return unescape(this.element.left);
965
+ } else if (parameter == 'lightwindow_type' && this.element.type) {
966
+ return unescape(this.element.type);
967
+ } else if (parameter == 'lightwindow_show_images' && this.element.showImages) {
968
+ return unescape(this.element.showImages);
969
+ } else if (parameter == 'lightwindow_height' && this.element.height) {
970
+ return unescape(this.element.height);
971
+ } else if (parameter == 'lightwindow_width' && this.element.width) {
972
+ return unescape(this.element.width);
973
+ } else if (parameter == 'lightwindow_loading_animation' && this.element.loadingAnimation) {
974
+ return unescape(this.element.loadingAnimation);
975
+ } else if (parameter == 'lightwindow_iframe_embed' && this.element.iframeEmbed) {
976
+ return unescape(this.element.iframeEmbed);
977
+ } else if (parameter == 'lightwindow_form' && this.element.form) {
978
+ return unescape(this.element.form);
979
+ } else {
980
+ if (!parameters) {
981
+ if (this.element.params) parameters = this.element.params;
982
+ else return;
983
+ }
984
+ var value;
985
+ var parameterArray = parameters.split(',');
986
+ var compareString = parameter+'=';
987
+ var compareLength = compareString.length;
988
+ for (var i = 0; i < parameterArray.length; i++) {
989
+ if (parameterArray[i].substr(0, compareLength) == compareString) {
990
+ var currentParameter = parameterArray[i].split('=');
991
+ value = currentParameter[1];
992
+ break;
993
+ }
994
+ }
995
+ if (!value) return false;
996
+ else return unescape(value);
997
+ }
998
+ },
999
+ //
1000
+ // Get the Browser Viewport Dimensions
1001
+ //
1002
+ _browserDimensions : function() {
1003
+ if (Prototype.Browser.IE) {
1004
+ this.dimensions.viewport.height = document.documentElement.clientHeight;
1005
+ this.dimensions.viewport.width = document.documentElement.clientWidth;
1006
+ } else {
1007
+ this.dimensions.viewport.height = window.innerHeight;
1008
+ this.dimensions.viewport.width = document.width || document.body.offsetWidth;
1009
+ }
1010
+ },
1011
+ //
1012
+ // Get the scrollbar offset, I don't like this method but there is really no other way I can find.
1013
+ //
1014
+ _getScrollerWidth : function() {
1015
+ var scrollDiv = Element.extend(document.createElement('div'));
1016
+ scrollDiv.setAttribute('id', 'lightwindow_scroll_div');
1017
+ scrollDiv.setStyle({
1018
+ position: 'absolute',
1019
+ top: '-10000px',
1020
+ left: '-10000px',
1021
+ width: '100px',
1022
+ height: '100px',
1023
+ overflow: 'hidden'
1024
+ });
1025
+
1026
+
1027
+
1028
+ var contentDiv = Element.extend(document.createElement('div'));
1029
+ contentDiv.setAttribute('id', 'lightwindow_content_scroll_div');
1030
+ contentDiv.setStyle({
1031
+ width: '100%',
1032
+ height: '200px'
1033
+ });
1034
+
1035
+ scrollDiv.appendChild(contentDiv);
1036
+
1037
+ var body = document.getElementsByTagName('body')[0];
1038
+ body.appendChild(scrollDiv);
1039
+
1040
+ var noScroll = $('lightwindow_content_scroll_div').offsetWidth;
1041
+ scrollDiv.style.overflow = 'auto';
1042
+ var withScroll = $('lightwindow_content_scroll_div').offsetWidth;
1043
+
1044
+ Element.remove($('lightwindow_scroll_div'));
1045
+
1046
+ this.scrollbarOffset = noScroll-withScroll;
1047
+ },
1048
+
1049
+
1050
+ //
1051
+ // Add a param to an object dynamically created
1052
+ //
1053
+ _addParamToObject : function(name, value, object, id) {
1054
+ var param = document.createElement('param');
1055
+ param.setAttribute('value', value);
1056
+ param.setAttribute('name', name);
1057
+ if (id) {
1058
+ param.setAttribute('id', id);
1059
+ }
1060
+ object.appendChild(param);
1061
+ return object;
1062
+ },
1063
+ //
1064
+ // Get the outer HTML of an object CROSS BROWSER
1065
+ //
1066
+ _outerHTML : function(object) {
1067
+ if (Prototype.Browser.IE) {
1068
+ return object.outerHTML;
1069
+ } else {
1070
+ var clone = object.cloneNode(true);
1071
+ var cloneDiv = document.createElement('div');
1072
+ cloneDiv.appendChild(clone);
1073
+ return cloneDiv.innerHTML;
1074
+ }
1075
+ },
1076
+ //
1077
+ // Convert an object to markup
1078
+ //
1079
+ _convertToMarkup : function(object, closeTag) {
1080
+ var markup = this._outerHTML(object).replace('</'+closeTag+'>', '');
1081
+ if (Prototype.Browser.IE) {
1082
+ for (var i = 0; i < object.childNodes.length; i++){
1083
+ markup += this._outerHTML(object.childNodes[i]);
1084
+ }
1085
+ markup += '</'+closeTag+'>';
1086
+ }
1087
+ return markup;
1088
+ },
1089
+ //
1090
+ // Depending what type of browser it is we have to append the object differently... DAMN YOU IE!!
1091
+ //
1092
+ _appendObject : function(object, closeTag, appendTo) {
1093
+ if (Prototype.Browser.IE) {
1094
+ appendTo.innerHTML += this._convertToMarkup(object, closeTag);
1095
+
1096
+ // Fix the Eolas activate thing but only for specified media, for example doing this to a quicktime film breaks it.
1097
+ if (this.options.EOLASFix.indexOf(this._fileType(this.element.href)) > -1) {
1098
+ var objectElements = document.getElementsByTagName('object');
1099
+ for (var i = 0; i < objectElements.length; i++) {
1100
+ if (objectElements[i].getAttribute("data")) objectElements[i].removeAttribute('data');
1101
+ objectElements[i].outerHTML = objectElements[i].outerHTML;
1102
+ objectElements[i].style.visibility = "visible";
1103
+ }
1104
+ }
1105
+ } else {
1106
+ appendTo.appendChild(object);
1107
+ }
1108
+ },
1109
+ //
1110
+ // Add in iframe
1111
+ //
1112
+ _appendIframe : function(scroll) {
1113
+ var iframe = document.createElement('iframe');
1114
+ iframe.setAttribute('id', 'lightwindow_iframe');
1115
+ iframe.setAttribute('name', 'lightwindow_iframe');
1116
+ iframe.setAttribute('src', 'about:blank');
1117
+ iframe.setAttribute('height', '100%');
1118
+ iframe.setAttribute('width', '100%');
1119
+ iframe.setAttribute('frameborder', '0');
1120
+ iframe.setAttribute('marginwidth', '0');
1121
+ iframe.setAttribute('marginheight', '0');
1122
+ iframe.setAttribute('scrolling', scroll);
1123
+
1124
+ this._appendObject(iframe, 'iframe', $('lightwindow_contents'));
1125
+ },
1126
+ //
1127
+ // Write Content to the iframe using the skin
1128
+ //
1129
+ _writeToIframe : function(content) {
1130
+ var template = this.options.skin.iframe;
1131
+ template = template.replace('{body_replace}', content);
1132
+ if ($('lightwindow_iframe').contentWindow){
1133
+ $('lightwindow_iframe').contentWindow.document.open();
1134
+ $('lightwindow_iframe').contentWindow.document.write(template);
1135
+ $('lightwindow_iframe').contentWindow.document.close();
1136
+ } else {
1137
+ $('lightwindow_iframe').contentDocument.open();
1138
+ $('lightwindow_iframe').contentDocument.write(template);
1139
+ $('lightwindow_iframe').contentDocument.close();
1140
+ }
1141
+ },
1142
+ //
1143
+ // Load the window Information
1144
+ //
1145
+ _loadWindow : function() {
1146
+ switch (this.windowType) {
1147
+ case 'image' :
1148
+
1149
+ var current = 0;
1150
+ var images = [];
1151
+ this.checkImage = [];
1152
+ this.resizeTo.height = this.resizeTo.width = 0;
1153
+ this.imageCount = this._getParameter('lightwindow_show_images') ? parseInt(this._getParameter('lightwindow_show_images')) : 1;
1154
+
1155
+ // If there is a gallery get it
1156
+ if (gallery = this._getGalleryInfo(this.element.rel)) {
1157
+ for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
1158
+ if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
1159
+ break;
1160
+ }
1161
+ }
1162
+ if (this.galleries[gallery[0]][gallery[1]][current-this.imageCount]) {
1163
+ this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current-this.imageCount];
1164
+ } else {
1165
+ this.navigationObservers.previous = false;
1166
+ }
1167
+ if (this.galleries[gallery[0]][gallery[1]][current+this.imageCount]) {
1168
+ this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current+this.imageCount];
1169
+ } else {
1170
+ this.navigationObservers.next = false;
1171
+ }
1172
+
1173
+ this.activeGallery = true;
1174
+ } else {
1175
+ this.navigationObservers.previous = false;
1176
+ this.navigationObservers.next = false;
1177
+
1178
+ this.activeGallery = false;
1179
+ }
1180
+
1181
+ for (var i = current; i < (current+this.imageCount); i++) {
1182
+
1183
+ if (gallery && this.galleries[gallery[0]][gallery[1]][i]) {
1184
+ this.contentToFetch = this.galleries[gallery[0]][gallery[1]][i].href;
1185
+
1186
+ this.galleryLocation = {current: (i+1)/this.imageCount, total: (this.galleries[gallery[0]][gallery[1]].length)/this.imageCount};
1187
+
1188
+ if (!this.galleries[gallery[0]][gallery[1]][i+this.imageCount]) {
1189
+ $('lightwindow_next').setStyle({
1190
+ display: 'none'
1191
+ });
1192
+ } else {
1193
+ $('lightwindow_next').setStyle({
1194
+ display: 'block'
1195
+ });
1196
+ $('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i+this.imageCount].title;
1197
+ }
1198
+
1199
+ if (!this.galleries[gallery[0]][gallery[1]][i-this.imageCount]) {
1200
+ $('lightwindow_previous').setStyle({
1201
+ display: 'none'
1202
+ });
1203
+ } else {
1204
+ $('lightwindow_previous').setStyle({
1205
+ display: 'block'
1206
+ });
1207
+ $('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][i-this.imageCount].title;
1208
+ }
1209
+ }
1210
+
1211
+ images[i] = document.createElement('img');
1212
+ images[i].setAttribute('id', 'lightwindow_image_'+i);
1213
+ images[i].setAttribute('border', '0');
1214
+ images[i].setAttribute('src', this.contentToFetch);
1215
+ $('lightwindow_contents').appendChild(images[i]);
1216
+
1217
+ // We have to do this instead of .onload
1218
+ this.checkImage[i] = new PeriodicalExecuter(function(i) {
1219
+ if (!(typeof $('lightwindow_image_'+i).naturalWidth != "undefined" && $('lightwindow_image_'+i).naturalWidth == 0)) {
1220
+
1221
+ this.checkImage[i].stop();
1222
+
1223
+ var imageHeight = $('lightwindow_image_'+i).getHeight();
1224
+ if (imageHeight > this.resizeTo.height) {
1225
+ this.resizeTo.height = imageHeight;
1226
+ }
1227
+ this.resizeTo.width += $('lightwindow_image_'+i).getWidth();
1228
+ this.imageCount--;
1229
+
1230
+ $('lightwindow_image_'+i).setStyle({
1231
+ height: '100%'
1232
+ });
1233
+
1234
+ if (this.imageCount == 0) {
1235
+ this._processWindow();
1236
+ }
1237
+ }
1238
+
1239
+ }.bind(this, i), 1);
1240
+ }
1241
+
1242
+
1243
+ break;
1244
+
1245
+ case 'media' :
1246
+
1247
+ var current = 0;
1248
+ this.resizeTo.height = this.resizeTo.width = 0;
1249
+
1250
+ // If there is a gallery get it
1251
+ if (gallery = this._getGalleryInfo(this.element.rel)) {
1252
+ for (current = 0; current < this.galleries[gallery[0]][gallery[1]].length; current++) {
1253
+ if (this.contentToFetch.indexOf(this.galleries[gallery[0]][gallery[1]][current].href) > -1) {
1254
+ break;
1255
+ }
1256
+ }
1257
+
1258
+ if (this.galleries[gallery[0]][gallery[1]][current-1]) {
1259
+ this.navigationObservers.previous = this.galleries[gallery[0]][gallery[1]][current-1];
1260
+ } else {
1261
+ this.navigationObservers.previous = false;
1262
+ }
1263
+ if (this.galleries[gallery[0]][gallery[1]][current+1]) {
1264
+ this.navigationObservers.next = this.galleries[gallery[0]][gallery[1]][current+1];
1265
+ } else {
1266
+ this.navigationObservers.next = false;
1267
+ }
1268
+
1269
+ this.activeGallery = true;
1270
+ } else {
1271
+ this.navigationObservers.previous = false;
1272
+ this.navigationObservers.next = false;
1273
+
1274
+ this.activeGallery = false;
1275
+ }
1276
+
1277
+
1278
+ if (gallery && this.galleries[gallery[0]][gallery[1]][current]) {
1279
+ this.contentToFetch = this.galleries[gallery[0]][gallery[1]][current].href;
1280
+
1281
+ this.galleryLocation = {current: current+1, total: this.galleries[gallery[0]][gallery[1]].length};
1282
+
1283
+ if (!this.galleries[gallery[0]][gallery[1]][current+1]) {
1284
+ $('lightwindow_next').setStyle({
1285
+ display: 'none'
1286
+ });
1287
+ } else {
1288
+ $('lightwindow_next').setStyle({
1289
+ display: 'block'
1290
+ });
1291
+ $('lightwindow_next_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current+1].title;
1292
+ }
1293
+
1294
+ if (!this.galleries[gallery[0]][gallery[1]][current-1]) {
1295
+ $('lightwindow_previous').setStyle({
1296
+ display: 'none'
1297
+ });
1298
+ } else {
1299
+ $('lightwindow_previous').setStyle({
1300
+ display: 'block'
1301
+ });
1302
+ $('lightwindow_previous_title').innerHTML = this.galleries[gallery[0]][gallery[1]][current-1].title;
1303
+ }
1304
+ }
1305
+
1306
+ if (this._getParameter('lightwindow_iframe_embed')) {
1307
+ this.resizeTo.height = this.dimensions.viewport.height;
1308
+ this.resizeTo.width = this.dimensions.viewport.width;
1309
+ } else {
1310
+ this.resizeTo.height = this._getParameter('lightwindow_height');
1311
+ this.resizeTo.width = this._getParameter('lightwindow_width');
1312
+ }
1313
+
1314
+ this._processWindow();
1315
+
1316
+ break;
1317
+
1318
+ case 'external' :
1319
+
1320
+ this._appendIframe('auto');
1321
+
1322
+ this.resizeTo.height = this.dimensions.viewport.height;
1323
+ this.resizeTo.width = this.dimensions.viewport.width;
1324
+
1325
+ this._processWindow();
1326
+
1327
+ break;
1328
+
1329
+ case 'page' :
1330
+
1331
+ var newAJAX = new Ajax.Request(
1332
+ this.contentToFetch, {
1333
+ method: 'get',
1334
+ parameters: '',
1335
+ onComplete: function(response) {
1336
+ $('lightwindow_contents').innerHTML += response.responseText;
1337
+ this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
1338
+ this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
1339
+ this._processWindow();
1340
+ }.bind(this)
1341
+ }
1342
+ );
1343
+
1344
+ break;
1345
+
1346
+ case 'inline' :
1347
+
1348
+ var content = this.contentToFetch;
1349
+ if (content.indexOf('?') > -1) {
1350
+ content = content.substring(0, content.indexOf('?'));
1351
+ }
1352
+ content = content.substring(content.indexOf('#')+1);
1353
+
1354
+ new Insertion.Top($('lightwindow_contents'), $(content).innerHTML);
1355
+
1356
+ this.resizeTo.height = $('lightwindow_contents').scrollHeight+(this.options.contentOffset.height);
1357
+ this.resizeTo.width = $('lightwindow_contents').scrollWidth+(this.options.contentOffset.width);
1358
+
1359
+ this._toggleTroubleElements('hidden', true);
1360
+ this._processWindow();
1361
+
1362
+ break;
1363
+
1364
+ default :
1365
+ throw("Page Type could not be determined, please amend this lightwindow URL "+this.contentToFetch);
1366
+ break;
1367
+ }
1368
+ },
1369
+ //
1370
+ // Resize the Window to fit the viewport if necessary
1371
+ //
1372
+ _resizeWindowToFit : function() {
1373
+ if (this.resizeTo.height+this.dimensions.cruft.height > this.dimensions.viewport.height) {
1374
+ var heightRatio = this.resizeTo.height/this.resizeTo.width;
1375
+ this.resizeTo.height = this.dimensions.viewport.height-this.dimensions.cruft.height-(2*this.options.viewportPadding);
1376
+ // We only care about ratio's with this window type
1377
+ if (this.windowType == 'image' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
1378
+ this.resizeTo.width = this.resizeTo.height/heightRatio;
1379
+ $('lightwindow_data_slide_inner').setStyle({
1380
+ width: this.resizeTo.width+'px'
1381
+ });
1382
+ }
1383
+ }
1384
+ if (this.resizeTo.width+this.dimensions.cruft.width > this.dimensions.viewport.width) {
1385
+ var widthRatio = this.resizeTo.width/this.resizeTo.height;
1386
+ this.resizeTo.width = this.dimensions.viewport.width-2*this.dimensions.cruft.width-(2*this.options.viewportPadding);
1387
+ // We only care about ratio's with this window type
1388
+ if (this.windowType == 'image' || (this.windowType == 'media' && !this._getParameter('lightwindow_iframe_embed'))) {
1389
+ this.resizeTo.height = this.resizeTo.width/widthRatio;
1390
+ $('lightwindow_data_slide_inner').setStyle({
1391
+ height: this.resizeTo.height+'px'
1392
+ });
1393
+ }
1394
+ }
1395
+
1396
+ },
1397
+ //
1398
+ // Set the Window to a preset size
1399
+ //
1400
+ _presetWindowSize : function() {
1401
+ if (this._getParameter('lightwindow_height')) {
1402
+ this.resizeTo.height = parseFloat(this._getParameter('lightwindow_height'));
1403
+ }
1404
+ if (this._getParameter('lightwindow_width')) {
1405
+ this.resizeTo.width = parseFloat(this._getParameter('lightwindow_width'));
1406
+ }
1407
+ },
1408
+ //
1409
+ // Process the Window
1410
+ //
1411
+ _processWindow : function() {
1412
+ // Clean out our effects
1413
+ this.dimensions.dataEffects = [];
1414
+
1415
+ // Set up the data-slide if we have caption information
1416
+ if (this.element.caption || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
1417
+ if (this.element.caption) {
1418
+ $('lightwindow_data_caption').innerHTML = this.element.caption;
1419
+ $('lightwindow_data_caption').setStyle({
1420
+ display: 'block'
1421
+ });
1422
+ } else {
1423
+ $('lightwindow_data_caption').setStyle({
1424
+ display: 'none'
1425
+ });
1426
+ }
1427
+ if (this.element.author) {
1428
+ $('lightwindow_data_author').innerHTML = this.element.author;
1429
+ $('lightwindow_data_author_container').setStyle({
1430
+ display: 'block'
1431
+ });
1432
+ } else {
1433
+ $('lightwindow_data_author_container').setStyle({
1434
+ display: 'none'
1435
+ });
1436
+ }
1437
+ if (this.activeGallery && this.options.showGalleryCount) {
1438
+ $('lightwindow_data_gallery_current').innerHTML = this.galleryLocation.current;
1439
+ $('lightwindow_data_gallery_total').innerHTML = this.galleryLocation.total;
1440
+ $('lightwindow_data_gallery_container').setStyle({
1441
+ display: 'block'
1442
+ });
1443
+ } else {
1444
+ $('lightwindow_data_gallery_container').setStyle({
1445
+ display: 'none'
1446
+ });
1447
+ }
1448
+
1449
+ $('lightwindow_data_slide_inner').setStyle({
1450
+ width: this.resizeTo.width+'px',
1451
+ height: 'auto',
1452
+ visibility: 'visible',
1453
+ display: 'block'
1454
+ });
1455
+ $('lightwindow_data_slide').setStyle({
1456
+ height: $('lightwindow_data_slide').getHeight()+'px',
1457
+ width: '1px',
1458
+ overflow: 'hidden',
1459
+ display: 'block'
1460
+ });
1461
+ } else {
1462
+ $('lightwindow_data_slide').setStyle({
1463
+ display: 'none',
1464
+ width: 'auto'
1465
+ });
1466
+ $('lightwindow_data_slide_inner').setStyle({
1467
+ display: 'none',
1468
+ visibility: 'hidden',
1469
+ width: this.resizeTo.width+'px',
1470
+ height: '0px'
1471
+ });
1472
+ }
1473
+
1474
+ if (this.element.title != 'null') {
1475
+ $('lightwindow_title_bar_title').innerHTML = this.element.title;
1476
+ } else {
1477
+ $('lightwindow_title_bar_title').innerHTML = '';
1478
+ }
1479
+
1480
+ var originalContainerDimensions = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
1481
+ // Position the window
1482
+ $('lightwindow_container').setStyle({
1483
+ height: 'auto',
1484
+ // We need to set the width to a px not auto as opera has problems with it
1485
+ width: $('lightwindow_container').getWidth()+this.options.contentOffset.width-(this.windowActive ? this.options.contentOffset.width : 0)+'px'
1486
+ });
1487
+ var newContainerDimensions = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
1488
+
1489
+ // We need to record the container dimension changes
1490
+ this.containerChange = {height: originalContainerDimensions.height-newContainerDimensions.height, width: originalContainerDimensions.width-newContainerDimensions.width};
1491
+
1492
+ // Get out general dimensions
1493
+ this.dimensions.container = {height: $('lightwindow_container').getHeight(), width: $('lightwindow_container').getWidth()};
1494
+ this.dimensions.cruft = {height: this.dimensions.container.height-$('lightwindow_contents').getHeight()+this.options.contentOffset.height, width: this.dimensions.container.width-$('lightwindow_contents').getWidth()+this.options.contentOffset.width};
1495
+
1496
+ // Set Sizes if we need too
1497
+ this._presetWindowSize();
1498
+ this._resizeWindowToFit(); // Even if the window is preset we still don't want it to go outside of the viewport
1499
+
1500
+ if (!this.windowActive) {
1501
+ // Position the window
1502
+ $('lightwindow_container').setStyle({
1503
+ left: -(this.dimensions.container.width/2)+'px',
1504
+ top: -(this.dimensions.container.height/2)+'px'
1505
+ });
1506
+ }
1507
+ $('lightwindow_container').setStyle({
1508
+ height: this.dimensions.container.height+'px',
1509
+ width: this.dimensions.container.width+'px'
1510
+ });
1511
+
1512
+ // We are ready, lets show this puppy off!
1513
+ this._displayLightWindow('block', 'visible');
1514
+ this._animateLightWindow();
1515
+ },
1516
+ //
1517
+ // Fire off our animation handler
1518
+ //
1519
+ _animateLightWindow : function() {
1520
+ if (this.options.animationHandler) {
1521
+ this.options.animationHandler().bind(this);
1522
+ } else {
1523
+ this._defaultAnimationHandler();
1524
+ }
1525
+ },
1526
+ //
1527
+ // Fire off our transition handler
1528
+ //
1529
+ _handleNavigation : function(display) {
1530
+ if (this.options.navigationHandler) {
1531
+ this.options.navigationHandler().bind(this, display);
1532
+ } else {
1533
+ this._defaultDisplayNavigation(display);
1534
+ }
1535
+ },
1536
+ //
1537
+ // Fire off our transition handler
1538
+ //
1539
+ _handleTransition : function() {
1540
+ if (this.options.transitionHandler) {
1541
+ this.options.transitionHandler().bind(this);
1542
+ } else {
1543
+ this._defaultTransitionHandler();
1544
+ }
1545
+ },
1546
+ //
1547
+ // Handle the finish of the window animation
1548
+ //
1549
+ _handleFinalWindowAnimation : function(delay) {
1550
+ if (this.options.finalAnimationHandler) {
1551
+ this.options.finalAnimationHandler().bind(this, delay);
1552
+ } else {
1553
+ this._defaultfinalWindowAnimationHandler(delay);
1554
+ }
1555
+ },
1556
+ //
1557
+ // Handle the gallery Animation
1558
+ //
1559
+ _handleGalleryAnimation : function(list) {
1560
+ if (this.options.galleryAnimationHandler) {
1561
+ this.options.galleryAnimationHandler().bind(this, list);
1562
+ } else {
1563
+ this._defaultGalleryAnimationHandler(list);
1564
+ }
1565
+ },
1566
+ //
1567
+ // Display the navigation
1568
+ //
1569
+ _defaultDisplayNavigation : function(display) {
1570
+ if (display) {
1571
+ $('lightwindow_navigation').setStyle({
1572
+ display: 'block',
1573
+ height: $('lightwindow_contents').getHeight()+'px',
1574
+ width: '100%',
1575
+ marginTop: this.options.dimensions.titleHeight+'px'
1576
+ });
1577
+ } else {
1578
+ $('lightwindow_navigation').setStyle({
1579
+ display: 'none',
1580
+ height: 'auto',
1581
+ width: 'auto'
1582
+ });
1583
+ }
1584
+ },
1585
+ //
1586
+ // This is the default animation handler for LightWindow
1587
+ //
1588
+ _defaultAnimationHandler : function() {
1589
+ // Now that we have figures out the cruft lets make the caption go away and add its effects
1590
+ if (this.element.caption || this.element.author || (this.activeGallery && this.options.showGalleryCount)) {
1591
+ $('lightwindow_data_slide').setStyle({
1592
+ display: 'none',
1593
+ width: 'auto'
1594
+ });
1595
+ this.dimensions.dataEffects.push(
1596
+ new Effect.SlideDown('lightwindow_data_slide', {sync: true}),
1597
+ new Effect.Appear('lightwindow_data_slide', {sync: true, from: 0.0, to: 1.0})
1598
+ );
1599
+ }
1600
+
1601
+ // Set up the Title if we have one
1602
+ $('lightwindow_title_bar_inner').setStyle({
1603
+ height: '0px',
1604
+ marginTop: this.options.dimensions.titleHeight+'px'
1605
+ });
1606
+
1607
+ // We always want the title bar as well
1608
+ this.dimensions.dataEffects.push(
1609
+ new Effect.Morph('lightwindow_title_bar_inner', {sync: true, style: {height: this.options.dimensions.titleHeight+'px', marginTop: '0px'}}),
1610
+ new Effect.Appear('lightwindow_title_bar_inner', {sync: true, from: 0.0, to: 1.0})
1611
+ );
1612
+
1613
+ if (!this.options.hideGalleryTab) {
1614
+ this._handleGalleryAnimation(false);
1615
+ if ($('lightwindow_galleries_tab_container').getHeight() == 0) {
1616
+ this.dimensions.dataEffects.push(
1617
+ new Effect.Morph('lightwindow_galleries_tab_container', {sync: true, style: {height: '20px', marginTop: '0px'}})
1618
+ );
1619
+ $('lightwindow_galleries').setStyle({
1620
+ width: '0px'
1621
+ });
1622
+ }
1623
+ }
1624
+
1625
+ var resized = false;
1626
+ var ratio = this.dimensions.container.width-$('lightwindow_contents').getWidth()+this.resizeTo.width+this.options.contentOffset.width;
1627
+ if (ratio != $('lightwindow_container').getWidth()) {
1628
+ new Effect.Parallel([
1629
+ new Effect.Scale('lightwindow_contents', 100*(this.resizeTo.width/$('lightwindow_contents').getWidth()), {scaleFrom: 100*($('lightwindow_contents').getWidth()/($('lightwindow_contents').getWidth()+(this.options.contentOffset.width))), sync: true, scaleY: false, scaleContent: false}),
1630
+ new Effect.Scale('lightwindow_container', 100*(ratio/(this.dimensions.container.width)), {sync: true, scaleY: false, scaleFromCenter: true, scaleContent: false})
1631
+ ], {
1632
+ duration: this.duration,
1633
+ delay: 0.25,
1634
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1635
+ }
1636
+ );
1637
+ }
1638
+
1639
+ ratio = this.dimensions.container.height-$('lightwindow_contents').getHeight()+this.resizeTo.height+this.options.contentOffset.height;
1640
+ if (ratio != $('lightwindow_container').getHeight()) {
1641
+ new Effect.Parallel([
1642
+ new Effect.Scale('lightwindow_contents', 100*(this.resizeTo.height/$('lightwindow_contents').getHeight()), {scaleFrom: 100*($('lightwindow_contents').getHeight()/($('lightwindow_contents').getHeight()+(this.options.contentOffset.height))), sync: true, scaleX: false, scaleContent: false}),
1643
+ new Effect.Scale('lightwindow_container', 100*(ratio/(this.dimensions.container.height)), {sync: true, scaleX: false, scaleFromCenter: true, scaleContent: false})
1644
+ ], {
1645
+ duration: this.duration,
1646
+ afterFinish: function() {
1647
+ if (this.dimensions.dataEffects.length > 0) {
1648
+ if (!this.options.hideGalleryTab) {
1649
+ $('lightwindow_galleries').setStyle({
1650
+ width: this.resizeTo.width+'px'
1651
+ });
1652
+ }
1653
+ new Effect.Parallel(this.dimensions.dataEffects, {
1654
+ duration: this.duration,
1655
+ afterFinish: function() {
1656
+ this._finishWindow();
1657
+ }.bind(this),
1658
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1659
+ }
1660
+ );
1661
+ }
1662
+ }.bind(this),
1663
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1664
+ }
1665
+ );
1666
+ resized = true;
1667
+ }
1668
+
1669
+ // We need to do our data effect since there was no resizing
1670
+ if (!resized && this.dimensions.dataEffects.length > 0) {
1671
+ new Effect.Parallel(this.dimensions.dataEffects, {
1672
+ duration: this.duration,
1673
+ beforeStart: function() {
1674
+ if (!this.options.hideGalleryTab) {
1675
+ $('lightwindow_galleries').setStyle({
1676
+ width: this.resizeTo.width+'px'
1677
+ });
1678
+ }
1679
+ if (this.containerChange.height != 0 || this.containerChange.width != 0) {
1680
+ new Effect.MoveBy('lightwindow_container', this.containerChange.height, this.containerChange.width, {transition: Effect.Transitions.sinoidal});
1681
+ }
1682
+ }.bind(this),
1683
+ afterFinish: function() {
1684
+ this._finishWindow();
1685
+ }.bind(this),
1686
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1687
+ }
1688
+ );
1689
+ }
1690
+
1691
+ },
1692
+ //
1693
+ // Finish up Window Animation
1694
+ //
1695
+ _defaultfinalWindowAnimationHandler : function(delay) {
1696
+ if (this.windowType == 'media' || this._getParameter('lightwindow_loading_animation')) {
1697
+ // Because of major flickering with the overlay we just hide it in this case
1698
+ Element.hide('lightwindow_loading');
1699
+ this._handleNavigation(this.activeGallery);
1700
+ this._setStatus(false);
1701
+ } else {
1702
+ Effect.Fade('lightwindow_loading', {
1703
+ duration: 0.75,
1704
+ delay: 1.0,
1705
+ afterFinish: function() {
1706
+ // Just in case we need some scroll goodness (this also avoids the swiss cheese effect)
1707
+ if (this.windowType != 'image' && this.windowType != 'media' && this.windowType != 'external') {
1708
+ $('lightwindow_contents').setStyle({
1709
+ overflow: 'auto'
1710
+ });
1711
+ }
1712
+ this._handleNavigation(this.activeGallery);
1713
+ this._defaultGalleryAnimationHandler();
1714
+ this._setStatus(false);
1715
+ }.bind(this),
1716
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1717
+ });
1718
+ }
1719
+ },
1720
+ //
1721
+ // Handle the gallery Animation
1722
+ //
1723
+ _defaultGalleryAnimationHandler : function(list) {
1724
+ if (this.activeGallery) {
1725
+ $('lightwindow_galleries').setStyle({
1726
+ display: 'block',
1727
+ marginBottom: $('lightwindow_data_slide').getHeight()+this.options.contentOffset.height/2+'px'
1728
+ });
1729
+ $('lightwindow_navigation').setStyle({
1730
+ height: $('lightwindow_contents').getHeight()-20+'px'
1731
+ });
1732
+ } else {
1733
+ $('lightwindow_galleries').setStyle({
1734
+ display: 'none'
1735
+ });
1736
+ $('lightwindow_galleries_tab_container').setStyle({
1737
+ height: '0px',
1738
+ marginTop: '20px'
1739
+ });
1740
+ $('lightwindow_galleries_list').setStyle({
1741
+ height: '0px'
1742
+ });
1743
+ return false;
1744
+ }
1745
+
1746
+ if (list) {
1747
+ if ($('lightwindow_galleries_list').getHeight() == 0) {
1748
+ var height = $('lightwindow_contents').getHeight()*0.80;
1749
+ $('lightwindow_galleries_tab_span').className = 'down';
1750
+ } else {
1751
+ var height = 0;
1752
+ $('lightwindow_galleries_tab_span').className = 'up';
1753
+ }
1754
+
1755
+ new Effect.Morph('lightwindow_galleries_list', {
1756
+ duration: this.duration,
1757
+ transition: Effect.Transitions.sinoidal,
1758
+ style: {height: height+'px'},
1759
+ beforeStart: function() {
1760
+ $('lightwindow_galleries_list').setStyle({
1761
+ overflow: 'hidden'
1762
+ });
1763
+ },
1764
+ afterFinish: function() {
1765
+ $('lightwindow_galleries_list').setStyle({
1766
+ overflow: 'auto'
1767
+ });
1768
+ },
1769
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1770
+ });
1771
+ }
1772
+
1773
+
1774
+ },
1775
+ //
1776
+ // Default Transition Handler
1777
+ //
1778
+ _defaultTransitionHandler : function() {
1779
+ // Clean out our effects
1780
+ this.dimensions.dataEffects = [];
1781
+
1782
+ // Now that we have figures out the cruft lets make the caption go away and add its effects
1783
+ if ($('lightwindow_data_slide').getStyle('display') != 'none') {
1784
+ this.dimensions.dataEffects.push(
1785
+ new Effect.SlideUp('lightwindow_data_slide', {sync: true}),
1786
+ new Effect.Fade('lightwindow_data_slide', {sync: true, from: 1.0, to: 0.0})
1787
+ );
1788
+ }
1789
+
1790
+ if (!this.options.hideGalleryTab) {
1791
+ if ($('lightwindow_galleries').getHeight() != 0 && !this.options.hideGalleryTab) {
1792
+ this.dimensions.dataEffects.push(
1793
+ new Effect.Morph('lightwindow_galleries_tab_container', {sync: true, style: {height: '0px', marginTop: '20px'}})
1794
+ );
1795
+ }
1796
+
1797
+ if ($('lightwindow_galleries_list').getHeight() != 0) {
1798
+ $('lightwindow_galleries_tab_span').className = 'up';
1799
+ this.dimensions.dataEffects.push(
1800
+ new Effect.Morph('lightwindow_galleries_list', {
1801
+ sync: true,
1802
+ style: {height: '0px'},
1803
+ transition: Effect.Transitions.sinoidal,
1804
+ beforeStart: function() {
1805
+ $('lightwindow_galleries_list').setStyle({
1806
+ overflow: 'hidden'
1807
+ });
1808
+ },
1809
+ afterFinish: function() {
1810
+ $('lightwindow_galleries_list').setStyle({
1811
+ overflow: 'auto'
1812
+ });
1813
+ }
1814
+ })
1815
+ );
1816
+ }
1817
+ }
1818
+
1819
+ // We always want the title bar as well
1820
+ this.dimensions.dataEffects.push(
1821
+ new Effect.Morph('lightwindow_title_bar_inner', {sync: true, style: {height: '0px', marginTop: this.options.dimensions.titleHeight+'px'}}),
1822
+ new Effect.Fade('lightwindow_title_bar_inner', {sync: true, from: 1.0, to: 0.0})
1823
+ );
1824
+
1825
+ new Effect.Parallel(this.dimensions.dataEffects, {
1826
+ duration: this.duration,
1827
+ afterFinish: function() {
1828
+ this._loadWindow();
1829
+ }.bind(this),
1830
+ queue: {position: 'end', scope: 'lightwindowAnimation'}
1831
+ }
1832
+ );
1833
+ },
1834
+ //
1835
+ // Default Form handler for LightWindow
1836
+ //
1837
+ _defaultFormHandler : function(e) {
1838
+ var element = Event.element(e).parentNode;
1839
+ var parameterString = Form.serialize(this._getParameter('lightwindow_form', element.getAttribute('params')));
1840
+ if (this.options.formMethod == 'post') {
1841
+ var newAJAX = new Ajax.Request(element.href, {
1842
+ method: 'post',
1843
+ postBody: parameterString,
1844
+ onComplete: this.openWindow.bind(this, element)
1845
+ });
1846
+ } else if (this.options.formMethod == 'get') {
1847
+ var newAJAX = new Ajax.Request(element.href, {
1848
+ method: 'get',
1849
+ parameters: parameterString,
1850
+ onComplete: this.openWindow.bind(this, element)
1851
+ });
1852
+ }
1853
+ },
1854
+ //
1855
+ // Wrap everything up
1856
+ //
1857
+ _finishWindow : function() {
1858
+ if (this.windowType == 'external') {
1859
+ // We set the externals source here because it allows for a much smoother animation
1860
+ $('lightwindow_iframe').setAttribute('src', this.element.href);
1861
+ this._handleFinalWindowAnimation(1);
1862
+ } else if (this.windowType == 'media') {
1863
+
1864
+ var outerObject = document.createElement('object');
1865
+ outerObject.setAttribute('classid', this.options.classids[this._fileExtension(this.contentToFetch)]);
1866
+ outerObject.setAttribute('codebase', this.options.codebases[this._fileExtension(this.contentToFetch)]);
1867
+ outerObject.setAttribute('id', 'lightwindow_media_primary');
1868
+ outerObject.setAttribute('name', 'lightwindow_media_primary');
1869
+ outerObject.setAttribute('width', this.resizeTo.width);
1870
+ outerObject.setAttribute('height', this.resizeTo.height);
1871
+ outerObject = this._addParamToObject('movie', this.contentToFetch, outerObject);
1872
+ outerObject = this._addParamToObject('src', this.contentToFetch, outerObject);
1873
+ outerObject = this._addParamToObject('controller', 'true', outerObject);
1874
+ outerObject = this._addParamToObject('wmode', 'transparent', outerObject);
1875
+ outerObject = this._addParamToObject('cache', 'false', outerObject);
1876
+ outerObject = this._addParamToObject('quality', 'high', outerObject);
1877
+
1878
+ if (!Prototype.Browser.IE) {
1879
+ var innerObject = document.createElement('object');
1880
+ innerObject.setAttribute('type', this.options.mimeTypes[this._fileExtension(this.contentToFetch)]);
1881
+ innerObject.setAttribute('data', this.contentToFetch);
1882
+ innerObject.setAttribute('id', 'lightwindow_media_secondary');
1883
+ innerObject.setAttribute('name', 'lightwindow_media_secondary');
1884
+ innerObject.setAttribute('width', this.resizeTo.width);
1885
+ innerObject.setAttribute('height', this.resizeTo.height);
1886
+ innerObject = this._addParamToObject('controller', 'true', innerObject);
1887
+ innerObject = this._addParamToObject('wmode', 'transparent', innerObject);
1888
+ innerObject = this._addParamToObject('cache', 'false', innerObject);
1889
+ innerObject = this._addParamToObject('quality', 'high', innerObject);
1890
+
1891
+ outerObject.appendChild(innerObject);
1892
+ }
1893
+
1894
+ if (this._getParameter('lightwindow_iframe_embed')) {
1895
+ this._appendIframe('no');
1896
+ this._writeToIframe(this._convertToMarkup(outerObject, 'object'));
1897
+ } else {
1898
+ this._appendObject(outerObject, 'object', $('lightwindow_contents'));
1899
+ }
1900
+
1901
+ this._handleFinalWindowAnimation(0);
1902
+ } else {
1903
+ this._handleFinalWindowAnimation(0);
1904
+ }
1905
+
1906
+ // Initialize any actions
1907
+ this._setupActions();
1908
+ }
1909
+ }
1910
+
1911
+ /*-----------------------------------------------------------------------------------------------*/
1912
+
1913
+ Event.observe(window, 'load', lightwindowInit, false);
1914
+
1915
+ //
1916
+ // Set up all of our links
1917
+ //
1918
+ var myLightWindow = null;
1919
+ function lightwindowInit() {
1920
+ myLightWindow = new lightwindow();
1921
+ }