Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browser-sync-client

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-sync-client - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

113

dist/index.js

@@ -40,2 +40,6 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

if (data.override) {
return true;
}
var canSync = true;

@@ -812,3 +816,2 @@

exports.init = function (options) {
if (shouldReload && options.reloadOnRestart) {

@@ -841,3 +844,3 @@ utils.reloadBrowser();

socket.on("disconnect", function () {
notify.flash("Disconnected From BrowserSync");
notify.flash("Disconnected from BrowserSync");
shouldReload = true;

@@ -921,10 +924,11 @@ });

if (bs.canSync(data, OPT_PATH)) {
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var elem = bs.utils.getSingleElement(data.tagName, data.index);
var elem = bs.utils.getSingleElement(data.tagName, data.index);
if (elem) {
exports.canEmitEvents = false;
eventManager.triggerClick(elem);
}
if (elem) {
exports.canEmitEvents = false;
eventManager.triggerClick(elem);
}

@@ -988,10 +992,11 @@ };

if (bs.canSync(data, OPT_PATH)) {
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var elem = bs.utils.getSingleElement(data.tagName, data.index);
var elem = bs.utils.getSingleElement(data.tagName, data.index);
if (elem) {
elem.value = data.value;
return elem;
}
if (elem) {
elem.value = data.value;
return elem;
}

@@ -1085,13 +1090,18 @@

return function (data) {
if (bs.canSync(data, OPT_PATH)) {
var elem = bs.utils.getSingleElement(data.tagName, data.index);
exports.canEmitEvents = false;
if (elem && data.type === "submit") {
elem.submit();
}
if (elem && data.type === "reset") {
elem.reset();
}
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var elem = bs.utils.getSingleElement(data.tagName, data.index);
exports.canEmitEvents = false;
if (elem && data.type === "submit") {
elem.submit();
}
if (elem && data.type === "reset") {
elem.reset();
}
return false;

@@ -1173,23 +1183,22 @@ };

if (bs.canSync(data, OPT_PATH)) {
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
exports.canEmitEvents = false;
exports.canEmitEvents = false;
var elem = bs.utils.getSingleElement(data.tagName, data.index);
var elem = bs.utils.getSingleElement(data.tagName, data.index);
if (elem) {
if (data.type === "radio") {
elem.checked = true;
}
if (data.type === "checkbox") {
elem.checked = data.checked;
}
if (data.tagName === "SELECT") {
elem.value = data.value;
}
return elem;
if (elem) {
if (data.type === "radio") {
elem.checked = true;
}
return false;
if (data.type === "checkbox") {
elem.checked = data.checked;
}
if (data.tagName === "SELECT") {
elem.value = data.value;
}
return elem;
}
return false;

@@ -1234,3 +1243,3 @@ };

exports.init = function (bs) {
bs.socket.on(EVENT_NAME, exports.socketEvent());
bs.socket.on(EVENT_NAME, exports.socketEvent(bs));
};

@@ -1242,10 +1251,14 @@

exports.socketEvent = function (bs) {
return function (data) {
if (data.override || bs.canSync(data, OPT_PATH)) {
if (data.path) {
exports.setPath(data.path);
} else {
exports.setUrl(data.url);
}
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
if (data.path) {
exports.setPath(data.path);
} else {
exports.setUrl(data.url);
}
};

@@ -1297,2 +1310,6 @@ };

if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var scrollSpace = utils.getScrollSpace();

@@ -1302,6 +1319,2 @@

if (!bs.canSync(data, OPT_PATH)) {
return false;
}
if (bs.options && bs.options.scrollProportionally) {

@@ -1308,0 +1321,0 @@ return window.scrollTo(0, scrollSpace.y * data.position.proportional); // % of y axis of scroll to px

@@ -1,1 +0,1 @@

!function t(e,n,o){function i(s,c){if(!n[s]){if(!e[s]){var a="function"==typeof require&&require;if(!c&&a)return a(s,!0);if(r)return r(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=n[s]={exports:{}};e[s][0].call(u.exports,function(t){var n=e[s][1][t];return i(n?n:t)},u,u.exports,t,e,n,o)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;s<o.length;s++)i(o[s]);return i}({1:[function(t,e){"use strict";function n(t){return"undefined"==typeof t}function o(t,e){for(var n=0,o=e.split("."),i=o.length;i>n;n++){if(!t||"object"!=typeof t)return!1;t=t[o[n]]}return"undefined"==typeof t?!1:t}var i=t("./socket"),r=t("./emitter"),s=(t("./notify"),t("./browser.utils")),c=function(t){this.options=t,this.socket=i,this.emitter=r,this.utils=s.utils;var e=this;i.on("options:set",function(t){r.emit("notify","Setting options..."),e.options=t.options})};c.prototype.canSync=function(t,e){t=t||{};var n=!0;return e&&(n=this.getOption(e)),n&&t.url===window.location.pathname},c.prototype.getOption=function(t){if(t&&t.match(/\./))return o(this.options,t);var e=this.options[t];return n(e)?!1:e},e.exports=c},{"./browser.utils":2,"./emitter":5,"./notify":16,"./socket":17}],2:[function(t,e,n){"use strict";n.getWindow=function(){return window},n.getDocument=function(){return document},n.utils={getBrowserScrollPosition:function(){var t,e,o=n.getWindow(),i=n.getDocument(),r=i.documentElement,s=i.body;return void 0!==o.pageYOffset?(t=o.pageXOffset,e=o.pageYOffset):(t=r.scrollLeft||s.scrollLeft||0,e=r.scrollTop||s.scrollTop||0),{x:t,y:e}},getScrollSpace:function(){var t=n.getDocument(),e=t.documentElement,o=t.body;return{x:o.scrollHeight-e.clientWidth,y:o.scrollHeight-e.clientHeight}},saveScrollPosition:function(){var t=n.utils.getBrowserScrollPosition();t=[t.x,t.y],document.cookie="bs_scroll_pos="+t.join(",")},restoreScrollPosition:function(){var t=document.cookie.replace(/(?:(?:^|.*;\s*)bs_scroll_pos\s*\=\s*([^;]*).*$)|^.*$/,"$1").split(",");window.scrollTo(t[0],t[1])},getElementIndex:function(t,e){var n=document.getElementsByTagName(t);return Array.prototype.indexOf.call(n,e)},forceChange:function(t){t.blur(),t.focus()},getElementData:function(t){var e=t.tagName,o=n.utils.getElementIndex(e,t);return{tagName:e,index:o}},getSingleElement:function(t,e){var n=document.getElementsByTagName(t);return n[e]},getBody:function(){return document.getElementsByTagName("body")[0]},reloadBrowser:function(){n.getWindow().location.reload(!0)},getWindow:n.getWindow,getDocument:n.getDocument,isOldIe:function(){return"undefined"!=typeof window.attachEvent}}},{}],3:[function(){"indexOf"in Array.prototype||(Array.prototype.indexOf=function(t,e){void 0===e&&(e=0),0>e&&(e+=this.length),0>e&&(e=0);for(var n=this.length;n>e;e+=1)if(e in this&&this[e]===t)return e;return-1})},{}],4:[function(t,e,n){"use strict";var o,i=t("./events"),r=t("./browser.utils").utils,s={tagNames:{css:"link",jpg:"img",jpeg:"img",png:"img",svg:"img",gif:"img",js:"script"},attrs:{link:"href",img:"src",script:"src"}},c="codeSync",a=function(){return window.location.pathname};n.init=function(t){n.saveScroll(r.getWindow(),r.getDocument()),t.socket.on("file:reload",n.reload(t)),t.socket.on("browser:reload",function(){t.canSync({url:a()},c)&&n.reloadBrowser(!0)})},n.saveScroll=function(t,e){r.isOldIe()&&("complete"===e.readyState?r.restoreScrollPosition():i.manager.addEvent(e,"readystatechange",function(){"complete"===e.readyState&&r.restoreScrollPosition()}),i.manager.addEvent(window,"beforeunload",r.saveScrollPosition))},n.swapFile=function(t,e,n){var i=t[e],r=(new Date).getTime(),s="?rel="+r,c=/^[^\?]+(?=\?)/.exec(i);c&&(i=c[0]),n&&(n.timestamps||(s="")),t[e]=i+s;var a=document.body;return setTimeout(function(){o?(o.style.display="none",o.style.display="block"):(o=document.createElement("DIV"),a.appendChild(o))},200),{elem:t,timeStamp:r}},n.reload=function(t){return function(e){if(t.canSync({url:a()},c)){var o,i=t.options,r=t.emitter;if((e.url||!i.injectChanges)&&n.reloadBrowser(!0),e.assetFileName&&e.fileExtension){var s=n.getElems(e.fileExtension),u=n.getMatches(s.elems,e.assetFileName,s.attr);u.length&&i.notify&&r.emit("notify",{message:"Injected: "+e.assetFileName});for(var l=0,d=u.length;d>l;l+=1)o=n.swapFile(u[l],s.attr,i)}return o}}},n.getTagName=function(t){return s.tagNames[t]},n.getAttr=function(t){return s.attrs[t]},n.getMatches=function(t,e,n){for(var o=[],i=0,r=t.length;r>i;i+=1)-1!==t[i][n].indexOf(e)&&o.push(t[i]);return o},n.getElems=function(t){var e=n.getTagName(t),o=n.getAttr(e);return{elems:document.getElementsByTagName(e),attr:o}},n.getWindow=function(){return window},n.reloadBrowser=function(t){var e=n.getWindow();t&&e.location.reload(!0)}},{"./browser.utils":2,"./events":6}],5:[function(t,e,n){"use strict";n.events={},n.emit=function(t,e){var o,i=n.events[t];if(i&&i.listeners){o=i.listeners;for(var r=0,s=o.length;s>r;r+=1)o[r](e)}},n.on=function(t,e){var o=n.events;o[t]?o[t].listeners.push(e):o[t]={listeners:[e]}}},{}],6:[function(t,e,n){n._ElementCache=function(){var t={},e=1,n="data"+(new Date).getTime();this.getData=function(o){var i=o[n];return i||(i=o[n]=e++,t[i]={}),t[i]},this.removeData=function(e){var o=e[n];if(o){delete t[o];try{delete e[n]}catch(i){e.removeAttribute&&e.removeAttribute(n)}}}},n._fixEvent=function(t){function e(){return!0}function n(){return!1}if(!t||!t.stopPropagation){var o=t||window.event;t={};for(var i in o)t[i]=o[i];if(t.target||(t.target=t.srcElement||document),t.relatedTarget=t.fromElement===t.target?t.toElement:t.fromElement,t.preventDefault=function(){t.returnValue=!1,t.isDefaultPrevented=e},t.isDefaultPrevented=n,t.stopPropagation=function(){t.cancelBubble=!0,t.isPropagationStopped=e},t.isPropagationStopped=n,t.stopImmediatePropagation=function(){this.isImmediatePropagationStopped=e,this.stopPropagation()},t.isImmediatePropagationStopped=n,null!=t.clientX){var r=document.documentElement,s=document.body;t.pageX=t.clientX+(r&&r.scrollLeft||s&&s.scrollLeft||0)-(r&&r.clientLeft||s&&s.clientLeft||0),t.pageY=t.clientY+(r&&r.scrollTop||s&&s.scrollTop||0)-(r&&r.clientTop||s&&s.clientTop||0)}t.which=t.charCode||t.keyCode,null!=t.button&&(t.button=1&t.button?0:4&t.button?1:2&t.button?2:0)}return t},n._EventManager=function(t){function e(e,n){function o(t){for(var e in t)return!1;return!0}var i=t.getData(e);0===i.handlers[n].length&&(delete i.handlers[n],document.removeEventListener?e.removeEventListener(n,i.dispatcher,!1):document.detachEvent&&e.detachEvent("on"+n,i.dispatcher)),o(i.handlers)&&(delete i.handlers,delete i.dispatcher),o(i)&&t.removeData(e)}var o=1;this.addEvent=function(e,i,r){var s=t.getData(e);s.handlers||(s.handlers={}),s.handlers[i]||(s.handlers[i]=[]),r.guid||(r.guid=o++),s.handlers[i].push(r),s.dispatcher||(s.disabled=!1,s.dispatcher=function(t){if(!s.disabled){t=n._fixEvent(t);var o=s.handlers[t.type];if(o)for(var i=0;i<o.length;i++)o[i].call(e,t)}}),1==s.handlers[i].length&&(document.addEventListener?e.addEventListener(i,s.dispatcher,!1):document.attachEvent&&e.attachEvent("on"+i,s.dispatcher))},this.removeEvent=function(n,o,i){var r=t.getData(n);if(r.handlers){var s=function(t){r.handlers[t]=[],e(n,t)};if(o){var c=r.handlers[o];if(c){if(!i)return void s(o);if(i.guid)for(var a=0;a<c.length;a++)c[a].guid===i.guid&&c.splice(a--,1);e(n,o)}}else for(var u in r.handlers)s(u)}},this.proxy=function(t,e){e.guid||(e.guid=o++);var n=function(){return e.apply(t,arguments)};return n.guid=e.guid,n}},n.triggerClick=function(t){var e;document.createEvent?window.setTimeout(function(){e=document.createEvent("MouseEvents"),e.initEvent("click",!0,!0),t.dispatchEvent(e)},0):window.setTimeout(function(){document.createEventObject&&(e=document.createEventObject(),e.cancelBubble=!0,t.fireEvent("onclick",e))},0)};var o=new n._ElementCache,i=new n._EventManager(o);i.triggerClick=n.triggerClick,n.manager=i},{}],7:[function(t,e,n){"use strict";var o=t("./socket"),i=(t("./client-shims"),t("./notify")),r=t("./code-sync"),s=t("./browser-sync"),c=t("./ghostmode"),a=(t("./emitter"),t("./events"),t("./browser.utils").utils),u=!1;n.init=function(t){u&&t.reloadOnRestart&&a.reloadBrowser();var e=window.___browserSync___||{};if(!e.client){e.client=!0;var n=new s(t);c.init(n),r.init(n),t.notify&&(i.init(n),i.flash("Connected to BrowserSync"))}},o.on("connection",n.init),o.on("disconnect",function(){i.flash("Disconnected From BrowserSync"),u=!0})},{"./browser-sync":1,"./browser.utils":2,"./client-shims":3,"./code-sync":4,"./emitter":5,"./events":6,"./ghostmode":13,"./ghostmode.clicks":8,"./ghostmode.forms":10,"./ghostmode.forms.input":9,"./ghostmode.forms.submit":11,"./ghostmode.forms.toggles":12,"./ghostmode.location":14,"./ghostmode.scroll":15,"./notify":16,"./socket":17}],8:[function(t,e,n){"use strict";var o="click",i="ghostMode.clicks";n.canEmitEvents=!0,n.init=function(t,e){e.addEvent(document.body,o,n.browserEvent(t)),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var i=e.target||e.srcElement;if("checkbox"===i.type||"radio"===i.type)return void t.utils.forceChange(i);t.socket.emit(o,t.utils.getElementData(i))}else n.canEmitEvents=!0}},n.socketEvent=function(t,e){return function(o){if(t.canSync(o,i)){var r=t.utils.getSingleElement(o.tagName,o.index);r&&(n.canEmitEvents=!1,e.triggerClick(r))}}}},{}],9:[function(t,e,n){"use strict";var o="input:text",i="ghostMode.forms.inputs";n.canEmitEvents=!0,n.init=function(t,e){e.addEvent(document.body,"keyup",n.browserEvent(t)),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){var i,r=e.target||e.srcElement;n.canEmitEvents?("INPUT"===r.tagName||"TEXTAREA"===r.tagName)&&(i=t.utils.getElementData(r),i.value=r.value,t.socket.emit(o,i)):n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(t.canSync(e,i)){var n=t.utils.getSingleElement(e.tagName,e.index);if(n)return n.value=e.value,n}return!1}}},{}],10:[function(t,e,n){"use strict";n.plugins={inputs:t("./ghostmode.forms.input"),toggles:t("./ghostmode.forms.toggles"),submit:t("./ghostmode.forms.submit")},n.init=function(t,e){function o(o){n.plugins[o].init(t,e)}var i=!0,r=t.options.ghostMode.forms;r===!0&&(i=!1);for(var s in n.plugins)i?r[s]&&o(s):o(s)}},{"./ghostmode.forms.input":9,"./ghostmode.forms.submit":11,"./ghostmode.forms.toggles":12}],11:[function(t,e,n){"use strict";var o="form:submit",i="ghostMode.forms.submit";n.canEmitEvents=!0,n.init=function(t,e){var i=n.browserEvent(t);e.addEvent(document.body,"submit",i),e.addEvent(document.body,"reset",i),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var i=e.target||e.srcElement,r=t.utils.getElementData(i);r.type=e.type,t.socket.emit(o,r)}else n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(t.canSync(e,i)){var o=t.utils.getSingleElement(e.tagName,e.index);return n.canEmitEvents=!1,o&&"submit"===e.type&&o.submit(),o&&"reset"===e.type&&o.reset(),!1}return!1}}},{}],12:[function(t,e,n){"use strict";var o="input:toggles",i="ghostMode.forms.toggles";n.canEmitEvents=!0,n.init=function(t,e){var i=n.browserEvent(t);n.addEvents(e,i),t.socket.on(o,n.socketEvent(t,e))},n.addEvents=function(t,e){function n(n){for(var o=0,i=n.length;i>o;o+=1)t.addEvent(n[o],"change",e)}var o=document.getElementsByTagName("select"),i=document.getElementsByTagName("input");n(o),n(i)},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var i,r=e.target||e.srcElement;("radio"===r.type||"checkbox"===r.type||"SELECT"===r.tagName)&&(i=t.utils.getElementData(r),i.type=r.type,i.value=r.value,i.checked=r.checked,t.socket.emit(o,i))}else n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(t.canSync(e,i)){n.canEmitEvents=!1;var o=t.utils.getSingleElement(e.tagName,e.index);return o?("radio"===e.type&&(o.checked=!0),"checkbox"===e.type&&(o.checked=e.checked),"SELECT"===e.tagName&&(o.value=e.value),o):!1}return!1}}},{}],13:[function(t,e,n){"use strict";var o=t("./events").manager;n.plugins={scroll:t("./ghostmode.scroll"),clicks:t("./ghostmode.clicks"),forms:t("./ghostmode.forms"),location:t("./ghostmode.location")},n.init=function(t){for(var e in n.plugins)n.plugins[e].init(t,o)}},{"./events":6,"./ghostmode.clicks":8,"./ghostmode.forms":10,"./ghostmode.location":14,"./ghostmode.scroll":15}],14:[function(t,e,n){"use strict";var o="browser:location",i="ghostMode.location";n.canEmitEvents=!0,n.init=function(t){t.socket.on(o,n.socketEvent())},n.socketEvent=function(t){return function(e){(e.override||t.canSync(e,i))&&(e.path?n.setPath(e.path):n.setUrl(e.url))}},n.setUrl=function(t){window.location=t},n.setPath=function(t){window.location=window.location.protocol+"//"+window.location.host+t}},{}],15:[function(t,e,n){"use strict";var o,i="scroll",r="ghostMode.scroll";n.canEmitEvents=!0,n.init=function(t,e){o=t.utils,e.addEvent(window,i,n.browserEvent(t)),t.socket.on(i,n.socketEvent(t))},n.socketEvent=function(t){return function(e){var i=o.getScrollSpace();return n.canEmitEvents=!1,t.canSync(e,r)?t.options&&t.options.scrollProportionally?window.scrollTo(0,i.y*e.position.proportional):window.scrollTo(0,e.position.raw):!1}},n.browserEvent=function(t){return function(){var e=n.canEmitEvents;e&&t.socket.emit(i,{position:n.getScrollPosition()}),n.canEmitEvents=!0}},n.getScrollPosition=function(){var t=o.getBrowserScrollPosition();return{raw:t,proportional:n.getScrollTopPercentage(t)}},n.getScrollPercentage=function(t,e){var n=e.x/t.x,o=e.y/t.y;return{x:n||0,y:o}},n.getScrollTopPercentage=function(t){var e=o.getScrollSpace(),i=n.getScrollPercentage(e,t);return i.y}},{}],16:[function(t,e,n){"use strict";var o,i,r,s,c=(t("./ghostmode.scroll"),["display: none","padding: 15px","font-family: sans-serif","position: fixed","font-size: 0.9em","z-index: 9999","right: 0px","top: 0px","border-bottom-left-radius: 5px","background-color: #1B2032","margin: 0","color: white","text-align: center"]);n.init=function(t){o=t,r=t.options;var e=c;r.notify.styles&&(e=r.notify.styles),i=document.createElement("DIV"),i.id="__bs_notify__",i.style.cssText=e.join(";"),document.getElementsByTagName("body")[0].appendChild(i);var s=n.watchEvent();return o.emitter.on("notify",s),o.socket.on("browser:notify",s),i},n.watchEvent=function(){return function(t){return"string"==typeof t?n.flash(t):void n.flash(t.message,t.timeout)}},n.getElem=function(){return i},n.getScrollTop=function(){return o.utils.getBrowserScrollPosition().y},n.flash=function(t,e){var o=n.getElem();return o?(o.innerHTML=t,o.style.display="block",s&&(clearTimeout(s),s=void 0),s=window.setTimeout(function(){o.style.display="none"},e||2e3),o):!1}},{"./ghostmode.scroll":15}],17:[function(t,e,n){"use strict";var o=window.___browserSync___||{};n.socket=o.socket||{emit:function(){},on:function(){}},n.getPath=function(){return window.location.pathname},n.emit=function(t,e){var o=n.socket;o&&o.emit&&(e.url=n.getPath(),o.emit(t,e))},n.on=function(t,e){n.socket.on(t,e)}},{}]},{},[7]);
!function t(e,n,o){function i(s,c){if(!n[s]){if(!e[s]){var a="function"==typeof require&&require;if(!c&&a)return a(s,!0);if(r)return r(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=n[s]={exports:{}};e[s][0].call(u.exports,function(t){var n=e[s][1][t];return i(n?n:t)},u,u.exports,t,e,n,o)}return n[s].exports}for(var r="function"==typeof require&&require,s=0;s<o.length;s++)i(o[s]);return i}({1:[function(t,e){"use strict";function n(t){return"undefined"==typeof t}function o(t,e){for(var n=0,o=e.split("."),i=o.length;i>n;n++){if(!t||"object"!=typeof t)return!1;t=t[o[n]]}return"undefined"==typeof t?!1:t}var i=t("./socket"),r=t("./emitter"),s=(t("./notify"),t("./browser.utils")),c=function(t){this.options=t,this.socket=i,this.emitter=r,this.utils=s.utils;var e=this;i.on("options:set",function(t){r.emit("notify","Setting options..."),e.options=t.options})};c.prototype.canSync=function(t,e){if(t=t||{},t.override)return!0;var n=!0;return e&&(n=this.getOption(e)),n&&t.url===window.location.pathname},c.prototype.getOption=function(t){if(t&&t.match(/\./))return o(this.options,t);var e=this.options[t];return n(e)?!1:e},e.exports=c},{"./browser.utils":2,"./emitter":5,"./notify":16,"./socket":17}],2:[function(t,e,n){"use strict";n.getWindow=function(){return window},n.getDocument=function(){return document},n.utils={getBrowserScrollPosition:function(){var t,e,o=n.getWindow(),i=n.getDocument(),r=i.documentElement,s=i.body;return void 0!==o.pageYOffset?(t=o.pageXOffset,e=o.pageYOffset):(t=r.scrollLeft||s.scrollLeft||0,e=r.scrollTop||s.scrollTop||0),{x:t,y:e}},getScrollSpace:function(){var t=n.getDocument(),e=t.documentElement,o=t.body;return{x:o.scrollHeight-e.clientWidth,y:o.scrollHeight-e.clientHeight}},saveScrollPosition:function(){var t=n.utils.getBrowserScrollPosition();t=[t.x,t.y],document.cookie="bs_scroll_pos="+t.join(",")},restoreScrollPosition:function(){var t=document.cookie.replace(/(?:(?:^|.*;\s*)bs_scroll_pos\s*\=\s*([^;]*).*$)|^.*$/,"$1").split(",");window.scrollTo(t[0],t[1])},getElementIndex:function(t,e){var n=document.getElementsByTagName(t);return Array.prototype.indexOf.call(n,e)},forceChange:function(t){t.blur(),t.focus()},getElementData:function(t){var e=t.tagName,o=n.utils.getElementIndex(e,t);return{tagName:e,index:o}},getSingleElement:function(t,e){var n=document.getElementsByTagName(t);return n[e]},getBody:function(){return document.getElementsByTagName("body")[0]},reloadBrowser:function(){n.getWindow().location.reload(!0)},getWindow:n.getWindow,getDocument:n.getDocument,isOldIe:function(){return"undefined"!=typeof window.attachEvent}}},{}],3:[function(){"indexOf"in Array.prototype||(Array.prototype.indexOf=function(t,e){void 0===e&&(e=0),0>e&&(e+=this.length),0>e&&(e=0);for(var n=this.length;n>e;e+=1)if(e in this&&this[e]===t)return e;return-1})},{}],4:[function(t,e,n){"use strict";var o,i=t("./events"),r=t("./browser.utils").utils,s={tagNames:{css:"link",jpg:"img",jpeg:"img",png:"img",svg:"img",gif:"img",js:"script"},attrs:{link:"href",img:"src",script:"src"}},c="codeSync",a=function(){return window.location.pathname};n.init=function(t){n.saveScroll(r.getWindow(),r.getDocument()),t.socket.on("file:reload",n.reload(t)),t.socket.on("browser:reload",function(){t.canSync({url:a()},c)&&n.reloadBrowser(!0)})},n.saveScroll=function(t,e){r.isOldIe()&&("complete"===e.readyState?r.restoreScrollPosition():i.manager.addEvent(e,"readystatechange",function(){"complete"===e.readyState&&r.restoreScrollPosition()}),i.manager.addEvent(window,"beforeunload",r.saveScrollPosition))},n.swapFile=function(t,e,n){var i=t[e],r=(new Date).getTime(),s="?rel="+r,c=/^[^\?]+(?=\?)/.exec(i);c&&(i=c[0]),n&&(n.timestamps||(s="")),t[e]=i+s;var a=document.body;return setTimeout(function(){o?(o.style.display="none",o.style.display="block"):(o=document.createElement("DIV"),a.appendChild(o))},200),{elem:t,timeStamp:r}},n.reload=function(t){return function(e){if(t.canSync({url:a()},c)){var o,i=t.options,r=t.emitter;if((e.url||!i.injectChanges)&&n.reloadBrowser(!0),e.assetFileName&&e.fileExtension){var s=n.getElems(e.fileExtension),u=n.getMatches(s.elems,e.assetFileName,s.attr);u.length&&i.notify&&r.emit("notify",{message:"Injected: "+e.assetFileName});for(var l=0,f=u.length;f>l;l+=1)o=n.swapFile(u[l],s.attr,i)}return o}}},n.getTagName=function(t){return s.tagNames[t]},n.getAttr=function(t){return s.attrs[t]},n.getMatches=function(t,e,n){for(var o=[],i=0,r=t.length;r>i;i+=1)-1!==t[i][n].indexOf(e)&&o.push(t[i]);return o},n.getElems=function(t){var e=n.getTagName(t),o=n.getAttr(e);return{elems:document.getElementsByTagName(e),attr:o}},n.getWindow=function(){return window},n.reloadBrowser=function(t){var e=n.getWindow();t&&e.location.reload(!0)}},{"./browser.utils":2,"./events":6}],5:[function(t,e,n){"use strict";n.events={},n.emit=function(t,e){var o,i=n.events[t];if(i&&i.listeners){o=i.listeners;for(var r=0,s=o.length;s>r;r+=1)o[r](e)}},n.on=function(t,e){var o=n.events;o[t]?o[t].listeners.push(e):o[t]={listeners:[e]}}},{}],6:[function(t,e,n){n._ElementCache=function(){var t={},e=1,n="data"+(new Date).getTime();this.getData=function(o){var i=o[n];return i||(i=o[n]=e++,t[i]={}),t[i]},this.removeData=function(e){var o=e[n];if(o){delete t[o];try{delete e[n]}catch(i){e.removeAttribute&&e.removeAttribute(n)}}}},n._fixEvent=function(t){function e(){return!0}function n(){return!1}if(!t||!t.stopPropagation){var o=t||window.event;t={};for(var i in o)t[i]=o[i];if(t.target||(t.target=t.srcElement||document),t.relatedTarget=t.fromElement===t.target?t.toElement:t.fromElement,t.preventDefault=function(){t.returnValue=!1,t.isDefaultPrevented=e},t.isDefaultPrevented=n,t.stopPropagation=function(){t.cancelBubble=!0,t.isPropagationStopped=e},t.isPropagationStopped=n,t.stopImmediatePropagation=function(){this.isImmediatePropagationStopped=e,this.stopPropagation()},t.isImmediatePropagationStopped=n,null!=t.clientX){var r=document.documentElement,s=document.body;t.pageX=t.clientX+(r&&r.scrollLeft||s&&s.scrollLeft||0)-(r&&r.clientLeft||s&&s.clientLeft||0),t.pageY=t.clientY+(r&&r.scrollTop||s&&s.scrollTop||0)-(r&&r.clientTop||s&&s.clientTop||0)}t.which=t.charCode||t.keyCode,null!=t.button&&(t.button=1&t.button?0:4&t.button?1:2&t.button?2:0)}return t},n._EventManager=function(t){function e(e,n){function o(t){for(var e in t)return!1;return!0}var i=t.getData(e);0===i.handlers[n].length&&(delete i.handlers[n],document.removeEventListener?e.removeEventListener(n,i.dispatcher,!1):document.detachEvent&&e.detachEvent("on"+n,i.dispatcher)),o(i.handlers)&&(delete i.handlers,delete i.dispatcher),o(i)&&t.removeData(e)}var o=1;this.addEvent=function(e,i,r){var s=t.getData(e);s.handlers||(s.handlers={}),s.handlers[i]||(s.handlers[i]=[]),r.guid||(r.guid=o++),s.handlers[i].push(r),s.dispatcher||(s.disabled=!1,s.dispatcher=function(t){if(!s.disabled){t=n._fixEvent(t);var o=s.handlers[t.type];if(o)for(var i=0;i<o.length;i++)o[i].call(e,t)}}),1==s.handlers[i].length&&(document.addEventListener?e.addEventListener(i,s.dispatcher,!1):document.attachEvent&&e.attachEvent("on"+i,s.dispatcher))},this.removeEvent=function(n,o,i){var r=t.getData(n);if(r.handlers){var s=function(t){r.handlers[t]=[],e(n,t)};if(o){var c=r.handlers[o];if(c){if(!i)return void s(o);if(i.guid)for(var a=0;a<c.length;a++)c[a].guid===i.guid&&c.splice(a--,1);e(n,o)}}else for(var u in r.handlers)s(u)}},this.proxy=function(t,e){e.guid||(e.guid=o++);var n=function(){return e.apply(t,arguments)};return n.guid=e.guid,n}},n.triggerClick=function(t){var e;document.createEvent?window.setTimeout(function(){e=document.createEvent("MouseEvents"),e.initEvent("click",!0,!0),t.dispatchEvent(e)},0):window.setTimeout(function(){document.createEventObject&&(e=document.createEventObject(),e.cancelBubble=!0,t.fireEvent("onclick",e))},0)};var o=new n._ElementCache,i=new n._EventManager(o);i.triggerClick=n.triggerClick,n.manager=i},{}],7:[function(t,e,n){"use strict";var o=t("./socket"),i=(t("./client-shims"),t("./notify")),r=t("./code-sync"),s=t("./browser-sync"),c=t("./ghostmode"),a=(t("./emitter"),t("./events"),t("./browser.utils").utils),u=!1;n.init=function(t){u&&t.reloadOnRestart&&a.reloadBrowser();var e=window.___browserSync___||{};if(!e.client){e.client=!0;var n=new s(t);c.init(n),r.init(n),t.notify&&(i.init(n),i.flash("Connected to BrowserSync"))}},o.on("connection",n.init),o.on("disconnect",function(){i.flash("Disconnected from BrowserSync"),u=!0})},{"./browser-sync":1,"./browser.utils":2,"./client-shims":3,"./code-sync":4,"./emitter":5,"./events":6,"./ghostmode":13,"./ghostmode.clicks":8,"./ghostmode.forms":10,"./ghostmode.forms.input":9,"./ghostmode.forms.submit":11,"./ghostmode.forms.toggles":12,"./ghostmode.location":14,"./ghostmode.scroll":15,"./notify":16,"./socket":17}],8:[function(t,e,n){"use strict";var o="click",i="ghostMode.clicks";n.canEmitEvents=!0,n.init=function(t,e){e.addEvent(document.body,o,n.browserEvent(t)),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var i=e.target||e.srcElement;if("checkbox"===i.type||"radio"===i.type)return void t.utils.forceChange(i);t.socket.emit(o,t.utils.getElementData(i))}else n.canEmitEvents=!0}},n.socketEvent=function(t,e){return function(o){if(!t.canSync(o,i))return!1;var r=t.utils.getSingleElement(o.tagName,o.index);r&&(n.canEmitEvents=!1,e.triggerClick(r))}}},{}],9:[function(t,e,n){"use strict";var o="input:text",i="ghostMode.forms.inputs";n.canEmitEvents=!0,n.init=function(t,e){e.addEvent(document.body,"keyup",n.browserEvent(t)),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){var i,r=e.target||e.srcElement;n.canEmitEvents?("INPUT"===r.tagName||"TEXTAREA"===r.tagName)&&(i=t.utils.getElementData(r),i.value=r.value,t.socket.emit(o,i)):n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(!t.canSync(e,i))return!1;var n=t.utils.getSingleElement(e.tagName,e.index);return n?(n.value=e.value,n):!1}}},{}],10:[function(t,e,n){"use strict";n.plugins={inputs:t("./ghostmode.forms.input"),toggles:t("./ghostmode.forms.toggles"),submit:t("./ghostmode.forms.submit")},n.init=function(t,e){function o(o){n.plugins[o].init(t,e)}var i=!0,r=t.options.ghostMode.forms;r===!0&&(i=!1);for(var s in n.plugins)i?r[s]&&o(s):o(s)}},{"./ghostmode.forms.input":9,"./ghostmode.forms.submit":11,"./ghostmode.forms.toggles":12}],11:[function(t,e,n){"use strict";var o="form:submit",i="ghostMode.forms.submit";n.canEmitEvents=!0,n.init=function(t,e){var i=n.browserEvent(t);e.addEvent(document.body,"submit",i),e.addEvent(document.body,"reset",i),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var i=e.target||e.srcElement,r=t.utils.getElementData(i);r.type=e.type,t.socket.emit(o,r)}else n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(!t.canSync(e,i))return!1;var o=t.utils.getSingleElement(e.tagName,e.index);return n.canEmitEvents=!1,o&&"submit"===e.type&&o.submit(),o&&"reset"===e.type&&o.reset(),!1}}},{}],12:[function(t,e,n){"use strict";var o="input:toggles",i="ghostMode.forms.toggles";n.canEmitEvents=!0,n.init=function(t,e){var i=n.browserEvent(t);n.addEvents(e,i),t.socket.on(o,n.socketEvent(t,e))},n.addEvents=function(t,e){function n(n){for(var o=0,i=n.length;i>o;o+=1)t.addEvent(n[o],"change",e)}var o=document.getElementsByTagName("select"),i=document.getElementsByTagName("input");n(o),n(i)},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var i,r=e.target||e.srcElement;("radio"===r.type||"checkbox"===r.type||"SELECT"===r.tagName)&&(i=t.utils.getElementData(r),i.type=r.type,i.value=r.value,i.checked=r.checked,t.socket.emit(o,i))}else n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(!t.canSync(e,i))return!1;n.canEmitEvents=!1;var o=t.utils.getSingleElement(e.tagName,e.index);return o?("radio"===e.type&&(o.checked=!0),"checkbox"===e.type&&(o.checked=e.checked),"SELECT"===e.tagName&&(o.value=e.value),o):!1}}},{}],13:[function(t,e,n){"use strict";var o=t("./events").manager;n.plugins={scroll:t("./ghostmode.scroll"),clicks:t("./ghostmode.clicks"),forms:t("./ghostmode.forms"),location:t("./ghostmode.location")},n.init=function(t){for(var e in n.plugins)n.plugins[e].init(t,o)}},{"./events":6,"./ghostmode.clicks":8,"./ghostmode.forms":10,"./ghostmode.location":14,"./ghostmode.scroll":15}],14:[function(t,e,n){"use strict";var o="browser:location",i="ghostMode.location";n.canEmitEvents=!0,n.init=function(t){t.socket.on(o,n.socketEvent(t))},n.socketEvent=function(t){return function(e){return t.canSync(e,i)?void(e.path?n.setPath(e.path):n.setUrl(e.url)):!1}},n.setUrl=function(t){window.location=t},n.setPath=function(t){window.location=window.location.protocol+"//"+window.location.host+t}},{}],15:[function(t,e,n){"use strict";var o,i="scroll",r="ghostMode.scroll";n.canEmitEvents=!0,n.init=function(t,e){o=t.utils,e.addEvent(window,i,n.browserEvent(t)),t.socket.on(i,n.socketEvent(t))},n.socketEvent=function(t){return function(e){if(!t.canSync(e,r))return!1;var i=o.getScrollSpace();return n.canEmitEvents=!1,t.options&&t.options.scrollProportionally?window.scrollTo(0,i.y*e.position.proportional):window.scrollTo(0,e.position.raw)}},n.browserEvent=function(t){return function(){var e=n.canEmitEvents;e&&t.socket.emit(i,{position:n.getScrollPosition()}),n.canEmitEvents=!0}},n.getScrollPosition=function(){var t=o.getBrowserScrollPosition();return{raw:t,proportional:n.getScrollTopPercentage(t)}},n.getScrollPercentage=function(t,e){var n=e.x/t.x,o=e.y/t.y;return{x:n||0,y:o}},n.getScrollTopPercentage=function(t){var e=o.getScrollSpace(),i=n.getScrollPercentage(e,t);return i.y}},{}],16:[function(t,e,n){"use strict";var o,i,r,s,c=(t("./ghostmode.scroll"),["display: none","padding: 15px","font-family: sans-serif","position: fixed","font-size: 0.9em","z-index: 9999","right: 0px","top: 0px","border-bottom-left-radius: 5px","background-color: #1B2032","margin: 0","color: white","text-align: center"]);n.init=function(t){o=t,r=t.options;var e=c;r.notify.styles&&(e=r.notify.styles),i=document.createElement("DIV"),i.id="__bs_notify__",i.style.cssText=e.join(";"),document.getElementsByTagName("body")[0].appendChild(i);var s=n.watchEvent();return o.emitter.on("notify",s),o.socket.on("browser:notify",s),i},n.watchEvent=function(){return function(t){return"string"==typeof t?n.flash(t):void n.flash(t.message,t.timeout)}},n.getElem=function(){return i},n.getScrollTop=function(){return o.utils.getBrowserScrollPosition().y},n.flash=function(t,e){var o=n.getElem();return o?(o.innerHTML=t,o.style.display="block",s&&(clearTimeout(s),s=void 0),s=window.setTimeout(function(){o.style.display="none"},e||2e3),o):!1}},{"./ghostmode.scroll":15}],17:[function(t,e,n){"use strict";var o=window.___browserSync___||{};n.socket=o.socket||{emit:function(){},on:function(){}},n.getPath=function(){return window.location.pathname},n.emit=function(t,e){var o=n.socket;o&&o.emit&&(e.url=n.getPath(),o.emit(t,e))},n.on=function(t,e){n.socket.on(t,e)}},{}]},{},[7]);

@@ -39,2 +39,6 @@ "use strict";

if (data.override) {
return true;
}
var canSync = true;

@@ -41,0 +45,0 @@

@@ -55,12 +55,13 @@ "use strict";

if (bs.canSync(data, OPT_PATH)) {
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var elem = bs.utils.getSingleElement(data.tagName, data.index);
var elem = bs.utils.getSingleElement(data.tagName, data.index);
if (elem) {
exports.canEmitEvents = false;
eventManager.triggerClick(elem);
}
if (elem) {
exports.canEmitEvents = false;
eventManager.triggerClick(elem);
}
};
};

@@ -55,10 +55,11 @@ "use strict";

if (bs.canSync(data, OPT_PATH)) {
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var elem = bs.utils.getSingleElement(data.tagName, data.index);
var elem = bs.utils.getSingleElement(data.tagName, data.index);
if (elem) {
elem.value = data.value;
return elem;
}
if (elem) {
elem.value = data.value;
return elem;
}

@@ -65,0 +66,0 @@

@@ -47,15 +47,20 @@ "use strict";

return function (data) {
if (bs.canSync(data, OPT_PATH)) {
var elem = bs.utils.getSingleElement(data.tagName, data.index);
exports.canEmitEvents = false;
if (elem && data.type === "submit") {
elem.submit();
}
if (elem && data.type === "reset") {
elem.reset();
}
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var elem = bs.utils.getSingleElement(data.tagName, data.index);
exports.canEmitEvents = false;
if (elem && data.type === "submit") {
elem.submit();
}
if (elem && data.type === "reset") {
elem.reset();
}
return false;
};
};

@@ -73,25 +73,24 @@ "use strict";

if (bs.canSync(data, OPT_PATH)) {
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
exports.canEmitEvents = false;
exports.canEmitEvents = false;
var elem = bs.utils.getSingleElement(data.tagName, data.index);
var elem = bs.utils.getSingleElement(data.tagName, data.index);
if (elem) {
if (data.type === "radio") {
elem.checked = true;
}
if (data.type === "checkbox") {
elem.checked = data.checked;
}
if (data.tagName === "SELECT") {
elem.value = data.value;
}
return elem;
if (elem) {
if (data.type === "radio") {
elem.checked = true;
}
return false;
if (data.type === "checkbox") {
elem.checked = data.checked;
}
if (data.tagName === "SELECT") {
elem.value = data.value;
}
return elem;
}
return false;
};
};

@@ -15,3 +15,3 @@ "use strict";

exports.init = function (bs) {
bs.socket.on(EVENT_NAME, exports.socketEvent());
bs.socket.on(EVENT_NAME, exports.socketEvent(bs));
};

@@ -23,10 +23,14 @@

exports.socketEvent = function (bs) {
return function (data) {
if (data.override || bs.canSync(data, OPT_PATH)) {
if (data.path) {
exports.setPath(data.path);
} else {
exports.setUrl(data.url);
}
if (!bs.canSync(data, OPT_PATH)) {
return false;
}
if (data.path) {
exports.setPath(data.path);
} else {
exports.setUrl(data.url);
}
};

@@ -33,0 +37,0 @@ };

@@ -30,2 +30,6 @@ "use strict";

if (!bs.canSync(data, OPT_PATH)) {
return false;
}
var scrollSpace = utils.getScrollSpace();

@@ -35,6 +39,2 @@

if (!bs.canSync(data, OPT_PATH)) {
return false;
}
if (bs.options && bs.options.scrollProportionally) {

@@ -41,0 +41,0 @@ return window.scrollTo(0, scrollSpace.y * data.position.proportional); // % of y axis of scroll to px

@@ -19,3 +19,2 @@ "use strict";

exports.init = function (options) {
if (shouldReload && options.reloadOnRestart) {

@@ -22,0 +21,0 @@ utils.reloadBrowser();

{
"name": "browser-sync-client",
"description": "Client-side scripts for BrowserSync",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/shakyshane/browser-sync-client",

@@ -6,0 +6,0 @@ "author": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc