polyblock 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5167a870413707136181d0211eeb379d516afdb2
4
- data.tar.gz: 023d6566dddfbd6e236dce083d39175e206daadd
3
+ metadata.gz: 3071b0b4fbcb4cbda758658ce2e1cbedd4dea609
4
+ data.tar.gz: 588004b16ffdac1d54ff674dc787d4888cfb2074
5
5
  SHA512:
6
- metadata.gz: 5ce4d7bdaaab32a4cb42decd7bef403fddc9943055bb822e8acb48474ba3f4f6f873689cea01c12a599705f68c8863a33655b1866bcce0f9e28df016b719ba16
7
- data.tar.gz: 8dc0af791b25478ab1f2fc24bdbce31fb0abbe0ccd876e7971c7a83981ba0a0bd3f43e0308094ca83451dc3106c16d09e3276d5984086f9a6b2456f76cdcb1cd
6
+ metadata.gz: 11536f64f9533d77f48102547ad5a7686d8cc03f3b6e4d7a048e40d99cd756b132938ff6fd0029562b31a2465188e89e13699816ea13eb2269c85e3964061bfd
7
+ data.tar.gz: 3e39a8fe52c0ee177ea9ef13270706c6c5edba44aa6513b0e7fa8b954d3eaec3c35d2708600c60d714f7ade4f21f29a3f077ccf32a92837f07ac981be86e790b
@@ -1,11 +1,12 @@
1
1
  CKEDITOR.disableAutoInline = true;
2
- unsavedChanges = false
3
- window.onbeforeunload = -> return "Are you sure you want to leave this page? Your unsaved changes will not be stored!" if unsavedChanges
4
2
 
5
3
  $ ->
4
+ $.unsavedChanges = false
5
+ window.onbeforeunload = ->
6
+ return "Are you sure you want to leave this page? Your unsaved changes will not be stored!" if $.unsavedChanges
6
7
  $(document).ready ->
7
8
  # Find blocks
8
- fetch_blocks = -> $(".polyblock[contenteditable='true']").not('.polyblock-condensed')
9
+ fetch_blocks = => $(".polyblock[contenteditable='true']").not('.polyblock-condensed')
9
10
  blocks = fetch_blocks()
10
11
  return unless blocks.length
11
12
 
@@ -19,11 +20,14 @@ $ ->
19
20
  instanciateCKEditor = (id)->
20
21
  editor = CKEDITOR.inline id,
21
22
  on:
22
- contentDom: ->
23
- editor.document.on 'keydown', (e)->
23
+ contentDom: =>
24
+ editor.document.on 'keydown', (e)=>
24
25
  if (e.data.$.ctrlKey or e.data.$.metaKey) and e.data.$.keyCode == 83
25
26
  try e.data.$.preventDefault()
26
- saveChanges()
27
+ # console.log "Before: " + $.unsavedChanges
28
+ saveChanges =>
29
+ $.unsavedChanges = false
30
+ # console.log "After: " + $.unsavedChanges
27
31
  false
28
32
  focus: (e)->
29
33
  editorModeOn()
@@ -32,7 +36,7 @@ $ ->
32
36
  blocks.each ->
33
37
  id = $(@).attr('id')
34
38
  blockclones[id] = $(@).clone()
35
- instanciateCKEditor(id) unless _.contains(_.keys(CKEDITOR.instances),id)
39
+ instanciateCKEditor(id) unless _.contains(_.keys(CKEDITOR.instances), id)
36
40
 
37
41
  # Wait for changes
38
42
  verbose = false
@@ -46,23 +50,27 @@ $ ->
46
50
  changeChecker = setInterval ->
47
51
  console.log("Checking for changes...") if verbose
48
52
  reading = CKEDITOR.instances[which].getData()
49
- if reading!=buffer and !unsavedChanges then showUnsavedChanges()
50
- else if reading==buffer and unsavedChanges then showSavedChanges()
51
- #buffer = reading
53
+ if reading!=buffer and !$.unsavedChanges then showUnsavedChanges()
54
+ else if reading==buffer and $.unsavedChanges then showSavedChanges()
52
55
  , 1000
