polyblock 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64f4b2c5eb999676b3e136bcac43dde5ea22fa2d
4
- data.tar.gz: 45dd681084b86ea05ebca40dbdcc4029d2520b36
3
+ metadata.gz: 5c6367b67597e23403b1b324302ac4b9294ad8ad
4
+ data.tar.gz: 8d8f624ef68c9637668d988d5475b33d7dc1b22b
5
5
  SHA512:
6
- metadata.gz: d5e367d5e00d4b1ec2947fad012d53b4c94d1f0d0b099f2d47ba6a0db2de45f680e84853252d4170e9f0c68e3528b32988bf05bd381e3b94d7092ed23ca840c7
7
- data.tar.gz: 11a3805c74cab423527f57126e0e1d2a33afc0510630db404698b648ef8cb38ee640d2b0657377ad7748542d47c1011c2ef08dcb25f61cc8d33392795aa5ca95
6
+ metadata.gz: 7ea9a74bae0f7979416fe296b244815beec2619b0d094815365bcb8223b1b30312b4ea80902b0b3419bf3dcf781b67a66db91fd077879825d497ee6aba8d2afb
7
+ data.tar.gz: 58c958b3cf5e13cdf6a70899baf94518af428f4bee92734f942c821daae0ca769a91835bce9b9416abf5fb414fbb60297b73c2e1163685247016e7df6999dc48
@@ -11,150 +11,152 @@ $ ->
11
11
  # Find switches
12
12
  pb_switch = $('.polyblock-switch')
13
13
  has_switch = pb_switch.is('*')
14
- switch_list = []
15
14
 
16
- # Clone each block and instanciate CKeditor on the original
17
- blockclones = {}
18
- instanciateCKEditor = (id)->
19
- CKEDITOR.inline id,
20
- on:
21
- focus:(e)->
22
- editorModeOn()
23
- startListening(id)
24
- blur:(e)-> stopListening()
25
- blocks.each ->
26
- id = $(@).attr('id')
27
- blockclones[id] = $(@).clone()
28
- unless _.contains(_.keys(CKEDITOR.instances),id)
29
- if has_switch then switch_list.push(id)
30
- else instanciateCKEditor(id)
15
+ initialize = ->
16
+ # Clone each block and instanciate CKeditor on the original
17
+ blockclones = {}
18
+ instanciateCKEditor = (id)->
19
+ CKEDITOR.inline id,
20
+ on:
21
+ focus:(e)->
22
+ editorModeOn()
23
+ startListening(id)
24
+ blur:(e)-> stopListening()
25
+ blocks.each ->
26
+ id = $(@).attr('id')
27
+ blockclones[id] = $(@).clone()
28
+ instanciateCKEditor(id) unless _.contains(_.keys(CKEDITOR.instances),id)
31
29
 
32
- if has_switch
33
- pb_switch.click (e)->
34
- e.preventDefault()
35
- if $(@).hasClass("active") then window.location.reload()
36
- else
37
- instanciateCKEditor(id) for id in switch_list
38
- $(@).addClass("active")
39
-
40
- # Wait for changes
41
- verbose = false
42
- changeChecker = null
43
- indicator = $('.pb-change-indicator')
44
- changeText = $('.pb-change-text')
45
- startListening = (which)->
46
- stopListening()
47
- console.log("I'm listening...") if verbose
48
- buffer = CKEDITOR.instances[which].getData()
49
- changeChecker = setInterval ->
50
- console.log("Checking for changes...") if verbose
51
- reading = CKEDITOR.instances[which].getData()
52
- if reading!=buffer and !unsavedChanges then showUnsavedChanges()
53
- else if reading==buffer and unsavedChanges then showSavedChanges()
54
- #buffer = reading
55
- , 1000
56
- stopListening = ->
57
- return unless changeChecker?
58
- console.log("I'm no longer listening.") if verbose
59
- clearInterval(changeChecker)
30
+ # Wait for changes
31
+ verbose = false
60
32
  changeChecker = null
