Skip to content

Commit

Permalink
easy test was integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
studentIvan committed Jan 6, 2015
1 parent 0fb02a1 commit c60f82c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 49 deletions.
7 changes: 4 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "dueljs",
"name": "duel",
"version": "1.0.0",
"homepage": "http://dueljs.studentivan.ru",
"authors": [
"Maslov Ivan <[email protected]>"
],
"description": "JavaScript HTML5 Master/Slave Browser Tabs Helper",
"main": "lib/duel.js",
"main": "public/lib/duel.js",
"keywords": [
"dueljs",
"duel",
Expand All @@ -15,7 +15,8 @@
"window",
"javascript",
"onfocus",
"broadcasting"
"broadcasting",
"document.hidden"
],
"license": "MIT",
"ignore": [
Expand Down
25 changes: 0 additions & 25 deletions example.html

This file was deleted.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "dueljs",
"name": "duel",
"version": "1.0.0",
"description": "DuelJS - JavaScript HTML5 Master/Slave Browser Tabs Helper",
"main": "lib/duel.js",
"main": "public/lib/duel.js",
"devDependencies": {

"http-server": "^0.6.1"
},
"scripts": {
"test": "test"
"pretest": "npm install",
"test": "http-server -a localhost -p 8624 -o -c-1"
},
"repository": {
"type": "git",
Expand All @@ -21,7 +22,8 @@
"window",
"javascript",
"onfocus",
"broadcasting"
"broadcasting",
"document.hidden"
],
"author": "Maslov Ivan <[email protected]>",
"license": "MIT",
Expand Down
35 changes: 35 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Duel page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//yastatic.net/bootstrap/3.3.1/css/bootstrap.min.css">
<script type="text/javascript" src="lib/duel.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h2>Window <small id="wndID">...</small></h2>
<div><a class="btn btn-default" href="index.html" target="_blank">Open new window</a>&nbsp;
<button class="btn btn-default" onclick="channel.broadcast('demo_trigger', 'ya', duel.getWindowID())">
channel.broadcast('demo_trigger', 'ya', duel.getWindowID())
</button></div>
<div style="margin-top: 10px; color: #777777"><em>
Hint: open the developer console before broadcasting.
</em></div>
</div>
<script type="text/javascript">
var channel = duel.channel('test');
document.title = 'Master ' + duel.getWindowID();
document.getElementById('wndID').innerHTML = (duel.getWindowID()).toString();

channel.on('demo_trigger', function (message, wndID) {
console.info(wndID, (new Date), message);
});

setInterval(function () {
document.title = (window.isMaster() ? 'Master ' : 'Slave ') + duel.getWindowID();
}, 100);
</script>
</body>
</html>
32 changes: 16 additions & 16 deletions lib/duel.js → public/lib/duel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ duel.DuelAbstractChannel = (function () {
* @returns {string}
*/
DuelAbstractChannel.prototype.getName = function () {
return this._name
return this._name;
};

/**
* @returns {boolean}
*/
DuelAbstractChannel.prototype.setCurrentWindowAsMaster = function () {
return true
return true;
};

/**
* @returns {boolean}
*/
DuelAbstractChannel.prototype.currentWindowIsMaster = function () {
return true
return true;
};

/**
Expand All @@ -82,7 +82,7 @@ duel.DuelAbstractChannel = (function () {
this.executeTrigger({
name: trigger,
args: Array.prototype.slice.call(arguments, 1)
})
});
}
};

Expand Down Expand Up @@ -122,15 +122,15 @@ duel.DuelAbstractChannel = (function () {
*/
duel._generateWindowID = function () {
this._windowID = +Math.random().toString().split('.')[1];
return this._windowID
return this._windowID;
};

/**
* Get unique tab ID
* @returns {number}
*/
duel.getWindowID = function () {
return this._windowID ? this._windowID : this._generateWindowID()
return this._windowID ? this._windowID : this._generateWindowID();
};

/**
Expand Down Expand Up @@ -170,13 +170,13 @@ duel.DuelLocalStorageChannel.prototype.setCurrentWindowAsMaster = function () {
} else {
ch[wIndex].master = true
}
localStorage.setItem(chName, JSON.stringify(ch))
localStorage.setItem(chName, JSON.stringify(ch));
} else {
localStorage.setItem(chName, JSON.stringify([
{id: wID, master: true}
]))
]));
}
return true
return true;
};

/**
Expand All @@ -192,9 +192,9 @@ duel.DuelLocalStorageChannel.prototype.currentWindowIsMaster = function () {
break;
}
}
return (wIndex === -1) ? false : ch[wIndex].master
return (wIndex === -1) ? false : ch[wIndex].master;
} else {
return false
return false;
}
};

Expand Down Expand Up @@ -250,7 +250,7 @@ duel.channel = function (name) {
var channel = this.isLocalStorageAvailable()
? new this.DuelLocalStorageChannel(name) : new this.DuelFakeChannel(name);
duel.activeChannels.push(channel);
return channel
return channel;
};

/**
Expand All @@ -260,7 +260,7 @@ duel.channel = function (name) {
duel.makeCurrentWindowMaster = function () {
for (var i = duel.activeChannels.length - 1; i >= 0; i--) {
try {
duel.activeChannels[i].setCurrentWindowAsMaster()
duel.activeChannels[i].setCurrentWindowAsMaster();
} catch (e) {
// stop to exceptions
}
Expand All @@ -271,7 +271,7 @@ duel.makeCurrentWindowMaster = function () {
* Makes tab focus trigger for special browsers
*/
window.onfocus = function () {
duel.makeCurrentWindowMaster()
duel.makeCurrentWindowMaster();
};

/**
Expand All @@ -280,7 +280,7 @@ window.onfocus = function () {
*/
window.isMaster = function () {
return duel.activeChannels.length ?
duel.activeChannels[0].currentWindowIsMaster() : false
duel.activeChannels[0].currentWindowIsMaster() : false;
};

/**
Expand Down Expand Up @@ -333,7 +333,7 @@ duel.storageEvent = function (event) {
for (var i = duel.activeChannels.length - 1; i >= 0; i--) {
try {
if (duel.activeChannels[i].getName() == eventDetails.channelName) {
duel.activeChannels[i].executeTrigger(eventDetails.triggerDetails)
duel.activeChannels[i].executeTrigger(eventDetails.triggerDetails);
}
} catch (e) {
// stop to exceptions
Expand Down
File renamed without changes.

0 comments on commit c60f82c

Please sign in to comment.