Skip to content

Commit

Permalink
Remove extension to string class
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Feb 24, 2024
1 parent 6d7a1fb commit 0e626aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
9 changes: 3 additions & 6 deletions app/javascript/src/classes/browser_view.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PreloadContainer from 'src/classes/preload_container'
import { escapeHtml } from 'src/utils/dom'
import { escapeHtml, stringToDom } from 'src/utils/dom'
import { removeImageElement } from 'src/utils/image'
import { numberToHumanSize } from 'src/utils/math'
import FrameEditor from './frame_editor'
Expand Down Expand Up @@ -675,14 +675,11 @@ export default class BrowserView
sequence = pool_post.sequence
if sequence.match(/^[0-9]/)
sequence = '#' + sequence
html = '<div class="pool-info">Post ${sequence} in <a class="pool-link" href="/post/browse#/pool:${pool_id}">${desc}</a> ' + '(<a target="_blank" href="/pool/show/${pool_id}">pool page</a>)'
html = "<div class='pool-info'>Post #{sequence} in <a class='pool-link' href='/post/browse#/pool:#{pool_id}'>#{escapeHtml(pool_title)}</a> (<a target='_blank' href='/pool/show/#{pool_id}'>pool page</a>)"
if Pool.can_edit_pool(pool)
html += '<span class="advanced-editing"> (<a href="#" class="remove-pool-from-post">remove</a>)</span>'
html += '</div>'
div = html.subst(
sequence: sequence
pool_id: pool_id
desc: escapeHtml(pool_title)).createElement()
div = stringToDom html
div.post_id = post.id
div.pool_id = pool_id
pool_info.appendChild div
Expand Down
15 changes: 0 additions & 15 deletions app/javascript/src/legacy/common.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,6 @@ window.clone_event = (orig) ->
e = document.createEventObject(orig)
Event.extend e

Object.extend String.prototype,
subst: (subs) ->
text = this
for s of subs
r = new RegExp('\\${' + s + '}', 'g')
to = subs[s]
if !to?
to = ''
text = text.replace(r, to)
text
createElement: ->
container = document.createElement('div')
container.innerHTML = this
container.removeChild container.firstChild

window.onerror = (error, file, line) ->
ReportError error, file, line, null
return
Expand Down
6 changes: 6 additions & 0 deletions app/javascript/src/utils/dom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export escapeHtml = (str) -> str.replace(/[&<>"']/g, (str) => ({
export hideEl = (el) -> el.style.display = 'none'

export showEl = (el) -> el.style.display = ''

export stringToDom = (str) ->
container = document.createElement('div')
container.innerHTML = str

container.firstChild

0 comments on commit 0e626aa

Please sign in to comment.