61
- showUnsavedChanges = ->
62
- indicator.transition({rotate:"-30deg",color:"red"})
63
- changeText.html("You have unsaved changes.").transition({color:"red"})
64
- unsavedChanges = true
65
- showSavedChanges = ->
66
- indicator.transition({rotate:"0deg",color:"green"})
67
- changeText.html("All changes saved.").transition({color:"green"})
68
- unsavedChanges = false
69
-
70
- # Editor functionality toggles
71
- initialBodyPadding = $('body').css("padding-bottom")
72
- editorModeOn = (pb)->
73
- $('#pb_bar').show "slide", {direction:"down"}, 250, ->
74
- $('body').css("padding-bottom",$("#pb_bar").height() + 20)
75
- pb?()
76
- editorModeOff = (pb)->
77
- $('#pb_bar').hide "slide", {direction:"down"}, 250, ->
78
- $('body').css("padding-bottom",initialBodyPadding)
79
- pb?()
33
+ indicator = $('.pb-change-indicator')
34
+ changeText = $('.pb-change-text')
35
+ startListening = (which)->
36
+ stopListening()
37
+ console.log("I'm listening...") if verbose
38
+ buffer = CKEDITOR.instances[which].getData()
39
+ changeChecker = setInterval ->
40
+ console.log("Checking for changes...") if verbose
41
+ reading = CKEDITOR.instances[which].getData()
42
+ if reading!=buffer and !unsavedChanges then showUnsavedChanges()
43
+ else if reading==buffer and unsavedChanges then showSavedChanges()
44
+ #buffer = reading
45
+ , 1000
46
+ stopListening = ->
47
+ return unless changeChecker?
48
+ console.log("I'm no longer listening.") if verbose
49
+ clearInterval(changeChecker)
50
+ changeChecker = null
51
+ showUnsavedChanges = ->
52
+ indicator.transition({rotate:"-30deg",color:"red"})
53
+ changeText.html("You have unsaved changes.").transition({color:"red"})
54
+ unsavedChanges = true
55
+ showSavedChanges = ->
56
+ indicator.transition({rotate:"0deg",color:"green"})
57
+ changeText.html("All changes saved.").transition({color:"green"})
58
+ unsavedChanges = false
80
59
 
81
- # Change storage
82
- saveChanges = ->
83
- showSavedChanges()
84
- pbs = _.object(_.map(blocks,(b)-> $(b).data("pbid")), _.map(blocks,(b)-> $(b).html()))
85
- $.post "/polyblock/update", {pbs:pbs}, (data)-> editorModeOff -> alertify.success("Your changes have been saved.")
86
- revertChanges = (pb)->
87
- return unless confirm("Are you sure you want to discard your changes?")
88
- editorModeOff ->
89
- blocks.each -> $(@).replaceWith(blockclones[$(@).attr("id")])
90
- alertify.success("Your changes have been discarded.")
60
+ # Editor functionality toggles
61
+ initialBodyPadding = $('body').css("padding-bottom")
62
+ editorModeOn = (pb)->
63
+ $('#pb_bar').show "slide", {direction:"down"}, 250, ->
64
+ $('body').css("padding-bottom",$("#pb_bar").height() + 20)
65
+ pb?()
66
+ editorModeOff = (pb)->
67
+ $('#pb_bar').hide "slide", {direction:"down"}, 250, ->
68
+ $('body').css("padding-bottom",initialBodyPadding)
69
+ pb?()
91
70
 
