refinerycms 0.9.5.31 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/.gitignore +1 -0
  2. data/VERSION +1 -1
  3. data/bin/refinery +2 -1
  4. data/config/environment.rb +1 -1
  5. data/config/environments/development.rb +3 -0
  6. data/contributors.md +2 -0
  7. data/db/migrate/20100202034802_remove_custom_title_image_id_and_image_id_from_pages.rb +13 -0
  8. data/db/migrate/20100204011654_change_part_titles_to_titleized_version_for_new_format.rb +13 -0
  9. data/db/schema.rb +6 -10
  10. data/public/javascripts/admin.js +1 -1
  11. data/public/javascripts/jquery-ui-1.8rc1.min.js +375 -0
  12. data/public/javascripts/jquery.js +4231 -2529
  13. data/public/javascripts/refinery/admin.js +609 -38
  14. data/public/javascripts/refinery/boot_wym.js +3 -3
  15. data/public/javascripts/thickbox.js +116 -129
  16. data/public/javascripts/wymeditor/jquery.refinery.wymeditor.js +3674 -3732
  17. data/public/javascripts/wymeditor/skins/refinery/skin.js +8 -8
  18. data/public/stylesheets/refinery/refinery.css +142 -32
  19. data/public/stylesheets/wymeditor/skins/refinery/skin.css +8 -1
  20. data/readme.md +35 -21
  21. data/test/fixtures/page_parts.yml +9 -0
  22. data/test/fixtures/pages.yml +88 -0
  23. data/test/performance/browsing_test.rb +9 -0
  24. data/test/test_helper.rb +38 -0
  25. data/test/unit/image_test.rb +14 -0
  26. data/test/unit/page_part_test.rb +19 -0
  27. data/test/unit/page_test.rb +130 -0
  28. data/vendor/plugins/authentication/app/controllers/sessions_controller.rb +1 -1
  29. data/vendor/plugins/authentication/app/views/admin/users/index.html.erb +1 -2
  30. data/vendor/plugins/authentication/authentication.md +9 -1
  31. data/vendor/plugins/dashboard/dashboard.md +3 -3
  32. data/vendor/plugins/images/app/controllers/admin/images_controller.rb +17 -13
  33. data/vendor/plugins/images/app/helpers/admin/images_helper.rb +6 -0
  34. data/vendor/plugins/images/app/models/image.rb +24 -39
  35. data/vendor/plugins/images/app/views/admin/images/_form.html.erb +11 -4
  36. data/vendor/plugins/images/app/views/admin/images/_grid_view.html.erb +1 -2
  37. data/vendor/plugins/images/app/views/admin/images/_list_view_image.html.erb +1 -2
  38. data/vendor/plugins/images/app/views/admin/images/index.html.erb +1 -1
  39. data/vendor/plugins/images/app/views/admin/images/insert.html.erb +8 -71
  40. data/vendor/plugins/images/images.md +12 -7
  41. data/vendor/plugins/inquiries/app/views/admin/inquiries/_inquiry.html.erb +6 -13
  42. data/vendor/plugins/inquiries/app/views/admin/inquiry_settings/index.html.erb +1 -2
  43. data/vendor/plugins/inquiries/inquiries.md +8 -8
  44. data/vendor/plugins/news/app/views/admin/news_items/_news_item.html.erb +1 -2
  45. data/vendor/plugins/news/news.md +4 -4
  46. data/vendor/plugins/pages/app/controllers/admin/page_dialogs_controller.rb +11 -10
  47. data/vendor/plugins/pages/app/controllers/admin/page_parts_controller.rb +5 -1
  48. data/vendor/plugins/pages/app/controllers/admin/pages_controller.rb +2 -2
  49. data/vendor/plugins/pages/app/models/page.rb +75 -29
  50. data/vendor/plugins/pages/app/models/page_part.rb +1 -1
  51. data/vendor/plugins/pages/app/views/admin/page_dialogs/_page_link.html.erb +2 -2
  52. data/vendor/plugins/pages/app/views/admin/page_dialogs/link_to.html.erb +8 -112
  53. data/vendor/plugins/pages/app/views/admin/pages/_form.html.erb +50 -154
  54. data/vendor/plugins/pages/app/views/admin/pages/_list.html.erb +10 -10
  55. data/vendor/plugins/pages/app/views/admin/pages/_page_part_field.html.erb +4 -4
  56. data/vendor/plugins/pages/app/views/admin/pages/_sortable_list.html.erb +1 -1
  57. data/vendor/plugins/pages/pages.md +30 -25
  58. data/vendor/plugins/refinery/app/views/admin/_head.html.erb +5 -14
  59. data/vendor/plugins/refinery/app/views/admin/_menu.html.erb +2 -64
  60. data/vendor/plugins/refinery/app/views/shared/_message.html.erb +0 -6
  61. data/vendor/plugins/refinery/app/views/shared/admin/_error_messages_for.html.erb +1 -6
  62. data/vendor/plugins/refinery/app/views/shared/admin/_form_actions.html.erb +8 -10
  63. data/vendor/plugins/refinery/app/views/shared/admin/_image_picker.html.erb +22 -38
  64. data/vendor/plugins/refinery/app/views/shared/admin/_make_sortable.html.erb +6 -65
  65. data/vendor/plugins/refinery/app/views/shared/admin/_resource_picker.html.erb +16 -16
  66. data/vendor/plugins/refinery/app/views/shared/admin/_sortable_list.html.erb +3 -4
  67. data/vendor/plugins/refinery/lib/crud.rb +1 -1
  68. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_singular_name.html.erb +1 -1
  69. data/vendor/plugins/refinery/lib/generators/refinery/templates/views/admin/_sortable_list.html.erb +1 -1
  70. data/vendor/plugins/refinery/plugins.md +19 -12
  71. data/vendor/plugins/refinery_dialogs/app/controllers/admin/dialogs_controller.rb +6 -4
  72. data/vendor/plugins/refinery_dialogs/app/views/admin/dialogs/show.html.erb +3 -3
  73. data/vendor/plugins/refinery_dialogs/app/views/layouts/admin_dialog.html.erb +7 -14
  74. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_refinery_setting.html.erb +1 -1
  75. data/vendor/plugins/refinery_settings/settings.md +51 -1
  76. data/vendor/plugins/resources/app/controllers/admin/resources_controller.rb +16 -11
  77. data/vendor/plugins/resources/app/views/admin/resources/_form.html.erb +9 -2
  78. data/vendor/plugins/resources/app/views/admin/resources/_resource.html.erb +1 -3
  79. data/vendor/plugins/resources/app/views/admin/resources/index.html.erb +2 -2
  80. data/vendor/plugins/resources/app/views/admin/resources/insert.html.erb +14 -60
  81. data/vendor/plugins/resources/resources.md +1 -1
  82. data/vendor/plugins/themes/app/controllers/admin/themes_controller.rb +6 -6
  83. data/vendor/plugins/themes/app/models/theme.rb +3 -3
  84. data/vendor/plugins/themes/app/views/admin/themes/_theme.html.erb +14 -20
  85. data/vendor/plugins/themes/themes.md +21 -19
  86. metadata +18 -19
  87. data/public/javascripts/builder.js +0 -136
  88. data/public/javascripts/controls.js +0 -963
  89. data/public/javascripts/dragdrop.js +0 -973
  90. data/public/javascripts/effects.js +0 -1128
  91. data/public/javascripts/fastinit.js +0 -84
  92. data/public/javascripts/livepipe.js +0 -180
  93. data/public/javascripts/prototype.js +0 -4874
  94. data/public/javascripts/refinery/dialog.js +0 -52
  95. data/public/javascripts/refinery/parse_url.js +0 -38
  96. data/public/javascripts/refinery/prototype.enhancements.js +0 -24
  97. data/public/javascripts/refinery/tooltips.js +0 -173
  98. data/public/javascripts/scriptaculous.js +0 -47
  99. data/public/javascripts/slider.js +0 -275
  100. data/public/javascripts/tabs.js +0 -149
  101. data/vendor/plugins/refinery_settings/app/views/admin/refinery_settings/_make_sortable.html.erb +0 -7
