Skip to content

Commit

Permalink
replace \n with ^
Browse files Browse the repository at this point in the history
  • Loading branch information
brownman committed Nov 16, 2012
1 parent a99f86d commit 6b81744
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 90 deletions.
Binary file not shown.
34 changes: 15 additions & 19 deletions app/assets/javascripts/backbone/models/comment.js.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel


@array = [] @array = []
defaults: defaults:
content: null content: 'content'
direction: true direction: true
title: null title: 'title'


initialize: () -> initialize: () ->
tmp = @get('content')
if (tmp && tmp.length > 0)
@array = @split()


obj = { counter: 0 }
_.extend(obj,Backbone.Events) this.on('change:content', @update_array)
obj.on('event', @update_array()
() -> obj.counter += 1
)
obj.trigger('event')
@equal1(obj.counter,1,'counter should be incremented.')
obj.trigger('event')
obj.trigger('event')
obj.trigger('event')
obj.trigger('event')
@equal1(obj.counter, 5, 'counter should be incremented five times.')
#console.log(this) #console.log(this)
#save: -> #save: ->


update_array: () =>
#alert('update array')
tmp = @get('content')
if (tmp && tmp.length > 0)
@array = @split()


equal1: (a,b,c) -> equal1: (a,b,c) ->
#alert(a + '|' + '|' +c) #alert(a + '|' + '|' +c)
Expand All @@ -47,8 +40,11 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel
split : () -> split : () ->
str = @get('content') str = @get('content')
story_enc = str story_enc = str
# story_enc = story_enc.replace(/\n/g, "^") story_enc = story_enc.replace(/\n/g, "^")
arr_symbols = [',', '!', '.', "?", ":", ";", "=", "\n" ]
arr_symbols = [',', '!', '.', "?", ":", ";", "=" ]
#if !@direction
#arr_symbols.push "\n"
story_enc = @replace(story_enc, arr_symbols) story_enc = @replace(story_enc, arr_symbols)
story_arr = story_enc.split('$') story_arr = story_enc.split('$')
story_arr story_arr
Expand Down
41 changes: 19 additions & 22 deletions app/assets/javascripts/backbone/models/comment.js.coffee~
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel


@array = [] @array = []
defaults: defaults:
content: null content: 'content'
direction: true direction: true
title: null title: 'title'


initialize: () -> initialize: () ->
tmp = @get('content')
if (tmp && tmp.length > 0)
@array = @split()


obj = { counter: 0 }
_.extend(obj,Backbone.Events) this.on('change:content', @update_array)
obj.on('event', @update_array()
() -> obj.counter += 1
)
obj.trigger('event')
@equal1(obj.counter,1,'counter should be incremented.')
obj.trigger('event')
obj.trigger('event')
obj.trigger('event')
obj.trigger('event')
@equal1(obj.counter, 5, 'counter should be incremented five times.')
#console.log(this) #console.log(this)
#save: -> #save: ->


update_array: () =>
#alert('update array')
tmp = @get('content')
if (tmp && tmp.length > 0)
@array = @split()


equal1: (a,b,c) -> equal1: (a,b,c) ->
#alert(a + '|' + '|' +c) #alert(a + '|' + '|' +c)
Expand All @@ -47,8 +40,11 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel
split : () -> split : () ->
str = @get('content') str = @get('content')
story_enc = str story_enc = str
# story_enc = story_enc.replace(/\n/g, "^") story_enc = story_enc.replace(/\n/g, "^")
arr_symbols = [',', '!', '.', "?", ":", ";", "=", "\n" ]
arr_symbols = [',', '!', '.', "?", ":", ";", "=" ]
#if !@direction
#arr_symbols.push "\n"
story_enc = @replace(story_enc, arr_symbols) story_enc = @replace(story_enc, arr_symbols)
story_arr = story_enc.split('$') story_arr = story_enc.split('$')
story_arr story_arr
Expand Down Expand Up @@ -84,8 +80,9 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co




