Ejemplo n.º 1
0
        void BubbleClasses(SelectorData parent)
        {
            foreach (var s in parent.SubID.ToArray())
            {
                BubbleClasses(s);

                foreach (var sub in s.SubClass)
                {
                    if (parent.Type == SelectorType.Class && parent.Selector == sub.Selector)
                        continue;

                    parent.AddElement(sub);
                }
            }

            foreach (var s in parent.SubClass.ToArray())
            {
                BubbleClasses(s);

                foreach (var sub in s.SubClass)
                {
                    if (parent.Type == SelectorType.Class && parent.Selector == sub.Selector)
                        continue;

                    parent.AddElement(sub);
                }
            }
        }
Ejemplo n.º 2
0
        void BubbleID(SelectorData parent)
        {
            foreach (var s in parent.SubID.ToArray())
            {
                //Add IDs to top level
                if (data.SubID.Contains(s) == false)
                    data.AddElement(s);

                BubbleID(s);

                foreach (var sub in s.SubID)
                    parent.AddElement(sub);
            }

            foreach (var s in parent.SubClass.ToArray())
            {
                BubbleID(s);

                foreach (var sub in s.SubID)
                    parent.AddElement(sub);
            }
        }
Ejemplo n.º 3
0
        public void WriteElements(string cssSelector, string cssSelectorObfuscated, SelectorData sel)
        {
            //Console.WriteLine("WriteElements: " + sel);
            if (sel.SubID.Count + sel.SubClass.Count == 0)
            {
                WriteLine("//Empty " + sel.Type + " " + sel.Selector);
                return;
            }

            //CSS selectors
            if (sel.Type == SelectorType.ID)
            {
                cssSelector = "#" + sel.Selector;
                cssSelectorObfuscated = "#" + ob.ObfuscateID(sel.Selector);
            }
            if (sel.Type == SelectorType.Class)
            {
                cssSelector = (cssSelector + " ." + sel.Selector).Trim();
                cssSelectorObfuscated = (cssSelectorObfuscated + " ." + ob.ObfuscateClass(sel.Selector)).Trim();
            }

            //ID
            RenderSubID(sel);
            RenderSubElement(sel);
            //Class
            RenderSubClass(sel);

            //Selector
            RenderSubSelector(sel, cssSelector, cssSelectorObfuscated);

            if (options.MinimizeNames)
                WriteLine("#if DEBUG");
            RenderIdSelectors(sel, false);
            if (options.MinimizeNames)
            {
                WriteLine("#else");
                RenderIdSelectors(sel, true);
                WriteLine("#endif");
            }

            //Sub element classes
            foreach (var sub in sel.SubID)
            {
                if (sub.SubID.Count + sub.SubClass.Count == 0)
                    continue;

                WriteLine("[JsType(JsMode.Json)]");
                Bracket("public class " + sub.ClassName + " : " + SharpKitClasses.FromSelectorData(sub));
                WriteElements(cssSelector, cssSelectorObfuscated, sub);
                EndBracket();
            }
            foreach (var sub in sel.SubClass)
            {
                if (sub.SubID.Count + sub.SubClass.Count == 0)
                    continue;

                WriteLine("[JsType(JsMode.Json)]");
                Bracket("public class " + sub.ClassName + " : " + SharpKitClasses.FromSelectorData(sub));
                WriteElements(cssSelector, cssSelectorObfuscated, sub);
                EndBracket();
            }
        }
Ejemplo n.º 4
0
        void RenderSubSelector(SelectorData sel, string selector, string obSelector)
        {
            if (sel.SubClass.Count + sel.SubID.Count == 0)
                return;

            WriteLine("[JsType(JsMode.Json)]");
            Bracket("public static class Selector");
            if (options.MinimizeNames)
                WriteLine("#if DEBUG");

            foreach (var i in sel.SubID)
                WriteLine("public const string " + i.PropertyName + " = \"#" + i.Selector + "\";");
            foreach (var i in sel.SubClass)
                WriteLine("public const string " + i.PropertyName + " = \"" + (selector + " ." + i.Selector).Trim() + "\";");

            if (options.MinimizeNames)
            {
                WriteLine("#else");

                foreach (var i in sel.SubID)
                    WriteLine("public const string " + i.PropertyName + " = \"#" + ob.ObfuscateID(i.Selector) + "\";");
                foreach (var i in sel.SubClass)
                    WriteLine("public const string " + i.PropertyName + " = \"" + (obSelector + " ." + ob.ObfuscateClass(i.Selector)).Trim() + "\";");

                WriteLine("#endif");
            }
            EndBracket();
        }