@@ -1,52 +0,0 @@
1
- switch_area = function(area)
2
- {
3
- $$('#dialog_menu_left span.selected_radio').each(function(span)
4
- {
5
- span.removeClassName('selected_radio');
6
- });
7
- $($(area).parentNode).addClassName('selected_radio');
8
-
9
- $$('#dialog_main div.dialog_area').each(function(div)
10
- {
11
- div.hide();
12
- });
13
-
14
- $(area.value + '_area').show();
15
- }
16
-
17
- FastInit.addOnLoad(function()
18
- {
19
- radios = $$('#dialog_menu_left input[type=radio]');
20
- selected = $$('#dialog_menu_left .selected_radio input[type=radio]')[0] || radios[0];
21
-
22
- radios.each(function(input)
23
- {
24
- input.observe('click', function()
25
- {
26
- switch_area(this);
27
- });
28
- });
29
-
30
- if (selected)
31
- {
32
- selected.checked = true;
33
- switch_area(selected);
34
- }
35
-
36
- $$('#TB_title .close_dialog', '#dialog_container .close_dialog').each(function(close) {
37
- close.observe('click', function(e)
38
- {
39
- if (parent && typeof(parent.tb_remove) == "function") {
40
- parent.tb_remove();
41
- }
42
- else if (typeof(tb_remove) == 'function') {
43
- tb_remove();
44
- }
45
-
46
- if (e)
47
- {
48
- e.stop();
49
- }
50
- });
51
- });
52
- });
@@ -1,38 +0,0 @@
1
- //parse a URL to form an object of properties
2
- function parseURL(url)
3
- {
4
- //save the unmodified url to href property
5
- //so that the object we get back contains
6
- //all the same properties as the built-in location object
7
- var loc = { 'href' : url };
8
-
9
- //split the URL by single-slashes to get the component parts
10
- var parts = url.replace('//', '/').split('/');
11
-
12
- //store the protocol and host
13
- loc.protocol = parts[0];
14
- loc.host = parts[1];
15
-
16
- //extract any port number from the host
17
- //from which we derive the port and hostname
18
- parts[1] = parts[1].split(':');
19
- loc.hostname = parts[1][0];
20
- loc.port = parts[1].length > 1 ? parts[1][1] : '';
21
-
22
- //splice and join the remainder to get the pathname
23
- parts.splice(0, 2);
24
- loc.pathname = '/' + parts.join('/');
25
-
26
- //extract any hash and remove from the pathname
27
- loc.pathname = loc.pathname.split('#');
28
- loc.hash = loc.pathname.length > 1 ? '#' + loc.pathname[1] : '';
29
- loc.pathname = loc.pathname[0];
30
-
31
- //extract any search query and remove from the pathname
32
- loc.pathname = loc.pathname.split('?');
33
- loc.search = loc.pathname.length > 1 ? '?' + loc.pathname[1] : '';
34
- loc.pathname = loc.pathname[0];
35
-
36
- //return the final object
37
- return loc;
38
- }
@@ -1,24 +0,0 @@
1
- Element.addMethods('iframe',
2
- {
3
- document: function(element) {
4
- element = $(element);
5
- if (element.contentWindow)
6
- return element.contentWindow.document;
7
- else if (element.contentDocument)
8
- return element.contentDocument;
9
- else
10
- return null;
11
- },
12
- $: function(element, frameElement) {
13
- element = $(element);
14
- var frameDocument = element.document();
15
- if (arguments.length > 2) {
16
- for (var i = 1, frameElements = [], length = arguments.length; i < length; i++)
17
- frameElements.push(element.$(arguments[i]));
18
- return frameElements;
19
- }
20
- if (Object.isString(frameElement))
21
- frameElement = frameDocument.getElementById(frameElement);
22
- return frameElement || element;
23
- }
24
- });
@@ -1,173 +0,0 @@
1
- // Tooltip Object
2
- var Tooltip = Class.create();
3
- Tooltip.prototype = {
4
- initialize: function(el, options) {
5
- this.el = $(el);
6
- // Removing title from DOM element to avoid showing it
7
- if ((this.content = this.el.title) != null && this.content.length > 0) {
8
- this.el.title = '';
9
- this.el.tooltip = this;
10
- this.initialized = false;
11
- this.setOptions(options);
12
- this.options.relativeTo = $(this.options.relativeTo);
13
-
14
- // Event handlers
15
- this.showEvent = this.show.bindAsEventListener(this);
16
- this.hideEvent = this.hide.bindAsEventListener(this);
17
- this.updateEvent = this.update.bindAsEventListener(this);
18
- Event.observe(this.el, "mouseover", this.showEvent );
19
- Event.observe(this.el, "mouseout", this.hideEvent );
20
-
21
- // If descendant elements has 'alt' attribute defined, clear it
22
- this.el.descendants().each(function(el){
23
- if(Element.readAttribute(el, 'alt'))
24
- el.alt = "";
25
- });
26
-
27
- rounding = this.options.rounded ? ["xb1", "xb2", "xb3", "xb4"] : [];
28
-
29
- // Building tooltip container
30
- tooltipClassName = this.options.rounded ? "tooltip tooltip-rounded" : "tooltip tooltip-square";
31
- this.tooltip = new Element("div", {style: 'display:none'}).addClassName(tooltipClassName);
32
-
33
- xtop = new Element("div").addClassName("xtop");
34
- rounding.each(function(rounder)
35
- {
36
- xtop.insert(new Element("div").addClassName(rounder));
37
- });
38
- this.tooltip.insert(xtop);
39
- this.tooltip.insert(new Element("div").addClassName("xboxcontent").update(this.content));
40
-
41
- xbottom = new Element("div").addClassName("xbottom");
42
- rounding.reverse(false).each(function(rounder)
43
- {
44
- xbottom.insert(new Element("div").addClassName(rounder));
45
- });
46
- this.tooltip.insert(xbottom);
47
-
48
- return this;
49
- }
50
- },
51
- setOptions: function(options) {
52
- this.options = {
53
- maxWidth: 250 // Default tooltip width
54
- ,align: "left" // Default align
55
- ,delay: 250 // Default delay before tooltip appears in ms
56
- ,mouseFollow: true // Tooltips follows the mouse moving
57
- ,opacity: .75 // Default tooltips opacity
58
- ,appearDuration: .25 // Default appear duration in sec
59
- ,hideDuration: .25 // Default disappear duration in sec
60
- ,position: 'top'
61
- ,rounded: true
62
- ,spacing:{x:0,y:6}
63
- ,relativeTo:this.el
64
- ,maxHeight:600 // Default tooltip height
65
- };
66
- Object.extend(this.options, options || {});
67
- },
68
- show: function(e) {
69
- this.update();
70
-
71
- if (!this.insertedIntoDocument)
72
- {
73
- $('tooltip_container').insert(this.tooltip);
74
-
75
- this.options.width = this.tooltip.getWidth() + 2 // adding 2 seems to display tooltips on one line in FF, yay;
76
- this.tooltip.style.minWidth = (this.options.width < this.options.maxWidth ? this.options.width : this.options.maxWidth) + 'px'; // IE7 needs width to be defined. Use min-width because we can sacrifice older browser compatibility.
77
-
78
- this.insertedIntoDocument = true;
79
- }
80
-
81
- if(!this.initialized)
82
- this.timeout = window.setTimeout(this.appear.bind(this), this.options.delay);
83
- },
84
- hide: function(e) {
85
- if(this.initialized) {
86
- if (this.appearingFX != null)
87
- {
88
- this.appearingFX.cancel();
89
- }
90
- if(this.options.mouseFollow)
91
- {
92
- Event.stopObserving(this.el, "mousemove", this.updateEvent);
93
- }
94
- if (this.options.hideDuration > 0)
95
- {
96
- new Effect.Fade(this.tooltip, {duration: this.options.hideDuration, afterFinish: function() { Element.remove(this.tooltip) }.bind(this) });
97
- }
98
- else
99
- {
100
- this.tooltip.hide();
101
- }
102
- }
103
- this._clearTimeout(this.timeout);
104
-
105
- this.initialized = false;
106
- },
107
- update: function(e){
108
- offset = this.options.relativeTo.cumulativeOffset();
109
- this.xCord = offset[0];//Event.pointerX(e);
110
- this.yCord = offset[1];//Event.pointerY(e);
111
- this.setup();
112
- },
113
- appear: function() {
114
- Element.extend(this.tooltip); // IE needs element to be manually extended
115
-
116
- if(this.options.mouseFollow)
117
- {
118
- Event.observe(this.el, "mousemove", this.updateEvent);
119
- }
120
-
121
- this.setup();
122
-
123
- this.initialized = true;
124
- if (this.options.appearDuration > 0)
125
- {
126
- this.appearingFX = new Effect.Appear(this.tooltip, {duration: this.options.appearDuration, to: this.options.opacity });
127
- }
128
- else
129
- {
130
- this.tooltip.show();
131
- }
132
- },
133
- setup: function(){
134
- // If content width is more then allowed max width, set width to max
135
- if(this.options.width > this.options.maxWidth) {
136
- this.options.width = this.options.maxWidth;
137
- this.tooltip.style.width = this.options.width + 'px';
138
- }
139
-
140
- // Tooltip doesn't fit the current document dimensions
141
- if(this.xCord + this.options.width >= Element.getWidth(document.body)) {
142
- this.options.align = "right";
143
- this.xCord = this.xCord - this.options.width + 20;
144
- }
145
-
146
- switch(this.options.position)
147
- {
148
- case "left":
149
- {
150
- this.tooltip.style.left = (this.xCord - this.options.relativeTo.getWidth() - this.options.spacing.x) + "px";
151
- this.tooltip.style.top = this.yCord + this.options.spacing.y + "px";
152
- break;
153
- }
154
- case "right":
155
- {
156
- this.tooltip.style.left = (this.xCord + this.options.relativeTo.getWidth() + this.options.spacing.x) + "px";
157
- this.tooltip.style.top = this.yCord + this.options.spacing.y + "px";
158
- break;
159
- }
160
- default:
161
- {
162
- this.tooltip.style.left = this.xCord - (this.tooltip.getWidth() / 2) + (this.options.relativeTo.getWidth() / 2) - this.options.spacing.x + "px";
163
- this.tooltip.style.top = this.yCord - this.tooltip.getHeight() - this.options.spacing.y + "px";
164
- break;
165
- }
166
- }
167
- },
168
- _clearTimeout: function(timer) {
169
- clearTimeout(timer);
170
- clearInterval(timer);
171
- return null;
172
- }
173
- };
@@ -1,47 +0,0 @@
1
- // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining
4
- // a copy of this software and associated documentation files (the
5
- // "Software"), to deal in the Software without restriction, including
6
- // without limitation the rights to use, copy, modify, merge, publish,
7
- // distribute, sublicense, and/or sell copies of the Software, and to
8
- // permit persons to whom the Software is furnished to do so, subject to
9
- // the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be
12
- // included in all copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- var Scriptaculous = {
23
- Version: '1.6.2',
24
- require: function(libraryName) {
25
- // inserting via DOM fails in Safari 2.0, so brute force approach
26
- document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
27
- },
28
- load: function() {
29
- if((typeof Prototype=='undefined') ||
30
- (typeof Element == 'undefined') ||
31
- (typeof Element.Methods=='undefined') ||
32
- parseFloat(Prototype.Version.split(".")[0] + "." +
33
- Prototype.Version.split(".")[1]) < 1.5)
34
- throw("script.aculo.us requires the Prototype JavaScript framework >= 1.5.0");
35
-
36
- $A(document.getElementsByTagName("script")).findAll( function(s) {
37
- return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/))
38
- }).each( function(s) {
39
- var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,'');
40
- var includes = s.src.match(/\?.*load=([a-z,]*)/);
41
- (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider').split(',').each(
42
- function(include) { Scriptaculous.require(path+include+'.js') });
43
- });
44
- }
45
- }
46
-
47
- Scriptaculous.load();
@@ -1,275 +0,0 @@
1
- // script.aculo.us slider.js v1.8.2, Tue Nov 18 18:30:58 +0100 2008
2
-
3
- // Copyright (c) 2005-2008 Marty Haught, Thomas Fuchs
4
- //
5
- // script.aculo.us is freely distributable under the terms of an MIT-style license.
6
- // For details, see the script.aculo.us web site: http://script.aculo.us/
7
-
8
- if (!Control) var Control = { };
9
-
10
- // options:
11
- // axis: 'vertical', or 'horizontal' (default)
12
- //
13
- // callbacks:
14
- // onChange(value)
15
- // onSlide(value)
16
- Control.Slider = Class.create({
17
- initialize: function(handle, track, options) {
18
- var slider = this;
19
-
20
- if (Object.isArray(handle)) {
21
- this.handles = handle.collect( function(e) { return $(e) });
22
- } else {
23
- this.handles = [$(handle)];
24
- }
25
-
26
- this.track = $(track);
27
- this.options = options || { };
28
-
29
- this.axis = this.options.axis || 'horizontal';
30
- this.increment = this.options.increment || 1;
31
- this.step = parseInt(this.options.step || '1');
32
- this.range = this.options.range || $R(0,1);
33
-
34
- this.value = 0; // assure backwards compat
35
- this.values = this.handles.map( function() { return 0 });
36
- this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
37
- this.options.startSpan = $(this.options.startSpan || null);
38
- this.options.endSpan = $(this.options.endSpan || null);
39
-
40
- this.restricted = this.options.restricted || false;
41
-
42
- this.maximum = this.options.maximum || this.range.end;
43
- this.minimum = this.options.minimum || this.range.start;
44
-
45
- // Will be used to align the handle onto the track, if necessary
46
- this.alignX = parseInt(this.options.alignX || '0');
47
- this.alignY = parseInt(this.options.alignY || '0');
48
-
49
- this.trackLength = this.maximumOffset() - this.minimumOffset();
50
-
51
- this.handleLength = this.isVertical() ?
52
- (this.handles[0].offsetHeight != 0 ?
53
- this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) :
54
- (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth :
55
- this.handles[0].style.width.replace(/px$/,""));
56
-
57
- this.active = false;
58
- this.dragging = false;
59
- this.disabled = false;
60
-
61
- if (this.options.disabled) this.setDisabled();
62
-
63
- // Allowed values array
64
- this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
65
- if (this.allowedValues) {
66
- this.minimum = this.allowedValues.min();
67
- this.maximum = this.allowedValues.max();
68
- }
69
-
70
- this.eventMouseDown = this.startDrag.bindAsEventListener(this);
71
- this.eventMouseUp = this.endDrag.bindAsEventListener(this);
72
- this.eventMouseMove = this.update.bindAsEventListener(this);
73
-
74
- // Initialize handles in reverse (make sure first handle is active)
75
- this.handles.each( function(h,i) {
76
- i = slider.handles.length-1-i;
77
- slider.setValue(parseFloat(
78
- (Object.isArray(slider.options.sliderValue) ?
79
- slider.options.sliderValue[i] : slider.options.sliderValue) ||
80
- slider.range.start), i);
81
- h.makePositioned().observe("mousedown", slider.eventMouseDown);
82
- });
83
-
84
- this.track.observe("mousedown", this.eventMouseDown);
85
- document.observe("mouseup", this.eventMouseUp);
86
- document.observe("mousemove", this.eventMouseMove);
87
-
88
- this.initialized = true;
89
- },
90
- dispose: function() {
91
- var slider = this;
92
- Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
93
- Event.stopObserving(document, "mouseup", this.eventMouseUp);
94
- Event.stopObserving(document, "mousemove", this.eventMouseMove);
95
- this.handles.each( function(h) {
96
- Event.stopObserving(h, "mousedown", slider.eventMouseDown);
97
- });
98
- },
99
- setDisabled: function(){
100
- this.disabled = true;
101
- },
102
- setEnabled: function(){
103
- this.disabled = false;
104
- },
105
- getNearestValue: function(value){
106
- if (this.allowedValues){
107
- if (value >= this.allowedValues.max()) return(this.allowedValues.max());
108
- if (value <= this.allowedValues.min()) return(this.allowedValues.min());
109
-
110
- var offset = Math.abs(this.allowedValues[0] - value);
111
- var newValue = this.allowedValues[0];
112
- this.allowedValues.each( function(v) {
113
- var currentOffset = Math.abs(v - value);
114
- if (currentOffset <= offset){
115
- newValue = v;
116
- offset = currentOffset;
117
- }
118
- });
119
- return newValue;
120
- }
121
- if (value > this.range.end) return this.range.end;
122
- if (value < this.range.start) return this.range.start;
123
- return value;
124
- },
125
- setValue: function(sliderValue, handleIdx){
126
- if (!this.active) {
127
- this.activeHandleIdx = handleIdx || 0;
128
- this.activeHandle = this.handles[this.activeHandleIdx];
129
- this.updateStyles();
130
- }
131
- handleIdx = handleIdx || this.activeHandleIdx || 0;
132
- if (this.initialized && this.restricted) {
133
- if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
134
- sliderValue = this.values[handleIdx-1];
135
- if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
136
- sliderValue = this.values[handleIdx+1];
137
- }
138
- sliderValue = this.getNearestValue(sliderValue);
139
- this.values[handleIdx] = sliderValue;
140
- this.value = this.values[0]; // assure backwards compat
141
-
142
- this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
143
- this.translateToPx(sliderValue);
144
-
145
- this.drawSpans();
146
- if (!this.dragging || !this.event) this.updateFinished();
147
- },
148
- setValueBy: function(delta, handleIdx) {
149
- this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
150
- handleIdx || this.activeHandleIdx || 0);
151
- },
152
- translateToPx: function(value) {
153
- return Math.round(
154
- ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) *
155
- (value - this.range.start)) + "px";
156
- },
157
- translateToValue: function(offset) {
158
- return ((offset/(this.trackLength-this.handleLength) *
159
- (this.range.end-this.range.start)) + this.range.start);
160
- },
161
- getRange: function(range) {
162
- var v = this.values.sortBy(Prototype.K);
163
- range = range || 0;
164
- return $R(v[range],v[range+1]);
165
- },
166
- minimumOffset: function(){
167
- return(this.isVertical() ? this.alignY : this.alignX);
168
- },
169
- maximumOffset: function(){
170
- return(this.isVertical() ?
171
- (this.track.offsetHeight != 0 ? this.track.offsetHeight :
172
- this.track.style.height.replace(/px$/,"")) - this.alignY :
173
- (this.track.offsetWidth != 0 ? this.track.offsetWidth :
174
- this.track.style.width.replace(/px$/,"")) - this.alignX);
175
- },
176
- isVertical: function(){
177
- return (this.axis == 'vertical');
178
- },
179
- drawSpans: function() {
180
- var slider = this;
181
- if (this.spans)
182
- $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
183
- if (this.options.startSpan)
184
- this.setSpan(this.options.startSpan,
185
- $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
186
- if (this.options.endSpan)
187
- this.setSpan(this.options.endSpan,
188
- $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
189
- },
190
- setSpan: function(span, range) {
191
- if (this.isVertical()) {
192
- span.style.top = this.translateToPx(range.start);
193
- span.style.height = this.translateToPx(range.end - range.start + this.range.start);
194
- } else {
195
- span.style.left = this.translateToPx(range.start);
196
- span.style.width = this.translateToPx(range.end - range.start + this.range.start);
197
- }
198
- },
199
- updateStyles: function() {
200
- this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
201
- Element.addClassName(this.activeHandle, 'selected');
202
- },
203
- startDrag: function(event) {
204
- if (Event.isLeftClick(event)) {
205
- if (!this.disabled){
206
- this.active = true;
207
-
208
- var handle = Event.element(event);
209
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
210
- var track = handle;
211
- if (track==this.track) {
212
- var offsets = Position.cumulativeOffset(this.track);
213
- this.event = event;
214
- this.setValue(this.translateToValue(
215
- (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
216
- ));
217
- var offsets = Position.cumulativeOffset(this.activeHandle);
218
- this.offsetX = (pointer[0] - offsets[0]);
219
- this.offsetY = (pointer[1] - offsets[1]);
220
- } else {
221
- // find the handle (prevents issues with Safari)
222
- while((this.handles.indexOf(handle) == -1) && handle.parentNode)
223
- handle = handle.parentNode;
224
-
225
- if (this.handles.indexOf(handle)!=-1) {
226
- this.activeHandle = handle;
227
- this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
228
- this.updateStyles();
229
-
230
- var offsets = Position.cumulativeOffset(this.activeHandle);
231
- this.offsetX = (pointer[0] - offsets[0]);
232
- this.offsetY = (pointer[1] - offsets[1]);
233
- }
234
- }
235
- }
236
- Event.stop(event);
237
- }
238
- },
239
- update: function(event) {
240
- if (this.active) {
241
- if (!this.dragging) this.dragging = true;
242
- this.draw(event);
243
- if (Prototype.Browser.WebKit) window.scrollBy(0,0);
244
- Event.stop(event);
245
- }
246
- },
247
- draw: function(event) {
248
- var pointer = [Event.pointerX(event), Event.pointerY(event)];
249
- var offsets = Position.cumulativeOffset(this.track);
250
- pointer[0] -= this.offsetX + offsets[0];
251
- pointer[1] -= this.offsetY + offsets[1];
252
- this.event = event;
253
- this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
254
- if (this.initialized && this.options.onSlide)
255
- this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
256
- },
257
- endDrag: function(event) {
258
- if (this.active && this.dragging) {
259
- this.finishDrag(event, true);
260
- Event.stop(event);
261
- }
262
- this.active = false;
263
- this.dragging = false;
264
- },
265
- finishDrag: function(event, success) {
266
- this.active = false;
267
- this.dragging = false;
268
- this.updateFinished();
269
- },
270
- updateFinished: function() {
271
- if (this.initialized && this.options.onChange)
272
- this.options.onChange(this.values.length>1 ? this.values : this.value, this);
273
- this.event = null;
274
- }
275
- });