{"id":13571825,"url":"https://github.com/jquery-boilerplate/jquery-patterns","last_synced_at":"2025-05-16T05:06:10.275Z","repository":{"id":69927683,"uuid":"2310149","full_name":"jquery-boilerplate/jquery-patterns","owner":"jquery-boilerplate","description":"A variety of jQuery plugin patterns for jump starting your plugin development","archived":false,"fork":false,"pushed_at":"2016-01-30T14:06:23.000Z","size":1851,"stargazers_count":1587,"open_issues_count":9,"forks_count":241,"subscribers_count":95,"default_branch":"master","last_synced_at":"2025-04-09T11:08:02.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jquery-boilerplate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-01T20:28:13.000Z","updated_at":"2025-01-04T20:11:22.000Z","dependencies_parsed_at":"2023-04-23T13:35:27.591Z","dependency_job_id":null,"html_url":"https://github.com/jquery-boilerplate/jquery-patterns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jquery-boilerplate%2Fjquery-patterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jquery-boilerplate%2Fjquery-patterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jquery-boilerplate%2Fjquery-patterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jquery-boilerplate%2Fjquery-patterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jquery-boilerplate","download_url":"https://codeload.github.com/jquery-boilerplate/jquery-patterns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"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":"2024-08-01T14:01:06.895Z","updated_at":"2025-05-16T05:06:10.257Z","avatar_url":"https://github.com/jquery-boilerplate.png","language":"JavaScript","readme":"# jQuery Plugin Patterns [![Build Status](https://secure.travis-ci.org/jquery-boilerplate/jquery-patterns.svg?branch=master)](https://travis-ci.org/jquery-boilerplate/jquery-patterns)\n\nSo, you've tried out [jQuery Boilerplate](https://github.com/jquery-boilerplate/jquery-boilerplate) or written a few of your own plugins before. They work to a degree and are readable, but you're interested in learning if there are better ways your plugin can be structured.\n\nPerhaps you're just looking for something that works better with the jQuery UI Widget factory, RequireJS or has built-in support for Publish/Subscribe. This repo hopes to provide a number of alternative boilerplates for kick-starting your jQuery plugin development catered towards the intermediate to advanced developer.\n\nThis project won't seek to provide implementations for every possible pattern, but will attempt to cover popular patterns developers often use in the wild.\n\n## Patterns\n\n-   **[A lightweight start](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.basic.plugin-boilerplate.js)**: perfect as a generic template for beginners\n    and above, uses a basic defaults object, simple constructor for\n    assigning the element to work with and extending options with\n    defaults and a lightweight wrapper around the constructor to avoid\n    issues with multiple instantiations\n-   **[Widget factory](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.widget-factory.plugin-boilerplate.js)**: for building complex, stateful plugins based on\n    object-oriented principles. The majority of jQueryUI heavily relies\n    on the widget factory as a base for components and this template\n    covers almost all supported default methods including triggering\n    events\n-   **[Widget factory + RequireJS](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.widget-factory.requirejs.boilerplate.js)**: for wrapping jQueryUI widgets inside\n    RequireJS compatible modules. Also demonstrates very basic widget\n    templating\n-   **[Widget factory for jQuery mobile](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.widget-factory.mobile-plugin.boilerplate.js)** - demonstrating best practices\n    for building mobile widgets, includes many of the same concepts as\n    the widget factory boilerplate, but also JQM specific usage\n    advice/tips in the comments\n-   **[Namespaced pattern](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.namespace.plugin-boilerplate.js)**: to avoid collisions and improve code\n    organization when working with components under another namespace\n-   **[Best options](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.best.options.plugin-boilerplate.js)**: globally/Per-call overridable options for\n    greater option customization, based on Ben Almans [pluginization](http://benalman.com/talks/jquery-pluginization.html) talk\n-   **[Custom events (Publish/Subscribe)](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.customevents.plugin-boilerplate.js)**: for better application\n    decoupling. Uses the Widget factory, but could be applied to the\n    generic template\n-   **[Extend pattern](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.extend-skeleton.js)**: Extended options\n-   **[Non Widget-factory widget](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.simplewidget.plugin-boilerplate.js])**: if you wish to stay away from the\n    widget factory. Uses Ben Alman’s simplewidget including coverage for\n    creation, instantiation and other best practices that may be helpful\n-   **[Prototypal inheritance pattern](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.prototypal-inheritance.plugin-boilerplate.js)**: use a bridge to generate a\n    plugin from an object (literal). Useful for code organization,\n    readability, functionality heavily based around DOM element\n    selection\n-   **[Universal Module Definition pattern](https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/amd%2Bcommonjs/pluginCore.js)**: create AMD and CommonJS\n    compatible plugin modules which are compatible with a number of\n    different script loaders. You may also be interested in the [UMD](https://github.com/umdjs) project.\n\n\n## Further reading\n\nMore information about the patterns in this repo can be found in [Learning JavaScript Design Patterns](http://addyosmani.com/resources/essentialjsdesignpatterns/book/#jquerypluginpatterns).\n\n## Contributing\n\nIf you have ideas for improvements that can be made to patterns currently in the repo, please feel free to create a new issue for discussion or send a pull request upstream. The same can be said about new patterns you wish to propose being added; for the sake of limiting confusion and complexity, I would ideally like to keep the number of overall patterns in the repo, but there are plans to separate these out into folders based on concerns.\n\n## Team\n\njQuery Patterns was made with love by these people and a bunch of awesome [contributors](https://github.com/jquery-boilerplate/jquery-patterns/graphs/contributors).\n\n[![Addy Osmani](http://gravatar.com/avatar/96270e4c3e5e9806cf7245475c00b275?s=70)](http://addyosmani.com) | [![Zeno Rocha](http://gravatar.com/avatar/e190023b66e2b8aa73a842b106920c93?s=70)](http://zenorocha.com)\n--- | --- | --- | --- | --- | --- | ---\n[Addy Osmani](http://addyosmani.com) | [Zeno Rocha](http://zenorocha.com)\n\n## Credits\n\nThanks to [@peol](http://github.com/peol), [@ajpiano](http://github.com/ajpiano), [@mathias](http://github.com/mathias), [@cowboy](http://github.com/cowboy), [@dougneiner](http://github.com/dougneiner) and others for their previous work (or tips) in this area. Some of this work is used as a basis for further improvements.\n\n","funding_links":[],"categories":["JavaScript","38. 实用工具/其他插件 ##","ES6入门","Resources"],"sub_categories":["13.20 视差滚动(Parallax Scrolling) ###","24.3 Web Sockets","Tutorials"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjquery-boilerplate%2Fjquery-patterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjquery-boilerplate%2Fjquery-patterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjquery-boilerplate%2Fjquery-patterns/lists"}