Skip to content

Commit

Permalink
Added debug: 'error', fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsz committed Sep 16, 2021
1 parent e4bb290 commit 17569f8
Show file tree
Hide file tree
Showing 7 changed files with 531 additions and 909 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.6.0] - 2021-09-16
### Added
- ```debug: 'error'``` to output only failed initialization calls
### Fixed
- Error when ```debug``` mode is on
- Spelling
### Changed
- Updated documentation
- Updated dependencies

## [1.5.0] - 2020-10-13
### Added
- `$.app.call(element, [settings], [pluginNames])` - added `plugins` optional argument to allow calling only a specific list of plugins
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ $(DIV_ELEMENT).pluginB({
| -------- | ------- | ---------------------------------------- | -------- |
| namespace | String | Data attribute name using which list of plugin names are defined | ```"plugin"``` |
| namespaceOptions | Boolean | Pass to plugin only data from attributes starting with plugin name, eg. data-datepicker. If set to false all data is passed to plugin as ```options``` and without removing prefixes | ```true``` |
| debug | Boolean | Output all successful and failed plugin initialization calls to the console | ```false``` |
| debug | Boolean or String | Output all successful and failed plugin initialization calls to the console. If value is "error" then output only failed plugin initialization calls | ```false``` |


#### namespaceOptions
Expand Down
9 changes: 5 additions & 4 deletions dist/jquery-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var REGEX_SPLIT = /(\s*,\s*|\s+)/;
var REGEX_NOT_LOWERCASE = /[^a-z]/;
var PROPERTY_NAME = 'jQueryAppData';
var LEVEL_ERROR = 'error';

$.app = {

Expand Down Expand Up @@ -62,10 +63,10 @@
var options = $.app.getPluginOptions($element, plugin, settings);
$element[plugin](options);

if (settings.debug) {
if (settings.debug && settings.debug !== LEVEL_ERROR) {
console.log('$.app called plugin "%s" on %o with options %O', plugin, element, options);
}
} else if (settings.debug) {
} else if (settings.debug && settings.debug !== LEVEL_ERROR) {
console.log('$.app skipped plugin "%s" on %o because it already has been called previously', plugin, element);
}
});
Expand All @@ -84,11 +85,11 @@
var plugins = ($(element).data(settings.namespace) || '').split(REGEX_SPLIT);

return plugins.filter(function (plugin) {
if (plugin) {
if (plugin.trim()) {
if (typeof $.fn[plugin] === 'function') {
return true;
} else if (settings.debug) {
console.error('$.app coundn\'t find jQuery plugin "%s" declared on element %o', plugin, $element.get(0));
console.error('$.app coundn\'t find jQuery plugin "%s" declared on element %o', plugin, $(element).get(0));
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery-app.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 17569f8

Please sign in to comment.