-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Patternslib/modernize
Update pat-content-mirror
- Loading branch information
Showing
8 changed files
with
4,145 additions
and
4,938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import registry from "@patternslib/patternslib/src/core/registry.js"; | ||
import "./src/pat-content-mirror.js"; | ||
import registry from "@patternslib/patternslib/src/core/registry"; | ||
import "./src/pat-content-mirror"; | ||
|
||
registry.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Webpack entry point for module federation. | ||
import "@patternslib/patternslib/webpack/module_federation"; | ||
// The next import needs to be kept with brackets, otherwise we get this error: | ||
|
||
// This import needs to be kept with brackets, otherwise we get this error: | ||
// "Shared module is not available for eager consumption." | ||
import("./bundle-config"); | ||
import("./bundle"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,57 @@ | ||
import $ from "jquery"; | ||
import Base from "@patternslib/patternslib/src/core/base"; | ||
import { BasePattern } from "@patternslib/patternslib/src/core/basepattern"; | ||
import events from "@patternslib/patternslib/src/core/events"; | ||
import Parser from "@patternslib/patternslib/src/core/parser"; | ||
import registry from "@patternslib/patternslib/src/core/registry"; | ||
|
||
const parser = new Parser("content-mirror"); | ||
parser.addArgument("target", "p.content-mirror .text"); | ||
|
||
export default Base.extend({ | ||
name: "content-mirror", | ||
trigger: ".pat-content-mirror", | ||
class Pattern extends BasePattern { | ||
static name = "content-mirror"; | ||
static trigger = ".pat-content-mirror"; | ||
static parser = parser; | ||
|
||
init: function content_mirror_init($el) { | ||
this.options = parser.parse(this.el, this.options); | ||
const $mirror = $(this.options.target).parents("p.content-mirror").first(); | ||
$el.on( | ||
"input propertychange", | ||
$.proxy(this.updateMirror, this, this.options.target) | ||
async init() { | ||
this.target = document.querySelector(this.options.target); | ||
events.add_event_listener( | ||
this.el, | ||
"input", | ||
"pat-content-mirror--update-mirror", | ||
this.update_mirror.bind(this) | ||
); | ||
$el.parents("form") | ||
.first() | ||
.on("reset", function () { | ||
$el.val(""); | ||
$mirror.html($mirror.html()); | ||
}); | ||
$(".placeholder", this.options.target).text($el.attr("placeholder") || ""); | ||
}, | ||
|
||
updateMirror: function updateMirror(target, ev) { | ||
const $el = $(ev.target); | ||
const the_mirror = $(target); | ||
the_mirror.text($el.val()); | ||
if (!$el.val().length) { | ||
const placeholder = $el.attr("placeholder"); | ||
|
||
const form = this.el.form || this.el.closest("form"); | ||
events.add_event_listener( | ||
form, | ||
"reset", | ||
`pat-content-mirror--reset--${this.uuid}`, | ||
() => { | ||
this.el.value = ""; | ||
this.el.dispatchEvent(events.input_event()); | ||
} | ||
); | ||
|
||
const placeholder = this.target.querySelector(".placeholder"); | ||
if (placeholder) { | ||
placeholder.textContent = this.el.getAttribute("placeholder") || ""; | ||
} | ||
} | ||
|
||
update_mirror(ev) { | ||
const el = ev.target; | ||
const the_mirror = this.target; | ||
const value = el.value; | ||
the_mirror.textContent = value; | ||
if (!value) { | ||
const placeholder = this.el.getAttribute("placeholder"); | ||
if (placeholder) { | ||
the_mirror.html('<em class="placeholder">' + placeholder + "</em>"); | ||
the_mirror.innerHTML = `<em class="placeholder">${placeholder}</em>`; | ||
} | ||
} | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
registry.register(Pattern); | ||
|
||
export default Pattern; | ||
export { Pattern }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.