card-mod-script 0.13.1 → 0.13.2

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/assets/script/decko/autosave.js.coffee +30 -0
  3. data/assets/script/decko/bridge.js.coffee +31 -0
  4. data/assets/script/decko/card_menu.js.coffee +26 -0
  5. data/assets/script/decko/components.js.coffee +46 -0
  6. data/assets/script/decko/decko.js.coffee +97 -0
  7. data/assets/script/decko/doubleclick.js.coffee +30 -0
  8. data/assets/script/decko/editor.js.coffee +55 -0
  9. data/assets/script/decko/filter.js.coffee +176 -0
  10. data/assets/script/decko/filter_items.js.coffee +128 -0
  11. data/assets/script/decko/filter_links.js.coffee +81 -0
  12. data/assets/script/decko/follow.js.coffee +22 -0
  13. data/assets/script/decko/layout.js.coffee +76 -0
  14. data/assets/script/decko/link_editor.js.coffee +61 -0
  15. data/assets/script/decko/mod.js.coffee +85 -0
  16. data/assets/script/decko/modal.js.coffee +113 -0
  17. data/assets/script/decko/name_editor.js.coffee +58 -0
  18. data/assets/script/decko/navbox.js.coffee +74 -0
  19. data/assets/script/decko/nest_editor.js.coffee +166 -0
  20. data/assets/script/decko/nest_editor_name.js.coffee +102 -0
  21. data/assets/script/decko/nest_editor_options.js.coffee +93 -0
  22. data/assets/script/decko/nest_editor_rules.js.coffee +3 -0
  23. data/assets/script/decko/overlay.js.coffee +57 -0
  24. data/assets/script/decko/recaptcha.js.coffee +19 -0
  25. data/assets/script/decko/selectable_filtered_content.js.coffee +12 -0
  26. data/assets/script/decko/slot.js.coffee +182 -0
  27. data/assets/script/decko/slot_ready.js.coffee +11 -0
  28. data/assets/script/decko/slotter.js.coffee +276 -0
  29. data/assets/script/decko/upload.js.coffee +57 -0
  30. data/assets/script/jquery-ui.js +10 -0
  31. data/assets/script/jquery.autosize.js +274 -0
  32. data/assets/script/manifest.yml +44 -0
  33. data/assets/script/script_pointer_config.js.coffee +80 -0
  34. data/assets/script/script_pointer_list_editor.js.coffee +67 -0
  35. metadata +42 -9
