Exemplo n.º 1
0
        internal void ChangedEventReceived()
        {
            bool newIsChecked = Convert.ToBoolean(CSHTML5.Interop.ExecuteJavaScript("$0.checked", INTERNAL_OptionalSpecifyDomElementConcernedByFocus)); //Note: this should be sufficient since a RadioButton cannot be in an indeterminate state.

            if (IsChecked != newIsChecked)
            {
                IsChecked = newIsChecked;
            }
            if (newIsChecked == true)
            {
                UnselectOtherRadioButtonsFromSameGroup();
            }
            else
            {
                //if the RadioButton has just been unchecked, we set isLastChecked to undefined so that we do not trigger the "change" event for no reason when another radioButton will be selected:
                if (INTERNAL_CheckBoxAndRadioButtonHelpers.IsRunningInJavaScript())
                {
#if !BRIDGE
                    JSIL.Verbatim.Expression(@"$0.isLastChecked = undefined;", INTERNAL_OptionalSpecifyDomElementConcernedByFocus);
#else
                    Script.Write(@"{0}.isLastChecked = undefined;", INTERNAL_OptionalSpecifyDomElementConcernedByFocus);
#endif
                }
                else
                {
                    string javaScriptCodeToExecute = string.Format(@"document.getElementById(""{0}"").isLastChecked = undefined;", ((INTERNAL_HtmlDomElementReference)INTERNAL_OptionalSpecifyDomElementConcernedByFocus).UniqueIdentifier);
                    INTERNAL_HtmlDomManager.ExecuteJavaScriptWithResult(javaScriptCodeToExecute);
                }
            }
        }
