/[drupal]/contributions/modules/ad_ubercart/ad_ubercart_js.js
ViewVC logotype

Contents of /contributions/modules/ad_ubercart/ad_ubercart_js.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Wed Feb 25 00:36:37 2009 UTC (8 months, 4 weeks ago) by neochief
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +45 -38 lines
File MIME type: text/javascript
@damn, it seems that I commited everything to /cvs/drupal-contrib/ad_ubercart during last week. Anyway, now it's simply doesn't exists, so moving everything to new location.

New features:
Added JS price preview.
Added second step in cart addition form (ad node form).
Modified cart description, added theme function there.
Added cron cleanup for old temporary ad nodes.
Refactored a bit.
1 Drupal.behaviors.ad_ubercart = function(context) {
2 Drupal.settings.calendar.renderCallback = function($td, thisDate, month, year) {
3 if (Drupal.settings.calendar.in_cart[thisDate.asString()]) {
4 $td.addClass('used');
5 }
6 if (Drupal.settings.calendar.disabled_dates[thisDate.asString()]) {
7 $td.addClass('disabled');
8 }
9 if ($td.is('.today')) {
10 $td.addClass('disabled');
11 }
12 }
13
14 $('.calendar:not(.adub-processed)', context).addClass('adub-processed').each(function() {
15 include_calendar('.calendar', Drupal.settings.calendar, Drupal.settings.calendar.monthsToDisplay);
16 });
17
18 // Price estimates calculation
19 $('.price-holder', context).hide();
20 $('#edit-period:not(.adub-processed), input[@name=period]:not(.adub-processed)', context).addClass('adub-processed').change(function(){
21 val = $(this).val();
22 // DayPicker stores his values in hidden field as string,
23 // so we need to split up it's values to get length
24 if ($(this).is('input')) {
25 if (val) {
26 val = val.split(',');
27 }
28 }
29 if (val) {
30 price = val.length * $(this).attr('price');
31 total = 'Estimated price: <b>$'+ price.toFixed(2) +'</b>';
32 $('.price-holder', $(this).parents('form')).html(total).slideDown();
33
34 }
35 else {
36 $('.price-holder', $(this).parents('form')).slideUp('fast',function(){ $(this).empty(); });
37 }
38 });
39 }
40
41 // Global calendar variables
42 var dates = new Array();
43 var calendars = new Array();
44
45 /**
46 * Includes calendar on page
47 * @param container
48 * Selector which points to DOM element where calendar will be placed.
49 * @param value
50 * Selector to hidden value, where will be stored input.
51 * @param settings
52 * Calendar settings object.
53 * @param num
54 * Nymber of calendars to output.
55 */
56 function include_calendar(container, settings, num) {
57 // initialize calendar format
58 Date.firstDayOfWeek = 7;
59 Date.format = 'yyyy-mm-dd';
60
61 // Don't touch this, it's dovumented initializer for datePicker
62 for (var i = 0; i < num; i++) {
63 calendars[i] = $('<div class="cal" index="'+i+'" />')
64 .datePicker(settings)
65 .bind(
66 'dpMonthChanged',
67 function(event, displayedMonth, displayedYear)
68 {
69 for (var i = 0; i < num; i++) {
70 if (i != $(this).attr('index')) {
71 $(".cal[index="+i+"]").dpSetDisplayedMonth(displayedMonth+(i-$(this).attr('index')), displayedYear);
72 }
73 }
74 }
75 )
76 .bind(
77 'dateSelected',
78 function(event, date, $td, status)
79 {
80 for (var i = 0; i < num; i++) {
81 if (i != $(this).attr('index')) {
82 $(".cal[index="+i+"]").dpSetSelected(date.asString(), status, false);
83 }
84 }
85 select_date(event, date, $td, status, $(this).parent(container).prev('input'));
86 }
87 );
88 if ((num > 0) && (i < num-1)) {
89 // remove the "forward" navigation from the first date picker
90 $('.dp-nav-next', calendars[i]).html('');
91 }
92 if ((num > 0) && (i > 0)) {
93 // remove the "backward" navigation from the first date picker
94 $('.dp-nav-prev', calendars[i]).html('');
95 }
96 }
97
98 // initialise the date pickers to consecutive months ($date1 defaults to this month so set $date2 to next month)
99 var now = new Date();
100 for (var i = 1; i < num; i++) {
101 calendars[i].dpSetDisplayedMonth(now.getMonth()+i, now.getFullYear());
102 }
103 // add the generated combined plugin to the document
104 $(container).html('');
105 for (var i = 0; i < num; i++) {
106 $(container).append(calendars[i]);
107 }
108 }
109
110 // A way to sync multiple calendars
111 function select_date(e, date, $td, state, field) {
112 if (state) {
113 if (dates.indexOf(date.asString()) == -1) {
114 dates.push(date.asString());
115 }
116 }
117 else {
118 pos = dates.indexOf(date.asString());
119 if (pos >= 0) {
120 dates.splice(pos,1);
121 }
122 }
123 // Write our value to hidden field
124 field.val(dates.toString());
125 field.trigger('change');
126 }
127
128 // IE fix
129 if (!Array.prototype.indexOf)
130 {
131 Array.prototype.indexOf = function(elt /*, from*/)
132 {
133 var len = this.length;
134
135 var from = Number(arguments[1]) || 0;
136 from = (from < 0)
137 ? Math.ceil(from)
138 : Math.floor(from);
139 if (from < 0)
140 from += len;
141
142 for (; from < len; from++)
143 {
144 if (from in this &&
145 this[from] === elt)
146 return from;
147 }
148 return -1;
149 };
150 }

  ViewVC Help
Powered by ViewVC 1.1.2