card-mod-format 0.14.1 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/assets/script/decko/clicks_and_hovers.js.coffee +49 -0
  3. data/assets/script/decko/decko.js.coffee +32 -0
  4. data/assets/script/decko/decko_jquery.js.coffee +25 -0
  5. data/assets/script/decko/slot.js.coffee +150 -0
  6. data/assets/script/decko/slot_ready.js.coffee +11 -0
  7. data/assets/script/decko/slotter.js.coffee +208 -0
  8. data/assets/script/jquery/jquery-ui.min.js +13 -0
  9. data/assets/script/jquery/jquery.autosize.js +274 -0
  10. data/assets/script/jquery/jquery.ui.autocomplete.html.js +41 -0
  11. data/assets/script/manifest.yml +38 -0
  12. data/assets/style/common.scss +73 -0
  13. data/assets/style/logo_and_credit.scss +24 -0
  14. data/assets/style/menu.scss +43 -0
  15. data/assets/style/messaging.scss +59 -0
  16. data/assets/style/misc.scss +90 -0
  17. data/assets/style/open_and_closed.scss +68 -0
  18. data/data/files/credit_image.svg +59 -0
  19. data/data/files/mod_format_script_asset_output/file.js +66 -0
  20. data/data/real.yml +67 -0
  21. data/lib/card/format/html_format.rb +0 -2
  22. data/lib/card/mod/format.rb +4 -0
  23. data/lib/card/path.rb +20 -20
  24. data/set/all/base.rb +1 -11
  25. data/set/all/content.rb +3 -11
  26. data/set/all/csv.rb +22 -74
  27. data/set/all/data.rb +2 -2
  28. data/set/all/demo.rb +6 -2
  29. data/set/all/error.rb +1 -1
  30. data/set/all/html/error.rb +1 -1
  31. data/set/all/html/head.rb +22 -12
  32. data/set/all/html/header.rb +10 -40
  33. data/set/all/html/header_wrap.haml +3 -4
  34. data/set/all/html/labeled.haml +1 -1
  35. data/set/all/html/menu.rb +36 -12
  36. data/set/all/html/views.rb +8 -17
  37. data/set/all/html/wrap.rb +5 -4
  38. data/set/all/html.rb +2 -3
  39. data/set/all/json.rb +1 -5
  40. data/set/right/head.rb +1 -0
  41. data/set/type/cardtype.rb +4 -6
  42. data/set/type/json.rb +1 -1
  43. data/set/type/number.rb +1 -16
  44. data/vendor/jquery_file_upload/LICENSE.txt +20 -0
  45. data/vendor/jquery_file_upload/README.md +224 -0
  46. data/vendor/jquery_file_upload/SECURITY.md +227 -0
  47. data/vendor/jquery_file_upload/VULNERABILITIES.md +118 -0
  48. data/vendor/jquery_file_upload/cors/postmessage.html +85 -0
  49. data/vendor/jquery_file_upload/cors/result.html +26 -0
  50. data/vendor/jquery_file_upload/css/jquery.fileupload-noscript.css +22 -0
  51. data/vendor/jquery_file_upload/css/jquery.fileupload-ui-noscript.css +17 -0
  52. data/vendor/jquery_file_upload/css/jquery.fileupload-ui.css +68 -0
  53. data/vendor/jquery_file_upload/css/jquery.fileupload.css +36 -0
  54. data/vendor/jquery_file_upload/docker-compose.yml +55 -0
  55. data/vendor/jquery_file_upload/img/loading.gif +0 -0
  56. data/vendor/jquery_file_upload/img/progressbar.gif +0 -0
  57. data/vendor/jquery_file_upload/index.html +357 -0
  58. data/vendor/jquery_file_upload/js/cors/jquery.postmessage-transport.js +126 -0
  59. data/vendor/jquery_file_upload/js/cors/jquery.xdr-transport.js +97 -0
  60. data/vendor/jquery_file_upload/js/demo.js +75 -0
  61. data/vendor/jquery_file_upload/js/jquery.fileupload-audio.js +101 -0
  62. data/vendor/jquery_file_upload/js/jquery.fileupload-image.js +347 -0
  63. data/vendor/jquery_file_upload/js/jquery.fileupload-process.js +170 -0
  64. data/vendor/jquery_file_upload/js/jquery.fileupload-ui.js +759 -0
  65. data/vendor/jquery_file_upload/js/jquery.fileupload-validate.js +119 -0
  66. data/vendor/jquery_file_upload/js/jquery.fileupload-video.js +101 -0
  67. data/vendor/jquery_file_upload/js/jquery.fileupload.js +1604 -0
  68. data/vendor/jquery_file_upload/js/jquery.iframe-transport.js +227 -0
  69. data/vendor/jquery_file_upload/js/vendor/jquery.ui.widget.js +805 -0
  70. data/vendor/jquery_file_upload/package-lock.json +6853 -0
  71. data/vendor/jquery_file_upload/package.json +116 -0
  72. data/vendor/jquery_file_upload/server/gae-python/app.yaml +18 -0
  73. data/vendor/jquery_file_upload/server/gae-python/main.py +204 -0
  74. data/vendor/jquery_file_upload/server/gae-python/static/favicon.ico +0 -0
  75. data/vendor/jquery_file_upload/server/gae-python/static/robots.txt +2 -0
  76. data/vendor/jquery_file_upload/server/php/Dockerfile +44 -0
  77. data/vendor/jquery_file_upload/server/php/UploadHandler.php +1480 -0
  78. data/vendor/jquery_file_upload/server/php/index.php +15 -0
  79. data/vendor/jquery_file_upload/server/php/php.ini +5 -0
  80. data/vendor/jquery_file_upload/test/index.html +49 -0
  81. data/vendor/jquery_file_upload/test/unit.js +989 -0
  82. data/vendor/jquery_file_upload/test/vendor/chai.js +10854 -0
  83. data/vendor/jquery_file_upload/test/vendor/mocha.css +325 -0
  84. data/vendor/jquery_file_upload/test/vendor/mocha.js +18178 -0
  85. data/vendor/jquery_file_upload/wdio/LICENSE.txt +20 -0
  86. data/vendor/jquery_file_upload/wdio/assets/black+white-3x2.jpg +0 -0
  87. data/vendor/jquery_file_upload/wdio/assets/black+white-60x40.gif +0 -0
  88. data/vendor/jquery_file_upload/wdio/conf/chrome.js +40 -0
  89. data/vendor/jquery_file_upload/wdio/conf/firefox.js +25 -0
  90. data/vendor/jquery_file_upload/wdio/hooks/index.js +36 -0
  91. data/vendor/jquery_file_upload/wdio/test/pages/file-upload.js +79 -0
  92. data/vendor/jquery_file_upload/wdio/test/specs/01-file-upload.js +25 -0
  93. data/vendor/jquery_file_upload/wdio/wdio.conf.js +4 -0
  94. data/vendor/jquery_rails/CHANGELOG.md +359 -0
  95. data/vendor/jquery_rails/CONTRIBUTING.md +132 -0
  96. data/vendor/jquery_rails/Gemfile +22 -0
  97. data/vendor/jquery_rails/MIT-LICENSE +21 -0
  98. data/vendor/jquery_rails/README.md +75 -0
  99. data/vendor/jquery_rails/Rakefile +59 -0
  100. data/vendor/jquery_rails/VERSIONS.md +62 -0
  101. data/vendor/jquery_rails/jquery-rails.gemspec +26 -0
  102. data/vendor/jquery_rails/lib/jquery/assert_select.rb +149 -0
  103. data/vendor/jquery_rails/lib/jquery/rails/engine.rb +6 -0
  104. data/vendor/jquery_rails/lib/jquery/rails/version.rb +9 -0
  105. data/vendor/jquery_rails/lib/jquery/rails.rb +8 -0
  106. data/vendor/jquery_rails/lib/jquery-rails.rb +1 -0
  107. data/vendor/jquery_rails/test/assert_select_jquery_test.rb +85 -0
  108. data/vendor/jquery_rails/test/test_helper.rb +6 -0
  109. data/vendor/jquery_rails/vendor/assets/javascripts/jquery.js +11008 -0
  110. data/vendor/jquery_rails/vendor/assets/javascripts/jquery.min.js +5 -0
  111. data/vendor/jquery_rails/vendor/assets/javascripts/jquery.min.map +1 -0
  112. data/vendor/jquery_rails/vendor/assets/javascripts/jquery2.js +9814 -0
  113. data/vendor/jquery_rails/vendor/assets/javascripts/jquery2.min.js +4 -0
  114. data/vendor/jquery_rails/vendor/assets/javascripts/jquery2.min.map +1 -0
  115. data/vendor/jquery_rails/vendor/assets/javascripts/jquery3.js +10364 -0
  116. data/vendor/jquery_rails/vendor/assets/javascripts/jquery3.min.js +2 -0
  117. data/vendor/jquery_rails/vendor/assets/javascripts/jquery3.min.map +1 -0
  118. data/vendor/jquery_rails/vendor/assets/javascripts/jquery_ujs.js +555 -0
  119. metadata +104 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dc960bb48dd11ee9c71a5c8b570b93e626be8608eed453410bcdbae6d02c362