92
- # Modes
93
- currentMode = previousMode = "WYSIWYG"
94
- convertToTextarea = (block,content=null,tab="\t")->
95
- tabchars = tab.replace(/\\/,"").length
96
- previous_textarea = $("textarea[data-pbid=#{block.attr("data-pbid")}]")
97
- content ?= if previous_textarea.is("*") then previous_textarea.val() else block.html()
98
- textarea = $('<textarea />')
99
- .addClass("form-control")
100
- .attr("data-pbid",block.attr("data-pbid"))
101
- .val(content)
102
- .css("font-family": 'Monaco, Menlo, Consolas, "Courier New", monospace')
103
- .on "keydown", (e)->
104
- keycode = e.keyCode or e.which
105
- return unless keycode == 9 or keycode == 8 or keycode == 46
106
- start = $(@).get(0).selectionStart
107
- end = $(@).get(0).selectionEnd
108
- if keycode == 9
109
- e.preventDefault()
110
- $(@).val("#{$(@).val().substring(0,start)}#{tab}#{$(@).val().substring(end)}")
111
- $(@).get(0).selectionStart = $(@).get(0).selectionEnd = start + tabchars
112
- else if keycode == 8
113
- return unless currentMode=="HAML" and $(@).val().substring(start-tabchars,start) == tab
114
- e.preventDefault()
115
- $(@).val("#{$(@).val().substring(0,start-tabchars)}#{$(@).val().substring(end)}")
116
- $(@).get(0).selectionStart = $(@).get(0).selectionEnd = start-tabchars
117
- else if keycode == 46
118
- return unless currentMode=="HAML" and $(@).val().substring(start,start+tabchars) == tab
119
- e.preventDefault()
120
- $(@).val("#{$(@).val().substring(0,start)}#{$(@).val().substring(end+tabchars)}")
121
- $(@).get(0).selectionStart = $(@).get(0).selectionEnd = start
122
- replaceIt = (html)=>
123
- if !previous_textarea.is("*") then block.replaceWith(textarea)
124
- else previous_textarea.replaceWith(textarea)
125
- textarea.autosize().focus()
126
- if previousMode != "HAML" then replaceIt(content)
127
- else $.post "/convert_haml_to_html", {haml: content}, (data)=> replaceIt(data)
128
- convertFromTextarea = (block)->
129
- textarea = $("textarea[data-pbid=#{block.attr("data-pbid")}]")
130
- replaceIt = (html)=>
131
- console.log "Replacing with html: #{html}"
132
- textarea.replaceWith(block)
133
- block.html(html)
134
- if previousMode != "HAML" then replaceIt(textarea.text())
135
- else $.post "/convert_haml_to_html", {haml: textarea.val()}, (data)=> replaceIt(data)
71
+ # Change storage
72
+ saveChanges = ->
73
+ showSavedChanges()
74
+ pbs = _.object(_.map(blocks,(b)-> $(b).data("pbid")), _.map(blocks,(b)-> $(b).html()))
75
+ $.post "/polyblock/update", {pbs:pbs}, (data)-> editorModeOff -> alertify.success("Your changes have been saved.")
76
+ revertChanges = (pb)->
77
+ return unless confirm("Are you sure you want to discard your changes?")
78
+ editorModeOff ->
79
+ blocks.each -> $(@).replaceWith(blockclones[$(@).attr("id")])
80
+ alertify.success("Your changes have been discarded.")
136
81
 
137
- $('#pb_bar_format_buttons button').click (e)->
138
- e.preventDefault()
139
- return if $(@).hasClass("active")
140
- previousMode = currentMode
141
- currentMode = $(@).html()
142
- changeModes = (block)=>
82
+ # Modes
83
+ currentMode = previousMode = "WYSIWYG"
84
+ convertToTextarea = (block,content=null,tab="\t")->
85
+ tabchars = tab.replace(/\\/,"").length
86
+ previous_textarea = $("textarea[data-pbid=#{block.attr("data-pbid")}]")
87
+ content ?= if previous_textarea.is("*") then previous_textarea.val() else block.html()
88
+ textarea = $('<textarea />')
89
+ .addClass("form-control")
90
+ .attr("data-pbid",block.attr("data-pbid"))
91
+ .val(content)
92
+ .css("font-family": 'Monaco, Menlo, Consolas, "Courier New", monospace')
93
+ .on "keydown", (e)->
94
+ keycode = e.keyCode or e.which
95
+ return unless keycode == 9 or keycode == 8 or keycode == 46
96
+ start = $(@).get(0).selectionStart
97
+ end = $(@).get(0).selectionEnd
98
+ if keycode == 9
99
+ e.preventDefault()
100
+ $(@).val("#{$(@).val().substring(0,start)}#{tab}#{$(@).val().substring(end)}")
101
+ $(@).get(0).selectionStart = $(@).get(0).selectionEnd = start + tabchars
102
+ else if keycode == 8
103
+ return unless currentMode=="HAML" and $(@).val().substring(start-tabchars,start) == tab
104
+ e.preventDefault()
105
+ $(@).val("#{$(@).val().substring(0,start-tabchars)}#{$(@).val().substring(end)}")
106
+ $(@).get(0).selectionStart = $(@).get(0).selectionEnd = start-tabchars
107
+ else if keycode == 46
108
+ return unless currentMode=="HAML" and $(@).val().substring(start,start+tabchars) == tab
109
+ e.preventDefault()
110
+ $(@).val("#{$(@).val().substring(0,start)}#{$(@).val().substring(end+tabchars)}")
111
+ $(@).get(0).selectionStart = $(@).get(0).selectionEnd = start
112
+ replaceIt = (html)=>
113
+ if !previous_textarea.is("*") then block.replaceWith(textarea)
114
+ else previous_textarea.replaceWith(textarea)
115
+ textarea.autosize().focus()
116
+ if previousMode != "HAML" then replaceIt(content)
117
+ else $.post "/convert_haml_to_html", {haml: content}, (data)=> replaceIt(data)
118
+ convertFromTextarea = (block)->
143
119
  textarea = $("textarea[data-pbid=#{block.attr("data-pbid")}]")