Ejemplo n.º 5
0
        void RenderSubElement(SelectorData sel)
        {
            if (!options.GenerateElementProperties)
                return;
            if (sel.SubID.Count == 0)
                return;

            WriteLine("[JsType(JsMode.Json)]");
            Bracket("public static class ElementById");
            if (options.MinimizeNames)
                WriteLine("#if DEBUG");
            foreach (var i in sel.SubID)
            {
                WriteLine("[JsProperty(Name=\"document.getElementById(\\\"" + i.Selector + "\\\")\", NativeField = true, Global = true)]");
                WriteLine("public static " + i.ClassName + " " + i.PropertyName + " { get { return null; } }");
            }
            if (options.MinimizeNames)
            {
                WriteLine("#else");
                foreach (var i in sel.SubID)
                {
                    WriteLine("[JsProperty(Name=\"document.getElementById(\\\"" + ob.ObfuscateID(i.Selector) + "\\\")\", NativeField = true, Global = true)]");
                    WriteLine("public static " + i.ClassName + " " + i.PropertyName + " { get { return null; } }");
                }
                WriteLine("#endif");
            }
            EndBracket();
        }
Ejemplo n.º 6
0
        void RenderIdSelectors(SelectorData sel, bool obfuscate)
        {
            if (sel.SubID.Count + sel.SubClass.Count == 0)
                return;

            //Sub element properties
            WriteLine("[JsProperty(Name=\"\", NativeField = true)]");
            WriteLine("public ElementsClass By { get; set; }");
            WriteLine("[JsType(JsMode.Json)]");
            Bracket("public class ElementsClass");
            foreach (var sub in sel.SubID)
            {
                string id = (obfuscate ? ob.ObfuscateID(sub.Selector) : sub.Selector);
                WriteLine("[JsProperty(Name=\"querySelector(\\\"#" + id + "\\\")\", NativeField = true)]");
                WriteLine("public " + sub.ClassName + " " + sub.PropertyName + " { get; set; }");
            }
            foreach (var sub in sel.SubClass)
            {
                string classname = (obfuscate ? ob.ObfuscateClass(sub.Selector) : sub.Selector);
                WriteLine("[JsProperty(Name=\"getElementsByClassName(\\\"" + classname + "\\\")[0]\", NativeField = true)]");
                WriteLine("public " + sub.ClassName + " " + sub.PropertyName + " { get; set; }");
            }
            EndBracket();
        }
