Skip to content

Commit

Permalink
rename tandem -> scribe
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Nov 28, 2012
1 parent 23a1b7e commit f2823a5
Show file tree
Hide file tree
Showing 29 changed files with 372 additions and 380 deletions.
4 changes: 2 additions & 2 deletions demo/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
%script{:type => 'text/javascript', :src => '../src/editor.js'}
%script{:type => 'text/javascript', :src => '../src/debug.js'}
:javascript
var editor = new Tandem.Editor('editor-container');
var editor = new Scribe.Editor('editor-container');

_.each(['bold', 'italic', 'strike', 'underline', 'bullet', 'list', 'indent', 'outdent'], function(format) {
$('#formatting-container .' + format).click(function() {
Expand All @@ -173,7 +173,7 @@
else
editor.selection.applyAttribute('link', 'http://www.google.com');
});
editor.on(Tandem.Editor.events.SELECTION_CHANGE, function(selection) {
editor.on(Scribe.Editor.events.SELECTION_CHANGE, function(selection) {
attributes = selection.getAttributes()
$("#formatting-container .format-button").removeClass('active');
for (key in attributes) {
Expand Down
6 changes: 3 additions & 3 deletions demo/scripts/dual.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#= require jquery

listenEditor = (source, target) ->
source.on(Tandem.Editor.events.TEXT_CHANGE, (delta) ->
source.on(Scribe.Editor.events.TEXT_CHANGE, (delta) ->
target.applyDelta(delta, false)
sourceDelta = source.doc.toDelta()
targetDelta = target.doc.toDelta()
console.assert(_.isEqual(sourceDelta, targetDelta), "Editor diversion!", source, target)
)

editors = _.map([1, 2], (num) ->
editor = new Tandem.Editor('editor-container' + num)
editor = new Scribe.Editor('editor-container' + num)
_.each(['bold', 'italic', 'strike', 'underline', 'bullet', 'list', 'indent', 'outdent'], (format) ->
$("#formatting-container#{num} .#{format}").click( ->
editor.selection.applyAttribute(format, !$(this).hasClass('active'))
Expand All @@ -27,7 +27,7 @@ editors = _.map([1, 2], (num) ->
else
editor.selection.applyAttribute('link', 'http://www.google.com')
)
editor.on(Tandem.Editor.events.SELECTION_CHANGE, (selection) ->
editor.on(Scribe.Editor.events.SELECTION_CHANGE, (selection) ->
attributes = selection.getAttributes()
$("#formatting-container#{num} .format-button").removeClass('active')
for key,value of attributes when value
Expand Down
6 changes: 3 additions & 3 deletions demo/scripts/iphone-ot.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(document).ready( ->
window.editor = editor = new Tandem.Editor('editor-container')
window.editor = editor = new Scribe.Editor('editor-container')

editor.on Tandem.Editor.events.SELECTION_CHANGE, (selection) ->
editor.on Scribe.Editor.events.SELECTION_CHANGE, (selection) ->
attributes = selection.getAttributes()
GAJavaScript.performSelector 'attributesUpdated:', JSON.stringify(attributes)
#$.post('/ios-message/format-change', {json: JSON.stringify(attributes)})
Expand Down Expand Up @@ -44,7 +44,7 @@ $(document).ready( ->
jetClient.addState(textState)
jetClient.connect(Stypi.configs.docId, Stypi.configs.version)

editor.on(Tandem.Editor.events.TEXT_CHANGE, (delta) =>
editor.on(Scribe.Editor.events.TEXT_CHANGE, (delta) =>
if Stypi.configs.userId
_.each(delta.deltas, (delta, index) ->
delta.attributes['author'] = Stypi.configs.userId if delta.text?
Expand Down
6 changes: 3 additions & 3 deletions demo/scripts/ot.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
$(document).ready( ->
editor = new Tandem.Editor('editor-container')
editor = new Scribe.Editor('editor-container')
_.each(['bold', 'italic', 'strike', 'underline'], (format) ->
$("#formatting-container .#{format}").click( ->
editor.selection.applyAttribute(format, !$(this).hasClass('active'))
)
)
editor.on(Tandem.Editor.events.SELECTION_CHANGE, (selection) ->
editor.on(Scribe.Editor.events.SELECTION_CHANGE, (selection) ->
attributes = selection.getAttributes()
$("#formatting-container .format-button").removeClass('active')
for key,value of attributes when value == true
Expand Down Expand Up @@ -38,7 +38,7 @@ $(document).ready( ->
jetClient.addState(textState)
jetClient.connect(Stypi.configs.docId, Stypi.configs.version)

editor.on(Tandem.Editor.events.TEXT_CHANGE, (delta) =>
editor.on(Scribe.Editor.events.TEXT_CHANGE, (delta) =>
if Stypi.configs.userId
_.each(delta.deltas, (delta, index) ->
delta.attributes['author'] = Stypi.configs.userId if delta.text?
Expand Down
4 changes: 2 additions & 2 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ module.exports = function(grunt) {
concat: {
dist: {
src: ['<banner:meta.banner>', 'bin/src/*.js'],
dest: 'build/tandem.js'
dest: 'build/scribe.js'
}
},
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'build/tandem.min.js'
dest: 'build/scribe.min.js'
}
},
uglify: {}
Expand Down
20 changes: 10 additions & 10 deletions src/constants.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Arrays must be alphabetized, so we can use binary search

TandemConstants =
ScribeConstants =
ALIGN_ATTRIBUTES: [
'center'
'justify'
Expand Down Expand Up @@ -120,16 +120,16 @@ TandemConstants =
EXTERNAL: 'ext'


TandemConstants.LINE_ATTRIBUTES = [].concat(_.keys(TandemConstants.INDENT_ATTRIBUTES), TandemConstants.ALIGN_ATTRIBUTES).sort()
ScribeConstants.LINE_ATTRIBUTES = [].concat(_.keys(ScribeConstants.INDENT_ATTRIBUTES), ScribeConstants.ALIGN_ATTRIBUTES).sort()

TandemConstants.SPAN_ATTRIBUTES =
'background' : TandemConstants.FONT_BACKGROUNDS
'color' : TandemConstants.FONT_COLORS
'family' : TandemConstants.FONT_FAMILIES
'size' : TandemConstants.FONT_SIZES
ScribeConstants.SPAN_ATTRIBUTES =
'background' : ScribeConstants.FONT_BACKGROUNDS
'color' : ScribeConstants.FONT_COLORS
'family' : ScribeConstants.FONT_FAMILIES
'size' : ScribeConstants.FONT_SIZES

# Array of possbile values mostly for consistency with SPAN_ATTRIBUTES, not actually used in codebase
TandemConstants.TAG_ATTRIBUTES =
ScribeConstants.TAG_ATTRIBUTES =
'bold' : [true, false]
'italic' : [true, false]
'link' : [true, false] # Link value could actually also be any string representing the href
Expand All @@ -138,6 +138,6 @@ TandemConstants.TAG_ATTRIBUTES =



window.Tandem ||= {}
window.Tandem.Constants = TandemConstants
window.Scribe ||= {}
window.Scribe.Constants = ScribeConstants

18 changes: 9 additions & 9 deletions src/cursor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ class MultiCursorManager
this.setCursor(cursor.userId, cursor.index + Math.max(length, index - cursor.index), cursor.name, cursor.color)

setCursor: (userId, index, name, color) ->
cursor = @doc.root.ownerDocument.getElementById(TandemEditor.CURSOR_PREFIX + userId)
cursor = @doc.root.ownerDocument.getElementById(ScribeEditor.CURSOR_PREFIX + userId)
unless cursor?
cursor = @doc.root.ownerDocument.createElement('span')
cursor.classList.add('cursor')
cursor.classList.add(Tandem.Constants.SPECIAL_CLASSES.EXTERNAL)
cursor.id = TandemEditor.CURSOR_PREFIX + userId
cursor.classList.add(Scribe.Constants.SPECIAL_CLASSES.EXTERNAL)
cursor.id = ScribeEditor.CURSOR_PREFIX + userId
inner = @doc.root.ownerDocument.createElement('span')
inner.classList.add('cursor-inner')
inner.classList.add(Tandem.Constants.SPECIAL_CLASSES.EXTERNAL)
inner.classList.add(Scribe.Constants.SPECIAL_CLASSES.EXTERNAL)
nameNode = @doc.root.ownerDocument.createElement('span')
nameNode.classList.add('cursor-name')
nameNode.classList.add(Tandem.Constants.SPECIAL_CLASSES.EXTERNAL)
nameNode.classList.add(Scribe.Constants.SPECIAL_CLASSES.EXTERNAL)
nameNode.textContent = name
inner.style['background-color'] = nameNode.style['background-color'] = color
cursor.appendChild(nameNode)
Expand All @@ -65,13 +65,13 @@ class MultiCursorManager
color: color
userId: userId
}
position = new Tandem.Position(this, index)
[left, right, didSplit] = Tandem.Utils.splitNode(position.leafNode, position.offset)
position = new Scribe.Position(this, index)
[left, right, didSplit] = Scribe.Utils.splitNode(position.leafNode, position.offset)
if right? && (right.offsetTop != 0 || right.offsetLeft != 0)
cursor.style.top = right.parentNode
cursor.style.top = right.offsetTop
cursor.style.left = right.offsetLeft
Tandem.Utils.mergeNodes(left, right) if didSplit
Scribe.Utils.mergeNodes(left, right) if didSplit
else if left?
span = left.ownerDocument.createElement('span')
left.parentNode.appendChild(span)
Expand All @@ -95,5 +95,5 @@ class MultiCursorManager
)

removeCursor: (userId) ->
cursor = @doc.root.ownerDocument.getElementById(TandemEditor.CURSOR_PREFIX + userId)
cursor = @doc.root.ownerDocument.getElementById(ScribeEditor.CURSOR_PREFIX + userId)
cursor.parentNode.removeChild(cursor) if cursor?
16 changes: 8 additions & 8 deletions src/debug.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
window.Tandem ||= {}
window.Scribe ||= {}

window.Tandem.Debug =
window.Scribe.Debug =
getEditor: (editor) ->
editor ||= Tandem.Editor.editors[0]
return if _.isNumber(editor) then Tandem.Editor.editors[editor] else editor
editor ||= Scribe.Editor.editors[0]
return if _.isNumber(editor) then Scribe.Editor.editors[editor] else editor

getHtml: (editor) ->
doc = this.getDocument(editor)
Expand All @@ -17,7 +17,7 @@ window.Tandem.Debug =
nodesByLine = _.map(doc.root.childNodes, (lineNode) ->
nodes = lineNode.querySelectorAll('*')
return _.filter(nodes, (node) ->
return node.nodeType == node.ELEMENT_NODE && !node.classList.contains(Tandem.Constants.SPECIAL_CLASSES.EXTERNAL) && (node.nodeName == 'BR' || !node.firstChild? || node.firstChild.nodeType == node.TEXT_NODE)
return node.nodeType == node.ELEMENT_NODE && !node.classList.contains(Scribe.Constants.SPECIAL_CLASSES.EXTERNAL) && (node.nodeName == 'BR' || !node.firstChild? || node.firstChild.nodeType == node.TEXT_NODE)
)
)
lines = doc.lines.toArray()
Expand Down Expand Up @@ -88,7 +88,7 @@ window.Tandem.Debug =
console.error "doc.lines and nodesByLine differ in length", lines, nodesByLine
return false
return false if _.any(lines, (line, index) =>
calculatedLength = _.reduce(line.node.childNodes, ((length, node) -> Tandem.Utils.getNodeLength(node) + length), 0)
calculatedLength = _.reduce(line.node.childNodes, ((length, node) -> Scribe.Utils.getNodeLength(node) + length), 0)
if line.length != calculatedLength
console.error line, line.length, calculatedLength, 'differ in length'
return true
Expand Down Expand Up @@ -144,10 +144,10 @@ window.Tandem.Debug =
index = editor.doc.length
else
index = Math.floor(Math.random() * editor.doc.length)
length = Tandem.Debug.Test.getRandomLength() + 1
length = Scribe.Debug.Test.getRandomLength() + 1
rand = Math.random()
if rand < 0.5
return {op: 'insertAt', args: [index, Tandem.Debug.Test.getRandomString(alphabet, length)]}
return {op: 'insertAt', args: [index, Scribe.Debug.Test.getRandomString(alphabet, length)]}
length = Math.min(length, editor.doc.length - index)
return null if length <= 0
if rand < 0.75
Expand Down
Loading

0 comments on commit f2823a5

Please sign in to comment.