fix linting of examples

This commit is contained in:
Kevin Jahns 2017-07-05 18:33:16 +02:00
parent a7550fe5d3
commit 6225fb4dfd
7 changed files with 1219 additions and 38 deletions

View File

@ -1,5 +1,4 @@
/* @flow */ /* global Y, chat */
/* global Y */
// initialize a shared object. This function call returns a promise! // initialize a shared object. This function call returns a promise!
Y({ Y({
@ -20,7 +19,7 @@ Y({
function appendMessage (message, position) { function appendMessage (message, position) {
var p = document.createElement('p') var p = document.createElement('p')
var uname = document.createElement('span') var uname = document.createElement('span')
uname.appendChild(document.createTextNode(message.username + ": ")) uname.appendChild(document.createTextNode(message.username + ': '))
p.appendChild(uname) p.appendChild(uname)
p.appendChild(document.createTextNode(message.message)) p.appendChild(document.createTextNode(message.message))
document.querySelector('#chat').insertBefore(p, chat.children[position] || null) document.querySelector('#chat').insertBefore(p, chat.children[position] || null)
@ -28,9 +27,8 @@ Y({
// This function makes sure that only 7 messages exist in the chat history. // This function makes sure that only 7 messages exist in the chat history.
// The rest is deleted // The rest is deleted
function cleanupChat () { function cleanupChat () {
var len if (y.share.chat.length > 7) {
while ((len = y.share.chat.length) > 7) { y.share.chat.delete(0, y.chat.length - 7)
y.share.chat.delete(0)
} }
} }
// Insert the initial content // Insert the initial content
@ -40,11 +38,11 @@ Y({
// whenever content changes, make sure to reflect the changes in the DOM // whenever content changes, make sure to reflect the changes in the DOM
y.share.chat.observe(function (event) { y.share.chat.observe(function (event) {
if (event.type === 'insert') { if (event.type === 'insert') {
for (var i = 0; i < event.length; i++) { for (let i = 0; i < event.length; i++) {
appendMessage(event.values[i], event.index + i) appendMessage(event.values[i], event.index + i)
} }
} else if (event.type === 'delete') { } else if (event.type === 'delete') {
for (var i = 0; i < event.length; i++) { for (let i = 0; i < event.length; i++) {
chat.children[event.index].remove() chat.children[event.index].remove()
} }
} }
@ -54,8 +52,8 @@ Y({
document.querySelector('#chatform').onsubmit = function (event) { document.querySelector('#chatform').onsubmit = function (event) {
// the form is submitted // the form is submitted
var message = { var message = {
username: this.querySelector("[name=username]").value, username: this.querySelector('[name=username]').value,
message: this.querySelector("[name=message]").value message: this.querySelector('[name=message]').value
} }
if (message.username.length > 0 && message.message.length > 0) { if (message.username.length > 0 && message.message.length > 0) {
if (y.share.chat.length > 6) { if (y.share.chat.length > 6) {
@ -66,7 +64,7 @@ Y({
// This will call the observe function (see line 40) // This will call the observe function (see line 40)
// and reflect the change in the DOM // and reflect the change in the DOM
y.share.chat.push([message]) y.share.chat.push([message])
this.querySelector("[name=message]").value = "" this.querySelector('[name=message]').value = ''
} }
// Do not send this form! // Do not send this form!
event.preventDefault() event.preventDefault()

View File

@ -23,7 +23,12 @@ Y({
var drag = d3.behavior.drag() var drag = d3.behavior.drag()
.on('dragstart', function (params) { .on('dragstart', function (params) {
// get the translation of the element // get the translation of the element
var translation = d3.select(this).attr('transform').slice(10,-1).split(',').map(Number) var translation = d3
.select(this)
.attr('transform')
.slice(10, -1)
.split(',')
.map(Number)
// mouse coordinates // mouse coordinates
var mouse = d3.mouse(this.parentNode) var mouse = d3.mouse(this.parentNode)
origin = { origin = {
@ -31,11 +36,11 @@ Y({
y: mouse[1] - translation[1] y: mouse[1] - translation[1]
} }
}) })
.on("drag", function(){ .on('drag', function () {
var mouse = d3.mouse(this.parentNode) var mouse = d3.mouse(this.parentNode)
var x = mouse[0] - origin.x // =^= mouse - mouse at dragstart + translation at dragstart var x = mouse[0] - origin.x // =^= mouse - mouse at dragstart + translation at dragstart
var y = mouse[1] - origin.y var y = mouse[1] - origin.y
d3.select(this).attr("transform", "translate(" + x + "," + y + ")") d3.select(this).attr('transform', 'translate(' + x + ',' + y + ')')
}) })
.on('dragend', function (piece, i) { .on('dragend', function (piece, i) {
// save the current translation of the puzzle piece // save the current translation of the puzzle piece
@ -46,13 +51,13 @@ Y({
}) })
var data = [y.share.piece1, y.share.piece2, y.share.piece3, y.share.piece4] var data = [y.share.piece1, y.share.piece2, y.share.piece3, y.share.piece4]
var pieces = d3.select(document.querySelector("#puzzle-example")).selectAll("path").data(data) var pieces = d3.select(document.querySelector('#puzzle-example')).selectAll('path').data(data)
pieces pieces
.classed('draggable', true) .classed('draggable', true)
.attr("transform", function (piece) { .attr('transform', function (piece) {
var translation = piece.get('translation') || {x: 0, y: 0} var translation = piece.get('translation') || {x: 0, y: 0}
return "translate(" + translation.x + "," + translation.y + ")" return 'translate(' + translation.x + ',' + translation.y + ')'
}).call(drag) }).call(drag)
data.forEach(function (piece) { data.forEach(function (piece) {
@ -60,9 +65,9 @@ Y({
// whenever a property of a piece changes, update the translation of the pieces // whenever a property of a piece changes, update the translation of the pieces
pieces pieces
.transition() .transition()
.attr("transform", function (piece) { .attr('transform', function (piece) {
var translation = piece.get('translation') || {x: 0, y: 0} var translation = piece.get('translation') || {x: 0, y: 0}
return "translate(" + translation.x + "," + translation.y + ")" return 'translate(' + translation.x + ',' + translation.y + ')'
}) })
}) })
}) })

View File

@ -1,8 +1,8 @@
/* global Y */ /* global Y, monaco */
require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' } }) require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' } })
require(['vs/editor/editor.main'], function() {
require(['vs/editor/editor.main'], function () {
// Initialize a shared object. This function call returns a promise! // Initialize a shared object. This function call returns a promise!
Y({ Y({
db: { db: {
@ -28,4 +28,3 @@ require(['vs/editor/editor.main'], function() {
y.share.monaco.bindMonaco(editor) y.share.monaco.bindMonaco(editor)
}) })
}) })

1173
examples/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -6,5 +6,11 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"monaco-editor": "^0.8.3" "monaco-editor": "^0.8.3"
},
"devDependencies": {
"standard": "^10.0.2"
},
"standard": {
"ignore": ["bower_components"]
} }
} }

View File

@ -33,7 +33,7 @@ Y({
] ]
}, },
theme: 'snow' theme: 'snow'
}); })
// bind quill to richtext type // bind quill to richtext type
y.share.richtext.bind(window.quill) y.share.richtext.bind(window.quill)
}) })

View File

@ -5,9 +5,9 @@ if('serviceWorker' in navigator){
// Register service worker // Register service worker
// it is important to copy yjs-sw-template to the root directory! // it is important to copy yjs-sw-template to the root directory!
navigator.serviceWorker.register('./yjs-sw-template.js').then(function (reg) { navigator.serviceWorker.register('./yjs-sw-template.js').then(function (reg) {
console.log("Yjs service worker registration succeeded. Scope is " + reg.scope); console.log('Yjs service worker registration succeeded. Scope is ' + reg.scope)
}).catch(function (err) { }).catch(function (err) {
console.error("Yjs service worker registration failed with error " + err); console.error('Yjs service worker registration failed with error ' + err)
}) })
} }