memo/client/script.js

1140 lines
30 KiB
JavaScript
Raw Normal View History

2011-03-10 08:20:27 -05:00
var cards = {};
var totalcolumns = 0;
var columns = [];
2011-03-12 13:40:44 -05:00
var currentTheme = "bigcards";
2011-05-29 15:36:30 -04:00
var boardInitialized = false;
var keyTrap = null;
2011-03-10 08:20:27 -05:00
var baseurl = location.pathname.substring(0, location.pathname.lastIndexOf('/'));
var socket = io.connect({path: baseurl + "/socket.io"});
2011-03-10 08:20:27 -05:00
moment.locale(navigator.language || navigator.languages[0]);
2017-07-05 19:42:34 -04:00
marked.setOptions({sanitize: true});
2011-03-10 08:20:27 -05:00
//an action has happened, send it to the
//server
2014-09-13 02:04:27 -04:00
function sendAction(a, d) {
//console.log('--> ' + a);
2014-09-13 02:04:27 -04:00
var message = {
action: a,
data: d
};
2014-09-13 02:04:27 -04:00
socket.json.send(message);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
socket.on('connect', function() {
//console.log('successful socket.io connect');
//let the final part of the path be the room name
var room = location.pathname.substring(location.pathname.lastIndexOf('/'));
2014-09-13 02:04:27 -04:00
//imediately join the room which will trigger the initializations
sendAction('joinRoom', room);
2014-09-01 15:44:07 -04:00
});
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
socket.on('disconnect', function() {
2016-08-03 16:12:11 +02:00
blockUI("Serveur déconnecté. Veuillez rafraîchir la page pour essayer de vous reconnecter…");
2014-09-13 02:04:27 -04:00
//$('.blockOverlay').click($.unblockUI);
2011-03-10 08:20:27 -05:00
});
2014-09-13 02:04:27 -04:00
socket.on('message', function(data) {
getMessage(data);
2014-09-01 15:44:07 -04:00
});
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
function unblockUI() {
2014-10-12 13:33:43 -04:00
$.unblockUI({fadeOut: 50});
2011-05-29 15:36:30 -04:00
}
2014-09-13 02:04:27 -04:00
function blockUI(message) {
2016-08-03 16:12:11 +02:00
message = message || 'En attente…';
2014-09-13 02:04:27 -04:00
$.blockUI({
message: message,
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: 0.5,
color: '#fff',
fontSize: '20px'
2014-10-12 13:33:43 -04:00
},
fadeOut: 0,
fadeIn: 10
2014-09-13 02:04:27 -04:00
});
2011-05-29 15:36:30 -04:00
}
2011-03-10 08:20:27 -05:00
//respond to an action event
2014-09-13 02:04:27 -04:00
function getMessage(m) {
var message = m; //JSON.parse(m);
var action = message.action;
var data = message.data;
//console.log('<-- ' + action);
switch (action) {
case 'roomAccept':
//okay we're accepted, then request initialization
//(this is a bit of unnessary back and forth but that's okay for now)
sendAction('initializeMe', null);
break;
case 'roomDeny':
//this doesn't happen yet
break;
case 'moveCard':
moveCard($("#" + data.id), data.position);
break;
case 'initCards':
initCards(data);
break;
case 'createCard':
//console.log(data);
drawNewCard(data.id, data.text, data.x, data.y, data.rot, data.colour,
null);
break;
case 'deleteCard':
$("#" + data.id).fadeOut(500,
function() {
$(this).remove();
}
);
break;
case 'editCard':
$("#" + data.id).children('.content:first').attr('data-text', data.value);
$("#" + data.id).children('.content:first').html(marked(data.value));
2014-09-13 02:04:27 -04:00
break;
case 'initColumns':
initColumns(data);
break;
case 'updateColumns':
initColumns(data);
break;
case 'changeTheme':
changeThemeTo(data);
break;
case 'join-announce':
displayUserJoined(data.sid, data.user_name);
break;
case 'leave-announce':
displayUserLeft(data.sid);
break;
case 'initialUsers':
displayInitialUsers(data);
break;
case 'nameChangeAnnounce':
updateName(message.data.sid, message.data.user_name);
break;
case 'addSticker':
addSticker(message.data.cardId, message.data.stickerId);
break;
case 'setBoardSize':
resizeBoard(message.data);
break;
2016-09-13 09:06:15 +02:00
case 'export':
download(message.data.filename, message.data.text);
break;
case 'addRevision':
addRevision(message.data);
break;
case 'deleteRevision':
$('#revision-'+message.data).remove();
break;
case 'initRevisions':
$('#revisions-list').empty();
for (var i = 0; i < message.data.length; i++) {
addRevision(message.data[i]);
}
break;
2014-09-13 02:04:27 -04:00
default:
//unknown message
2016-08-03 16:12:11 +02:00
alert('action inconnue : ' + JSON.stringify(message));
2014-09-13 02:04:27 -04:00
break;
}
2011-03-10 08:20:27 -05:00
}
$(document).bind('keyup', function(event) {
2014-09-13 02:04:27 -04:00
keyTrap = event.which;
});
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
function drawNewCard(id, text, x, y, rot, colour, sticker, animationspeed) {
//cards[id] = {id: id, text: text, x: x, y: y, rot: rot, colour: colour};
2014-09-13 02:04:27 -04:00
var h = '<div id="' + id + '" class="card ' + colour +
' draggable" style="-webkit-transform:rotate(' + rot +
'deg);\
">\
<img src="images/icons/token/Xion.png" class="card-icon delete-card-icon" />\
<img class="card-image" src="images/' +
2014-09-13 02:04:27 -04:00
colour + '-card.png">\
<div id="content:' + id +
'" class="content stickertarget droppable" data-text="">' +
marked(text) + '</div><span class="filler"></span>\
2011-03-10 08:20:27 -05:00
</div>';
2011-06-14 07:42:04 +08:00
2014-09-13 02:04:27 -04:00
var card = $(h);
card.appendTo('#board');
$("#" + id).children('.content:first').attr('data-text', text);
2014-09-13 02:04:27 -04:00
//@TODO
//Draggable has a bug which prevents blur event
//http://bugs.jqueryui.com/ticket/4261
//So we have to blur all the cards and editable areas when
//we click on a card
//The following doesn't work so we will do the bug
//fix recommended in the above bug report
// card.click( function() {
// $(this).focus();
// } );
card.draggable({
snap: false,
snapTolerance: 5,
containment: [0, 0, 2000, 2000],
stack: ".card",
start: function(event, ui) {
keyTrap = null;
},
drag: function(event, ui) {
if (keyTrap == 27) {
ui.helper.css(ui.originalPosition);
return false;
}
2014-09-13 09:33:50 -04:00
},
handle: "div.content"
2014-09-13 02:04:27 -04:00
});
//After a drag:
card.bind("dragstop", function(event, ui) {
if (keyTrap == 27) {
keyTrap = null;
return;
}
var data = {
id: this.id,
position: ui.position,
oldposition: ui.originalPosition,
};
sendAction('moveCard', data);
});
card.children(".droppable").droppable({
accept: '.sticker',
drop: function(event, ui) {
var stickerId = ui.draggable.attr("id");
var cardId = $(this).parent().attr('id');
addSticker(cardId, stickerId);
var data = {
cardId: cardId,
stickerId: stickerId
};
sendAction('addSticker', data);
//remove hover state to everything on the board to prevent
//a jquery bug where it gets left around
$('.card-hover-draggable').removeClass('card-hover-draggable');
},
hoverClass: 'card-hover-draggable'
});
var speed = Math.floor(Math.random() * 1000);
if (typeof(animationspeed) != 'undefined') speed = animationspeed;
var startPosition = $("#create-card").position();
card.css('top', startPosition.top - card.height() * 0.5);
card.css('left', startPosition.left - card.width() * 0.5);
card.animate({
left: x + "px",
top: y + "px"
}, speed);
card.hover(
function() {
$(this).addClass('hover');
$(this).children('.card-icon').fadeIn(10);
},
function() {
$(this).removeClass('hover');
$(this).children('.card-icon').fadeOut(150);
}
);
card.children('.card-icon').hover(
function() {
$(this).addClass('card-icon-hover');
},
function() {
$(this).removeClass('card-icon-hover');
}
);
card.children('.delete-card-icon').click(
function() {
$("#" + id).remove();
//notify server of delete
sendAction('deleteCard', {
'id': id
});
}
);
card.children('.content').editable(function(value, settings) {
$("#" + id).children('.content:first').attr('data-text', value);
2014-09-13 02:04:27 -04:00
onCardChange(id, value);
return (marked(value));
2014-09-13 02:04:27 -04:00
}, {
type: 'textarea',
data: function() {
return $("#" + id).children('.content:first').attr('data-text');
},
2014-09-13 02:04:27 -04:00
submit: 'OK',
style: 'inherit',
cssclass: 'card-edit-form',
2016-08-03 16:12:11 +02:00
placeholder: 'Double cliquez pour méditer',
2014-09-13 02:04:27 -04:00
onblur: 'submit',
event: 'dblclick', //event: 'mouseover'
});
//add applicable sticker
if (sticker !== null)
addSticker(id, sticker);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function onCardChange(id, text) {
sendAction('editCard', {
id: id,
value: text
});
2011-03-10 08:20:27 -05:00
}
2011-06-14 07:42:04 +08:00
function moveCard(card, position) {
2014-09-13 02:04:27 -04:00
card.animate({
left: position.left + "px",
top: position.top + "px"
}, 500);
2011-06-14 07:42:04 +08:00
}
2014-09-13 02:04:27 -04:00
function addSticker(cardId, stickerId) {
2014-09-13 02:04:27 -04:00
stickerContainer = $('#' + cardId + ' .filler');
2014-09-13 02:04:27 -04:00
if (stickerId === "nosticker") {
stickerContainer.html("");
return;
}
2014-09-13 02:04:27 -04:00
if (Array.isArray(stickerId)) {
for (var i in stickerId) {
stickerContainer.prepend('<img src="images/stickers/' + stickerId[i] +
'.png">');
}
} else {
if (stickerContainer.html().indexOf(stickerId) < 0)
stickerContainer.prepend('<img src="images/stickers/' + stickerId +
'.png">');
}
2011-03-10 08:20:27 -05:00
}
//----------------------------------
// cards
//----------------------------------
2014-09-13 02:04:27 -04:00
function createCard(id, text, x, y, rot, colour) {
drawNewCard(id, text, x, y, rot, colour, null);
2014-09-13 02:04:27 -04:00
var action = "createCard";
2014-09-13 02:04:27 -04:00
var data = {
id: id,
text: text,
x: x,
y: y,
rot: rot,
colour: colour
};
2014-09-13 02:04:27 -04:00
sendAction(action, data);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function randomCardColour() {
var colours = ['yellow', 'green', 'blue', 'white'];
2014-09-13 02:04:27 -04:00
var i = Math.floor(Math.random() * colours.length);
2014-09-13 02:04:27 -04:00
return colours[i];
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function initCards(cardArray) {
//first delete any cards that exist
$('.card').remove();
2014-09-13 02:04:27 -04:00
cards = cardArray;
2014-09-13 02:04:27 -04:00
for (var i in cardArray) {
card = cardArray[i];
2014-09-13 02:04:27 -04:00
drawNewCard(
card.id,
card.text,
card.x,
card.y,
card.rot,
card.colour,
2014-10-12 13:33:43 -04:00
card.sticker,
0
2014-09-13 02:04:27 -04:00
);
}
2011-05-29 15:36:30 -04:00
2014-09-13 02:04:27 -04:00
boardInitialized = true;
unblockUI();
2011-03-10 08:20:27 -05:00
}
//----------------------------------
// cols
//----------------------------------
2014-09-13 02:04:27 -04:00
function drawNewColumn(columnName) {
var cls = "col";
if (totalcolumns === 0) {
cls = "col first";
}
$('#icon-col').before('<td class="' + cls +
'" width="10%" style="display:none"><h2 id="col-' + (totalcolumns + 1) +
'" class="editable">' + columnName + '</h2></td>');
$('.editable').editable(function(value, settings) {
onColumnChange(this.id, value);
return (value);
}, {
style: 'inherit',
cssclass: 'card-edit-form',
type: 'textarea',
2016-08-03 16:12:11 +02:00
placeholder: 'Nouveau',
2014-09-13 02:04:27 -04:00
onblur: 'submit',
width: '',
height: '',
xindicator: '<img src="images/ajax-loader.gif">',
2014-09-13 02:04:27 -04:00
event: 'dblclick', //event: 'mouseover'
});
$('.col:last').fadeIn(1500);
totalcolumns++;
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function onColumnChange(id, text) {
var names = Array();
2014-09-13 02:04:27 -04:00
//console.log(id + " " + text );
2014-09-13 02:04:27 -04:00
//Get the names of all the columns right from the DOM
$('.col').each(function() {
2014-09-13 02:04:27 -04:00
//get ID of current column we are traversing over
var thisID = $(this).children("h2").attr('id');
2014-09-13 02:04:27 -04:00
if (id == thisID) {
names.push(text);
} else {
names.push($(this).text());
}
2014-09-13 02:04:27 -04:00
});
2014-09-13 02:04:27 -04:00
updateColumns(names);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function displayRemoveColumn() {
if (totalcolumns <= 0) return false;
2014-09-13 02:04:27 -04:00
$('.col:last').fadeOut(150,
function() {
$(this).remove();
}
);
2014-09-13 02:04:27 -04:00
totalcolumns--;
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function createColumn(name) {
if (totalcolumns >= 8) return false;
2014-09-13 02:04:27 -04:00
drawNewColumn(name);
columns.push(name);
2014-09-13 02:04:27 -04:00
var action = "updateColumns";
2014-09-13 02:04:27 -04:00
var data = columns;
2014-09-13 02:04:27 -04:00
sendAction(action, data);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function deleteColumn() {
if (totalcolumns <= 0) return false;
2014-09-13 02:04:27 -04:00
displayRemoveColumn();
columns.pop();
2014-09-13 02:04:27 -04:00
var action = "updateColumns";
2014-09-13 02:04:27 -04:00
var data = columns;
2014-09-13 02:04:27 -04:00
sendAction(action, data);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function updateColumns(c) {
columns = c;
2014-09-13 02:04:27 -04:00
var action = "updateColumns";
2014-09-13 02:04:27 -04:00
var data = columns;
2014-09-13 02:04:27 -04:00
sendAction(action, data);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function deleteColumns(next) {
//delete all existing columns:
$('.col').fadeOut('slow', next());
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function initColumns(columnArray) {
totalcolumns = 0;
columns = columnArray;
2014-09-13 02:04:27 -04:00
$('.col').remove();
2014-09-13 02:04:27 -04:00
for (var i in columnArray) {
column = columnArray[i];
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
drawNewColumn(
column
);
}
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function changeThemeTo(theme) {
currentTheme = theme;
$("link[title=cardsize]").attr("href", "css/" + theme + ".css");
2011-03-10 08:20:27 -05:00
}
//////////////////////////////////////////////////////////
////////// NAMES STUFF ///////////////////////////////////
//////////////////////////////////////////////////////////
2014-09-13 02:04:27 -04:00
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays === null) ? "" : "; expires=" +
exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function setName(name) {
sendAction('setUserName', name);
2014-09-13 02:04:27 -04:00
setCookie('scrumscrum-username', name, 365);
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function displayInitialUsers(users) {
for (var i in users) {
//console.log(users);
displayUserJoined(users[i].sid, users[i].user_name);
}
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function displayUserJoined(sid, user_name) {
name = '';
if (user_name)
name = user_name;
else
name = sid.substring(0, 5);
2014-09-13 02:04:27 -04:00
$('#names-ul').append('<li id="user-' + sid + '">' + name + '</li>');
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function displayUserLeft(sid) {
name = '';
if (name)
name = user_name;
else
name = sid;
2014-09-13 02:04:27 -04:00
var id = '#user-' + sid.toString();
2014-09-13 02:04:27 -04:00
$('#names-ul').children(id).fadeOut(1000, function() {
$(this).remove();
});
2011-03-10 08:20:27 -05:00
}
2014-09-13 02:04:27 -04:00
function updateName(sid, name) {
var id = '#user-' + sid.toString();
2014-09-13 02:04:27 -04:00
$('#names-ul').children(id).text(name);
2011-03-10 08:20:27 -05:00
}
2011-05-27 01:08:25 -04:00
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
2014-09-13 02:04:27 -04:00
function boardResizeHappened(event, ui) {
var newsize = ui.size;
2011-06-14 07:42:04 +08:00
2014-09-13 02:04:27 -04:00
sendAction('setBoardSize', newsize);
2011-05-27 01:08:25 -04:00
}
2014-09-13 02:04:27 -04:00
function resizeBoard(size) {
$(".board-outline").animate({
height: size.height,
width: size.width
});
2011-05-27 01:08:25 -04:00
}
2011-03-10 08:20:27 -05:00
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
2011-06-14 07:42:04 +08:00
function calcCardOffset() {
2014-09-13 02:04:27 -04:00
var offsets = {};
$(".card").each(function() {
var card = $(this);
$(".col").each(function(i) {
var col = $(this);
if (col.offset().left + col.outerWidth() > card.offset().left +
card.outerWidth() || i === $(".col").size() - 1) {
offsets[card.attr('id')] = {
col: col,
x: ((card.offset().left - col.offset().left) / col.outerWidth())
};
return false;
}
});
});
return offsets;
2011-06-14 07:42:04 +08:00
}
2011-06-23 19:12:53 -04:00
//moves cards with a resize of the Board
//doSync is false if you don't want to synchronize
//with all the other users who are in this room
function adjustCard(offsets, doSync) {
2014-09-13 01:55:57 -04:00
$(".card").each(function() {
var card = $(this);
var offset = offsets[this.id];
if (offset) {
var data = {
id: this.id,
position: {
left: offset.col.position().left + (offset.x * offset.col
.outerWidth()),
top: parseInt(card.css('top').slice(0, -2))
},
oldposition: {
left: parseInt(card.css('left').slice(0, -2)),
top: parseInt(card.css('top').slice(0, -2))
}
}; //use .css() instead of .position() because css' rotate
//console.log(data);
if (!doSync) {
card.css('left', data.position.left);
card.css('top', data.position.top);
} else {
//note that in this case, data.oldposition isn't accurate since
//many moves have happened since the last sync
//but that's okay becuase oldPosition isn't used right now
moveCard(card, data.position);
sendAction('moveCard', data);
}
}
});
2011-06-14 07:42:04 +08:00
}
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
2016-09-13 09:06:15 +02:00
function download(filename, text) {
var element = document.createElement('a');
var mime = 'text/plain';
if (filename.match(/.csv$/)) {
mime = 'text/csv';
}
element.setAttribute('href', 'data:'+mime+';charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function addRevision(timestamp) {
var li = $('<li id="revision-'+timestamp+'"></li>');
var s1 = $('<span></span>');
var s2 = $('<img src="../images/stickers/sticker-deletestar.png" alt="delete revision">');
if (typeof(timestamp) === 'string') {
timestamp = parseInt(timestamp);
}
s1.text(moment(timestamp).format('LLLL'));
li.append(s1);
li.append(s2);
$('#revisions-list').append(li);
s1.click(function() {
socket.json.send({
action: 'exportRevision',
data: timestamp
});
});
s2.click(function() {
socket.json.send({
action: 'deleteRevision',
data: timestamp
});
});
}
2016-09-13 09:06:15 +02:00
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
2011-03-10 08:20:27 -05:00
$(function() {
2014-09-13 09:33:50 -04:00
//disable image dragging
//window.ondragstart = function() { return false; };
2014-09-13 02:04:27 -04:00
if (boardInitialized === false)
blockUI('<img src="images/ajax-loader.gif" width=43 height=11/>');
2011-05-29 15:36:30 -04:00
2014-09-13 02:04:27 -04:00
//setTimeout($.unblockUI, 2000);
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
$("#create-card")
.click(function() {
var rotation = Math.random() * 10 - 5; //add a bit of random rotation (+/- 10deg)
uniqueID = Math.round(Math.random() * 99999999); //is this big enough to assure uniqueness?
//alert(uniqueID);
createCard(
'card' + uniqueID,
'',
58, $('div.board-outline').height(), // hack - not a great way to get the new card coordinates, but most consistant ATM
rotation,
randomCardColour());
});
2014-09-13 02:04:27 -04:00
// Style changer
$("#smallify").click(function() {
if (currentTheme == "bigcards") {
changeThemeTo('smallcards');
} else if (currentTheme == "smallcards") {
changeThemeTo('bigcards');
}
/*else if (currentTheme == "nocards")
2011-03-10 08:20:27 -05:00
{
2011-03-12 13:40:44 -05:00
currentTheme = "bigcards";
2011-03-10 08:20:27 -05:00
$("link[title=cardsize]").attr("href", "css/bigcards.css");
}*/
2014-09-13 02:04:27 -04:00
sendAction('changeTheme', currentTheme);
2014-09-13 02:04:27 -04:00
return false;
});
2014-09-13 02:04:27 -04:00
$('#icon-col').hover(
function() {
$('.col-icon').fadeIn(10);
},
function() {
$('.col-icon').fadeOut(150);
}
);
2014-09-13 02:04:27 -04:00
$('#add-col').click(
function() {
2016-08-03 16:12:11 +02:00
createColumn('Nouveau');
2014-09-13 02:04:27 -04:00
return false;
}
);
2014-09-13 02:04:27 -04:00
$('#delete-col').click(
function() {
deleteColumn();
return false;
}
);
2014-09-13 02:04:27 -04:00
// $('#cog-button').click( function(){
// $('#config-dropdown').fadeToggle();
// } );
2014-09-13 02:04:27 -04:00
// $('#config-dropdown').hover(
// function(){ /*$('#config-dropdown').fadeIn()*/ },
// function(){ $('#config-dropdown').fadeOut() }
// );
//
2014-09-13 02:04:27 -04:00
var user_name = getCookie('scrumscrum-username');
2014-09-13 02:04:27 -04:00
$("#yourname-input").focus(function() {
2016-08-03 16:12:11 +02:00
if ($(this).val() == 'anonyme') {
2014-09-13 02:04:27 -04:00
$(this).val("");
}
2014-09-13 02:04:27 -04:00
$(this).addClass('focused');
2014-09-13 02:04:27 -04:00
});
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
$("#yourname-input").blur(function() {
if ($(this).val() === "") {
2016-08-03 16:12:11 +02:00
$(this).val('anonyme');
2014-09-13 02:04:27 -04:00
}
$(this).removeClass('focused');
2014-09-13 02:04:27 -04:00
setName($(this).val());
});
2014-09-13 02:04:27 -04:00
$("#yourname-input").val(user_name);
$("#yourname-input").blur();
2014-09-13 02:04:27 -04:00
$("#yourname-li").hide();
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
$("#yourname-input").keypress(function(e) {
code = (e.keyCode ? e.keyCode : e.which);
if (code == 10 || code == 13) {
$(this).blur();
}
});
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
$(".sticker").draggable({
revert: true,
zIndex: 1000
});
2011-03-10 08:20:27 -05:00
2014-09-13 02:04:27 -04:00
$(".board-outline").resizable({
ghost: false,
minWidth: 700,
minHeight: 400,
maxWidth: 3200,
maxHeight: 1800,
});
//A new scope for precalculating
(function() {
var offsets;
$(".board-outline").bind("resizestart", function() {
offsets = calcCardOffset();
});
$(".board-outline").bind("resize", function(event, ui) {
adjustCard(offsets, false);
});
$(".board-outline").bind("resizestop", function(event, ui) {
boardResizeHappened(event, ui);
adjustCard(offsets, true);
});
})();
$('#marker').draggable({
axis: 'x',
containment: 'parent'
});
$('#eraser').draggable({
axis: 'x',
containment: 'parent'
});
2011-03-10 08:20:27 -05:00
2016-09-13 09:06:15 +02:00
$('#export-txt').click(function() {
$('.nav-tabs a[href="#scrumblr"]').tab('show');
2016-09-13 09:06:15 +02:00
socket.json.send({
action: 'exportTxt',
data: ($('.col').length !== 0) ? $('.col').css('width').replace('px', '') : null
});
})
2011-10-11 09:51:31 -04:00
2016-09-13 09:06:15 +02:00
$('#export-csv').click(function() {
$('.nav-tabs a[href="#scrumblr"]').tab('show');
2016-09-13 09:06:15 +02:00
socket.json.send({
action: 'exportCsv',
data: ($('.col').length !== 0) ? $('.col').css('width').replace('px', '') : null
});
})
$('#export-json').click(function() {
socket.json.send({
action: 'exportJson',
data: {
width: $('.board-outline').css('width').replace('px', ''),
height: $('.board-outline').css('height').replace('px', '')
}
});
})
$('#import-file').click(function(evt) {
evt.stopPropagation();
evt.preventDefault();
var f = $('#import-input').get(0).files[0];
var fr = new FileReader();
fr.onloadend = function() {
var text = fr.result;
socket.json.send({
action: 'importJson',
data: JSON.parse(text)
});
};
fr.readAsText(f);
2016-09-13 09:06:15 +02:00
})
$('#create-revision').click(function() {
socket.json.send({
action: 'createRevision',
data: {
width: $('.board-outline').css('width').replace('px', ''),
height: $('.board-outline').css('height').replace('px', '')
}
});
})
2011-03-10 08:20:27 -05:00
});
2017-07-12 08:57:22 +02:00
/** Doubleclick on mobile + Layout Framemo with tabs **/
$(document).ready(function(){
if(window.location.href != window.location.protocol+'//'+window.location.host+'/') { // Not on homepage
/** Double click on mobile interface **/
var clickTimer = null;
var clickTarget = null;
var editTarget = null;
function doubletapCards( selector ) {
$(selector+' .stickertarget').addClass('doubletap'); // Escape multi bound
$(selector+' .doubletap').on('click', function() {
clickTarget = selector.replace('#','');
if (clickTimer == null) {
clickTimer = setTimeout(function () {
clickTimer = null;
}, 1000)
} else {
//console.log('doubleclick : '+clickTimer+':'+editTarget);
clearTimeout(clickTimer);
clickTimer = null;
if(editTarget == clickTarget && clickTarget !== undefined && clickTarget !== null) {
$('#'+clickTarget.replace('content:','')+' .doubletap').trigger('dblclick');
}
}
editTarget = clickTarget;
});
}
function doubletapTitle( selector ) {
$(selector).addClass('doubletap'); // Escape multi bound
$(selector+'.doubletap').on('click', function() {
clickTarget = selector.replace('#','');
if (clickTimer == null) {
clickTimer = setTimeout(function () {
clickTimer = null;
}, 1000)
} else {
//console.log('doubleclick : '+clickTimer+':'+editTarget);
clearTimeout(clickTimer);
clickTimer = null;
if(editTarget == clickTarget && clickTarget !== undefined && clickTarget !== null) {
$('#'+clickTarget+'.doubletap').trigger('dblclick');
}
}
editTarget = clickTarget;
});
}
setInterval(function() { // Add periodically the doubletap event on new cards
$('.stickertarget:not(.doubletap)').each(function(){
doubletapCards('#'+$(this).attr('id').replace('content:',''));
});
$('#board-table .col h2:not(.doubletap)').each(function(){
doubletapTitle('#'+$(this).attr('id'));
});
}, 500);
/** Layout Framemo - Tabs **/
// Defaut board real size (not 'auto' or 'inherit') saved in database
// in order to be able to center it
var boardReady = setInterval(function() {
if(boardInitialized) { // when board is ready
if($('.board-outline').attr('style') === undefined) { // check if size is imported from db
$('.board-outline').css({
'width':$('.board-outline.ui-resizable').width()+16+'px',
'height':'466px'
})
var data= {};
data.size = {
height: 466,
width: $('.board-outline.ui-resizable').width()+16
}
boardResizeHappened("resizestop", data) // using scrumblr function that keep size in db after a resize
}
clearInterval(boardReady);
}
}, 500);
2017-07-12 08:57:22 +02:00
// Tabs
2017-07-12 08:57:22 +02:00
$('.board-outline')
.before(
'<ul class="nav nav-tabs">'+
'<li role="presentation" class="active"><a href="#scrumblr" aria-controls="scrumblr" role="tab" data-toggle="tab"><i class="fa fa-fw fa-lg fa-object-group" aria-hidden="true"></i> Tableau</a></li>'+
'<li role="presentation" class="pull-right"><a href="javascript:void(0);" aria-hidden="true" id="full-page"><i class="fa fa-fw fa-lg fa-expand"></i></a></li>'+
'<li role="presentation" class="pull-right"><a href="#revisions" aria-controls="revisions" role="tab" data-toggle="tab"><i class="fa fa-fw fa-lg fa-history" aria-hidden="true"></i><span class="sr-only">'+$('.revision h3').text()+'</span></a></li>'+
'<li role="presentation" class="pull-right"><a href="#export-import" aria-controls="export-import" role="tab" data-toggle="tab"><i class="fa fa-fw fa-lg fa-exchange" aria-hidden="true"></i><span class="sr-only">'+$('.export h3').text()+'/'+$('.import h3').text()+'</span></a></li>'+
'<li role="presentation" class="pull-right"><a href="#about" aria-controls="about" role="tab" data-toggle="tab"><i class="fa fa-fw fa-lg fa-question-circle" aria-hidden="true"></i><span class="sr-only">'+$('#tuto-faq h2').text()+'</span></a></li>'+
'</ul>'
)
.wrap(
'<div class="tab-content" style="margin:20px 0"><div role="tabpanel" class="tab-pane active" id="scrumblr"></div></div>'
)
$('.names').css({'margin':'auto','width':'auto'}).addClass('pull-right');
$('#scrumblr')
.append($('.names, .stickers, .buttons'))
.after(
'<div role="tabpanel" class="tab-pane" id="export-import"></div>'+
'<div role="tabpanel" class="tab-pane" id="revisions"></div>'+
'<div role="tabpanel" class="tab-pane" id="about"></div>'
);
$('#export-import').append($('.export, .import'));
$('#revisions').append($('.revisions'));
$('#about').append($('#tuto-faq, #le-logiciel, #jardin'));
// Style
$('#create-card').addClass('vert fa-3x').css('opacity','1');
$('#smallify').removeClass('fa-expand').addClass('fa-search-minus').on('click',function(){
if (currentTheme == "bigcards") {
$(this).removeClass('fa-search-plus').addClass('fa-search-minus');
} else {
$(this).removeClass('fa-search-minus').addClass('fa-search-plus');
}
})
$('#full-page').on('click', function(){
if ($('.container.ombre').length) {
$(this).children('i').removeClass('fa-expand').addClass('fa-compress');
$('.container.ombre').removeClass('container').addClass('container-fluid');
} else {
$(this).children('i').removeClass('fa-compress').addClass('fa-expand');
$('.container-fluid.ombre').removeClass('container-fluid').addClass('container');
}
})
$('main hr').hide();
/** Mode iframe **/
if(top.location!=self.document.location) {
$('#full-page').hide().trigger('click');
$('main hr, header').hide();
}
}
});