add1: () => add1: () =>
console.log(this) console.log(this)
length_i = this.models.length length_i = this.models.length
if length_i > 0
length_j = this.models[0].array.length length_j = this.models[0].array.length


#find min array #find min array
Expand All @@ -104,7 +101,7 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
if ( num1 == length_i) if ( num1 == length_i)
for i in [0...length_i] for i in [0...length_i]
this.models[i].array[j..j] = [] this.models[i].array[j..j] = []
this.trigger('add2') this.trigger('add2')






Expand Down
24 changes: 17 additions & 7 deletions app/assets/javascripts/backbone/templates/comments/comment.jst.ejs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,28 +4,38 @@






<input type="checkbox" name="direction" class="direction checkbox span12" <%= obj.direction ? 'checked="checked"' : '' %> /> <input type="checkbox" name="direction" class="span12 direction checkbox " <%= obj.direction ? 'checked="checked"' : '' %> ></input>
<input class='span12' height='1em' type='text' value='<%= obj.title %>'></input>


id:
<input class='' height='1em' type='text' label='id' value='<%= obj.id %>'></input>
<br>
title:
<input class='title' height='1em' type='text' value='<%= obj.title %>'></input>
<br>










<input label='time: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj3 %>'></input> delay(s):
<input label='time: ' tooltip='delay in seconds' class='seconds' height='1em' type='text' value='<%= obj3 %>'></input>
<br>


<input label='span: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj4 %>'></input> span:
<input label='span: ' tooltip='delay in seconds' class='seconds' height='1em' type='text' value='<%= obj4 %>'></input>
<br>











content:
<textarea rows="4" height='1em' class='span12' name="content1" > <textarea class="content" rows="4" height='1em' class='' name="content1" >


<%= obj.content %> <%= obj.content %>
</textarea> </textarea>


<br>






Expand All @@ -47,4 +57,4 @@
<a href="/comments#/<%= obj.id %>/destroy" class="destroy">kill</a> <a href="/comments#/<%= obj.id %>/destroy" class="destroy">kill</a>


</div> </div>

<span padding='3px' height='100%'></span>
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,26 +4,38 @@






<input type="checkbox" name="direction" class="direction checkbox span12" <%= obj.direction ? 'checked="checked"' : '' %> /> <input type="checkbox" name="direction" class="span12 direction checkbox " <%= obj.direction ? 'checked="checked"' : '' %> ></input>
<input class='span12' height='1em' type='text' value='<%= obj.title %>'></input>


id:
<input class='' height='1em' type='text' label='id' value='<%= obj.id %>'></input>
<br>
title:
<input class='title' height='1em' type='text' value='<%= obj.title %>'></input>
<br>










<input label='time: ' tooltip='delay in seconds' class='seconds span12' height='1em' type='text' value='<%= obj3 %>'></input> delay(s):
<input label='time: ' tooltip='delay in seconds' class='seconds' height='1em' type='text' value='<%= obj3 %>'></input>
<br>


span:
<input label='span: ' tooltip='delay in seconds' class='seconds' height='1em' type='text' value='<%= obj4 %>'></input>
<br>










<textarea rows="4" height='1em' class='span12' name="content1" > content:
<textarea rows="4" height='1em' class='' name="content1" >


<%= obj.content %> <%= obj.content %>
</textarea> </textarea>


<br>






Expand All @@ -45,4 +57,4 @@
<a href="/comments#/<%= obj.id %>/destroy" class="destroy">kill</a> <a href="/comments#/<%= obj.id %>/destroy" class="destroy">kill</a>


</div> </div>

<span padding='3px' height='100%'></span>
3 changes: 3 additions & 0 deletions app/assets/javascripts/backbone/templates/posts/post.jst.ejs
Original file line number Original file line Diff line number Diff line change
@@ -1,16 +1,19 @@
<div class="accordion-heading"> <div class="accordion-heading">
<div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>"> <div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>">


