{"id":24383279,"url":"https://github.com/firstandthird/domodule","last_synced_at":"2025-04-11T01:12:24.188Z","repository":{"id":40751443,"uuid":"54734488","full_name":"firstandthird/domodule","owner":"firstandthird","description":"Declarative DOM module","archived":false,"fork":false,"pushed_at":"2024-07-23T02:13:07.000Z","size":1783,"stargazers_count":6,"open_issues_count":13,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-11T01:12:15.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/firstandthird.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-25T17:17:43.000Z","updated_at":"2024-07-23T02:09:35.000Z","dependencies_parsed_at":"2023-12-07T02:29:08.096Z","dependency_job_id":"1365ed12-5dc4-4b2d-9477-fc186c2e3d22","html_url":"https://github.com/firstandthird/domodule","commit_stats":{"total_commits":155,"total_committers":11,"mean_commits":"14.090909090909092","dds":0.6967741935483871,"last_synced_commit":"0a805cb05c82b3326207095c432ebed9476ace6d"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fdomodule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fdomodule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fdomodule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/firstandthird%2Fdomodule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/firstandthird","download_url":"https://codeload.github.com/firstandthird/domodule/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322571,"owners_count":21084337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-19T10:14:05.137Z","updated_at":"2025-04-11T01:12:24.172Z","avatar_url":"https://github.com/firstandthird.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003edomodule\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/firstandthird/domodule/actions/workflows/test.yaml\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/firstandthird/domodule/test.yaml?branch=main\u0026label=Tests\u0026style=for-the-badge\" alt=\"Test Status\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/firstandthird/domodule/actions/workflows/lint.yaml\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/firstandthird/domodule/lint.yaml?branch=main\u0026label=Lint\u0026style=for-the-badge\" alt=\"Lint Status\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/domodule\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/domodule.svg?label=npm\u0026style=for-the-badge\" alt=\"NPM Version\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nDomodule is a helper that allows you to create JavaScript modules with minimal effort while keeping code size down. It automatically binds to elements using the `data-module` attribute.\n\n## Installation\n\n```sh\nnpm install domodule\n```\n\n_or_\n\n```sh\nyarn add domodule\n```\n\n## Example usage\n\n```html\n\u003cdiv data-module=\"ExampleModule\" data-module-title=\"Example Module\"\u003e\n  \u003cdiv data-name=\"title\"\u003e\u003c/div\u003e\n  \u003cbutton type=\"button\" data-action=\"click\"\u003eShow Title\u003c/button\u003e\n\u003c/div\u003e\n```\n\n```js\nclass ExampleModule extends Domodule {\n  click() {\n    this.els.title.textContent = this.options.title;\n  }\n}\n```\n\n### Inherited methods\n\nEach module has access to these helper methods.\n\n- `find(\u003cselector\u003e)` - Returns an array of matched elements inside of the module.\n- `findOne(\u003cselector\u003e)` - Returns the first matched element inside of the module.\n- `findByName(\u003celement name\u003e)` - Alternative to `this.els[name]`.\n- `getOption(\u003coption\u003e)` - Returns value of an option (`data-module-*`).\n- `setupActions()` - Used to bind actions. Useful if the module adds elements in after Domodule inits. **Note:** Called by default. Calling again wont re-process elements.\n- `setupNamed()` - Same as `setupActions()` but binds to named elements. **Note:** Called by default. Calling again wont re-process elements.\n\n### Static Methods\n\n- `Domodule.getInstance(\u003celement\u003e)` - Returns an instance of the module.\n- `Domodule.discover(\u003cdom node, array of nodes, selector\u003e)` - Looks for `data-module` inside of matched elements. Will skip elements already processed. Calling just `Domodule.discover()` will search for all modules in the body.\n\n### Named elements\n\nAdding `data-name=\u003cname\u003e` to an element will bind it to `this.els.\u003cname\u003e`.\nAdding the same `data-name` to multiple elements will change `this.els.\u003cname\u003e` to an `Array\u003cHTMLElement\u003e`, sorted in DOM order.\n\n### Actions\n\nAdding `data-action=\u003cname\u003e` to an element binds it to click (or optionally `data-action-type=\u003ctouch|mouseover|etc\u003e`). Values can be passed through the event by adding data attributes starting with `data-action-`.\n\nCreate a method in the class matching the name given in the data attribute. Method will be passed: (the element, event object, values)\n\n### Properties\n\n- `this.el` - References the module element.\n- `this.els` - Object containing all `data-name` elements\n- `this.options` - Object containing anything passed in after `data-module-` (similar to action values).\n\n#### constructor\n\nA constructor method can be used but you will need to call `super(el)`. Constructor method gets el as it's only (and required) parameter. `super(el)` should be called before your code unless you need to modify core behavior. Element binding happens only when super is called.\n\n### Required options\n\nA module can pass an array of required options to the `super()` method. Module will fail to init if any number of the required options are not present. Example: `super(el, ['someOption', 'anotherOption'])`\n\n---\n\n\u003ca href=\"https://firstandthird.com\"\u003e\u003cimg src=\"https://firstandthird.com/_static/ui/images/safari-pinned-tab-62813db097.svg\" height=\"32\" width=\"32\" align=\"right\"\u003e\u003c/a\u003e\n\n_A [First + Third](https://firstandthird.com) Project_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fdomodule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirstandthird%2Fdomodule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirstandthird%2Fdomodule/lists"}