4
- data.tar.gz: c98318fd72600cd4a66c40af08c23a638cd80040eda0017cc625bcad29cae281
3
+ metadata.gz: a4831b05c3fabaa2fe6df1b4a0a7d4a548a89344fc174322e6afc98cdbed3c39
4
+ data.tar.gz: defeae8ec613a2044f7c1af895607f8f2718e5f5ed37972283f2eaa6f1f7eed0
5
5
  SHA512:
6
- metadata.gz: '015682b9e06d33fea65eba7ffcdf165054e8f076aa941378f21aa2744ea05afb63abf39fe1a0f77230f9e76f64fbc0e597aab42d8bcdb4a20908b6c87bba1a35'
7
- data.tar.gz: 827a8b652a37e1435f82e83e18fa1b968e0a5906baf56544c9ac98a0ef82227fee91b8e3a20d5e59a8152c3ebea122e45b68a4b85d0ac983096325b7bec936c7
6
+ metadata.gz: 35cb14e6738063019f3dda1925be996524b966de600a418f09d0685a4c067b94aba1e1d03dc320fe6c77c389acee0d6bc469c6a2ceb3d5a68caad50790726d0e
7
+ data.tar.gz: 950d8600fb84f203b40252d1481306733f8112c96b06a281d31d5fa45f1aa00fda5f5646a72f201085e13b781db59b0f5011801fb569863a4bd5ee0e62e2e1d6
@@ -0,0 +1,49 @@
1
+ $(window).ready ->
2
+ $('body').on 'click', '.submitter', ->
3
+ $(this).closest('form').submit()
4
+
5
+ $('body').on 'click', 'button.redirecter', ->
6
+ window.location = $(this).attr('href')
7
+
8
+ $('body').on 'click', '.render-error-link', (event) ->
9
+ msg = $(this).closest('.render-error').find '.render-error-message'
10
+ msg.show()
11
+ # msg.dialog()
12
+ event.preventDefault()
13
+
14
+ $(document).on 'click', '._stop_propagation', (event)->
15
+ event.stopPropagation()
16
+
17
+ $("body").on 'click', '._prevent_default', (event)->
18
+ event.preventDefault()
19
+
20
+ $('body').on 'mouseenter', 'a[data-hover-text]', ->
21
+ text = $(this).text()
22
+ $(this).data("original-text", text)
23
+ $(this).text($(this).data("hover-text"))
24
+
25
+ $('body').on 'mouseleave', 'a[data-hover-text]', ->
26
+ $(this).text($(this).data("original-text"))
27
+
28
+ $('body').on 'mouseenter', '[hover_content]', ->
29
+ $(this).attr 'hover_restore', $(this).html()
30
+ $(this).html $(this).attr( 'hover_content' )
31
+
32
+ $('body').on 'mouseleave', '[hover_content]', ->
33
+ $(this).html $(this).attr( 'hover_restore' )
34
+
35
+ decko.slot.ready (slot) ->
36
+ if isTouchDevice()
37
+ slot.find('._show-on-hover').removeClass('_show-on-hover')
38
+
39
+ isTouchDevice = ->
40
+ if 'ontouchstart' of window or window.DocumentTouch and
41
+ document instanceof DocumentTouch
42
+ true
43
+ else
44
+ detectMobileBrowser()
45
+
46
+ # source for this method: detectmobilebrowsers.com
47
+ detectMobileBrowser = (userAgent) ->
48
+ userAgent = navigator.userAgent or navigator.vendor or window.opera
49
+ /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(userAgent) or /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(userAgent.substr(0, 4))
@@ -0,0 +1,32 @@
1
+ window.decko =
2
+ rootUrl: "" # overwritten in inline script in head
3
+
4
+ # returns absolute path (starting with a slash)
5
+ # if rawPath is complete url, this returns the complete url
6
+ # if rawPath is relative (no slash), this adds relative root
7
+ path: (rawPath) ->
8
+ if rawPath.match /^\/|:\/\//
9
+ rawPath
10
+ else
11
+ decko.rootUrl + rawPath
12
+
13
+ editors:
14
+ init: {}
15
+ content: {}
16
+ add: (selector, initf, contentf)->
17
+ decko.editors.init[selector] = initf
18
+ decko.editors.content[selector] = contentf
19
+
20
+ warn: (stuff) -> console.log stuff if console?
21
+
22
+ snakeCase: (str)->
23
+ str.replace /([a-z])([A-Z])/g, (match) -> match[0] + '_' +
24
+ match[1].toLowerCase()
25
+
26
+
27
+ #~~~~~ ( EVENTS )
28
+
29
+ $(window).ready ->
30
+ $.ajaxSetup cache: false
31
+
32
+
@@ -0,0 +1,25 @@
1
+ jQuery.fn.extend
2
+ findCard: (id) -> @find("[data-card-id='" + id + "']")
3
+
4
+ isMain: -> @slot().parent('#main')[0]
5
+
6
+ cardMark: ->
7
+ if @data('cardId') then "~#{@data('cardId')}" else @data("cardName")
8
+
9
+ isMainOrMainModal: ->
10
+ el = $(this)
11
+ el = el.slotOrigin("modal") if el.closest(".modal")[0]
12
+ el && el.isMain()
13
+
14
+ notify: (message, status) ->
15
+ slot = @slot(status)
16
+ notice = slot.find '.card-notice'
17
+ unless notice[0]
18
+ notice = $('<div class="card-notice"></div>')
19
+ form = slot.find('.card-form')
20
+ if form[0]
21
+ $(form[0]).append notice
22
+ else
23
+ slot.append notice
24
+ notice.html message
25
+ notice.show 'blind'
@@ -0,0 +1,150 @@
1
+ decko.slot =
2
+ # returns full path with slot parameters
3
+ path: (path, slot)->
4
+ params = slotPathParams slot
5
+ decko.path(path) + ( (if path.match /\?/ then '&' else '?') + $.param(params) )
6
+
7
+ ready: (func)->
8
+ $('document').ready ->
9
+ $('body').on 'decko.slot.ready', '.card-slot', (e, slotter) ->
10
+ e.stopPropagation()
11
+ if slotter?
12
+ func.call this, $(this), $(slotter)
13
+ else
14
+ func.call this, $(this)
15
+
16
+ destroy: (func)->
17
+ $('document').ready ->
18
+ $('body').on 'decko.slot.destroy', '.card-slot, ._modal-slot', (e) ->
19
+ e.stopPropagation()
20
+ func.call this, $(this)
21
+
22
+
23
+ jQuery.fn.extend
24
+ isSlot: -> $(this).hasClass "card-slot"
25
+
26
+ triggerSlotReady: (slotter) ->
27
+ @trigger "decko.slot.ready", slotter if @isSlot()
28
+ @find(".card-slot").trigger "decko.slot.ready", slotter
29
+
30
+ slot: (status="success", mode="replace") ->
31
+ return @modalSlot() if mode == "modal"
32
+
33
+ @_slotSelect("slot-#{status}-selector") ||
34
+ @_slotSelect("slot-selector") ||
35
+ @closest(".card-slot")
36
+
37
+ slotUrl: ->
38
+ slot = $(this)
39
+ decko.slot.path "#{slot.cardMark()}/#{slot.data("slot")["view"]}"
40
+
41
+ slotFind: (selector) ->
42
+ switch selector
43
+ when "modal-origin" then @slotOrigin "modal"
44
+ when "overlay-origin" then @slotOrigin "overlay"
45
+ else slotScour @closest(selector), @closest(".card-slot"), selector
46
+
47
+ slotClear: () ->
48
+ @trigger "decko.slot.destroy"
49
+ @empty()
50
+
51
+ # type can be "modal" or "overlay"
52
+ slotOrigin: (type) ->
53
+ overlaySlot = @closest("[data-#{type}-origin-slot-id]")
54
+ origin_slot_id = overlaySlot.data("#{type}-origin-slot-id")
55
+ origin_slot = $("[data-slot-id=#{origin_slot_id}]")
56
+ if origin_slot[0]?
57
+ origin_slot
58
+ else
59
+ decko.warn "couldn't find origin with slot id #{origin_slot_id}"
60
+
61
+ slotReload: (url) ->
62
+ @each -> $(this)._slotReloadSingle url
63
+
64
+ slotUpdate: (newContent, mode) ->
65
+ mode ||= "replace"
66
+ @slotContent newContent, mode, $(this)
67
+
68
+ slotContent: (newContent, mode, $slotter) ->
69
+ v = $(newContent)[0] && $(newContent) || newContent
70
+
71
+ if typeof(v) == "string"
72
+ # Needed to support "TEXT: result" pattern in success (eg deleting nested cards)
73
+ @slot("success", mode)._slotFillOrReplace v, $slotter
74
+ else
75
+ if v.hasClass("_overlay")
76
+ mode = "overlay"
77
+ else if v.hasClass("_modal")
78
+ mode = "modal"
79
+ @slot("success", mode)._slotContentFromElement v, mode, $slotter
80
+ v
81
+
82
+ _slotContentFromElement: (el, mode, $slotter) ->
83
+ if mode == "overlay"
84
+ @addOverlay(el, $slotter)
85
+ else if el.hasClass("_modal-slot") or mode == "modal"
86
+ el.showAsModal($slotter)
87
+ else
88
+ slot_id = @data("slot-id")
89
+ el.attr("data-slot-id", slot_id) if slot_id
90
+ @trigger "decko.slot.destroy"
91
+ @_slotFillOrReplace el, $slotter
92
+ decko.contentLoaded(el, $slotter)
93
+
94
+ _slotFillOrReplace: (content, $slotter) ->
95
+ if @hasClass("_fixed-slot")
96
+ @html content
97
+ else
98
+ @replaceWith content
99
+ decko.contentLoaded(this, $slotter)
100
+
101
+ _slotSelect: (selectorName) ->
102
+ if selector = @data(selectorName)
103
+ slot = @slotFind selector
104
+ slot && slot[0] && slot
105
+
106
+ _slotReloadSingle: (url) ->
107
+ $slot = $(this)
108
+ url = $slot.slotUrl() unless url?
109
+ $slot.addClass 'slotter'
110
+ $slot.data "url", url
111
+ $slot.data "remote", true
112
+ $slot.attr 'href', url
113
+ this[0].href = url
114
+ # that's where handleRemote gets the url from
115
+ # .attr(href, url) only works for anchors
116
+ $.rails.handleRemote $slot
117
+
118
+ # ~~~~~~~~~~~~~~~~~~~~~~~~
119
+ # "private" helper methods
120
+
121
+ slotPathParams = (slot) ->
122
+ params = {}
123
+ main = $('#main').children('.card-slot').data 'cardName'
124
+ params['main'] = main if main?
125
+
126
+ if slot
127
+ params['is_main'] = true if slot.isMain()
128
+ slotdata = slot.data 'slot'
129
+ if slotdata?
130
+ slotParams slotdata, params, 'slot'
131
+ params['type'] = slotdata['type'] if slotdata['type']
132
+ params
133
+
134
+ slotParams = (raw, processed, prefix)->
135
+ $.each raw, (key, value)->
136
+ cgiKey = prefix + '[' + decko.snakeCase(key) + ']'
137
+ if key == 'items'
138
+ slotParams value, processed, cgiKey
139
+ else
140
+ processed[cgiKey] = value
141
+
142
+ slotScour = (target_slot, parent_slot, selector) ->
143
+ # if slot-selector doesn't apply to a child, search in all parent slots and finally in the body
144
+ while target_slot.length == 0 and parent_slot.length > 0
145
+ target_slot = $(parent_slot).find(selector)
146
+ parent_slot = $(parent_slot).parent().closest '.card-slot'
147
+ if target_slot.length == 0
148
+ $(selector)
149
+ else
150
+ target_slot
@@ -0,0 +1,11 @@
1
+ decko.slot.ready (slot) ->
2
+ slot.find('card-view-placeholder').each ->
3
+ $place = $(this)
4
+ return if $place.data("loading")
5
+
6
+ $place.data "loading", true
7
+ $.get $place.data("url"), (data, _status) ->
8
+ $place.replaceWith data
9
+
10
+ slot.find('._disappear').delay(5000).animate(
11
+ height: 0, 1000, -> $(this).hide())
@@ -0,0 +1,208 @@
1
+ # There are three places that can control what happens after an ajax request
2
+ # 1. the element that triggered the request (eg. a link or a button)
3
+ # 2. the closest ".slotter" element
4
+ # (if the trigger itself isn't a slotter,
5
+ # a common example is that a form is a slotter but the form buttons aren't)
6
+ # 3. the slot returned by the request
7
+ #
8
+ # A slot is an element marked with "card-slot" class, a slotter has a "slotter" class.
9
+ # By the default, the closest slot of the slotter is replaced with the new slot that the
10
+ # request returned. The behavior can be changed with css classes and data attributes.
11
+ #
12
+ # To 1. The trigger element has only a few options to override the slotter.
13
+ # classes:
14
+ # "_close-modal-on-success"
15
+ # "_close-overlay-on-success"
16
+ # "_update-origin"
17
+ #
18
+ # To 2. The slotter is the standard way to define what happens with request result
19
+ # data:
20
+ # slot-selector
21
+ # a css selector that defines which slot will be replaced.
22
+ # You can also use "modal-origin" and "overlay-origin" to refer to the origin slots.
23
+ # slot-success-selector/slot-error-selector
24
+ # the same as slot-selector but only used
25
+ # for success case or error case, respectively
26
+ # update-foreign-slot
27
+ # a css selector to specify an additional slot that will be
28
+ # updated after the request.
29
+ # update-foreign-slot-url
30
+ # a url to fetch the new content for the additional slot
31
+ # if not given the slot is updated with the same card and view that was used before
32
+ # update-origin
33
+ # if present then the slot from where the current modal or overlay slot was opened
34
+ # will be updated
35
+ # slotter-mode
36
+ # possible values are
37
+ # replace (default)
38
+ # replace the closest slot with new slot
39
+ # modal
40
+ # show new slot in modal; if there is already a modal then put it on top
41
+ # modal-replace
42
+ # replace existing modal
43
+ # overlay
44
+ # show new slot in overlay
45
+ # update-origin
46
+ # update closest slot of the slotter that opened the modal or overlay
47
+ # (assumes that the request was triggered from a modal or overlay)
48
+ # If you need the update-origin mode together with another mode then use
49
+ # data-update-origin="true".
50
+ # silent-success
51
+ # do nothing
52
+ #
53
+ # classes:
54
+ # _close-overlay
55
+ # _close-modal
56
+ #
57
+ # To 3. Similar as 1, the slot has only overlay and modal options.
58
+ # classes:
59
+ # _modal
60
+ # show slot in modal
61
+ # _overlay
62
+ # show slot in overlay
63
+ #
64
+ #
65
+ $(window).ready ->
66
+ $('body').on 'ajax:success', '.slotter', (event, data) ->
67
+ $(this).slotterSuccess event, data
68
+
69
+ $('body').on 'ajax:error', '.slotter', (event, xhr) ->
70
+ $(this).showErrorResponse xhr.status, xhr.responseText
71
+
72
+ $('body').on 'click', 'button.slotter', ->
73
+ return false if !$.rails.allowAction $(this)
74
+ $.rails.handleRemote $(this)
75
+
76
+ # $('body').on 'click', '._clickable.slotter', (event)->
77
+ # $(this)[0].href = $(this).attr("href") # that's where rails.handleRemote
78
+ # # expects the url
79
+ # $.rails.handleRemote $(this)
80
+
81
+ $('body').on 'click', '[data-bs-dismiss="overlay"]', ->
82
+ $(this).slotFind(".card-slot._overlay").removeOverlay()
83
+
84
+ $('body').on 'click', '._close-overlay-on-success', ->
85
+ $(this).closeOnSuccess("overlay")
86
+
87
+ $('body').on 'click', '._close-modal-on-success', ->
88
+ $(this).closeOnSuccess("modal")
89
+
90
+ $('body').on 'click', '._close-on-success', ->
91
+ $(this).closeOnSuccess()
92
+
93
+ $('body').on 'click', '._update-origin', ->
94
+ $(this).closest('.slotter').data("slotter-mode", "update-origin")
95
+
96
+ $('body').on 'submit', 'form.slotter', ->
97
+ form = $(this)
98
+ if form.data("main-success") and form.isMainOrMainModal()
99
+ form.mainSuccess()
100
+
101
+ $('body').on 'ajax:beforeSend', '.slotter', (event, xhr, opt)->
102
+ $(this).slotterBeforeSend opt
103
+
104
+ jQuery.fn.extend
105
+ mainSuccess: ()->
106
+ form = $(this)
107
+ $.each form.data("main-success"), (key, value)->
108
+ inputSelector = "[name=success\\[" + key + "\\]]"
109
+ input = form.find inputSelector
110
+ unless input[0]
111
+ input = $('<input type="hidden" name="success[' + key + ']"/>')
112
+ form.append input
113
+ input.val value
114
+
115
+ slotterSuccess: (event, responseData) ->
116
+ unless @hasClass("slotter")
117
+ console.log "warning: slotterSuccess called on non-slotter element #{this}"
118
+ return
119
+
120
+ return if event.slotSuccessful
121
+
122
+ @showSuccessResponse responseData, @data("slotter-mode")
123
+
124
+ if @hasClass "_close-overlay"
125
+ @removeOverlay()
126
+ if @hasClass "_close-modal"
127
+ @closest('.modal').modal "hide"
128
+
129
+ # should scroll to top after clicking on new page
130
+ if @hasClass "card-paging-link"
131
+ slot_top_pos = @slot().offset().top
132
+ $("body").scrollTop slot_top_pos
133
+ if @data("update-foreign-slot")
134
+ $slot = @slotFind @data("update-foreign-slot")
135
+ reload_url = @data("update-foreign-slot-url")
136
+ $slot.slotReload reload_url
137
+
138
+ if @data('original-slotter-mode')
139
+ @attr 'data-slotter-mode', @data('original-slotter-mode')
140
+ if @data('original-slot-selector')
141
+ @attr 'data-slot-selector', @data('original-slot-selector')
142
+
143
+ event.slotSuccessful = true
144
+
145
+ showSuccessResponse: (responseData, mode) ->
146
+ if responseData.redirect
147
+ window.location = responseData.redirect
148
+ else if responseData.reload
149
+ window.location.reload(true)
150
+ else
151
+ switch mode
152
+ when "silent-success" then return
153
+ when "update-modal-origin" then @updateModalOrigin()
154
+ when "update-origin" then @updateOrigin()
155
+ else @slotUpdate responseData, mode
156
+
157
+ showErrorResponse: (status, result) ->
158
+ if status == 403 #permission denied
159
+ $(result).showAsModal $(this)
160
+ else if status == 900
161
+ $(result).showAsModal $(this)
162
+ else
163
+ @notify result, "error"
164
+
165
+ if status == 409 #edit conflict
166
+ @slot().find('.current_revision_id').val(
167
+ @slot().find('.new-current-revision-id').text()
168
+ )
169
+
170
+ updateModalOrigin: () ->
171
+ if @overlaySlot()
172
+ overlayOrigin = @slotOrigin("overlay")
173
+ overlayOrigin.updateOrigin()
174
+ else if @closest("#modal-container")[0]
175
+ @updateOrigin()
176
+
177
+ updateOrigin: () ->
178
+ type = if @overlaySlot()
179
+ "overlay"
180
+ else if @closest("#modal-container")[0]
181
+ "modal"
182
+
183
+ return unless type?
184
+
185
+ origin = @slotOrigin(type)
186
+ if origin && origin[0]?
187
+ origin.slotReload()
188
+
189
+ registerAsOrigin: (type, slot) ->
190
+ if slot.hasClass("_modal-slot")
191
+ slot = slot.find(".modal-body") # put the origin slot id on the modal-body instead
192
+ # of on the slot, so that it survives slot reloads
193
+ slot.attr("data-#{type}-origin-slot-id", @slot().data("slot-id"))
194
+
195
+
196
+ # close modal or overlay
197
+ closeOnSuccess: (type) ->
198
+ slotter = @closest('.slotter')
199
+ if !type?
200
+ type = if @isInOverlay() then "overlay" else "modal"
201
+ slotter.addClass "_close-#{type}"
202
+
203
+ slotterBeforeSend: (opt) ->
204
+ return if opt.noSlotParams
205
+
206
+ # avoiding duplication. could be better test?
207
+ unless (opt.url.match(/home_view/) or @data("slotter-mode") == "modal")
208
+ opt.url = decko.slot.path opt.url, @slot()