Skip to content

Commit fdeabf1

Browse files
authored
Merge pull request #11 from CodingCarlos/dev
v0.1 functions
2 parents 0e43300 + 7852d3c commit fdeabf1

File tree

4 files changed

+104
-59
lines changed

4 files changed

+104
-59
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ To configure the chat, just use the object passed on IASChat instantiation. *Bol
4747
- hashSign: String Symbol or string to add before url hash when chat open (Default: '?'. I.e.: url#existentHash**?**ias=true)
4848
- defaultSupportName: String Default support name (if no supporter assigned)
4949
- defaultSupportPic: String Default support picture (if no supporter assigned)
50+
- uploadFiles: Boolean Enable or disable the option to upload and send files (Default: true)
51+
- onlyPictures: Boolean Allow only pictures, or all file types (Default: true)
5052

5153
In IASChatProvider, there are some extra features:
5254
- container: String Container for support panel (*#identifier* or *.className*. Default: *body*)
5355
- chatContainer: String Container for chat (*#identifier* or *.className*. Default: *body* or support container)
5456

55-
In the future, early future, I hope to add...
56-
- uploadFiles: Boolean Enable or disable the option to upload and send pictures.
57-
- onlyPictures: Boolean Allow only pictures, or all file types.
5857

5958
*I'm open to any suggestion or request for more configuration params. Don't hesitate to open a new Issue*
6059

@@ -118,9 +117,6 @@ Initialize the support user, and done.
118117
### Secure the panel
119118
This is your work. Support pannel in demo folder is not really a support panel, but a demo. This is not a fully control panel app, just a support chat "component" to add to your existing app.
120119

121-
122-
## Responsiveness
123-
Nope, right now is not desktop/tablet responsive, just mobile, but I'm doing my best to add larger screen support.
124120

125121
## Contribute
126122
You can use this code as you like. If you find a bug, or want to ask for a feature, just open an issue, and we'll do our best. If you can fix it, do a pull request to ``dev`` branch, and we promise to review it as fast as possible to merge it.

dist/chat.js

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function IASChat(config) {
1818
var defaultSupportPic = config.defaultSupportPic || 'https://s3.amazonaws.com/uifaces/faces/twitter/robertovivancos/128.jpg';
1919
var container = config.container || null;
2020
var hashSign = config.hashSign || '?';
21+
var uploadFiles = config.uploadFiles || true;
22+
var onlyPictures = config.onlyPictures || true;
2123

2224
// Prepare interface
2325
printInterface(container);
@@ -133,7 +135,7 @@ function IASChat(config) {
133135
}
134136

135137
// Also add the styles from css/style.css
136-
ias += '<style>#ias {font-family: \'Roboto\',\'Helvetica\',\'Arial\',sans-serif!important;position: fixed;top: 0;left: 0;height: 100%;width: 100%;z-index: 999;}#ias.hidden {display: none;}#ias_topbar {background-color: #ff9800;color: #fff;fill: #fff;height: 56px;width: 100%;}#ias_topbar #ias_topbar-pic {padding: 8px 16px;width: 40px;height: 40px;float: left;}#ias_topbar #ias_topbar-pic img {height: 100%;border-radius: 50%;}#ias_topbar #ias_topbar-text {float: left;margin-left: 6px;margin-top: 14px;font-size: 24px;}#ias_topbar #ias_topbar-close {color: #fff;float: right;font-size: 24px;margin: 16px 16px 0 0;}#ias_messages {background: #f7f8fb;height: calc(100% - 117px);overflow: auto;padding-top: 12px;}.ias_message {margin: 4px 8px;padding: 4px 12px;}.ias_message-sent {text-align: right;}.ias_message span {background-color: #fff;padding: 4px 12px;border-radius: 5px 5px 0 5px;box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);color: #333;display: inline-block;}.ias_message span img {margin: 8px 0 4px;max-width: 300px;max-height: 264px;}#ias_attachment {position: fixed;bottom: 48px;background: #fff;width: 100%;height: 220px;text-align: center;padding: 8px;box-sizing: border-box;border-top: 1px solid #efefef;}#ias_attachment.hidden {display: none;}#ias_attachment-close {position: absolute;top: 8px;right: 8px;}#ias_attachment #ias_attachment-preview img {max-height: 100%;max-width: 100%;}#ias_write {background-color: #fff;border-top: 1px solid #efefef;height: 48px;position: fixed;bottom: 0;left: 0;width: 100%;}#ias_write input {border: 0;border-bottom: 1px solid #ff9800;height: 31px;left: 0;margin: 0 48px;outline: none;padding: 8px 8px 0px 8px;position: absolute;top: 0;width: 70%;width: calc(100% - 122px);}#ias_write #ias_write-attachment svg {position: absolute;left: 12px;top: 13px;}#ias_write #ias_write-attachment input#ias_write-attachment-uploadFile {width: 24px;margin: 0px 4px;opacity: 0;position: absolute;top: 4px;left: 0px;}#ias_write button {background-color: #fff;border: none;position: fixed;right: 12px;bottom: 5px;border-radius: 50%;font-size: 24px;width: 34px;padding: 0;overflow: hidden;line-height: normal;}#ias-show {background-color: #ff9800;border-radius: 50%;bottom: 16px;box-shadow: 0 1px 1.5px 0 rgba(0, 0, 0, .12), 0 1px 1px 0 rgba(0, 0, 0, .24);box-sizing: border-box;color: #fff;fill: #fff;height: 56px;padding: 16px;position: fixed;right: 16px;width: 56px;}</style>';
138+
ias += '<style>#ias {font-family: \'Roboto\',\'Helvetica\',\'Arial\',sans-serif!important;position: fixed;top: 0;left: 0;height: 100%;width: 100%;z-index: 999;}#ias.hidden {display: none;}#ias_topbar {background-color: #ff9800;color: #fff;fill: #fff;height: 56px;width: 100%;}#ias_topbar #ias_topbar-pic {padding: 8px 16px;width: 40px;height: 40px;float: left;}#ias_topbar #ias_topbar-pic img {height: 100%;border-radius: 50%;}#ias_topbar #ias_topbar-text {float: left;margin-left: 6px;margin-top: 14px;font-size: 24px;}#ias_topbar #ias_topbar-close {color: #fff;float: right;font-size: 24px;margin: 16px 16px 0 0;}#ias_messages {background: #f7f8fb;height: calc(100% - 117px);overflow: auto;padding-top: 12px;}.ias_message {margin: 4px 8px;padding: 4px 12px;}.ias_message-sent {text-align: right;}.ias_message span {background-color: #fff;padding: 4px 12px;border-radius: 5px 5px 0 5px;box-shadow: 1px 1px 5px rgba(0, 0, 0, .1);color: #333;display: inline-block;}.ias_message span img {margin: 8px 0 4px;max-width: 300px;max-height: 264px;}#ias_attachment {position: fixed;bottom: 48px;background: #fff;width: 100%;height: 220px;text-align: center;padding: 8px;box-sizing: border-box;border-top: 1px solid #efefef;}#ias_attachment.hidden {display: none;}#ias_attachment-close {position: absolute;top: 8px;right: 8px;}#ias_attachment #ias_attachment-preview img {max-height: 100%;max-width: 100%;}#ias_write {background-color: #fff;border-top: 1px solid #efefef;height: 48px;position: fixed;bottom: 0;left: 0;width: 100%;}#ias_write input {border: 0;border-bottom: 1px solid #ff9800;height: 31px;left: 0;margin: 0 48px;outline: none;padding: 8px 8px 0px 8px;position: absolute;top: 0;width: 70%;width: calc(100% - 122px);}#ias_write #ias_write-attachment svg {position: absolute;left: 12px;top: 13px;}#ias_write #ias_write-attachment input#ias_write-attachment-uploadFile {width: 24px;margin: 0px 4px;opacity: 0;position: absolute;top: 4px;left: 0px;}#ias_write button {background-color: #fff;border: none;position: fixed;right: 12px;bottom: 5px;border-radius: 50%;font-size: 24px;width: 34px;padding: 0;overflow: hidden;line-height: normal;}#ias-show {background-color: #ff9800;border-radius: 50%;bottom: 16px;box-shadow: 0 1px 1.5px 0 rgba(0, 0, 0, .12), 0 1px 1px 0 rgba(0, 0, 0, .24);box-sizing: border-box;color: #fff;fill: #fff;height: 56px;padding: 16px;position: fixed;right: 16px;width: 56px;}@media screen and (min-width: 842px) {#ias{height: 600px;width: 368px;position: fixed;right: 0;bottom: 0;top: auto;overflow: hidden;left: auto;}#ias_message {height: 483px;}#ias_attachment, #ias_write {position: absolute;}}</style>';
137139

138140
var printplace = null;
139141

@@ -169,6 +171,13 @@ function IASChat(config) {
169171

170172
// Form colors
171173
form.children[0].style.borderColor = inputBorderColor;
174+
175+
// Upload form buttons
176+
if(!uploadFiles) {
177+
form.children[0].style.display = 'none';
178+
form.children[1].style.margin = '0 16px';
179+
form.children[1].style.width = 'calc(100% - 88px)';
180+
}
172181
}
173182

174183

@@ -199,7 +208,7 @@ function IASChat(config) {
199208

200209
var text = e.srcElement.children[1].value
201210

202-
if(text === '') {
211+
if(text === '' && attatchment === null) {
203212
console.log('tried to send empty form. Rejected.');
204213
return false;
205214
}
@@ -419,43 +428,48 @@ function IASChat(config) {
419428

420429
// File or Blob named mountains.jpg
421430
var file = attatchment; // uploadFile.files[0];
431+
var metadata;
422432

423433
if(!file) {
424434
console.error('Empty file');
425435
return false;
426436
}
427437

428-
var extension = validateExtension(file);
438+
if(onlyPictures) {
429439

430-
if(extension === null) {
431-
console.error('Invalid file extension');
432-
return false;
433-
}
440+
var extension = validateExtension(file);
434441

435-
var contentType = '';
436-
switch(extension) {
437-
case '.jpg':
438-
case '.jpeg':
439-
contentType = 'image/jpeg';
440-
break;
442+
if(extension === null) {
443+
console.error('Invalid file extension');
444+
return false;
445+
}
441446

442-
case '.png':
443-
contentType = 'image/png';
444-
break;
447+
var contentType = '';
448+
switch(extension) {
449+
case '.jpg':
450+
case '.jpeg':
451+
contentType = 'image/jpeg';
452+
break;
445453

446-
case '.bmp':
447-
contentType = 'image/bmp';
448-
break;
454+
case '.png':
455+
contentType = 'image/png';
456+
break;
449457

450-
case '.gif':
451-
contentType = 'image/gif';
452-
break;
453-
}
458+
case '.bmp':
459+
contentType = 'image/bmp';
460+
break;
454461

455-
// Create the file metadata
456-
var metadata = {
457-
contentType: contentType
458-
};
462+
case '.gif':
463+
contentType = 'image/gif';
464+
break;
465+
}
466+
467+
// Create the file metadata
468+
metadata = {
469+
contentType: contentType
470+
};
471+
472+
}
459473

460474
// Upload file and metadata to the object 'images/mountains.jpg'
461475
var uploadTask = storageRef.child('images/' + uid + '/' + file.name).put(file, metadata);

js/chat.js

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function IASChat(config) {
1818
var defaultSupportPic = config.defaultSupportPic || 'https://s3.amazonaws.com/uifaces/faces/twitter/robertovivancos/128.jpg';
1919
var container = config.container || null;
2020
var hashSign = config.hashSign || '?';
21+
var uploadFiles = config.uploadFiles || true;
22+
var onlyPictures = config.onlyPictures || true;
2123

2224
// Prepare interface
2325
printInterface(container);
@@ -169,6 +171,13 @@ function IASChat(config) {
169171

170172
// Form colors
171173
form.children[0].style.borderColor = inputBorderColor;
174+
175+
// Upload form buttons
176+
if(!uploadFiles) {
177+
form.children[0].style.display = 'none';
178+
form.children[1].style.margin = '0 16px';
179+
form.children[1].style.width = 'calc(100% - 88px)';
180+
}
172181
}
173182

174183

@@ -199,7 +208,7 @@ function IASChat(config) {
199208

200209
var text = e.srcElement.children[1].value
201210

202-
if(text === '') {
211+
if(text === '' && attatchment === null) {
203212
console.log('tried to send empty form. Rejected.');
204213
return false;
205214
}
@@ -419,43 +428,48 @@ function IASChat(config) {
419428

420429
// File or Blob named mountains.jpg
421430
var file = attatchment; // uploadFile.files[0];
431+
var metadata;
422432

423433
if(!file) {
424434
console.error('Empty file');
425435
return false;
426436
}
427437

428-
var extension = validateExtension(file);
438+
if(onlyPictures) {
429439

430-
if(extension === null) {
431-
console.error('Invalid file extension');
432-
return false;
433-
}
440+
var extension = validateExtension(file);
434441

435-
var contentType = '';
436-
switch(extension) {
437-
case '.jpg':
438-
case '.jpeg':
439-
contentType = 'image/jpeg';
440-
break;
442+
if(extension === null) {
443+
console.error('Invalid file extension');
444+
return false;
445+
}
441446

442-
case '.png':
443-
contentType = 'image/png';
444-
break;
447+
var contentType = '';
448+
switch(extension) {
449+
case '.jpg':
450+
case '.jpeg':
451+
contentType = 'image/jpeg';
452+
break;
445453

446-
case '.bmp':
447-
contentType = 'image/bmp';
448-
break;
454+
case '.png':
455+
contentType = 'image/png';
456+
break;
449457

450-
case '.gif':
451-
contentType = 'image/gif';
452-
break;
453-
}
458+
case '.bmp':
459+
contentType = 'image/bmp';
460+
break;
454461

455-
// Create the file metadata
456-
var metadata = {
457-
contentType: contentType
458-
};
462+
case '.gif':
463+
contentType = 'image/gif';
464+
break;
465+
}
466+
467+
// Create the file metadata
468+
metadata = {
469+
contentType: contentType
470+
};
471+
472+
}
459473

460474
// Upload file and metadata to the object 'images/mountains.jpg'
461475
var uploadTask = storageRef.child('images/' + uid + '/' + file.name).put(file, metadata);

template/ias_style.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,25 @@
151151
right: 16px;
152152
width: 56px;
153153
}
154+
155+
@media screen and (min-width: 842px) {
156+
#ias {
157+
height: 600px;
158+
width: 368px;
159+
position: fixed;
160+
right: 0;
161+
bottom: 0;
162+
top: auto;
163+
overflow: hidden;
164+
left: auto;
165+
}
166+
167+
#ias_message {
168+
height: 483px;
169+
}
170+
171+
#ias_attachment, #ias_write {
172+
position: absolute;
173+
}
174+
}
154175
</style>

0 commit comments

Comments
 (0)