@@ -0,0 +1,113 @@
1
+ $(window).ready ->
2
+ $('body').on 'hidden.bs.modal', (_event) ->
3
+ decko.removeModal()
4
+
5
+ $('body').on "show.bs.modal", "._modal-slot", (event, slot) ->
6
+ link = $(event.relatedTarget)
7
+ addModalDialogClasses $(this), link
8
+ $(this).modal("handleUpdate")
9
+ decko.contentLoaded $(event.target), link
10
+
11
+ $('._modal-slot').each ->
12
+ openModalIfPresent $(this)
13
+ addModalDialogClasses $(this)
14
+
15
+ $('body').on 'click', '.submit-modal', ->
16
+ $(this).closest('.modal-content').find('form').submit()
17
+
18
+ openModalIfPresent = (mslot) ->
19
+ modal_content = mslot.find(".modal-content")
20
+ if modal_content.length > 0 && modal_content.html().length > 0
21
+ $("#main > .card-slot").registerAsOrigin("modal", mslot)
22
+ mslot.modal("show")
23
+
24
+ addModalDialogClasses = ($modal_slot, $link) ->
25
+ dialog = $modal_slot.find(".modal-dialog")
26
+ classes_from_link =
27
+ if $link? then $link.data("modal-class") else $modal_slot.data("modal-class")
28
+ if classes_from_link? and dialog?
29
+ dialog.addClass classes_from_link
30
+
31
+ jQuery.fn.extend {
32
+ showAsModal: ($slotter) ->
33
+ el = @modalify($slotter) if $slotter?
34
+ if $("body > ._modal-slot").is(":visible")
35
+ @addModal el, $slotter
36
+ else
37
+ if $("body > ._modal-slot")[0]
38
+ $("._modal-slot").trigger "slotDestroy"
39
+ $("body > ._modal-slot").replaceWith el
40
+ else
41
+ $("body").append el
42
+
43
+ $slotter.registerAsOrigin("modal", el)
44
+ el.modal("show", $slotter)
45
+
46
+ addModal: (el, $slotter) ->
47
+ if $slotter.data("slotter-mode") == "modal-replace"
48
+ dialog = el.find(".modal-dialog")
49
+ el.adoptModalOrigin()
50
+ $("._modal-slot").trigger "slotDestroy"
51
+ $("body > ._modal-slot > .modal-dialog").replaceWith(dialog)
52
+ decko.contentLoaded(dialog, $slotter)
53
+ else
54
+ decko.pushModal el
55
+ $slotter.registerAsOrigin("modal", el)
56
+ el.modal("show", $slotter)
57
+
58
+ adoptModalOrigin: () ->
59
+ origin_slot_id = $("body > ._modal-slot .card-slot[data-modal-origin-slot-id]")
60
+ .data("modal-origin-slot-id")
61
+ @find(".modal-body .card-slot").attr("data-modal-origin-slot-id", origin_slot_id)
62
+
63
+ modalOriginSlot: ()->
64
+
65
+
66
+ modalSlot: ->
67
+ slot = $("#modal-container")
68
+ if slot.length > 0 then slot else decko.createModalSlot()
69
+
70
+ modalify: ($slotter) ->
71
+ if $slotter.data("modal-body")?
72
+ @find(".modal-body").append($slotter.data("modal-body"))
73
+
74
+ if @hasClass("_modal-slot")
75
+ this
76
+ else
77
+ modalSlot = $('<div/>', id: "modal-container", class: "modal fade _modal-slot")
78
+ modalSlot.append(
79
+ $('<div/>' , class: "modal-dialog").append(
80
+ $('<div/>', class: "modal-content").append(this)
81
+ )
82
+ )
83
+ modalSlot
84
+ }
85
+
86
+ $.extend decko,
87
+ createModalSlot: ->
88
+ slot = $('<div/>', id: "modal-container", class: "modal fade _modal-slot")
89
+ $("body").append(slot)
90
+ slot
91
+
92
+ removeModal: ->
93
+ if $("._modal-stack")[0]
94
+ decko.popModal()
95
+ else
96
+ $("._modal-slot").trigger "slotDestroy"
97
+ $(".modal-dialog").empty()
98
+
99
+ pushModal: (el) ->
100
+ mslot = $("body > ._modal-slot")
101
+ mslot.removeAttr("id")
102
+ mslot.removeClass("_modal-slot").addClass("_modal-stack").removeClass("modal").addClass("background-modal")
103
+ el.insertBefore mslot
104
+ $(".modal-backdrop").removeClass("show")
105
+
106
+ popModal: ->
107
+ $(".modal-backdrop").addClass("show")
108
+ $("body > ._modal-slot").trigger "slotDestroy"
109
+ $("body > ._modal-slot").remove()
110
+ modal = $($("._modal-stack")[0])
111
+ modal.addClass("_modal-slot").removeClass("_modal-stack").attr("id", "modal-container").addClass("modal").removeClass("background-modal")
112
+ $(document.body).addClass("modal-open")
113
+
@@ -0,0 +1,58 @@
1
+ checkNameAfterTyping = null
2
+
3
+ $(window).ready ->
4
+ $('body').on 'click', '._renamer-updater', ->
5
+ $(this).closest('form').find('#card_update_referers').val 'true'
6
+
7
+ $('body').on 'submit', '._rename-form', ->
8
+ f = $(this)
9
+ confirm = f.find '.alert'
10
+ if confirm.is ':hidden'
11
+ referenceConfirm f
12
+ confirm.show 'blind'
13
+ false
14
+
15
+ $('body').on 'keyup', '.name-editor input', (event) ->
16
+ clearTimeout(checkNameAfterTyping) if checkNameAfterTyping
17
+ input = $(this)
18
+ if event.which == 13
19
+ checkName(input)
20
+ checkNameAfterTyping = null
21
+ else
22
+ checkNameAfterTyping = setTimeout ->
23
+ checkName(input)
24
+ checkNameAfterTyping = null
25
+ , 400
26
+
27
+ referenceConfirm = (form)->
28
+ confirm = form.find '._rename-reference-confirm'
29
+ return unless confirm.data('referer-count') > 0
30
+ confirm.show()
31
+ btn = form.find '._renamer-updater'
32
+ btn.show()
33
+ btn.focus()
34
+
35
+ checkName = (box) ->
36
+ name = box.val()
37
+ decko.pingName name, (data)->
38
+ return null if box.val() != name # avert race conditions
39
+ status = data['status']
40
+ if status
41
+ ed = box.parent()
42
+ leg = box.closest('fieldset').find('legend')
43
+ msg = leg.find '.name-messages'
44
+ unless msg[0]
45
+ msg = $('<span class="name-messages"></span>')
46
+ leg.append msg?
47
+ ed.removeClass 'real-name virtual-name known-name'
48
+
49
+ # use id to avoid warning when renaming to name variant
50
+ slot_id = box.slot().data 'cardId'
51
+ if status != 'unknown' and !(slot_id && parseInt(slot_id) == data['id'])
52
+ ed.addClass status + '-name known-name'
53
+ qualifier = if status == 'virtual' then 'in virtual' else 'already in'
54
+ href = decko.path(data['url_key'])
55
+ msg.html "\"<a href='#{href}'>#{name}</a>\" #{qualifier} use"
56
+ else
57
+ msg.html ''
58
+
@@ -0,0 +1,74 @@
1
+ $(window).ready ->
2
+ navbox = $('._navbox')
3
+ navbox.select2
4
+ placeholder: navbox.attr("placeholder")
5
+ escapeMarkup: (markup) ->
6
+ markup
7
+ minimumInputLength: 1
8
+ maximumSelectionSize: 1
9
+ ajax:
10
+ delay: 200
11
+ url: decko.path ':search.json'
12
+ data: (params) ->
13
+ query: { keyword: params.term }
14
+ view: "complete"
15
+ processResults: (data) ->
16
+ results: navboxize(data)
17
+ cache: true
18
+ templateResult: formatNavboxItem
19
+ templateSelection: formatNavboxSelectedItem
20
+ multiple: true
21
+ containerCssClass: 'select2-navbox-autocomplete'
22
+ dropdownCssClass: 'select2-navbox-dropdown'
23
+ width: "100%!important"
24
+
25
+ navbox.on "select2:select", (e) ->
26
+ navboxSelect(e)
27
+
28
+ formatNavboxItem = (i) ->
29
+ if i.loading
30
+ return i.text
31
+ '<i class="material-icons">' + i.icon + '</i>' +
32
+ '<span class="navbox-item-label">' + i.prefix + ':</span> ' +
33
+ '<span class="navbox-item-value">' + i.label + '</span>'
34
+
35
+ formatNavboxSelectedItem = (i) ->
36
+ unless i.icon
37
+ return i.text
38
+ '<i class="material-icons">' + i.icon + '</i>' +
39
+ '<span class="navbox-item-value">' + i.label + '</span>'
40
+
41
+ navboxize = (results) ->
42
+ items = []
43
+ term = results.term
44
+ if results["search"]
45
+ # id is what the form sends
46
+ items.push navboxItem(prefix: "search", id: term, text: term)
47
+
48
+ $.each ['add', 'new'], (index, key) ->
49
+ if val = results[key]
50
+ items.push navboxItem(prefix: key, icon: "add", text: val[0], href: val[1])
51
+
52
+ $.each results['goto'], (index, val) ->
53
+ i = navboxItem(
54
+ prefix: "go to", id: index, icon: "arrow_forward",
55
+ text: val[0], href: val[1], label: val[2]
56
+ )
57
+ items.push i
58
+
59
+ items
60
+
61
+ navboxItem = (data) ->
62
+ data.id ||= data.prefix
63
+ data.icon ||= data.prefix
64
+ data.label ||= '<strong class="highlight">' + data.text + '</strong>'
65
+ data
66
+
67
+ navboxSelect = (event) ->
68
+ item = event.params.data
69
+ if item.href
70
+ window.location = decko.path(item.href)
71
+ else
72
+ $(event.target).closest('form').submit()
73
+
74
+ $(event.target).attr('disabled', 'disabled')
@@ -0,0 +1,166 @@
1
+ $(document).ready ->
2
+ $('body').on 'click', 'button._nest-apply', () ->
3
+ if $(this).data("index")?
4
+ nest.applyNestToNestListEditor($(this).data("index"))
5
+ else
6
+ nest.applyNestToTinymceEditor($(this).data("tinymce-id"), $(this).data("tm-snippet-start"), $(this).data("tm-snippet-size"))
7
+
8
+ $('body').on 'click', 'button._change-create-to-update', () ->
9
+ tm_id = $(this).closest("form").find("#success_tinymce_id").val()
10
+ nest.changeCreateToUpdate(tm_id)
11
+
12
+ $('body').on 'click', 'button._open-nest-editor', () ->
13
+ form = $(this).closest("._nest-form")
14
+ reference = form.find("._reference").val()
15
+ nest_options = form.find("._nest-options").val()
16
+ encoded_nest = encodeURIComponent "{{#{reference}|#{nest_options}}}"
17
+ nest.openNestEditorForSlot(
18
+ $(this).closest(".card-slot"),
19
+ $(this).closest(".slotter"),
20
+ "index=#{form.data('index')}&tm_snippet_raw=#{encoded_nest}"
21
+ )
22
+
23
+
24
+ window.nest ||= {}
25
+
26
+ $.extend nest,
27
+ # called by TinyMCE
28
+ openNestEditor: (tm, params) ->
29
+ params = nest.editParams(tm) unless params?
30
+ this.openEditorForTm(tm, params, "nest_editor", "modal_nest_editor")
31
+
32
+ openNestEditorForSlot: (slot, slotter, params) ->
33
+ card = if slot[0] then $(slot[0]).attr('data-card-name') else ":update"
34
+ nest.request(card, "nest_editor", "modal_nest_editor", slotter, params)
35
+
36
+ openEditorForTm: (tm, params, overlay_view, modal_view) ->
37
+ params += "&tinymce_id=#{tm.id}"
38
+ slot = $("##{tm.id}").closest(".card-slot")
39
+ slotter = $("##{tm.id}")
40
+ card = if slot[0] then $(slot[0]).attr('data-card-name') else ":update"
41
+ nest.request(card, overlay_view, modal_view, slotter, params)
42
+
43
+ # called by TinyMCE
44
+ openImageEditor: (tm) ->
45
+ params = nest.editParams(tm, "{{", "}}", false) unless params?
46
+ this.openEditorForTm(tm, params,"nest_image", "modal_nest_image")
47
+
48
+ changeCreateToUpdate: (tm_id) ->
49
+ form = $("##{tm_id}").closest("form")
50
+ new_action = form.attr("action").replace("card/create", "card/update")
51
+ form.attr("action", new_action)
52
+
53
+ insertNest: (tm, nest_string) ->
54
+ tm.insertContent(nest_string)
55
+ # insertIndex = nest.offsetAfterInsert(tm, nest_string)
56
+ # params = nest.paramsStr(insertIndex, nest_string)
57
+ # nest.openNestEditor(etm, params)
58
+
59
+
60
+ request: (card, overlay_view, modal_view, slotter, params) ->
61
+ slot = $(".bridge-sidebar > ._overlay-container-placeholder > .card-slot")
62
+
63
+ if slot[0]
64
+ view = overlay_view
65
+ mode = "overlay"
66
+ else
67
+ slot = $($(".card-slot")[0])
68
+ view = modal_view
69
+ mode = "modal"
70
+
71
+ nest.sendRequest(slotter, slot, mode, card, view, params)
72
+
73
+ sendRequest: (slotter, slot, mode, card, view, params) ->
74
+ params = "" unless params?
75
+ url = "/#{card}?view=#{view}&#{params}"
76
+ $.ajax
77
+ url: url
78
+ type: 'GET'
79
+ success: (html) ->
80
+ slot.setSlotContent html, mode, slotter
81
+
82
+ editParams: (tm, prefix="{{", postfix="}}", edit=true) ->
83
+ sel = tm.selection.getSel()
84
+ return nest.paramsStr(0) unless sel? and sel.anchorNode?
85
+
86
+ text = sel.anchorNode.data
87
+ return nest.paramsStr(sel.anchorOffset) unless text
88
+
89
+ offset = sel.anchorOffset
90
+ before = text.substr(0, offset)
91
+ after = text.substr(offset)
92
+ index = {
93
+ before: {
94
+ close: before.lastIndexOf(postfix)
95
+ open: before.lastIndexOf(prefix)
96
+ },
97
+ after: {
98
+ close: after.indexOf(postfix)
99
+ open: after.indexOf(prefix)
100
+ }
101
+ }
102
+ if index.before.open > index.before.close &&
103
+ index.after.close != -1 &&
104
+ (index.after.open == -1 || index.after.close < index.after.open)
105
+ nest_start = index.before.open
106
+ unless name?
107
+ nest_size = index.after.close + offset + 2 - nest_start
108
+ name = text.substr(nest_start, nest_size)
109
+ if edit
110
+ nest.paramsStr(nest_start, name)
111
+ else
112
+ nest.paramsStr(nest_start + nest_size)
113
+ else
114
+ nest.paramsStr(offset)
115
+
116
+ paramsStr: (start, name) ->
117
+ params = ""
118
+ if start?
119
+ params += "&tm_snippet_start=#{start}"
120
+ if name? and name.length > 0
121
+ params += "&tm_snippet_raw=#{encodeURIComponent(name)}"
122
+
123
+ params
124
+
125
+ offsetAfterInsert: (editor, content) ->
126
+ offset = editor.selection.getSel().anchorOffset
127
+ offset - content.lengthr
128
+
129
+ applyNestToTinymceEditor: (tinymce_id, nest_start, nest_size) ->
130
+ nest.applySnippet("nest", tinymce_id, nest_start, nest_size)
131
+
132
+ applyNestToNestListEditor: (index) ->
133
+ row = $("._nest-form[data-index='#{index}']")
134
+ row.find("._reference").val(nest.name())
135
+ row.find("._nest-options").val(nest.options())
136
+ decko.updateAddItemButton(row)
137
+
138
+
139
+ applySnippet: (snippet_type, tinymce_id, start, size) ->
140
+ content = $("._#{snippet_type}-preview").val()
141
+ editor = tinymce.get(tinymce_id)
142
+ if start?
143
+ nest.replaceSnippet(editor, start, size, content)
144
+ else
145
+ editor.insertContent content
146
+ offset = nest.offsetAfterInsert(editor, content)
147
+ $("button._#{snippet_type}-apply").attr("data-tm-snippet-start", offset)
148
+
149
+ $("button._#{snippet_type}-apply").attr("data-tm-snippet-size", content.length)
150
+
151
+ replaceSnippet: (editor, start, size, content) ->
152
+ sel = editor.selection.getSel()
153
+ if sel? and sel.anchorNode? and sel.anchorNode.data?
154
+ text = sel.anchorNode.data
155
+ size = 0 unless size?
156
+ text = "#{text.substr(0, start)}#{content}#{text.substr(start + size)}"
157
+ sel.anchorNode.data = text
158
+ else
159
+ editor.insertContent content
160
+
161
+ updatePreview: (new_val) ->
162
+ new_val = "{{#{nest.name()}|#{nest.options()}}}" unless new_val?
163
+ preview = $("._nest-preview")
164
+ preview.val new_val
165
+ preview.data("nest-options", nest.options())
166
+ preview.data("reference", nest.name())
@@ -0,0 +1,102 @@
1
+ nestNameTimeout = null
2
+
3
+ $(document).ready ->
4
+ $('body').on 'click', '._nest-field-toggle', () ->
5
+ if $(this).is(':checked')
6
+ nest.addPlus()
7
+ else
8
+ nest.removePlus()
9
+
10
+ $('body').on 'input', 'input._nest-name', (event) ->
11
+ nest.nameChanged()
12
+
13
+ unless event.which == 13
14
+ clearTimeout(nestNameTimeout) if nestNameTimeout
15
+ nestNameTimeout = setTimeout (-> nest.updateNameRelatedTabs()), 700
16
+
17
+ $('body').on 'keydown', 'input._nest-name', (event) ->
18
+ if event.which == 13
19
+ clearTimeout(nestNameTimeout) if nestNameTimeout
20
+ nest.updateNameRelatedTabs()
21
+
22
+ $.extend nest,
23
+ name: () ->
24
+ nest.evalFieldOption $('input._nest-name').val()
25
+
26
+ nameChanged: () ->
27
+ new_val = $("._nest-preview").val().replace(/^\{\{[^}|]*/, "{{" + nest.name())
28
+ nest.updatePreview new_val
29
+
30
+ evalFieldOption: (name) ->
31
+ if nest.isField() then "+#{name}" else name
32
+
33
+ isField: ->
34
+ $('._nest-field-toggle').is(":checked")
35
+
36
+ addPlus: () ->
37
+ new_val = $("._nest-preview").val().replace(/^\{\{\+?/, "{{+")
38
+ nest.updatePreview new_val
39
+ $(".input-group.hide-prefix").removeClass("hide-prefix").addClass("show-prefix")
40
+
41
+ removePlus: () ->
42
+ new_val = $("._nest-preview").val().replace(/^\{\{\+?/, "{{")
43
+ nest.updatePreview new_val
44
+ $(".input-group.show-prefix").removeClass("show-prefix").addClass("hide-prefix")
45
+
46
+ rulesTabSlot: () ->
47
+ $("._nest-editor .tab-pane-rules > .card-slot")
48
+
49
+ contentTabSlot: () ->
50
+ $("._nest-editor .tab-pane-content > .card-slot")
51
+
52
+ emptyNameAlert: (show) ->
53
+ if show
54
+ $("._empty-nest-name-alert").removeClass("d-none")
55
+ else
56
+ $("._empty-nest-name-alert:not(.d-none)").addClass("d-none")
57
+
58
+ updateNameRelatedTabs: () ->
59
+ nest.updateRulesTab()
60
+ nest.updateContentTab()
61
+
62
+ updateContentTab: () ->
63
+ $contentTab = nest.contentTabSlot()
64
+ if $contentTab.length > 0
65
+ url = decko.path "#{nest.fullName()}?view=nest_content"
66
+ nest.updateNameDependentSlot($contentTab, url)
67
+
68
+ updateRulesTab: () ->
69
+ $rulesTab = nest.rulesTabSlot()
70
+ url = decko.path "#{nest.setNameForRules()}?view=nest_rules"
71
+ nest.updateNameDependentSlot($rulesTab, url)
72
+
73
+ updateNameDependentSlot: ($slot, url) ->
74
+ name = $("input._nest-name").val()
75
+ if name? && name.length > 0
76
+ nest.emptyNameAlert(false)
77
+ $slot.reloadSlot url
78
+ else
79
+ $slot.clearSlot()
80
+ nest.emptyNameAlert(true)
81
+
82
+ fullName: () ->
83
+ input = $('input._nest-name')
84
+ nest_name = input.val()
85
+ if nest.isField() and input.attr("data-left-name")
86
+ "#{input.attr("data-left-name")}+#{nest_name}"
87
+ else
88
+ nest_name
89
+
90
+ # set in the sense of card set
91
+ setNameForRules: () ->
92
+ input = $('input._nest-name')
93
+ nest_name = input.val()
94
+ if nest.isField()
95
+ if input.attr("data-left-type")
96
+ "#{input.attr("data-left-type")}+#{nest_name}+*type plus right"
97
+ else
98
+ "#{nest_name}+*right"
99
+ else
100
+ return "#{nest_name}+*self"
101
+
102
+