<button class='open btn span2' >fetch</button>
<a class="id"><%= post.id %></a> <a class="id"><%= post.id %></a>
<input class="title" value=<%= post.title %> >title: </input> <input class="title" value=<%= post.title %> >title: </input>




<a href="#/posts<%= post.id %>/edit" class="edit">edit</a> <a href="#/posts<%= post.id %>/edit" class="edit">edit</a>


<a href="/posts#/<%= post.id %>/destroy" class="destroy">delete</a> <a href="/posts#/<%= post.id %>/destroy" class="destroy">delete</a>

<a class="c_length" >length:<%= length %> </a> <a class="c_length" >length:<%= length %> </a>





</div> </div>
</div> </div>
<div id="collapseOne<%= post.id %>" class="accordion-body collapse"> <div id="collapseOne<%= post.id %>" class="accordion-body collapse">
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,15 +1,19 @@
<div class="accordion-heading"> <div class="accordion-heading">
<div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>"> <div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>">


<button class='open btn span2' >open</button>
<a class="id"><%= post.id %></a> <a class="id"><%= post.id %></a>
<input class="title" value=<%= post.title %> >title: </input> <input class="title" value=<%= post.title %> >title: </input>




<a href="#/posts<%= post.id %>/edit" class="edit">edit</a> <a href="#/posts<%= post.id %>/edit" class="edit">edit</a>


<a class="c_length" >length:<%= length %> </a>
<a href="/posts#/<%= post.id %>/destroy" class="destroy">delete</a> <a href="/posts#/<%= post.id %>/destroy" class="destroy">delete</a>


<a class="c_length" >length:<%= length %> </a>



</div> </div>
</div> </div>
<div id="collapseOne<%= post.id %>" class="accordion-body collapse"> <div id="collapseOne<%= post.id %>" class="accordion-body collapse">
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,18 +18,45 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View


"blur .seconds" : "set_delay" "blur .seconds" : "set_delay"


"blur .content" : "set_content"

"keypress .title" : "updateOnEnter"




#"hover .todo-array button": "show_tooltip" #"hover .todo-array button": "show_tooltip"
set_content: (e) ->
console.log(e)
input = e.target.value

#this.$(".content");
console.log(input)

@model.set({ content: input })
#@render()


updateOnEnter: (e) ->

#this.trigger('somethingHappened')
if e.keyCode is 13
console.log(e)
@input = this.$(".title");
console.log(@input)


initialize: () => @model.save({ title: @input.val() })

#$(@el).removeClass("editing")
initialize: () ->




console.log(this) console.log(this)


console.log(@options) console.log(@options)
num = @options['c_length'] num =
#this.model.collection.length
this.model.collection.length

#@options['c_length']
@update_span(num) @update_span(num)
#@options.c_length #@options.c_length
@status = 'saved' @status = 'saved'
Expand All @@ -50,9 +77,10 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View


toggleDone : () -> toggleDone : () ->
@model.save( @model.save(

{direction : !this.model.get('direction') }
direction : !this.model.get('direction') {silent: true}
) )
@render()






Expand All @@ -65,10 +93,11 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View






render: => render: ->
listed2 = this.splitted2() listed2 = this.splitted2()


comment = @model.toJSON() comment = @model.toJSON()

status = @status.toString() status = @status.toString()
seconds = @seconds.toString() seconds = @seconds.toString()
spans = @el.className.toString() spans = @el.className.toString()
Expand All @@ -81,6 +110,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
'obj3': seconds 'obj3': seconds


'obj4': spans 'obj4': spans

) )
$(@el).html(tmp) $(@el).html(tmp)


Expand Down Expand Up @@ -132,7 +162,8 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
@model.save( @model.save(
content: text content: text
) )
this.trigger('somethingHappened'); #this.trigger('somethingHappened');
#@render






Expand Down
Loading

0 comments on commit 6b81744

Please sign in to comment.