X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fweb%2Froot%2Fsrc%2Fmain%2Fresources%2Fjs%2Ffuelux%2Fradio.js;fp=opendaylight%2Fweb%2Froot%2Fsrc%2Fmain%2Fresources%2Fjs%2Ffuelux%2Fradio.js;h=a09c07f1868060be387d4a57b02d0d8bc27e3b9e;hp=0000000000000000000000000000000000000000;hb=a98556048975c29541849689396e58c813b7558e;hpb=abe7cd0f3412d447cf054e618ce1c7c7fa096745 diff --git a/opendaylight/web/root/src/main/resources/js/fuelux/radio.js b/opendaylight/web/root/src/main/resources/js/fuelux/radio.js new file mode 100755 index 0000000000..a09c07f186 --- /dev/null +++ b/opendaylight/web/root/src/main/resources/js/fuelux/radio.js @@ -0,0 +1,109 @@ +/* + * Fuel UX Radio + * https://github.com/ExactTarget/fuelux + * + * Copyright (c) 2012 ExactTarget + * Licensed under the MIT license. + */ + +define(['require','jquery'],function (require) { + + var $ = require('jquery'); + + + // RADIO CONSTRUCTOR AND PROTOTYPE + + var Radio = function (element, options) { + this.$element = $(element); + this.options = $.extend({}, $.fn.radio.defaults, options); + + // cache elements + this.$label = this.$element.parent(); + this.$icon = this.$label.find('i'); + this.$radio = this.$label.find('input[type=radio]'); + this.groupName = this.$radio.attr('name'); + + // set default state + this.setState(this.$radio); + + // handle events + this.$radio.on('change', $.proxy(this.itemchecked, this)); + }; + + Radio.prototype = { + + constructor: Radio, + + setState: function ($radio, resetGroupState) { + var checked = $radio.is(':checked'); + var disabled = $radio.is(':disabled'); + + // set state of radio + if (checked === true) { + this.$icon.addClass('checked'); + } + if (disabled === true) { + this.$icon.addClass('disabled'); + } + }, + + resetGroup: function () { + // reset all radio buttons in group + $('input[name=' + this.groupName + ']').next().removeClass('checked'); + }, + + enable: function () { + this.$radio.attr('disabled', false); + this.$icon.removeClass('disabled'); + }, + + disable: function () { + this.$radio.attr('disabled', true); + this.$icon.addClass('disabled'); + }, + + itemchecked: function (e) { + var radio = $(e.target); + + this.resetGroup(); + this.setState(radio); + } + }; + + + // RADIO PLUGIN DEFINITION + + $.fn.radio = function (option, value) { + var methodReturn; + + var $set = this.each(function () { + var $this = $(this); + var data = $this.data('radio'); + var options = typeof option === 'object' && option; + + if (!data) $this.data('radio', (data = new Radio(this, options))); + if (typeof option === 'string') methodReturn = data[option](value); + }); + + return (methodReturn === undefined) ? $set : methodReturn; + }; + + $.fn.radio.defaults = {}; + + $.fn.radio.Constructor = Radio; + + + // RADIO DATA-API + + $(function () { + $(window).on('load', function () { + //$('i.radio').each(function () { + $('.radio-custom > input[type=radio]').each(function () { + var $this = $(this); + if ($this.data('radio')) return; + $this.radio($this.data()); + }); + }); + }); + +});