53
56
  stopListening = ->
54
57
  return unless changeChecker?
55
58
  console.log("I'm no longer listening.") if verbose
56
59
  clearInterval(changeChecker)
57
60
  changeChecker = null
58
- showUnsavedChanges = ->
61
+ showUnsavedChanges = =>
59
62
  indicator.transition({rotate:"-30deg",color:"red"})
60
63
  changeText.html("You have unsaved changes.").transition({color:"red"})
61
- unsavedChanges = true
64
+ $.unsavedChanges = true
62
65
  showSavedChanges = ->
63
66
  indicator.transition({rotate:"0deg",color:"green"})
64
67
  changeText.html("All changes saved.").transition({color:"green"})
65
- unsavedChanges = false
68
+ # console.log "In function: " + $.unsavedChanges
69
+ $.unsavedChanges = false
70
+ # console.log "In function: " + $.unsavedChanges
71
+ showSavingChanges = =>
72
+ indicator.transition({rotate:"30deg",color:"yellow"})
73
+ changeText.html("Saving changes...").transition({color:"yellow"})
66
74
 
67
75
  # Editor functionality toggles
68
76
  initialBodyPadding = $('body').css("padding-bottom")
@@ -76,21 +84,24 @@ $ ->
76
84
  pb?()
77
85
 
78
86
  # Change storage
79
- saveChanges = ->
80
- showSavedChanges()
81
- # pbs = _.object(_.map(blocks,(b)-> $(b).data("pbid")), _.map(blocks,(b)-> $(b).html()))
87
+ saveChanges = (cb)->
88
+ showSavingChanges()
82
89
  pbs = _.map blocks, (b)->
83
90
  {
84
91
  id: $(b).attr("data-pbid"),
85
92
  name: $(b).attr("data-pbname"),
86
93
  content: $(b).html()
87
94
  }
88
- $.post "/polyblock/update", {pbs: pbs}, (data)-> editorModeOff -> alertify.success("Your changes have been saved.")
95
+ $.post "/polyblock/update", {pbs: pbs}, (data)->
96
+ showSavedChanges()
97
+ editorModeOff ->
98
+ alertify.success("Your changes have been saved.") if alertify?
99
+ cb?()
89
100
  revertChanges = (pb)->
90
101
  return unless confirm("Are you sure you want to discard your changes?")
91
102
  editorModeOff ->
92
103
  blocks.each -> $(@).replaceWith(blockclones[$(@).attr("id")])
93
- alertify.success("Your changes have been discarded.")
104
+ alertify.success("Your changes have been discarded.") if alertify?
94
105
 
95
106
  # Modes
96
107
  currentMode = previousMode = "WYSIWYG"
@@ -1,7 +1,7 @@
1
1
  <div class="navbar navbar-inverse navbar-fixed-bottom" id="pb_bar" role="navigation" style="display:none;">
2
2
  <div class="navbar-header">
3
3
  <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".pbbar-collapse">
4
- <span class="sr-only">Toggle navigation</span>
4
+ <span class="sr-only">Enable Polyblock Editor</span>
5
5
  <span class="icon-bar"></span>
6
6
  <span class="icon-bar"></span>
7
7
  <span class="icon-bar"></span>
@@ -10,7 +10,7 @@
10
10
  <div class="collapse navbar-collapse pbbar-collapse">
11
11
  <span class="navbar-brand" style="margin:6px 0px;">
12
12
  <i class="icon-pencil pb-change-indicator" style="margin-right:6px;"></i>
13
- <span class="pb-change-text">Inline Editing Enabled</span>
13
+ <span class="pb-change-text">Polyblock Editor</span>
14
14
  </span>
15
15
  <div class="btn-group" id="pb_bar_format_buttons" style="padding-top:8px;">
16
16
  <button class="btn btn-default btn-navbar active" type="button">WYSIWYG</button>
@@ -1,3 +1,3 @@
1
1
  module Polyblock
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
Binary file