// smClipboardCopy [PLUGIN: allerinputfields ]
// A simple plugin for smClipboardCopy to copy form elements.
// Author - Igor Szyporyn
// Owner - System & Metode A/S

(function($) {

    var parentPrefix = 'smClipboardCopy',
        prefix = 'allerinputfields',
        parent = $.fn[parentPrefix];

    // namespace taken - exit
    if (parent[prefix]) { return false; }

    var methods = {

        init    : function( options ) {

            var settings =  $.extend(true, {}, {
                                beforeCopy  : $.noop,
                                afterCopy   : $.noop   
                            }, options),
                plugin = {
                    name        : prefix,
                    getItems    : function( element ) {

                        var newArray = [];

                        $.each( $(element).find('.iceCap-input-field'), function ( i, v ) {

                            var newObj = parent( 'createPluginBase', v ); // element (DOM node), dimensions (object)

                            newObj.onHighlight = function( isSelected ) {
                                if ( isSelected ) {
                                    $(this.element).addClass('selected').css('background-color','red');
                                } else {
                                    $(this.element).removeClass('selected').css('background-color','white');
                                }
                            };

                            newObj.getValue = function( isSelected ) {
                                var val = $(this.element).val();
                                return ( val && isSelected ? val + '\n' : false );
                            };

                            newArray.push(newObj);

                        });
                        return newArray;
                    },
                    onHighlight : true
                
                }
            
            return plugin;
        }

    }


    parent.allerinputfields = function( method ) {

        if ( methods[ method ] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.' + prefix );
        }

    }


  

})(jQuery);