Skip to content

Commit

Permalink
Merge pull request #16 from CodingCarlos/dev
Browse files Browse the repository at this point in the history
Fixed #14
  • Loading branch information
CodingCarlos authored Mar 7, 2017
2 parents fdeabf1 + 1ac4b12 commit e454370
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ To configure the chat, just use the object passed on IASChat instantiation. *Bol
- topbarColor: Color Chat topbar text and icons color
- buttonBg: Color Show button background color
- buttonColor: Color Show button text/icon color
- buttonIcon: String Image URI for the icon you want to add in the open button. SVG or PNG recommended, but all image types should work
- inputBorderColor: Color Chat text input border bottom color
- container: String Container for chat (*#identifier* or *.className*)
- hashSign: String Symbol or string to add before url hash when chat open (Default: '?'. I.e.: url#existentHash**?**ias=true)
Expand Down
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h1>User side support</h1>
button: true,
// topbarBg: 'lightgrey',
// topbarColor: '#000',
// buttonIcon: 'http://simpleicon.com/wp-content/uploads/rocket.png',
// buttonBg: 'red',
// buttonColor: '#ccc',
// inputBorderColor: 'rgba(0, 0, 0, .2)',
Expand Down
62 changes: 52 additions & 10 deletions dist/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function IASChat(config) {
var topbarColor = config.topbarColor || textColor;
var buttonBg = config.buttonBg || mainColor;
var buttonColor = config.buttonColor || textColor;
var buttonIcon = config.buttonIcon || null;
var inputBorderColor = config.inputBorderColor || mainColor;
var defaultSupportName = config.defaultSupportName || 'Support chat';
var defaultSupportPic = config.defaultSupportPic || 'https://s3.amazonaws.com/uifaces/faces/twitter/robertovivancos/128.jpg';
Expand Down Expand Up @@ -43,6 +44,9 @@ function IASChat(config) {

var attatchment = null;

var lastHash = '';
var lastPage = '';

// Listen event submit
if(show) {
show.addEventListener('click', showIAS.bind(this));
Expand All @@ -60,12 +64,8 @@ function IASChat(config) {
// Set user
setUser(config);

// Check url hash visibility
if(visibilityUrlHash() === true) {
showIAS();
} else {
hideIAS();
}
// Detect hash change to update IAS visibility
hashChange();


return {
Expand Down Expand Up @@ -178,6 +178,16 @@ function IASChat(config) {
form.children[1].style.margin = '0 16px';
form.children[1].style.width = 'calc(100% - 88px)';
}

// If changed button icon
if(buttonIcon) {
var icon = document.createElement('img');
icon.style.width = '24px';
icon.style.height = '24px';
icon.setAttribute('src', buttonIcon);
document.getElementById('ias-show').removeChild(document.getElementById('ias-show').firstChild);
document.getElementById('ias-show').appendChild(icon);
}
}


Expand Down Expand Up @@ -366,15 +376,47 @@ function IASChat(config) {
} else {
window.location.hash += '#ias=true';
}

lastPage = window.location.href.split('#')[0]

setTimeout(hashChange, 300);
}
}

function remUrlHash() {
if(window.location.hash) {
if(window.location.hash.indexOf( hashSign + 'ias=true') !== -1) {
window.location.hash = window.location.hash.replace( hashSign + 'ias=true', '');
} else if(window.location.hash.indexOf('#ias=true') !== -1) {
window.location.hash = window.location.hash.replace('ias=true', '');

if(lastPage === window.location.href.split('#')[0] && (lastHash.indexOf( hashSign + 'ias=true') !== -1 || lastHash.indexOf('#ias=true') !== -1)) {
window.history.back();
} else {
if(window.location.hash.indexOf( hashSign + 'ias=true') !== -1) {
window.location.hash = window.location.hash.replace( hashSign + 'ias=true', '');
} else if(window.location.hash.indexOf('#ias=true') !== -1) {
window.location.hash = window.location.hash.replace('ias=true', '');
}
}
}
}

function hashChange() {

var isHash = visibilityUrlHash();

if(window.location.hash !== lastHash) {

lastHash = window.location.hash;

if(isHash) {
showIAS();
} else {
hideIAS();
}

setTimeout(hashChange, 300);

} else {
if(isHash) {
setTimeout(hashChange, 300);
}
}
}
Expand Down
62 changes: 52 additions & 10 deletions js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function IASChat(config) {
var topbarColor = config.topbarColor || textColor;
var buttonBg = config.buttonBg || mainColor;
var buttonColor = config.buttonColor || textColor;
var buttonIcon = config.buttonIcon || null;
var inputBorderColor = config.inputBorderColor || mainColor;
var defaultSupportName = config.defaultSupportName || 'Support chat';
var defaultSupportPic = config.defaultSupportPic || 'https://s3.amazonaws.com/uifaces/faces/twitter/robertovivancos/128.jpg';
Expand Down Expand Up @@ -43,6 +44,9 @@ function IASChat(config) {

var attatchment = null;

var lastHash = '';
var lastPage = '';

// Listen event submit
if(show) {
show.addEventListener('click', showIAS.bind(this));
Expand All @@ -60,12 +64,8 @@ function IASChat(config) {
// Set user
setUser(config);

// Check url hash visibility
if(visibilityUrlHash() === true) {
showIAS();
} else {
hideIAS();
}
// Detect hash change to update IAS visibility
hashChange();


return {
Expand Down Expand Up @@ -178,6 +178,16 @@ function IASChat(config) {
form.children[1].style.margin = '0 16px';
form.children[1].style.width = 'calc(100% - 88px)';
}

// If changed button icon
if(buttonIcon) {
var icon = document.createElement('img');
icon.style.width = '24px';
icon.style.height = '24px';
icon.setAttribute('src', buttonIcon);
document.getElementById('ias-show').removeChild(document.getElementById('ias-show').firstChild);
document.getElementById('ias-show').appendChild(icon);
}
}


Expand Down Expand Up @@ -366,15 +376,47 @@ function IASChat(config) {
} else {
window.location.hash += '#ias=true';
}

lastPage = window.location.href.split('#')[0]

setTimeout(hashChange, 300);
}
}

function remUrlHash() {
if(window.location.hash) {
if(window.location.hash.indexOf( hashSign + 'ias=true') !== -1) {
window.location.hash = window.location.hash.replace( hashSign + 'ias=true', '');
} else if(window.location.hash.indexOf('#ias=true') !== -1) {
window.location.hash = window.location.hash.replace('ias=true', '');

if(lastPage === window.location.href.split('#')[0] && (lastHash.indexOf( hashSign + 'ias=true') !== -1 || lastHash.indexOf('#ias=true') !== -1)) {
window.history.back();
} else {
if(window.location.hash.indexOf( hashSign + 'ias=true') !== -1) {
window.location.hash = window.location.hash.replace( hashSign + 'ias=true', '');
} else if(window.location.hash.indexOf('#ias=true') !== -1) {
window.location.hash = window.location.hash.replace('ias=true', '');
}
}
}
}

function hashChange() {

var isHash = visibilityUrlHash();

if(window.location.hash !== lastHash) {

lastHash = window.location.hash;

if(isHash) {
showIAS();
} else {
hideIAS();
}

setTimeout(hashChange, 300);

} else {
if(isHash) {
setTimeout(hashChange, 300);
}
}
}
Expand Down

0 comments on commit e454370

Please sign in to comment.