├── .gitignore
├── js
├── main.js
└── OpeningHours.js
├── css
└── OpeningHours.css
├── tests
├── 3consecutiveDays.json
├── consecutiveDays.json
├── singleWeek.json
├── multipleHours.json
└── multipleWeeks_version.json
├── additionalData.json
├── index.html
├── License.md
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | /nbproject/private/
2 | /nbproject/
3 |
--------------------------------------------------------------------------------
/js/main.js:
--------------------------------------------------------------------------------
1 |
2 | $(function() {
3 |
4 | $.getJSON('tests/multipleWeeks_version.json', function(data) {
5 | if (data) {
6 | $('.openingHours').openingHours({
7 | json: data,
8 | lang: 'ro',
9 | daysForm: 'normal',
10 | weekPeriods: true
11 | });
12 | }
13 | });
14 |
15 | });
--------------------------------------------------------------------------------
/css/OpeningHours.css:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | Created on : 06.12.2013, 22:44:15
4 | Author : Cosmin
5 | */
6 |
7 | .openingHours {
8 | max-width:355px;
9 | display:table;
10 | }
11 |
12 | .dayContainer {
13 | width:100%;
14 | float:left;
15 | }
16 |
17 | .day {
18 | width:49%;
19 | float:left;
20 | }
21 |
22 | .hour {
23 | width:49%;
24 | float:right;
25 | }
26 |
--------------------------------------------------------------------------------
/tests/3consecutiveDays.json:
--------------------------------------------------------------------------------
1 | {
2 | "weekPeriod": [
3 | {
4 | "dayOfWeek": "Monday",
5 | "opens": "11:00:00",
6 | "closes": "18:00:00"
7 | },
8 | {
9 | "dayOfWeek": "Tuesday",
10 | "opens": "11:00:00",
11 | "closes": "18:00:00"
12 | },
13 | {
14 | "dayOfWeek": "Wednesday",
15 | "opens": "11:00:00",
16 | "closes": "18:00:00"
17 | },
18 | {
19 | "dayOfWeek": "Sunday",
20 | "opens": "14:00:00",
21 | "closes": "18:00:00"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/tests/consecutiveDays.json:
--------------------------------------------------------------------------------
1 | {
2 | "weekPeriod": [
3 |
4 | {
5 | "dayOfWeek": "Wednesday",
6 | "opens": "11:00:00",
7 | "closes": "18:00:00"
8 | },
9 | {
10 | "dayOfWeek": "Saturday",
11 | "opens": "14:00:00",
12 | "closes": "18:00:00"
13 | },
14 | {
15 | "dayOfWeek": "Friday",
16 | "opens": "14:00:00",
17 | "closes": "18:00:00"
18 | },
19 | {
20 | "dayOfWeek": "Sunday",
21 | "opens": "14:00:00",
22 | "closes": "18:00:00"
23 | }
24 | ]
25 | }
--------------------------------------------------------------------------------
/tests/singleWeek.json:
--------------------------------------------------------------------------------
1 | {
2 | "weekPeriod": [
3 | {
4 | "dayOfWeek": "Monday",
5 | "opens": "11:00:00",
6 | "closes": "18:00:00"
7 | },
8 | {
9 | "dayOfWeek": "Tuesday",
10 | "opens": "11:00:00",
11 | "closes": "18:00:00"
12 | },
13 | {
14 | "dayOfWeek": "Wednesday",
15 | "opens": "11:00:00",
16 | "closes": "18:00:00"
17 | },
18 | {
19 | "dayOfWeek": "Saturday",
20 | "opens": "14:00:00",
21 | "closes": "18:00:00"
22 | },
23 | {
24 | "dayOfWeek": "Friday",
25 | "opens": "11:00:00",
26 | "closes": "18:00:00"
27 | },
28 | {
29 | "dayOfWeek": "Sunday",
30 | "opens": "14:00:00",
31 | "closes": "18:00:00"
32 | }
33 | ]
34 | }
--------------------------------------------------------------------------------
/additionalData.json:
--------------------------------------------------------------------------------
1 | {
2 | "en": {
3 | "closedString": "closed",
4 | "header": "Opening hours"
5 | },
6 | "de": {
7 | "closedString": "geschlossen",
8 | "header": "Öffnungszeiten"
9 | },
10 | "ro": {
11 | "closedString": "închis",
12 | "header": "Program de lucru"
13 | },
14 | "it": {
15 | "closedString": "chiuso",
16 | "header": "Orari di apertura"
17 | },
18 | "es" : {
19 | "closedString" : "cerrado",
20 | "header" : "Horario"
21 | },
22 | "ru" : {
23 | "closedString" : "закрыто",
24 | "header" : "Рабочие часы"
25 | },
26 | "fr" : {
27 | "closedString" : "fermé",
28 | "header" : "Horaires d'ouverture"
29 | },
30 | "pt" : {
31 | "closedString" : "fechado",
32 | "header" : "Horário"
33 | },
34 | "bg" : {
35 | "closedString" : "затворен",
36 | "header" : "Разписание"
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 | Render your Opening Hours
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | (The MIT License)
2 |
3 | Copyright (C) 2014 Cosmin Paun
4 |
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 |
8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 |
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 |
--------------------------------------------------------------------------------
/tests/multipleHours.json:
--------------------------------------------------------------------------------
1 | {
2 | "weekPeriod": [
3 | {
4 | "dayOfWeek": "Monday",
5 | "opens": "11:00:00",
6 | "closes": "11:15:00"
7 | },
8 | {
9 | "dayOfWeek": "Monday",
10 | "opens": "11:30:00",
11 | "closes": "11:45:00"
12 | },
13 | {
14 | "dayOfWeek": "Tuesday",
15 | "opens": "21:30:00",
16 | "closes": "21:45:00"
17 | },
18 | {
19 | "dayOfWeek": "Tuesday",
20 | "opens": "11:30:00",
21 | "closes": "11:45:00"
22 | },
23 | {
24 | "dayOfWeek": "Wednesday",
25 | "opens": "11:00:00",
26 | "closes": "18:00:00"
27 | },
28 | {
29 | "dayOfWeek": "Saturday",
30 | "opens": "14:00:00",
31 | "closes": "18:00:00"
32 | },
33 | {
34 | "dayOfWeek": "Friday",
35 | "opens": "11:00:00",
36 | "closes": "18:00:00"
37 | },
38 | {
39 | "dayOfWeek": "Sunday",
40 | "opens": "14:00:00",
41 | "closes": "18:00:00"
42 | }
43 | ]
44 | }
--------------------------------------------------------------------------------
/tests/multipleWeeks_version.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "weekPeriod": [
4 | {
5 | "dayOfWeek": "Monday",
6 | "opens": "11:00:00",
7 | "closes": "18:00:00"
8 | },
9 | {
10 | "dayOfWeek": "Tuesday",
11 | "opens": "10:00:00",
12 | "closes": "18:00:00"
13 | },
14 | {
15 | "dayOfWeek": "Wednesday",
16 | "opens": "11:00:00",
17 | "closes": "18:00:00"
18 | },
19 | {
20 | "dayOfWeek": "Thursday",
21 | "opens": "14:00:00",
22 | "closes": "18:00:00"
23 | },
24 | {
25 | "dayOfWeek": "Sunday",
26 | "opens": "14:00:00",
27 | "closes": "18:00:00"
28 | },
29 | {
30 | "dayOfWeek": "Saturday",
31 | "opens": "13:00:00",
32 | "closes": "18:00:00"
33 | }
34 |
35 | ],
36 | "validFrom": "2014-01-15",
37 | "validThrough": "2014-03-20"
38 | },
39 | {
40 | "weekPeriod": [
41 | {
42 | "dayOfWeek": "Monday",
43 | "opens": "5:00:00",
44 | "closes": "18:00:00"
45 | },
46 | {
47 | "dayOfWeek": "Tuesday",
48 | "opens": "2:00:00",
49 | "closes": "18:00:00"
50 | },
51 | {
52 | "dayOfWeek": "Wednesday",
53 | "opens": "11:00:00",
54 | "closes": "18:00:00"
55 | },
56 | {
57 | "dayOfWeek": "Thursday",
58 | "opens": "14:00:00",
59 | "closes": "18:00:00"
60 | },
61 | {
62 | "dayOfWeek": "Sunday",
63 | "opens": "14:00:00",
64 | "closes": "18:00:00"
65 | },
66 | {
67 | "dayOfWeek": "Saturday",
68 | "opens": "13:00:00",
69 | "closes": "18:00:00"
70 | }
71 |
72 | ],
73 | "validFrom": "2014-06-10",
74 | "validThrough": "2014-12-20"
75 | }
76 | ]
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #OpeningHours.js
2 |
3 | An easy-to-use library for rendering your company's Opening Hours. All you need is JSON, [jQuery](http://jquery.com/) and [momentjs](http://momentjs.com/)
4 |
5 | ## Get Started
6 |
7 | ### Step 1 - Link files
8 |
9 | Link the [jQuery](http://jquery.com/ ), [momentjs](http://momentjs.com/) and OpeningHours libraries somewhere in the `````` of your document.
10 |
11 | ```html
12 |
13 |
14 |
15 |
16 | ```
17 |
18 | ### Step 2 - the JSON file
19 |
20 | Write the JSON file containing the information about the days of the week where there are opening hours. The JSON file should contain just the days when there are opening hours, following the format:
21 | ```
22 | {
23 | weekPeriod : [
24 | {
25 | "dayOfWeek" : Name of the day (Monday, Tuesday, Wednesday etc.)
26 | "opens" : The opening time - written in format HH:MM:SS
27 | "closes" : The closing time - written in format HH:MM:SS
28 | },
29 | ...
30 | ]
31 | }
32 | ```
33 | You can find more examples in the folder ```tests```:
34 |
35 | ```json
36 | {
37 | "weekPeriod": [
38 | {
39 | "dayOfWeek": "Monday",
40 | "opens": "11:00:00",
41 | "closes": "18:00:00"
42 | },
43 | {
44 | "dayOfWeek": "Tuesday",
45 | "opens": "11:00:00",
46 | "closes": "18:00:00"
47 | },
48 | {
49 | "dayOfWeek": "Wednesday",
50 | "opens": "11:00:00",
51 | "closes": "18:00:00"
52 | },
53 | {
54 | "dayOfWeek": "Saturday",
55 | "opens": "14:00:00",
56 | "closes": "18:00:00"
57 | },
58 | {
59 | "dayOfWeek": "Friday",
60 | "opens": "11:00:00",
61 | "closes": "18:00:00"
62 | }
63 | ]
64 | }
65 | ```
66 |
67 | ### Step 3 - Add the container
68 |
69 | Add the div container where you want to render the opening hours.
70 |
71 | ```html
72 |
73 |
74 | ```
75 |
76 | ### Step 4 - Create the opening hours
77 |
78 | Add the following JavaScript code into the `````` of your document, under the links from ```Step 1```
79 |
80 | ```javascript
81 | $(function() {
82 | if (OpeningHours) {
83 | $.getJSON('tests/multipleWeeks_version.json', function(data) {
84 | if (data) {
85 | $('.openingHours').openingHours({
86 | //options goes here
87 | });
88 | }
89 | });
90 | }
91 | });
92 | ```
93 |
94 | ## Options available
95 |
96 | ```
97 | daysForm - normal(default) | short | min //How the days should be displayed: Monday, Mon, Mo
98 | lang - en(default) | de | it ... //In which language should be the days displayed. Basically we can extend it to every language provided by MomentJS
99 | weekPeriods - true | false(default) //True in case you have 2 different opening hours periods during 1 year
100 |
101 | ```
102 |
103 | ```... more to come soon .... ```
--------------------------------------------------------------------------------
/js/OpeningHours.js:
--------------------------------------------------------------------------------
1 | ;
2 | (function($, window, document) {
3 | var pluginName = 'openingHours',
4 | defaults = {
5 | lang: "en",
6 | weekPeriods: false,
7 | daysForm: "normal"
8 | },
9 | additionalData = "",
10 | propertyDays = [{"name": "Monday", "hours": []}, {"name": "Tuesday", "hours": []}, {"name": "Wednesday", "hours": []}, {"name": "Thursday", "hours": []}, {"name": "Friday", "hours": []}, {"name": "Saturday", "hours": []}, {"name": "Sunday", "hours": []}];
11 | function Plugin(element, options) {
12 | this.element = element;
13 | this.settings = $.extend({}, defaults, options);
14 | this._defaults = defaults;
15 | this._name = pluginName;
16 | this._propertyDays = propertyDays;
17 | this._additionalData = additionalData;
18 | this.init();
19 | }
20 |
21 | Plugin.prototype = {
22 | init: function() {
23 | this.buildPropertyDays(this.settings.json);
24 | this.createOpeningHours(this.element, this._propertyDays, this.settings.lang, this.settings.daysForm);
25 | },
26 | /*
27 | * Simple Ajax call
28 | *
29 | * @param {type} url
30 | * @param {type} contentType
31 | * @returns {unresolved}
32 | */
33 | getData: function(url, contentType) {
34 | var data = null;
35 | var req = new XMLHttpRequest();
36 | req.open("GET", url, false);
37 | req.setRequestHeader("Content-Type", contentType);
38 | req.onreadystatechange = function() {
39 | if (req.readyState === 4 && req.status === 200) {
40 | data = req.responseText;
41 | }
42 | };
43 | req.send(null);
44 | return data;
45 | },
46 |
47 | getAdditionalData: function(lang) {
48 | var addData;
49 | $.ajax({
50 | type: "GET",
51 | url: "additionalData.json",
52 | async: false,
53 | dataType: "json",
54 | success: function(data) {
55 | addData = data;
56 | }
57 | });
58 | if (addData[lang]) {
59 | return addData[lang];
60 | } else {
61 | return 'language not found!';
62 | }
63 | },
64 | /**
65 | * Used to add the elements in the propertyDays array
66 | * @param {type} dayList
67 | * @param {type} dayPeriod
68 | * @returns {Boolean}
69 | */
70 | checkDayMatch: function(dayList, dayPeriod) {
71 | if (dayList.name === dayPeriod.dayOfWeek) {
72 | return true;
73 | } else {
74 | return false;
75 | }
76 | },
77 | /**
78 | *
79 | * @param {type} dayList
80 | * @param {type} dayPeriod
81 | * @returns {undefined}
82 | */
83 | addOpeningHours: function(dayList, dayPeriod) {
84 | if (dayList.hours.length === 0) {
85 | /*
86 | * if there is no opening time in the specific day, we just add an object to the hours list
87 | */
88 | dayList.hours.push({
89 | opens: dayPeriod.opens,
90 | closes: dayPeriod.closes
91 | });
92 | } else {
93 | var listLength = dayList.hours.length;
94 | var hours = dayList.hours;
95 | var boolean;
96 | for (var i = 0; i < listLength; i++) {
97 | if ((moment(hours[i].opens, "h:m:s").hour() === moment(dayPeriod.opens, "h:m:s").hour()) & (moment(hours[i].closes, "h:m:s").hour() === moment(dayPeriod.closes, "h:m:s").hour())) {
98 | if ((moment(hours[i].opens, "h:m:s").minute() === moment(dayPeriod.opens, "h:m:s").minute()) & (moment(hours[i].closes, "h:m:s").minute() === moment(dayPeriod.closes, "h:m:s").minute())) {
99 | boolean = true;
100 | break;
101 | } else {
102 | boolean = false;
103 | break;
104 | }
105 | //we have to avoid adding 2 objects with the same opening and closing time
106 | } else {
107 | boolean = false;
108 | }
109 | }
110 | if (!(boolean)) {
111 | hours.push({
112 | opens: dayPeriod.opens,
113 | closes: dayPeriod.closes
114 | });
115 | }
116 | }
117 | },
118 | /**
119 | *
120 | * @param {type} periods
121 | */
122 | getWeekPeriod: function(periods) {
123 | console.log(periods)
124 | if (periods instanceof Array) {
125 | for (var i = 0; i < periods.length; i++) {
126 | if ((moment().month() > moment(periods[i].validFrom, "YYYY-MM-DD").month()) & (moment().month() < moment(periods[i].validThrough, "YYYY-MM-DD").month())) {
127 | return periods[i].weekPeriod;
128 | } else if ((moment().month() === moment(periods[i].validFrom, "YYYY-MM-DD").month()) & (moment().month() === moment(periods[i].validThrough, "YYYY-MM-DD").month())) {
129 | if ((moment().date() >= moment(periods[i].validFrom, "YYYY-MM-DD").date()) & (moment().date() <= moment(periods[i].validThrough, "YYYY-MM-DD").date())) {
130 |
131 | return periods[i].weekPeriod;
132 | break;
133 | } else {
134 | continue;
135 | }
136 | }
137 | }
138 | }
139 | },
140 | /**
141 | * We add the opening hours to our ordered array
142 | * @param {type} data
143 | * @returns {undefined}
144 | */
145 | buildPropertyDays: function(data) {
146 | //take the weekPeriod array
147 |
148 | var weekPeriod, _this = this;
149 | if (this.settings.weekPeriods) {
150 |
151 | weekPeriod = this.getWeekPeriod(data);
152 | } else {
153 | weekPeriod = data["weekPeriod"];
154 | }
155 | try {
156 | var propertyDays = this._propertyDays;
157 | $.each(propertyDays, function(days) {
158 |
159 | $.each(weekPeriod, function(day) {
160 | //if we have an Object with the same name,
161 | if (_this.checkDayMatch(propertyDays[days], weekPeriod[day])) {
162 | //we add the openingHours
163 | _this.addOpeningHours(propertyDays[days], weekPeriod[day]);
164 | }
165 | });
166 | });
167 | } catch (e) {
168 | console.log(e);
169 | }
170 | for (var i = 0; i < this._propertyDays.length; i++) {
171 | //taking care the opening hours are ordered
172 | this.arrangeOpeningHours(this._propertyDays[i]);
173 | }
174 | },
175 | /**
176 | * Use to arrange the Opening Hours from a specific day
177 | * @param {type} array
178 | * @returns {unresolved}
179 | */
180 | arrangeOpeningHours: function(array) {
181 | if (array.hours.length > 1) {
182 | var hours = array.hours;
183 | for (var i = 0; i <= hours.length - 2; i++) {
184 |
185 | for (var j = i + 1; j <= hours.length - 1; j++) {
186 |
187 | if ((moment(hours[i].opens, "h:m:s").hour()) === (moment(hours[j].opens, "h:m:s").hour())) {
188 | if ((moment(hours[i].opens, "h:m:s").minute()) > (moment(hours[j].opens, "h:m:s").minute())) {
189 | var aux = hours[i];
190 | hours[i] = hours[j];
191 | hours[j] = aux;
192 | } else {
193 | continue;
194 | }
195 | } else if ((moment(hours[i].opens, "h:m:s").hour()) > (moment(hours[j].opens, "h:m:s").hour())) {
196 | var aux = hours[i];
197 | hours[i] = hours[j];
198 | hours[j] = aux;
199 | }
200 | }
201 | }
202 | }
203 | return array;
204 | },
205 | /**
206 | * Used for the days list from Moment
207 | * @param {type} arrayList
208 | * @returns {unresolved}
209 | */
210 | shiftList: function(arrayList) {
211 | arrayList[arrayList.length] = arrayList[0];
212 | arrayList.shift();
213 | return arrayList;
214 | },
215 | createHeader: function(container, string) {
216 | var header = $('');
217 | header.append('' + string + '');
218 | return $(container).append(header);
219 | },
220 | checkMatchingHours: function(firstList, secondList) {
221 |
222 | for (var i = 0; i < firstList.length; i++) {
223 | for (var j = 0; j < secondList.length; j++) {
224 | if ((moment(firstList[i].opens, "h:m:s").hour() === moment(secondList[i].opens, "h:m:s").hour()) &
225 | (moment(firstList[i].closes, "h:m:s").hour() === moment(secondList[i].closes, "h:m:s").hour())) {
226 | if ((moment(firstList[i].opens, "h:m:s").minute() === moment(secondList[i].opens, "h:m:s").minute()) &
227 | (moment(firstList[i].closes, "h:m:s").minute() === moment(secondList[i].closes, "h:m:s").minute())) {
228 | return true;
229 | } else {
230 | return false;
231 | }
232 | } else {
233 | return false;
234 | }
235 | }
236 | }
237 | },
238 | /**
239 | * Function used to display the Days
240 | *
241 | * @param {type} lang
242 | * @param {type} daysForm
243 | * @returns {unresolved}
244 | */
245 | createMomentDays: function(lang, daysForm) {
246 | moment.lang(lang);
247 |
248 | if (daysForm === "short") {
249 | return this.shiftList(moment.weekdaysShort());
250 | } else if (daysForm === "min") {
251 | return this.shiftList(moment.weekdaysMin());
252 | } else if (daysForm === "normal") {
253 | return this.shiftList(moment.weekdays());
254 | }
255 | },
256 | serie3: function(array, pos, container, momentDays) {
257 | var dayContainer = $('');
258 | var dayElement = $('');
259 | var hourElement = $('');
260 |
261 | if (array[pos].hours.length === 0) {
262 | dayElement.append(momentDays[pos] + "-");
263 | var temp = pos + 2;
264 | for (var j = pos + 2; j < array.length; j++) {
265 | if (array[j].hours.length !== 0) {
266 | dayElement.append(momentDays[j - 1] + ": ");
267 | pos = j - 1;
268 | break;
269 | } else if ((j === array.length - 1) & (array[j].hours.length === 0)) {
270 | dayElement.append(momentDays[j] + ": ");
271 | pos = j;
272 | break;
273 | }
274 | }
275 | hourElement.append(this._additionalData.closedString);
276 | }
277 | else if (array[pos].hours.length !== 0) {
278 | if ((this.checkMatchingHours(array[pos].hours, array[pos + 1].hours)) & (this.checkMatchingHours(array[pos + 1].hours, array[pos + 2].hours))) {
279 | var temp = pos + 2;
280 | dayElement.append(momentDays[pos] + "-");
281 | for (var j = temp; j < array.length; j++) {
282 | if ((array[j].hours.length === 0) || (!(this.checkMatchingHours(array[pos].hours, array[j].hours)))) {
283 | dayElement.append(momentDays[j - 1] + ": ");
284 | pos = j - 1;
285 | break;
286 | } else if ((j === array.length - 1) & (this.checkMatchingHours(array[j].hours, array[pos].hours))) {
287 | dayElement.append(momentDays[j] + ": ");
288 | pos = j;
289 | break;
290 | }
291 | }
292 |
293 | for (var x = 0; x < array[temp].hours.length; x++) {
294 | if (x === array[temp].hours.length - 1) {
295 | hourElement.append(moment(array[temp].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[temp].hours[x].closes, "h:m:s").format('H:mm'));
296 | } else {
297 | hourElement.append(moment(array[temp].hours[x].opens, "h:m:s").format('H:MM') + "-" + moment(array[temp].hours[x].closes, "h:m:s").format('H:mm') + ", ");
298 | }
299 | }
300 | }
301 | else if ((this.checkMatchingHours(array[pos].hours, array[pos + 1].hours)) & (!(this.checkMatchingHours(array[pos + 1].hours, array[pos + 2].hours)))) {
302 | dayElement.append(momentDays[pos] + ", " + momentDays[pos + 1] + ": ");
303 | for (var x = 0; x < array[temp].hours.length; x++) {
304 | if (x === array[temp].hours.length - 1) {
305 | hourElement.append(moment(array[temp].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[temp].hours[x].closes, "h:m:s").format('H:mm'));
306 | } else {
307 |
308 | hourElement.append(moment(array[temp].hours[x].opens, "h:m:s").format('H:MM') + "-" + moment(array[temp].hours[x].closes, "h:m:s").format('H:mm') + ", ");
309 | }
310 | }
311 | pos = pos + 1;
312 | } else if (!(this.checkMatchingHours(array[pos].hours, array[pos + 1].hours))) {
313 | dayElement.append(momentDays[pos] + ": ");
314 | for (var x = 0; x < array[pos].hours.length; x++) {
315 | if (x === array[pos].hours.length - 1) {
316 | hourElement.append(moment(array[pos].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[pos].hours[x].closes, "h:m:s").format('H:mm'));
317 | } else {
318 |
319 | hourElement.append(moment(array[pos].hours[x].opens, "h:m:s").format('H:MM') + "-" + moment(array[pos].hours[x].closes, "h:m:s").format('H:mm') + ", ");
320 | }
321 | }
322 | }
323 | }
324 |
325 | dayContainer.append(dayElement);
326 | dayContainer.append(hourElement);
327 | container.append(dayContainer);
328 | return pos;
329 | },
330 | serie2: function(array, pos, container, momentDays) {
331 | var dayContainer = $('');
332 | var dayElement = $('');
333 | var hourElement = $('');
334 |
335 |
336 | if (array[pos].hours.length === 0) {
337 | dayElement.append(momentDays[pos] + ", " + momentDays[pos + 1] + ": ");
338 | hourElement.append(this._additionalData.closedString);
339 | pos = pos + 1;
340 | } else {
341 | if (this.checkMatchingHours(array[pos].hours, array[pos + 1].hours)) {
342 | dayElement.append(momentDays[pos] + ", " + momentDays[pos + 1] + ": ");
343 | pos = pos + 1;
344 | } else {
345 | dayElement.append(momentDays[pos] + ": ");
346 | }
347 | for (var x = 0; x < array[pos].hours.length; x++) {
348 | if (x === array[pos].hours.length - 1) {
349 | hourElement.append(moment(array[pos].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[pos].hours[x].closes, "h:m:s").format('H:mm'));
350 | } else {
351 |
352 | hourElement.append(moment(array[pos].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[pos].hours[x].closes, "h:m:s").format('H:mm') + ", ");
353 | }
354 |
355 | }
356 | }
357 |
358 | dayContainer.append(dayElement);
359 | dayContainer.append(hourElement);
360 | container.append(dayContainer);
361 | return pos;
362 | },
363 | serie1: function(array, pos, container, momentDays) {
364 | var dayContainer = $('');
365 | var dayElement = $('');
366 | var hourElement = $('');
367 | dayElement.append(momentDays[pos] + ": ");
368 | if (array[pos].hours.length === 0) {
369 | hourElement.append(this._additionalData.closedString);
370 | } else {
371 | for (var x = 0; x < array[pos].hours.length; x++) {
372 | if (x === array[pos].hours.length - 1) {
373 | hourElement.append(moment(array[pos].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[pos].hours[x].closes, "h:m:s").format('H:mm'));
374 | } else {
375 |
376 | hourElement.append(moment(array[pos].hours[x].opens, "h:m:s").format('H:mm') + "-" + moment(array[pos].hours[x].closes, "h:m:s").format('H:mm') + ", ");
377 | }
378 | }
379 | }
380 | dayContainer.append(dayElement);
381 | dayContainer.append(hourElement);
382 | container.append(dayContainer);
383 |
384 | },
385 | /**
386 | *
387 | * @param {type} cont
388 | * @param {type} days
389 | * @param {type} lang
390 | * @param {type} daysType
391 | * @returns {undefined}
392 | */
393 | createOpeningHours: function(cont, days, lang, daysType) {
394 | var momentDays = this.createMomentDays(lang, daysType);
395 |
396 | var container = $(cont);
397 |
398 | this._additionalData = this.getAdditionalData(lang);
399 |
400 | this.createHeader(container, this._additionalData.header);
401 | for (var i = 0; i < days.length; i++) {
402 |
403 | if (i < days.length - 2) {
404 | if ((days[i].hours.length === days[i + 1].hours.length) & (days[i + 1].hours.length === days[i + 2].hours.length)) {
405 | i = this.serie3(days, i, container, momentDays);
406 | }
407 | else if ((days[i].hours.length === days[i + 1].hours.length) & (days[i + 2].hours.length !== days[i].hours.length)) {
408 | i = this.serie2(days, i, container, momentDays);
409 |
410 | }
411 | else if (days[i].hours.length !== days[i + 1].hours.length) {
412 |
413 | this.serie1(days, i, container, momentDays);
414 | }
415 | }
416 | else if (i === days.length - 2) {
417 | if (days[i].hours.length === days[i + 1].hours.length) {
418 | i = this.serie2(days, i, container, momentDays);
419 | } else {
420 | this.serie1(days, i, container, momentDays);
421 | }
422 | }
423 | else if (i === days.length - 1) {
424 | this.serie1(days, i, container, momentDays);
425 | }
426 | }
427 | }
428 | };
429 | $.fn[ pluginName ] = function(options) {
430 | this.each(function() {
431 | if (!$.data(this, "plugin_" + pluginName)) {
432 | $.data(this, "plugin_" + pluginName, new Plugin(this, options));
433 | }
434 | });
435 | // chain jQuery functions
436 | return this;
437 | };
438 | })(jQuery, window, document);
--------------------------------------------------------------------------------