/**
 * Patterns checkedflag - Add checked flag to checkbox labels
 *
 * Copyright 2013 Simplon B.V. - Wichert Akkerman
 * Copyright 2013 Florian Friesdorf
 */
define([
    "jquery",
    "../registry",
    "../utils"
], function($, patterns, utils) {
    var select_option = {
        name: "select-option",
        trigger: "label select",

        init: function($el) {
            $el.on("change.pat-select-option", select_option._onChange);
            select_option._onChange.call(this);
            return $el;
        },

        destroy: function($el) {
            return $el.off(".pat-select-option");
        },

        _onChange: function() {
            var label = utils.findLabel(this);
            if (label !== null) {
                $(label).attr('data-option', $(this).val() || "");
            }
        }
    };

    patterns.register(select_option);
    return select_option;
});

@@ -196,24 +196,8 @@
 try%22
-,%0A    %22../utils%22
 %0A%5D, 
@@ -220,15 +220,8 @@
 erns
-, utils
 ) %7B%0A
@@ -295,22 +295,16 @@
 igger: %22
-label 
 select%22,
@@ -355,157 +355,146 @@
 $el.
-on(%22change.pat-select-option%22, select_option._onChange);%0A            select_option._onChange.call(this);%0A            return $el;%0A
+each(function() %7B%0A                var $el = $(this);%0A                // create parent span if not direct child of a label%0A 
        
- %7D,%0A%0A
         
 dest
@@ -493,80 +493,87 @@
     
-destroy: function($el) %7B%0A            return $el.off(%22.pat-select-option%22
+if ($el.parent('label').length === 0) %7B%0A                    $el.wrap('%3Cspan /%3E'
 );%0A 
@@ -583,20 +583,16 @@
     
-%7D,%0A%0A
         
 _onC
@@ -591,109 +591,132 @@
     
-_onChange: function() %7B%0A            var label = utils.findLabel(this);%0A            if (label !== null
+%7D%0A                $el.parent().attr('data-option', $el.val() %7C%7C %22%22);%0A            %7D).on(%22change.pat-select-option%22, function(
 ) %7B%0A
@@ -733,21 +733,29 @@
       $(
-label
+this).parent(
 ).attr('
@@ -769,22 +769,18 @@
 tion', $
-(this)
+el
 .val() %7C
@@ -791,32 +791,129 @@
 );%0A            %7D
+);%0A        %7D,%0A%0A        destroy: function($el) %7B%0A            return $el.off(%22.pat-select-option%22);
 %0A        %7D%0A    %7D

create span parent if select has no label parent