├── LICENSE ├── README.md ├── bower.json ├── demo ├── index.html └── reload.php ├── package.json └── widgster.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 flatlogic.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Widgster 2 | ====================== 3 | 4 | Small jQuery plugin that provides an easy way to handle basic widget functions like collapsing, closing, ajax-refreshing & fullsreening. 5 | 6 | **[Demo](http://widgster.flatlogic.com/demo/index.html)** 7 | 8 | **[Advanced Demo](http://demo.flatlogic.com/4.0.1/dark/grid_live.html)** 9 | 10 | Use 11 | ------------ 12 | 13 | 14 | To apply all these features to your default widget you have to add appropriate links (or buttons) to it: 15 | 16 |
32 | 33 | In the example above links are put into a `.widget-controls` but you can put them anywhere inside of widget. 34 | 35 | Then widgster needs to be initialized via javascript: 36 | 37 | $('.widget').widgster(); 38 | 39 | As you could guess `data-widgster` attribute defines widget action to be performed when link is clicked. 40 | 41 | Actions 42 | ------------ 43 | 44 | * **close** - closes the widget; 45 | * **collapse** - collapses (minimizes) the widget. An element holding this data attribute will be hidden when widget gets expanded; 46 | * **expand** - expands the widget. An element holding this data attribute will be hidden when widget gets collapsed; 47 | * **fullscreen** - fullscreens the widget. An element holding this data attribute will be hidden when widget gets restored; 48 | * **restore** - restores the widget back to its position. An element holding this data attribute will be hidden when widget gets fullscreened; 49 | * **load** - reloads widget content from the url provided with `data-widget-load` attribute. 50 | 51 | All actions may be called via js: 52 | 53 | $('.widget').widgster('close'); 54 | 55 | Options 56 | ------------ 57 | 58 | * **collapsed** - if true collapses widget after page load; 59 | * **fullscreened** - if true fullscreens widget after page load; 60 | * **bodySelector** - widget body selector. Used for loading and collapsing. Default is `.body`; 61 | * **load** - an url to fetch widget body from. Default is `undefined`; 62 | * **showLoader** - whether to show a loader when ajax refresh performed. Default is `true`; 63 | * **autoload** - whether to automatically perform ajax refresh after page load. May be set to an integer value. If set, for example, to 2000 will refresh the widget every 2 seconds. Default is `false`; 64 | * **closePrompt(callback)** - a function to be called when closing. Closing is only performed when `callback` is called. 65 | 66 | Widgster accepts an object with options: 67 | 68 | $('.widget').widgster({ 69 | collapsed: true 70 | }); 71 | 72 | Events 73 | ------------ 74 | 75 | Each action fires both before and after event. Events have the same names as actions. Before event may be canceled. 76 | 77 | For example, to make refresh button spin: 78 | 79 | $('.widget').on("load.widgster", function(){ 80 | $(this).find('[data-widgster="load"] > i').addClass('fa-spin') 81 | }).on("loaded.widgster", function(){ 82 | $(this).find('[data-widgster="load"] > i').removeClass('fa-spin') 83 | }); 84 | 85 | How can I support the developers? 86 | ------------------------------------ 87 | - Star our GitHub repo :star: 88 | - Create pull requests, submit bugs, suggest new features or documentation updates :wrench: 89 | - Follow us on [Twitter](https://twitter.com/flatlogic) :feet: 90 | - Like our page on [Facebook](https://www.facebook.com/flatlogic/) :thumbsup: 91 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "widgster", 3 | "main": "widgster.js", 4 | "version": "0.0.3", 5 | "homepage": "https://github.com/okendoken/widgster", 6 | "authors": [ 7 | "okendoken (http://flatlogic.com)" 8 | ], 9 | "license": "MIT", 10 | "ignore": [ 11 | "**/.*", 12 | "node_modules", 13 | "bower_components", 14 | "test", 15 | "tests" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 26 | 27 |Yes, I was reloaded at , and yes, I am widget body. I may contain lots of cool stuff like lore ipsum, etc.
3 |But!
4 |This time I am going to show you something really cool. I will be just body and that's it. 5 | Can you imagine that?
-------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "widgster", 3 | "version": "1.0.0", 4 | "description": "jQuery plugin that provides an easy way to handle basic widget functions like collapsing, closing, ajax-refreshing & fullsreening", 5 | "main": "widgster.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/flatlogic/widgster.git" 12 | }, 13 | "keywords": [ 14 | "jquery", 15 | "widget" 16 | ], 17 | "author": "https://flatlogic.com", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/flatlogic/widgster/issues" 21 | }, 22 | "homepage": "https://github.com/flatlogic/widgster#readme" 23 | } 24 | -------------------------------------------------------------------------------- /widgster.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Widgster plugin. 3 | */ 4 | ( function( global, factory ) { 5 | "use strict"; 6 | 7 | if (global.jQuery && global.jQuery.fn) { 8 | factory(global.jQuery); 9 | } else { 10 | console.warn("Widgster must be executed in a browser environment with jQuery defined"); 11 | } 12 | } )( typeof window !== "undefined" ? window : this, function( $ ) { 13 | // WIDGSTER CLASS DEFINITION 14 | // ====================== 15 | 16 | var Widgster = function (el, options) { 17 | this.$element = $(el); 18 | this.$collapse = this.$element.find('[data-widgster=collapse]'); 19 | this.$expand = this.$element.find('[data-widgster=expand]'); 20 | this.$fullscreen = this.$element.find('[data-widgster=fullscreen]'); 21 | this.$restore = this.$element.find('[data-widgster=restore]'); 22 | this.options = options; 23 | this.collapsed = options.collapsed; 24 | this.fullscreened = options.fullscreened; 25 | 26 | this._initHandlers(); 27 | 28 | if (this.collapsed){ 29 | this.collapse(false); 30 | } else { 31 | this.$expand.hide(); 32 | } 33 | 34 | if (this.fullscreened){ 35 | this.fullscreen(); 36 | } else { 37 | this.$restore.hide(); 38 | } 39 | 40 | this.options.autoload && this.load(); 41 | var interval = parseInt(this.options.autoload); 42 | if (!isNaN(interval)){ 43 | var widgster = this; 44 | this._autoloadInterval = setInterval(function(){ 45 | widgster.load(); 46 | }, interval) 47 | } 48 | }; 49 | 50 | Widgster.DEFAULTS = { 51 | collapsed: false, 52 | fullscreened: false, 53 | transitionDuration: 150, 54 | bodySelector: '.body', 55 | showLoader: true, 56 | autoload: false, 57 | loaderTemplate: '