Ejemplo n.º 7
0
        public static string FromSelectorData(SelectorData sel)
        {
            if (sel.TagName == null)
                throw new ArgumentNullException("TagName can't be null");

            switch (sel.TagName)
            {
                case "a":
                    return "HtmlAnchorElement";
                case "applet":
                    return "HtmlAppletElement";
                case "area":
                    return "HtmlAreaElement";
                case "audio":
                    return "HtmlAudioElement";
                case "base":
                    return "HtmlBaseElement";
                case "basefont":
                    return "HtmlBaseFontElement";
                case "body":
                    return "HtmlBodyElement";
                case "br":
                    return "HtmlBRElement";
                case "button":
                    return "HtmlButtonElement";
                case "canvas":
                    return "HtmlCanvasElement";
                case "datalist":
                    return "HtmlDataListElement";
                case "details":
                    return "HtmlDetailsElement";
                case "dialog":
                    return "HtmlDialogElement";
                case "directory":
                    return "HtmlDirectoryElement";
                case "div":
                    return "HtmlDivElement";
                case "embed":
                    return "HtmlEmbedElement";
                case "fieldset":
                    return "HtmlFieldSetElement";
                case "font":
                    return "HtmlFontElement";
                case "form":
                    return "HtmlFormElement";
                case "frame":
                    return "HtmlFrameElement";
                case "frameset":
                    return "HtmlFrameSetElement";
                case "head":
                    return "HtmlHeadElement";
                case "heading":
                    return "HtmlHeadingElement";
                case "hr":
                    return "HtmlHRElement";
                case "html":
                    return "HtmlHtmlElement";
                case "iframe":
                    return "HtmlIFrameElement";
                case "img":
                    return "HtmlImageElement";
                case "input":
                    return "HtmlInputElement";
                case "intent":
                    return "HtmlIntentElement";
                case "keygen":
                    return "HtmlKeygenElement";
                case "label":
                    return "HtmlLabelElement";
                case "legend":
                    return "HtmlLegendElement";
                case "li":
                    return "HtmlLIElement";
                case "link":
                    return "HtmlLinkElement";
                case "map":
                    return "HtmlMapElement";
                case "media":
                    return "HtmlMediaElement";
                case "menu":
                    return "HtmlMenuElement";
                case "meta":
                    return "HtmlMetaElement";
                case "meter":
                    return "HtmlMeterElement";
                case "object":
                    return "HtmlObjectElement";
                case "ol":
                    return "HtmlOListElement";
                case "optgroup":
                    return "HtmlOptGroupElement";
                case "option":
                    return "HtmlOptionElement";
                case "output":
                    return "HtmlOutputElement";
                case "p":
                    return "HtmlParagraphElement";
                case "param":
                    return "HtmlParamElement";
                case "pre":
                    return "HtmlPreElement";
                case "progress":
                    return "HtmlProgressElement";
                case "quote":
                    return "HtmlQuoteElement";
                case "script":
                    return "HtmlScriptElement";
                case "select":
                    return "HtmlSelectElement";
                case "source":
                    return "HtmlSourceElement";
                case "span":
                    return "HtmlSpanElement";
                case "style":
                    return "HtmlStyleElement";
                case "caption":
                    return "HtmlTableCaptionElement";
                case "td":
                    return "HtmlTableCellElement";
                case "col":
                    return "HtmlTableColElement";
                case "table":
                    return "HtmlTableElement";
                case "tr":
                    return "HtmlTableRowElement";
                case "tbody":
                    return "HtmlTableSectionElement";
                case "template":
                    return "HtmlTemplateElement";
                case "textarea":
                    return "HtmlTextAreaElement";
                case "title":
                    return "HtmlTitleElement";
                case "track":
                    return "HtmlTrackElement";
                case "ul":
                    return "HtmlUListElement";
                case "video":
                    return "HtmlVideoElement";

                default:
                    return "HtmlElement";
            }
        }
Ejemplo n.º 8
0
        public void AddElement(SelectorData s)
        {
            SelectorData sub = Get(s);
            if (sub == null)
            {
                if (s.Type == SelectorType.ID)
                    SubID.Add(s);
                else if (s.Type == SelectorType.Class)
                    SubClass.Add(s);
                else
                    throw new NotImplementedException();
                return;
            }

            //Merge s into sub
            foreach (var e in s.SubID)
                sub.AddElement(e);
            foreach (var e in s.SubClass)
                sub.AddElement(e);
        }
Ejemplo n.º 9
0
 public SelectorData Get(SelectorData s)
 {
     if (s.Type == SelectorType.Class)
         return GetClass(s.Selector);
     if (s.Type == SelectorType.ID)
         return GetID(s.Selector);
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
        public SelectorData CreateID(string name, string tagName)
        {
            //Find existing
            var s = GetID(name);
            if (s != null)
                return s;

            //Create new
            s = new SelectorData();
            s.TagName = tagName;
            s.Selector = name;
            s.Type = SelectorType.ID;
            SubID.Add(s);
            return s;
        }