├── visibly.jquery.json ├── README.md ├── LICENSE └── js ├── jquery-visibly.min.js └── jquery-visibly.js /visibly.jquery.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "visibly", 3 | "title": "jQuery Visibly", 4 | "description": "A jQuery Plugin designed to easily show elements based on values of other elements.", 5 | "keywords": [ 6 | "Visibly", 7 | "visible", 8 | "input", 9 | "form", 10 | "forms" 11 | ], 12 | "version": "1.1.0", 13 | "author": { 14 | "name": "Daniel Rivers", 15 | "url": "http://www.danielrivers.com", 16 | "email": "me@danielrivers.com" 17 | }, 18 | "licenses": [ 19 | { 20 | "type": "MIT", 21 | "url": "https://github.com/jquery/jquery-color/blob/2.1.2/MIT-LICENSE.txt" 22 | } 23 | ], 24 | "bugs": "https://github.com/DanielRivers/jQuery-Visibly", 25 | "homepage": "https://github.com/DanielRivers/jQuery-Visibly", 26 | "docs": "https://github.com/DanielRivers/jQuery-Visibly", 27 | "download": "https://github.com/DanielRivers/jQuery-Visibly", 28 | "dependencies": { 29 | "jquery": ">=1.2" 30 | } 31 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jQuery-Visibly 2 | ============== 3 | 4 | A jQuery Plugin designed to easily show elements based on values of other elements 5 | 6 | ## Documentation 7 | 8 | ### Setup 9 | ```javascript 10 | $('[visibly]').Visibly(); 11 | ``` 12 | 13 | 14 | ### Options 15 | ```javascript 16 | clearOnHide: false, //Clear the data from the elements on hide 17 | regularExpression: false, //This determines if regular expression is to be used for the test 18 | attr: 'visibly', //Data attribute to use for the visibly data 19 | vdelim: ',', //Delimeter used to split the values a control can hold 20 | edelim: ':', //Delimeter between the field ID and the values 21 | fdelim: ';' //Delimeter between the fields 22 | rdelim: '%' //Delimeter between the rules 23 | ``` 24 | 25 | ## Examples 26 | 27 | ``` 28 |
29 | ``` 30 | 31 | The above rule will make the relevant element visible is the value of field1 is either 'a' or 'b' and field2 has value of '1' 32 | 33 | ## Help 34 | Full documentation can be found at: http://www.danielrivers.com/visibly -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Daniel Rivers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /js/jquery-visibly.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Visibly jQuery Plugin v1.1 3 | * 4 | * @version 1.1 (05/03/2015) 5 | * @author Daniel Rivers 6 | * @see https://github.com/DanielRivers/jQuery-Visibly/ 7 | * 8 | * Dual licensed under the MIT and GPLv3 Licenses 9 | * http://www.opensource.org/licenses/mit-license.php 10 | * http://www.gnu.org/licenses/gpl-3.0.html 11 | * 12 | */ 13 | !function(e){e.fn.rVal=function(){var i;return e(this).is("select")?e(this).find("option:selected").each(function(){e(this).parent().is("select")&&(i=e(this).val())}):i=e(this).val(),i}}(jQuery),function(e){e.fn.Visibly=function(i){var t=e.extend({clearOnHide:!1,attr:"visibly",vdelim:",",edelim:":",nedelim:"!",regularExpression:!1,fdelim:";",rdelim:"%"},i),n=[];return this.each(function(){var i=e(this),l=RegExp(t.edelim+"|"+t.nedelim);e.each(e(this).attr(t.attr).split(t.fdelim),function(s,r){var a=e("#"+r.split(l)[0]);0==a.length&&(a=e('INPUT[name="'+r.split(l)[0]+'"]')),a.bind("keyup change click",function(){var n=!0;e.each(i.attr(t.attr).split(t.rdelim),function(i,s){return n=!0,e.each(s.split(t.fdelim),function(i,s){var r=e("#"+s.split(l)[0]);if(0==r.length&&(r=e("INPUT[name='"+s.split(l)[0]+"']:checked")),void 0!=r.val()){var a="";if(r.is("select")?r.find("option:selected").each(function(){e(this).parent().is("select")&&(a=e(this).rVal())}):a=r.val(),null!=s.split(t.edelim)[1])var c=e.grep(s.split(t.edelim)[1].split(t.vdelim),function(i){return-1!=e.inArray(a,s.split(t.edelim)[1].split(t.vdelim))?!0:t.regularExpression?a.match(i):!1});if(null!=s.split(t.nedelim)[1])var c=e.grep(s.split(t.nedelim)[1].split(t.vdelim),function(i){return-1!=e.inArray(a,s.split(t.nedelim)[1].split(t.vdelim))?!1:t.regularExpression?!a.match(i):!0});0==c.length&&(n=!1)}else n=!1}),!n}),n?i.is("option")?i.parent("span.hide").length&&i.unwrap():i.show():i.is("option")?0==i.parent("span.hide").length&&(i.val()==i.closest("select").val()&&i.closest("select").rVal(""),i.trigger("change"),i.wrap('