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 +4 -4
- data/app/assets/javascripts/polyblock/polyblock.js.coffee +141 -139
- data/lib/polyblock/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c6367b67597e23403b1b324302ac4b9294ad8ad
|
4
|
+
data.tar.gz: 8d8f624ef68c9637668d988d5475b33d7dc1b22b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
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()
|
data/lib/polyblock/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|