144
- content = if textarea.is("*") then textarea.val() else block.html()
145
- switch currentMode
146
- when "WYSIWYG" then convertFromTextarea block
147
- when "HTML" then convertToTextarea block, html_beautify(content)
148
- when "HAML" then $.post "/convert_html_to_haml", {html: content}, (data)=> convertToTextarea(block,data," ")
149
- when "Markdown" then convertToTextarea block, html_beautify(content)
150
- blocks = $(".polyblock[contenteditable='true']") if previousMode == "WYSIWYG"
151
- blocks.each -> changeModes $(@)
152
- $(@).siblings().removeClass("active").end().addClass("active")
120
+ replaceIt = (html)=>
121
+ console.log "Replacing with html: #{html}"
122
+ textarea.replaceWith(block)
123
+ block.html(html)
124
+ if previousMode != "HAML" then replaceIt(textarea.text())
125
+ else $.post "/convert_haml_to_html", {haml: textarea.val()}, (data)=> replaceIt(data)
126
+
127
+ $('#pb_bar_format_buttons button').click (e)->
128
+ e.preventDefault()
129
+ return if $(@).hasClass("active")
130
+ previousMode = currentMode
131
+ currentMode = $(@).html()
132
+ changeModes = (block)=>
133
+ textarea = $("textarea[data-pbid=#{block.attr("data-pbid")}]")
134
+ content = if textarea.is("*") then textarea.val() else block.html()
135
+ switch currentMode
136
+ when "WYSIWYG" then convertFromTextarea block
137
+ when "HTML" then convertToTextarea block, html_beautify(content)
138
+ when "HAML" then $.post "/convert_html_to_haml", {html: content}, (data)=> convertToTextarea(block,data," ")
139
+ when "Markdown" then convertToTextarea block, html_beautify(content)
140
+ blocks = $(".polyblock[contenteditable='true']") if previousMode == "WYSIWYG"
141
+ blocks.each -> changeModes $(@)
142
+ $(@).siblings().removeClass("active").end().addClass("active")
153
143
 
154
- # Button handlers
155
- $('#pb_bar_revert').click (e)->
156
- e.preventDefault()
157
- revertChanges()
158
- $('#pb_bar_save').click (e)->
159
- e.preventDefault()
160
- saveChanges()
144
+ # Button handlers
145
+ $('#pb_bar_revert').click (e)->
146
+ e.preventDefault()
147
+ revertChanges()
148
+ $('#pb_bar_save').click (e)->
149
+ e.preventDefault()
150
+ saveChanges()
151
+
152
+ if has_switch
153
+ pb_switch.click (e)->
154
+ e.preventDefault()
155
+ if $(@).hasClass("active")
156
+ $(@).removeClass("active")
157
+ window.location.reload()
158
+ else
159
+ $(@).addClass("active")
160
+ initialize()
161
+ else
162
+ initialize()
@@ -1,3 +1,3 @@
1
1
  module Polyblock
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-07 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails