Skip to content

Commit b709289

Browse files
author
Michael Rozman
committed
Merge branch 'develop' of https://github.com/spark3dp/webapp-samples into develop
2 parents 71ef44a + c4e279b commit b709289

File tree

23 files changed

+6716
-4666
lines changed

23 files changed

+6716
-4666
lines changed

assets/css/common.css

+319-281
Large diffs are not rendered by default.

assets/scripts/common.js

+173-173
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,181 @@
11
var common = function ($) {
2-
'use strict';
3-
4-
5-
var shortMonth = function(month){
6-
var shortMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
7-
8-
return shortMonths[month];
9-
}
10-
11-
var commonObj = {
12-
13-
/**
14-
* Loads ajax loader whenever we want
15-
* @param elem - any jquery selector
16-
*/
17-
loadAjaxLogger: function (elem) {
18-
$(elem).load("plugins/ajaxlogger/loggers.html");
19-
},
20-
21-
/**
22-
* UI stuff
23-
*/
24-
setUIFunctionality: function () {
25-
26-
//set listener to tooltip hover
27-
$('.with_hover').hover(
28-
function () {
29-
$(this).next('.stooltip').find('span').show();
30-
},
31-
function () {
32-
$(this).next('.stooltip').find('span').hide();
33-
}
34-
);
35-
36-
//set listener to input focus to remove errors
37-
$('#asset-form').on('keyup', '.error', function () {
38-
if ($(this).val().length > 0) {
39-
$(this).next('.field_error').addClass('hidden');
40-
}
41-
});
42-
43-
//set listener to input focus to remove errors
44-
$('.sample-app-form').on('keyup', '.error', function () {
45-
if ($(this).val().length > 0) {
46-
$(this).next('.field_error').addClass('hidden');
47-
}
48-
});
49-
50-
//set listener to input focus to remove errors
51-
$('.sample-app-form').on('change', '.error', function () {
52-
if ($(this).val().length > 0) {
53-
$(this).next('.field_error').addClass('hidden');
54-
}
55-
});
56-
57-
//checkboxes
58-
//$('.chk')
59-
60-
},
61-
/**
62-
* Validates input and sets proper errors
63-
*/
64-
validateInput: function (elem) {
65-
66-
if (elem.val().length) {
67-
$('.error').removeClass('error');
68-
$('.error').next('.field_error').addClass('hidden');
69-
return true;
70-
} else {
71-
elem.addClass('error');
72-
elem.next('.field_error').removeClass('hidden');
73-
return false;
74-
}
75-
76-
},
77-
78-
/**
79-
* Adjsut string length to desired length
80-
*/
81-
maxLength: function(input, desiredLength, hidePoints) {
82-
if (input.length <= desiredLength) {
83-
return input;
84-
} else {
85-
return input.substring(0, desiredLength) + (!hidePoints ? '...' : '');
86-
}
87-
},
88-
89-
/**
90-
* Return date in the format mm-dd-yyyy
91-
* @param {Date} myDate - The Date object
92-
* @returns {string} - Formatted date
93-
*/
94-
formatDate: function(myDate){
95-
var yyyy = myDate.getFullYear().toString();
96-
var mm = (myDate.getMonth()+1).toString(); // getMonth() is zero-based
97-
var dd = myDate.getDate().toString();
98-
return (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]) + '-' + yyyy;
99-
},
100-
formatDateHuman: function(myDateString){
101-
var myDate = new Date(myDateString);
102-
var day = myDate.getDate().toString(),
103-
month = shortMonth(myDate.getMonth()),
104-
yyyy = myDate.getFullYear().toString();
105-
106-
return month + ' ' + day + ', ' + yyyy;
107-
},
108-
jsonToParams: function (jsonObj) {
109-
var str = '';
110-
for (var key in jsonObj) {
111-
str += key + '=' + jsonObj[key] + '&';
112-
}
113-
114-
return str;
115-
},
116-
/**
117-
* @description - Transform parameter strings to array of params
118-
* @param {String} prmstr - The GET query string
119-
* @returns {Object} - Associative array of parameters
120-
*/
121-
transformToAssocArray: function (prmstr) {
122-
var params = {};
123-
124-
if (prmstr) {
125-
var prmarr = prmstr.split('&');
126-
for (var i = 0; i < prmarr.length; i++) {
127-
var tmparr = prmarr[i].split('=');
128-
params[tmparr[0]] = tmparr[1];
129-
}
130-
}
131-
132-
return params;
133-
},
134-
135-
/**
136-
* @description - Extract params from URL
137-
* @param {String} prmstr - The GET query string
138-
* @returns {Object} - URL parameters
139-
*/
140-
extractParamsFromURL: function (prmstr) {
141-
prmstr = prmstr || window.location.search.substr(1) || window.location.hash.substr(1);
142-
143-
return prmstr ? this.transformToAssocArray(prmstr) : {};
144-
},
145-
146-
/**
147-
* Run some stuff as soon as everyting loads
148-
*/
149-
runOnLoad: function(){
150-
151-
//open the sample in a new window
152-
$('.sample-app-header').find('.si-popup-icon').on('click', function(e){
153-
e.preventDefault();
154-
var w = $('#container').width() + 30,
155-
h = 700,
156-
left = (screen.width / 2) - (w / 2),
157-
top = (screen.height / 3) - (h / 3);
158-
window.open(window.location.href + '?popup=true', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
159-
});
160-
161-
//remove open in new window button inside an opened window
162-
if (this.extractParamsFromURL().popup){
163-
$('.sample-app-header').find('.si-popup-icon').remove();
164-
}
165-
}
166-
167-
}
168-
169-
return commonObj;
2+
'use strict';
3+
4+
5+
var shortMonth = function (month) {
6+
var shortMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
7+
8+
return shortMonths[month];
9+
};
10+
11+
return {
12+
13+
/**
14+
* Loads ajax loader whenever we want
15+
* @param elem - any jquery selector
16+
*/
17+
loadAjaxLogger: function (elem) {
18+
$(elem).load("plugins/ajaxlogger/loggers.html");
19+
},
20+
21+
/**
22+
* UI stuff
23+
*/
24+
setUIFunctionality: function () {
25+
26+
//set listener to tooltip hover
27+
$('.with_hover').hover(
28+
function () {
29+
$(this).next('.stooltip').find('span').show();
30+
},
31+
function () {
32+
$(this).next('.stooltip').find('span').hide();
33+
}
34+
);
35+
36+
//set listener to input focus to remove errors
37+
$('#asset-form').on('keyup', '.error', function () {
38+
if ($(this).val().length > 0) {
39+
$(this).next('.field_error').addClass('hidden');
40+
}
41+
});
42+
43+
//set listener to input focus to remove errors
44+
$('.sample-app-form').on('keyup', '.error', function () {
45+
if ($(this).val().length > 0) {
46+
$(this).next('.field_error').addClass('hidden');
47+
}
48+
});
49+
50+
//set listener to input focus to remove errors
51+
$('.sample-app-form').on('change', '.error', function () {
52+
if ($(this).val().length > 0) {
53+
$(this).next('.field_error').addClass('hidden');
54+
}
55+
});
56+
57+
//checkboxes
58+
//$('.chk')
59+
60+
},
61+
/**
62+
* Validates input and sets proper errors
63+
*/
64+
validateInput: function (elem) {
65+
66+
if (elem.val().length) {
67+
$('.error').removeClass('error');
68+
$('.error').next('.field_error').addClass('hidden');
69+
return true;
70+
} else {
71+
elem.addClass('error');
72+
elem.next('.field_error').removeClass('hidden');
73+
return false;
74+
}
75+
76+
},
77+
78+
/**
79+
* Adjsut string length to desired length
80+
*/
81+
maxLength: function (input, desiredLength, hidePoints) {
82+
if (input.length <= desiredLength) {
83+
return input;
84+
} else {
85+
return input.substring(0, desiredLength) + (!hidePoints ? '...' : '');
86+
}
87+
},
88+
89+
/**
90+
* Return date in the format mm-dd-yyyy
91+
* @param {Date} myDate - The Date object
92+
* @returns {string} - Formatted date
93+
*/
94+
formatDate: function (myDate) {
95+
var yyyy = myDate.getFullYear().toString();
96+
var mm = (myDate.getMonth() + 1).toString(); // getMonth() is zero-based
97+
var dd = myDate.getDate().toString();
98+
return (mm[1] ? mm : "0" + mm[0]) + '-' + (dd[1] ? dd : "0" + dd[0]) + '-' + yyyy;
99+
},
100+
formatDateHuman: function (myDateString) {
101+
var myDate = new Date(myDateString);
102+
var day = myDate.getDate().toString(),
103+
month = shortMonth(myDate.getMonth()),
104+
yyyy = myDate.getFullYear().toString();
105+
106+
return month + ' ' + day + ', ' + yyyy;
107+
},
108+
jsonToParams: function (jsonObj) {
109+
var str = '';
110+
for (var key in jsonObj) {
111+
str += key + '=' + jsonObj[key] + '&';
112+
}
113+
114+
return str;
115+
},
116+
/**
117+
* @description - Transform parameter strings to array of params
118+
* @param {String} prmstr - The GET query string
119+
* @returns {Object} - Associative array of parameters
120+
*/
121+
transformToAssocArray: function (prmstr) {
122+
var params = {};
123+
124+
if (prmstr) {
125+
var prmarr = prmstr.split('&');
126+
for (var i = 0; i < prmarr.length; i++) {
127+
var tmparr = prmarr[i].split('=');
128+
params[tmparr[0]] = tmparr[1];
129+
}
130+
}
131+
132+
return params;
133+
},
134+
135+
/**
136+
* @description - Extract params from URL
137+
* @param {String} prmstr - The GET query string
138+
* @returns {Object} - URL parameters
139+
*/
140+
extractParamsFromURL: function (prmstr) {
141+
prmstr = prmstr || window.location.search.substr(1) || window.location.hash.substr(1);
142+
143+
return prmstr ? this.transformToAssocArray(prmstr) : {};
144+
},
145+
146+
/**
147+
* Run some stuff as soon as everyting loads
148+
*/
149+
runOnLoad: function () {
150+
151+
//open the sample in a new window
152+
$('.sample-app-header').find('.si-popup-icon').on('click', function (e) {
153+
e.preventDefault();
154+
var w = $('#container').width() + 30,
155+
h = 700,
156+
left = (screen.width / 2) - (w / 2),
157+
top = (screen.height / 3) - (h / 3);
158+
window.open(window.location.href + '?popup=true', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
159+
});
160+
161+
//remove open in new window button inside an opened window
162+
if (this.extractParamsFromURL().popup) {
163+
$('.sample-app-header').find('.si-popup-icon').remove();
164+
}
165+
}
166+
167+
};
170168

171169
}(jQuery);
172170

173171
//run some basic stuff
174172
common.runOnLoad();
175173

176174
//file size to human readable
177-
Object.defineProperty(Number.prototype,'fileSize',{value:function(a,b,c,d){
178-
return (a=a?[1e3,'k','B']:[1024,'K','iB'],b=Math,c=b.log,
179-
d=c(this)/c(a[0])|0,this/b.pow(a[0],d)).toFixed(0)
180-
+''+(d?(a[1]+'MGTPEZY')[--d]+a[2]:'Bytes');
181-
},writable:false,enumerable:false});
175+
Object.defineProperty(Number.prototype, 'fileSize', {
176+
value: function (a, b, c, d) {
177+
return (a = a ? [1e3, 'k', 'B'] : [1024, 'K', 'iB'], b = Math, c = b.log,
178+
d = c(this) / c(a[0]) | 0, this / b.pow(a[0], d)).toFixed(0)
179+
+ '' + (d ? (a[1] + 'MGTPEZY')[--d] + a[2] : 'Bytes');
180+
}, writable: false, enumerable: false
181+
});

0 commit comments

Comments
 (0)