Exemplo n.º 2
0
        internal override void SubscribeToClickEventForChildContainerDiv(dynamic divWhereToPlaceChild, dynamic checkBoxDomElement)
        {
            if (INTERNAL_CheckBoxAndRadioButtonHelpers.IsRunningInJavaScript())
            {
#if !BRIDGE
                JSIL.Verbatim.Expression(@"
$0.addEventListener('click', function(e) {
    if($1.checked === true)
    {
        $1.checked = false;
    }
    else
    {
        $1.checked = true;
    }
    var evt = document.createEvent('Event');
    evt.initEvent('change', false, false);
    $1.dispatchEvent(evt);
}, false);", divWhereToPlaceChild, checkBoxDomElement);
#else
                Script.Write(@"
{0}.addEventListener('click', function(e) {
    if({1}.checked === true)
    {
        {1}.checked = false;
    }
    else
    {
        {1}.checked = true;
    }
    var evt = document.createEvent('Event');
    evt.initEvent('change', false, false);
    {1}.dispatchEvent(evt);
}, false);", divWhereToPlaceChild, checkBoxDomElement);
#endif
            }
#if !BRIDGE
            else
            {
                // ---- SIMULATOR ----
                string javaScriptToExecute = string.Format(@"
var divWhereToPlaceChild = document.getElementById(""{0}"");
divWhereToPlaceChild.addEventListener('click', function(e) {{
var checkBoxDomElement = document.getElementById(""{1}"");
    if(checkBoxDomElement.checked === true)
    {{
        checkBoxDomElement.checked = false;
    }}
    else
    {{
        checkBoxDomElement.checked = true;
    }}
    var evt = document.createEvent('Event');
    evt.initEvent('change', false, false);
    checkBoxDomElement.dispatchEvent(evt);
}}, false);", ((INTERNAL_HtmlDomElementReference)divWhereToPlaceChild).UniqueIdentifier, ((INTERNAL_HtmlDomElementReference)checkBoxDomElement).UniqueIdentifier);
                INTERNAL_HtmlDomManager.ExecuteJavaScript(javaScriptToExecute);
            }
#endif
        }
Exemplo n.º 3
0
 protected override void UpdateDomBasedOnCheckedState(bool?isChecked)
 {
     INTERNAL_CheckBoxAndRadioButtonHelpers.UpdateDomBasedOnCheckedState(this, isChecked);
     //specifically sending the "change" event on the element that was changed programmatically so that it can then do the rest (setting the other radiobuttons' IsChecked to false and stuff).
     CSHTML5.Interop.ExecuteJavaScript(@"var evt = document.createEvent('Event');
                             evt.initEvent('change', false, false);
                             $0.dispatchEvent(evt);", INTERNAL_OptionalSpecifyDomElementConcernedByFocus);
 }
Exemplo n.º 4
0
        protected override void OnApplyTemplate()
#endif
        {
            base.OnApplyTemplate();
            INTERNAL_CheckBoxAndRadioButtonHelpers.UnSubscribeFromBasicEvents(this);
            CSHTML5.Interop.ExecuteJavaScript(@"if($0.childNodes.length == 2){
    $0.removeChild($0.firstChild);
    $1.INTERNAL_OptionalSpecifyDomElementConcernedByFocus = null;
    $1.INTERNAL_OptionalSpecifyDomElementConcernedByIsEnabled = null;
}", this.INTERNAL_OuterDomElement, this);
        }
Exemplo n.º 5
0
        protected internal override void INTERNAL_OnAttachedToVisualTree()
        {
            if (INTERNAL_IsTemplated)
            {
                //there is a template so we need to make specific changes to make it work with the other RadioButtons
                this.INTERNAL_OptionalSpecifyDomElementConcernedByFocus = this.INTERNAL_OuterDomElement;
                INTERNAL_HtmlDomManager.SetDomElementAttribute(this.INTERNAL_OptionalSpecifyDomElementConcernedByFocus, "checked", IsChecked, forceSimulatorExecuteImmediately: true);
                INTERNAL_CheckBoxAndRadioButtonHelpers.SubscribeToBasicEventsForRadioButton(this, this.INTERNAL_OptionalSpecifyDomElementConcernedByFocus, this.INTERNAL_OptionalSpecifyDomElementConcernedByFocus);
            }

            if (string.IsNullOrWhiteSpace(GroupName))
            {
                INTERNAL_HtmlDomManager.SetDomElementAttribute(this.INTERNAL_OptionalSpecifyDomElementConcernedByFocus, "name", ((UIElement)INTERNAL_VisualParent).INTERNAL_ChildrenRadioButtonDefaultName, forceSimulatorExecuteImmediately: true);
            }
        }
Exemplo n.º 6
0
 public override object CreateDomElement(object parentRef, out object domElementWhereToPlaceChildren)
 {
     return(INTERNAL_CheckBoxAndRadioButtonHelpers.CreateDomElement(this, "checkbox", parentRef, out domElementWhereToPlaceChildren));
 }
Exemplo n.º 7
0
 protected override void UpdateDomBasedOnCheckedState(bool?isChecked)
 {
     INTERNAL_CheckBoxAndRadioButtonHelpers.UpdateDomBasedOnCheckedState(this, isChecked);
 }
Exemplo n.º 8
0
        private void UnselectOtherRadioButtonsFromSameGroup()
        {
            string groupName = GroupName;

            if (string.IsNullOrWhiteSpace(groupName))
            {
                groupName = ((UIElement)INTERNAL_VisualParent).INTERNAL_ChildrenRadioButtonDefaultName;
            }

            //if the RadioButton has just been checked, we trigger the change event on the RadioButton of the same group that was checked before:
            if (INTERNAL_CheckBoxAndRadioButtonHelpers.IsRunningInJavaScript())
            {
#if !BRIDGE
                JSIL.Verbatim.Expression(@"
                        var radios = document.getElementsByName( $0 );
                        for(var i = 0; i < radios.length; i++ ) {
                            if( radios[i].isLastChecked === true && radios[i] !== $1) {
                                radios[i].checked = false;
                                radios[i].isLastChecked = undefined;
                                var evt = document.createEvent('Event');
                                evt.initEvent('change', false, false);
                                radios[i].dispatchEvent(evt);
                            }
                        }
                        $1.isLastChecked = true;
                    ", groupName, INTERNAL_OptionalSpecifyDomElementConcernedByFocus);
#else
                Script.Write(@"
var radios = document.getElementsByName( $0 );
                        for(var i = 0; i < radios.length; i++ ) {
                            if( radios[i].isLastChecked === true && radios[i] !== $1) {
                                radios[i].checked = false;
                                radios[i].isLastChecked = undefined;
                                var evt = document.createEvent('Event');
                                evt.initEvent('change', false, false);
                                radios[i].dispatchEvent(evt);
                            }
                        }
                        $1.isLastChecked = true;
                    ", groupName, INTERNAL_OptionalSpecifyDomElementConcernedByFocus);
#endif
            }
#if !BRIDGE
            else
            {
                string javaScriptCodeToExecute = string.Format(@"
                        var radios = document.getElementsByName( ""{0}"" );
                        var newlySelectedRadio = document.getElementById(""{1}"");
                            for(var i = 0; i < radios.length; i++ ) {{
                                if( radios[i].isLastChecked === true  && radios[i] !== newlySelectedRadio) {{
                                    radios[i].checked = false;
                                    radios[i].isLastChecked = undefined;
                                    var evt = document.createEvent('Event');
                                    evt.initEvent('change', false, false);
                                    radios[i].dispatchEvent(evt);
                                }}
                            }}
                            newlySelectedRadio.isLastChecked = true;
                        ", groupName, ((INTERNAL_HtmlDomElementReference)INTERNAL_OptionalSpecifyDomElementConcernedByFocus).UniqueIdentifier);
                INTERNAL_HtmlDomManager.ExecuteJavaScriptWithResult(javaScriptCodeToExecute);
            }
#endif
        }