browser-sync-client
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -668,2 +668,3 @@ (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){ | ||
window.__bs_submit__ = require("./ghostmode.forms.submit"); | ||
window.__bs_forms__ = require("./ghostmode.forms"); | ||
window.__bs_utils__ = require("./browser.utils"); | ||
@@ -678,3 +679,3 @@ window.__bs_emitter__ = emitter; | ||
/**debug:end**/ | ||
},{"./browser.utils":1,"./client-shims":2,"./code-sync":3,"./emitter":4,"./ghostmode":12,"./ghostmode.clicks":7,"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11,"./ghostmode.location":13,"./ghostmode.scroll":14,"./notify":15,"./socket":16}],7:[function(require,module,exports){ | ||
},{"./browser.utils":1,"./client-shims":2,"./code-sync":3,"./emitter":4,"./ghostmode":12,"./ghostmode.clicks":7,"./ghostmode.forms":9,"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11,"./ghostmode.location":13,"./ghostmode.scroll":14,"./notify":15,"./socket":16}],7:[function(require,module,exports){ | ||
"use strict"; | ||
@@ -812,10 +813,36 @@ | ||
},{}],9:[function(require,module,exports){ | ||
var inputs = require("./ghostmode.forms.input"); | ||
var toggles = require("./ghostmode.forms.toggles"); | ||
var submit = require("./ghostmode.forms.submit"); | ||
"use strict"; | ||
exports.plugins = { | ||
"inputs": require("./ghostmode.forms.input"), | ||
"toggles": require("./ghostmode.forms.toggles"), | ||
"submit": require("./ghostmode.forms.submit") | ||
}; | ||
/** | ||
* Load plugins for enabled options | ||
* @param bs | ||
*/ | ||
exports.init = function (bs, eventManager) { | ||
inputs.init(bs, eventManager); | ||
toggles.init(bs, eventManager); | ||
submit.init(bs, eventManager); | ||
var checkOpt = true; | ||
var opts = bs.opts.ghostMode.forms; | ||
if (opts === true) { | ||
checkOpt = false; | ||
} | ||
function init(name) { | ||
exports.plugins[name].init(bs, eventManager); | ||
} | ||
for (var name in exports.plugins) { | ||
if (!checkOpt) { | ||
init(name); | ||
} else { | ||
if (opts[name]) { | ||
init(name); | ||
} | ||
} | ||
} | ||
}; | ||
@@ -984,15 +1011,8 @@ },{"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11}],10:[function(require,module,exports){ | ||
exports.plugins = { | ||
"scroll": require("./ghostmode.scroll"), | ||
"clicks": require("./ghostmode.clicks"), | ||
"forms": require("./ghostmode.forms"), | ||
"scroll": require("./ghostmode.scroll"), | ||
"clicks": require("./ghostmode.clicks"), | ||
"forms": require("./ghostmode.forms"), | ||
"location": require("./ghostmode.location") | ||
}; | ||
var options = [ | ||
"scroll", | ||
"clicks", | ||
"forms", | ||
"location" | ||
]; | ||
/** | ||
@@ -1003,7 +1023,12 @@ * Load plugins for enabled options | ||
exports.init = function (bs) { | ||
var ghostMode = bs.opts.ghostMode; | ||
for (var i = 0, n = options.length; i < n; i += 1) { | ||
var item = options[i]; | ||
if (ghostMode[item]) { | ||
exports.plugins[item].init(bs, eventManager); | ||
function init(name) { | ||
exports.plugins[name].init(bs, eventManager); | ||
} | ||
for (var name in exports.plugins) { | ||
if (ghostMode[name]) { | ||
init(name); | ||
} | ||
@@ -1010,0 +1035,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function t(e,n,o){function r(c,s){if(!n[c]){if(!e[c]){var a="function"==typeof require&&require;if(!s&&a)return a(c,!0);if(i)return i(c,!0);throw new Error("Cannot find module '"+c+"'")}var u=n[c]={exports:{}};e[c][0].call(u.exports,function(t){var n=e[c][1][t];return r(n?n:t)},u,u.exports,t,e,n,o)}return n[c].exports}for(var i="function"==typeof require&&require,c=0;c<o.length;c++)r(o[c]);return r}({1:[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(),r=n.getDocument(),i=r.documentElement,c=r.body;return void 0!==o.pageYOffset?(t=o.pageXOffset,e=o.pageYOffset):(t=i.scrollLeft||c.scrollLeft||0,e=i.scrollTop||c.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}},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]}}},{}],2:[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})},{}],3:[function(t,e,n){"use strict";var o={tagNames:{css:"link",jpg:"img",jpeg:"img",png:"img",svg:"img",gif:"img",js:"script"},attrs:{link:"href",img:"src",script:"src"}};n.init=function(t){t.socket.on("file:reload",n.reload(t)),t.socket.on("browser:reload",function(){n.reloadBrowser(!0)})},n.swapFile=function(t,e,n){var o=t[e],r=(new Date).getTime(),i="?rel="+r,c=/^[^\?]+(?=\?)/.exec(o);return c&&(o=c[0]),n&&(n.timestamps||(i="")),t[e]=o+i,{elem:t,timeStamp:r}},n.reload=function(t){return function(e){var o,r=t.opts,i=t.emitter;if((e.url||!r.injectChanges)&&n.reloadBrowser(!0),e.assetFileName&&e.fileExtension){var c=n.getElems(e.fileExtension),s=n.getMatches(c.elems,e.assetFileName,c.attr);s.length&&r.notify&&i.emit("notify",{message:"Injected: "+e.assetFileName});for(var a=0,u=s.length;u>a;a+=1)o=n.swapFile(s[a],c.attr,r)}return o}},n.getTagName=function(t){return o.tagNames[t]},n.getAttr=function(t){return o.attrs[t]},n.getMatches=function(t,e,n){for(var o=[],r=0,i=t.length;i>r;r+=1)-1!==t[r][n].indexOf(e)&&o.push(t[r]);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)}},{}],4:[function(t,e,n){"use strict";n.events={},n.emit=function(t,e){var o,r=n.events[t];if(r&&r.listeners){o=r.listeners;for(var i=0,c=o.length;c>i;i+=1)o[i](e)}},n.on=function(t,e){var o=n.events;o[t]?o[t].listeners.push(e):o[t]={listeners:[e]}}},{}],5:[function(t,e,n){n._ElementCache=function(){var t={},e=1,n="data"+(new Date).getTime();this.getData=function(o){var r=o[n];return r||(r=o[n]=e++,t[r]={}),t[r]},this.removeData=function(e){var o=e[n];if(o){delete t[o];try{delete e[n]}catch(r){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 r in o)t[r]=o[r];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 i=document.documentElement,c=document.body;t.pageX=t.clientX+(i&&i.scrollLeft||c&&c.scrollLeft||0)-(i&&i.clientLeft||c&&c.clientLeft||0),t.pageY=t.clientY+(i&&i.scrollTop||c&&c.scrollTop||0)-(i&&i.clientTop||c&&c.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 r=t.getData(e);0===r.handlers[n].length&&(delete r.handlers[n],document.removeEventListener?e.removeEventListener(n,r.dispatcher,!1):document.detachEvent&&e.detachEvent("on"+n,r.dispatcher)),o(r.handlers)&&(delete r.handlers,delete r.dispatcher),o(r)&&t.removeData(e)}var o=1;this.addEvent=function(e,r,i){var c=t.getData(e);c.handlers||(c.handlers={}),c.handlers[r]||(c.handlers[r]=[]),i.guid||(i.guid=o++),c.handlers[r].push(i),c.dispatcher||(c.disabled=!1,c.dispatcher=function(t){if(!c.disabled){t=n._fixEvent(t);var o=c.handlers[t.type];if(o)for(var r=0;r<o.length;r++)o[r].call(e,t)}}),1==c.handlers[r].length&&(document.addEventListener?e.addEventListener(r,c.dispatcher,!1):document.attachEvent&&e.attachEvent("on"+r,c.dispatcher))},this.removeEvent=function(n,o,r){var i=t.getData(n);if(i.handlers){var c=function(t){i.handlers[t]=[],e(n,t)};if(o){var s=i.handlers[o];if(s){if(!r)return void c(o);if(r.guid)for(var a=0;a<s.length;a++)s[a].guid===r.guid&&s.splice(a--,1);e(n,o)}}else for(var u in i.handlers)c(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?(e=document.createEvent("MouseEvents"),e.initEvent("click",!0,!0),t.dispatchEvent(e)):document.createEventObject&&(e=document.createEventObject(),e.cancelBubble=!0,t.fireEvent("onclick",e))};var o=new n._ElementCache,r=new n._EventManager(o);r.triggerClick=n.triggerClick,n.manager=r},{}],6:[function(t,e,n){"use strict";var o=t("./socket"),r=(t("./client-shims"),t("./notify")),i=t("./code-sync"),c=t("./ghostmode"),s=t("./emitter"),a=t("./browser.utils"),u=function(){this.socket=o,this.emitter=s,this.utils=a.utils};u.prototype.canSync=function(t){return t.url===window.location.pathname};var l;n.init=function(t){l=new u,l.opts=t,t.notify&&(r.init(l),r.flash("Connected to BrowserSync :)")),t.ghostMode&&c.init(l),t.codeSync&&i.init(l)},o.on("connection",n.init)},{"./browser.utils":1,"./client-shims":2,"./code-sync":3,"./emitter":4,"./ghostmode":12,"./ghostmode.clicks":7,"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11,"./ghostmode.location":13,"./ghostmode.scroll":14,"./notify":15,"./socket":16}],7:[function(t,e,n){"use strict";var o="click";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 r=e.target||e.srcElement;if("checkbox"===r.type||"radio"===r.type)return void t.utils.forceChange(r);t.socket.emit(o,t.utils.getElementData(r))}else n.canEmitEvents=!0}},n.socketEvent=function(t,e){return function(o){if(t.canSync(o)){var r=t.utils.getSingleElement(o.tagName,o.index);r&&(n.canEmitEvents=!1,e.triggerClick(r))}}}},{}],8:[function(t,e,n){"use strict";var o="input:text";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 r,i=e.target||e.srcElement;n.canEmitEvents?("INPUT"===i.tagName||"TEXTAREA"===i.tagName)&&(r=t.utils.getElementData(i),r.value=i.value,t.socket.emit(o,r)):n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(t.canSync(e)){var n=t.utils.getSingleElement(e.tagName,e.index);if(n)return n.value=e.value,n}return!1}}},{}],9:[function(t,e,n){var o=t("./ghostmode.forms.input"),r=t("./ghostmode.forms.toggles"),i=t("./ghostmode.forms.submit");n.init=function(t,e){o.init(t,e),r.init(t,e),i.init(t,e)}},{"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11}],10:[function(t,e,n){"use strict";var o="form:submit";n.canEmitEvents=!0,n.init=function(t,e){var r=n.browserEvent(t);e.addEvent(document.body,"submit",r),e.addEvent(document.body,"reset",r),t.socket.on(o,n.socketEvent(t,e))},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var r=e.target||e.srcElement,i=t.utils.getElementData(r);i.type=e.type,t.socket.emit(o,i)}else n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(t.canSync(e)){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}}},{}],11:[function(t,e,n){"use strict";var o="input:toggles";n.canEmitEvents=!0,n.init=function(t,e){var r=n.browserEvent(t);n.addEvents(e,r),t.socket.on(o,n.socketEvent(t,e))},n.addEvents=function(t,e){function n(n){for(var o=0,r=n.length;r>o;o+=1)t.addEvent(n[o],"change",e)}var o=document.getElementsByTagName("select"),r=document.getElementsByTagName("input");n(o),n(r)},n.browserEvent=function(t){return function(e){if(n.canEmitEvents){var r,i=e.target||e.srcElement;("radio"===i.type||"checkbox"===i.type||"SELECT"===i.tagName)&&(r=t.utils.getElementData(i),r.type=i.type,r.value=i.value,r.checked=i.checked,t.socket.emit(o,r))}else n.canEmitEvents=!0}},n.socketEvent=function(t){return function(e){if(t.canSync(e)){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}}},{}],12:[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")};var r=["scroll","clicks","forms","location"];n.init=function(t){for(var e=t.opts.ghostMode,i=0,c=r.length;c>i;i+=1){var s=r[i];e[s]&&n.plugins[s].init(t,o)}}},{"./events":5,"./ghostmode.clicks":7,"./ghostmode.forms":9,"./ghostmode.location":13,"./ghostmode.scroll":14}],13:[function(t,e,n){"use strict";var o="location";n.canEmitEvents=!0,n.init=function(t){t.socket.on(o,n.socketEvent())},n.socketEvent=function(){return function(t){window.location=t.url}}},{}],14:[function(t,e,n){"use strict";var o,r="scroll";n.canEmitEvents=!0,n.init=function(t,e){o=t.utils,e.addEvent(window,r,n.browserEvent(t)),t.socket.on(r,n.socketEvent(t))},n.socketEvent=function(t){return function(e){var r=o.getScrollSpace();return n.canEmitEvents=!1,t.canSync(e)?t.opts&&t.opts.scrollProportionally?window.scrollTo(0,r.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(r,{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(),r=n.getScrollPercentage(e,t);return r.y}},{}],15:[function(t,e,n){"use strict";var o,r,i,c=(t("./ghostmode.scroll"),["background-color: black","color: white","padding: 10px","display: none","font-family: sans-serif","position: absolute","z-index: 9999","right: 0px","border-bottom-left-radius: 5px"]);n.init=function(t){o=t,i=t.opts;var e=c;return i.notify.styles&&(e=i.notify.styles),r=document.createElement("DIV"),r.id="notifyElem",r.style.cssText=e.join(";"),document.getElementsByTagName("body")[0].appendChild(r),o.emitter.on("notify",n.watchEvent()),r},n.watchEvent=function(){return function(t){n.flash(t.message)}},n.getElem=function(){return r},n.getScrollTop=function(){return o.utils.getBrowserScrollPosition().y},n.flash=function(t,e){var o=n.getElem();if(!o)return!1;var r=document.getElementsByTagName("HTML")[0];return r.style.position="relative",o.innerHTML=t,o.style.top=n.getScrollTop()+"px",o.style.display="block",window.setTimeout(function(){o.style.display="none"},e||2e3),o}},{"./ghostmode.scroll":14}],16:[function(t,e,n){"use strict";n.socket=window.___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)}},{}]},{},[6]); | ||
!function t(e,n,o){function i(c,s){if(!n[c]){if(!e[c]){var a="function"==typeof require&&require;if(!s&&a)return a(c,!0);if(r)return r(c,!0);throw new Error("Cannot find module '"+c+"'")}var u=n[c]={exports:{}};e[c][0].call(u.exports,function(t){var n=e[c][1][t];return i(n?n:t)},u,u.exports,t,e,n,o)}return n[c].exports}for(var r="function"==typeof require&&require,c=0;c<o.length;c++)i(o[c]);return i}({1:[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,c=i.body;return void 0!==o.pageYOffset?(t=o.pageXOffset,e=o.pageYOffset):(t=r.scrollLeft||c.scrollLeft||0,e=r.scrollTop||c.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}},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]}}},{}],2:[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})},{}],3:[function(t,e,n){"use strict";var o={tagNames:{css:"link",jpg:"img",jpeg:"img",png:"img",svg:"img",gif:"img",js:"script"},attrs:{link:"href",img:"src",script:"src"}};n.init=function(t){t.socket.on("file:reload",n.reload(t)),t.socket.on("browser:reload",function(){n.reloadBrowser(!0)})},n.swapFile=function(t,e,n){var o=t[e],i=(new Date).getTime(),r="?rel="+i,c=/^[^\?]+(?=\?)/.exec(o);return c&&(o=c[0]),n&&(n.timestamps||(r="")),t[e]=o+r,{elem:t,timeStamp:i}},n.reload=function(t){return function(e){var o,i=t.opts,r=t.emitter;if((e.url||!i.injectChanges)&&n.reloadBrowser(!0),e.assetFileName&&e.fileExtension){var c=n.getElems(e.fileExtension),s=n.getMatches(c.elems,e.assetFileName,c.attr);s.length&&i.notify&&r.emit("notify",{message:"Injected: "+e.assetFileName});for(var a=0,u=s.length;u>a;a+=1)o=n.swapFile(s[a],c.attr,i)}return o}},n.getTagName=function(t){return o.tagNames[t]},n.getAttr=function(t){return o.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)}},{}],4:[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,c=o.length;c>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]}}},{}],5:[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,c=document.body;t.pageX=t.clientX+(r&&r.scrollLeft||c&&c.scrollLeft||0)-(r&&r.clientLeft||c&&c.clientLeft||0),t.pageY=t.clientY+(r&&r.scrollTop||c&&c.scrollTop||0)-(r&&r.clientTop||c&&c.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 c=t.getData(e);c.handlers||(c.handlers={}),c.handlers[i]||(c.handlers[i]=[]),r.guid||(r.guid=o++),c.handlers[i].push(r),c.dispatcher||(c.disabled=!1,c.dispatcher=function(t){if(!c.disabled){t=n._fixEvent(t);var o=c.handlers[t.type];if(o)for(var i=0;i<o.length;i++)o[i].call(e,t)}}),1==c.handlers[i].length&&(document.addEventListener?e.addEventListener(i,c.dispatcher,!1):document.attachEvent&&e.attachEvent("on"+i,c.dispatcher))},this.removeEvent=function(n,o,i){var r=t.getData(n);if(r.handlers){var c=function(t){r.handlers[t]=[],e(n,t)};if(o){var s=r.handlers[o];if(s){if(!i)return void c(o);if(i.guid)for(var a=0;a<s.length;a++)s[a].guid===i.guid&&s.splice(a--,1);e(n,o)}}else for(var u in r.handlers)c(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?(e=document.createEvent("MouseEvents"),e.initEvent("click",!0,!0),t.dispatchEvent(e)):document.createEventObject&&(e=document.createEventObject(),e.cancelBubble=!0,t.fireEvent("onclick",e))};var o=new n._ElementCache,i=new n._EventManager(o);i.triggerClick=n.triggerClick,n.manager=i},{}],6:[function(t,e,n){"use strict";var o=t("./socket"),i=(t("./client-shims"),t("./notify")),r=t("./code-sync"),c=t("./ghostmode"),s=t("./emitter"),a=t("./browser.utils"),u=function(){this.socket=o,this.emitter=s,this.utils=a.utils};u.prototype.canSync=function(t){return t.url===window.location.pathname};var l;n.init=function(t){l=new u,l.opts=t,t.notify&&(i.init(l),i.flash("Connected to BrowserSync :)")),t.ghostMode&&c.init(l),t.codeSync&&r.init(l)},o.on("connection",n.init)},{"./browser.utils":1,"./client-shims":2,"./code-sync":3,"./emitter":4,"./ghostmode":12,"./ghostmode.clicks":7,"./ghostmode.forms":9,"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11,"./ghostmode.location":13,"./ghostmode.scroll":14,"./notify":15,"./socket":16}],7:[function(t,e,n){"use strict";var o="click";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)){var i=t.utils.getSingleElement(o.tagName,o.index);i&&(n.canEmitEvents=!1,e.triggerClick(i))}}}},{}],8:[function(t,e,n){"use strict";var o="input:text";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)){var n=t.utils.getSingleElement(e.tagName,e.index);if(n)return n.value=e.value,n}return!1}}},{}],9:[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.opts.ghostMode.forms;r===!0&&(i=!1);for(var c in n.plugins)i?r[c]&&o(c):o(c)}},{"./ghostmode.forms.input":8,"./ghostmode.forms.submit":10,"./ghostmode.forms.toggles":11}],10:[function(t,e,n){"use strict";var o="form: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)){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}}},{}],11:[function(t,e,n){"use strict";var o="input: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)){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}}},{}],12:[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){function e(e){n.plugins[e].init(t,o)}var i=t.opts.ghostMode;for(var r in n.plugins)i[r]&&e(r)}},{"./events":5,"./ghostmode.clicks":7,"./ghostmode.forms":9,"./ghostmode.location":13,"./ghostmode.scroll":14}],13:[function(t,e,n){"use strict";var o="location";n.canEmitEvents=!0,n.init=function(t){t.socket.on(o,n.socketEvent())},n.socketEvent=function(){return function(t){window.location=t.url}}},{}],14:[function(t,e,n){"use strict";var o,i="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)?t.opts&&t.opts.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}},{}],15:[function(t,e,n){"use strict";var o,i,r,c=(t("./ghostmode.scroll"),["background-color: black","color: white","padding: 10px","display: none","font-family: sans-serif","position: absolute","z-index: 9999","right: 0px","border-bottom-left-radius: 5px"]);n.init=function(t){o=t,r=t.opts;var e=c;return r.notify.styles&&(e=r.notify.styles),i=document.createElement("DIV"),i.id="notifyElem",i.style.cssText=e.join(";"),document.getElementsByTagName("body")[0].appendChild(i),o.emitter.on("notify",n.watchEvent()),i},n.watchEvent=function(){return function(t){n.flash(t.message)}},n.getElem=function(){return i},n.getScrollTop=function(){return o.utils.getBrowserScrollPosition().y},n.flash=function(t,e){var o=n.getElem();if(!o)return!1;var i=document.getElementsByTagName("HTML")[0];return i.style.position="relative",o.innerHTML=t,o.style.top=n.getScrollTop()+"px",o.style.display="block",window.setTimeout(function(){o.style.display="none"},e||2e3),o}},{"./ghostmode.scroll":14}],16:[function(t,e,n){"use strict";n.socket=window.___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)}},{}]},{},[6]); |
@@ -1,9 +0,35 @@ | ||
var inputs = require("./ghostmode.forms.input"); | ||
var toggles = require("./ghostmode.forms.toggles"); | ||
var submit = require("./ghostmode.forms.submit"); | ||
"use strict"; | ||
exports.plugins = { | ||
"inputs": require("./ghostmode.forms.input"), | ||
"toggles": require("./ghostmode.forms.toggles"), | ||
"submit": require("./ghostmode.forms.submit") | ||
}; | ||
/** | ||
* Load plugins for enabled options | ||
* @param bs | ||
*/ | ||
exports.init = function (bs, eventManager) { | ||
inputs.init(bs, eventManager); | ||
toggles.init(bs, eventManager); | ||
submit.init(bs, eventManager); | ||
var checkOpt = true; | ||
var opts = bs.opts.ghostMode.forms; | ||
if (opts === true) { | ||
checkOpt = false; | ||
} | ||
function init(name) { | ||
exports.plugins[name].init(bs, eventManager); | ||
} | ||
for (var name in exports.plugins) { | ||
if (!checkOpt) { | ||
init(name); | ||
} else { | ||
if (opts[name]) { | ||
init(name); | ||
} | ||
} | ||
} | ||
}; |
@@ -6,15 +6,8 @@ "use strict"; | ||
exports.plugins = { | ||
"scroll": require("./ghostmode.scroll"), | ||
"clicks": require("./ghostmode.clicks"), | ||
"forms": require("./ghostmode.forms"), | ||
"scroll": require("./ghostmode.scroll"), | ||
"clicks": require("./ghostmode.clicks"), | ||
"forms": require("./ghostmode.forms"), | ||
"location": require("./ghostmode.location") | ||
}; | ||
var options = [ | ||
"scroll", | ||
"clicks", | ||
"forms", | ||
"location" | ||
]; | ||
/** | ||
@@ -25,9 +18,14 @@ * Load plugins for enabled options | ||
exports.init = function (bs) { | ||
var ghostMode = bs.opts.ghostMode; | ||
for (var i = 0, n = options.length; i < n; i += 1) { | ||
var item = options[i]; | ||
if (ghostMode[item]) { | ||
exports.plugins[item].init(bs, eventManager); | ||
function init(name) { | ||
exports.plugins[name].init(bs, eventManager); | ||
} | ||
for (var name in exports.plugins) { | ||
if (ghostMode[name]) { | ||
init(name); | ||
} | ||
} | ||
}; |
@@ -63,2 +63,3 @@ "use strict"; | ||
window.__bs_submit__ = require("./ghostmode.forms.submit"); | ||
window.__bs_forms__ = require("./ghostmode.forms"); | ||
window.__bs_utils__ = require("./browser.utils"); | ||
@@ -65,0 +66,0 @@ window.__bs_emitter__ = emitter; |
{ | ||
"name": "browser-sync-client", | ||
"description": "Client-side scripts for BrowserSync", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"homepage": "https://github.com/shakyshane/browser-sync-client", | ||
@@ -6,0 +6,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144533
2191