Beispiel #1
0
        /// <summary>
        /// Creates a widget on given element. Widget gets a unique name like MyNamespace_MyWidget1234.
        /// </summary>
        /// <remarks>
        /// * A data value is added to element with this unique name as key, and the widget object as value.
        /// * Only one widget instance of same class can be created on a element.
        /// * All events attached by this widget class will be unbound when element is removed from document.
        /// * Elements gets a css class like "s-MyWidget" (it has no namespace by default, but this can be customized)
        /// </remarks>
        protected Widget(jQueryObject element)
        {
            this.element    = element;
            this.widgetName = WidgetExtensions.GetWidgetName(this.GetType());
            this.uniqueName = widgetName + (NextWidgetNumber++).ToString();

            if (element.GetDataValue(widgetName) != null)
            {
                throw new Exception(String.Format("The element already has widget '{0}'!", widgetName));
            }

            var self = this;

            element.Bind("remove." + widgetName, (e) => self.Destroy())
            .Data(widgetName, this);

            AddCssClass();

            if (IsAsyncWidget())
            {
                Window.SetTimeout(delegate()
                {
                    if (element != null && asyncPromise == null)
                    {
                        asyncPromise = this.InitializeAsync();
                    }
                }, 0);
            }
        }
Beispiel #2
0
        private IFiltering GetFilteringFor(jQueryObject row)
        {
            var field = GetFieldFor(row);

            if (field == null)
            {
                return(null);
            }

            IFiltering filtering = (IFiltering)row.GetDataValue("Filtering");

            if (filtering != null)
            {
                return(filtering);
            }

            var filteringType = FilteringTypeRegistry.Get(field.FilteringType ?? "String");

            jQueryObject editorDiv = row.Children("div.v");

            filtering = (IFiltering)Activator.CreateInstance(filteringType);
            ReflectionOptionsSetter.Set(filtering, field.FilteringParams);
            filtering.Container = editorDiv;
            filtering.Field     = field;
            row.Data("Filtering", filtering);

            return(filtering);
        }
Beispiel #3
0
        public static TWidget TryGetWidget <TWidget>(this jQueryObject element) where TWidget : class
        {
            if (element == null)
            {
                throw new Exception("Argument 'element' is null!");
            }

            TWidget widget;

            if (typeof(TWidget).IsAssignableFrom(typeof(Widget)))
            {
                var widgetName = WidgetExtensions.GetWidgetName(typeof(TWidget));

                widget = element.GetDataValue(widgetName) as TWidget;
                if (widget != null)
                {
                    return(widget);
                }
            }

            var data = element.GetData();

            foreach (string key in data.Keys)
            {
                widget = data[key] as TWidget;
                if (widget != null)
                {
                    return(widget);
                }
            }

            return(null);
        }
Beispiel #4
0
 private void RefreshIfNeeded()
 {
     if (Q.IsTrue(slickContainer.GetDataValue("needsRefresh")))
     {
         slickContainer.Data("needsRefresh", false);
         InternalRefresh();
     }
 }
Beispiel #5
0
        public static TWidget TryGetWidget <TWidget>(this jQueryObject element) where TWidget : Widget
        {
            if (element == null)
            {
                throw new Exception("Argument 'element' is null!");
            }

            var widgetName = WidgetExtensions.GetWidgetName(typeof(TWidget));

            return(element.GetDataValue(widgetName) as TWidget);
        }
        private IFilterHandler GetFilterHandlerFor(jQueryObject row)
        {
            FilterField field = GetFieldFor(row);

            if (field == null)
            {
                return(null);
            }

            IFilterHandler handler      = (IFilterHandler)row.GetDataValue("FilterHandler");
            string         handlerField = row.GetDataValue("FilterHandlerField").As <string>();

            if (handler != null)
            {
                if (handlerField != field.Name)
                {
                    row.Data("FilterHandler", null);
                    handler = null;
                }
                else
                {
                    return(handler);
                }
            }

            Type handlerType = Type.GetType("Sinerji." + (field.Handler ?? "??") + "FilterHandler");

            if (handlerType == null)
            {
                throw new Exception(String.Format("FilterHandler type Sinerji.{0}FilterHandler is not defined!", field.Handler));
            }

            jQueryObject editorDiv = row.Children("div.v");

            handler = (IFilterHandler)Activator.CreateInstance(handlerType, editorDiv, field);

            return(handler);
        }
Beispiel #7
0
        private void ResizeElement(jQueryObject element)
        {
            var xFactor = GetXFactor(element);

            if (xFactor != 0)
            {
                var initialWidth = element.GetDataValue("flexify-width").As <int?>();
                if (initialWidth == null)
                {
                    var width = element.GetWidth();
                    element.Data("flexify-width", width);
                    initialWidth = width;
                }

                element.Width(Math.Truncate(initialWidth.Value + xFactor * xDifference));
            }

            var yFactor = GetYFactor(element);

            if (yFactor != 0)
            {
                var initialHeight = element.GetDataValue("flexify-height").As <int?>();
                if (initialHeight == null)
                {
                    var height = element.GetHeight();
                    element.Data("flexify-height", height);
                    initialHeight = height;
                }

                element.Height(Math.Truncate(initialHeight.Value + yFactor * yDifference));
            }

            if (element.HasClass("require-layout"))
            {
                element.TriggerHandler("layout");
            }
        }
Beispiel #8
0
        private Double GetYFactor(jQueryObject element)
        {
            double?yFactor = null;

            if (options.GetYFactor != null)
            {
                yFactor = options.GetYFactor(element);
            }

            if (yFactor == null)
            {
                yFactor = element.GetDataValue("flex-y").As <double?>();
            }

            return(yFactor ?? 0);
        }
Beispiel #9
0
        private Double GetXFactor(jQueryObject element)
        {
            double?xFactor = null;

            if (options.GetXFactor != null)
            {
                xFactor = options.GetXFactor(element);
            }

            if (xFactor == null)
            {
                xFactor = element.GetDataValue("flex-x").As <double?>();
            }

            return(xFactor ?? 1);
        }
Beispiel #10
0
        /// <summary>
        /// Creates a widget on given element. Widget gets a unique name like MyNamespace_MyWidget1234.
        /// </summary>
        /// <remarks>
        /// * A data value is added to element with this unique name as key, and the widget object as value.
        /// * Only one widget instance of same class can be created on a element.
        /// * All events attached by this widget class will be unbound when element is removed from document.
        /// * Elements gets a css class like "s-MyWidget" (it has no namespace by default, but this can be customized)
        /// </remarks>
        protected Widget(jQueryObject element)
        {
            this.element    = element;
            this.widgetName = WidgetExtensions.GetWidgetName(this.GetType());
            this.uniqueName = widgetName + (NextWidgetNumber++).ToString();

            if (element.GetDataValue(widgetName) != null)
            {
                throw new Exception(String.Format("The element already has widget '{0}'!", widgetName));
            }

            var self = this;

            element.Bind("remove." + widgetName, (e) => self.Destroy())
            .Data(widgetName, this);

            AddCssClass();

            OnInit();
        }
Beispiel #11
0
        public static object TryGetWidget(this jQueryObject element, Type widgetType)
        {
            if (widgetType == null)
            {
                throw new Exception("Argument 'widgetType' is null!");
            }

            if (element == null)
            {
                throw new Exception("Argument 'element' is null!");
            }

            var widgetName = WidgetExtensions.GetWidgetName(widgetType);
            var widget     = element.GetDataValue(widgetName);

            if (widget != null && !widgetType.IsAssignableFrom(widget.GetType()))
            {
                return(null);
            }

            return(widget);
        }
        public static string GetItemId(jQueryObject link)
        {
            var value = link.GetDataValue("item-id");

            return(value == null ? null : value.ToString());
        }
 public static string GetItemType(jQueryObject link)
 {
     return(link.GetDataValue("item-type") as string);
 }
        static PhotoTilesPage()
        {
            jQuery.OnDocumentReady(delegate() {
                string apiKey = (string)jQuery.FromElement(Document.Body).GetDataValue("flickrKey");
                IPhotoService flickrService = new FlickrPhotoService();

                jQuery.Select("#searchButton").Click(delegate(jQueryEvent e) {
                    string tags = jQuery.Select("#tagsTextBox").GetValue();

                    flickrService.SearchPhotos(tags, 20).Done(
                        delegate(IEnumerable <Photo> photos) {
                        jQueryObject thumbnailList = jQuery.Select("#thumbsList");
                        thumbnailList.Empty();

                        if (photos == null)
                        {
                            return;
                        }

                        int photoIndex = 0;
                        foreach (Photo photo in photos)
                        {
                            if (photoIndex % 6 == 0)
                            {
                                jQuery.Select("#bigThumbnailTemplate").Plugin <jQueryTemplateObject>()
                                .RenderTemplate(photo)
                                .AppendTo(thumbnailList);
                            }
                            else if ((photoIndex % 3 == 0) || (photo.imageWidth == photo.imageHeight))
                            {
                                jQuery.Select("#sqThumbnailTemplate").Plugin <jQueryTemplateObject>()
                                .RenderTemplate(photo)
                                .AppendTo(thumbnailList);
                            }
                            else if (photo.thumbnailWidth > photo.thumbnailHeight)
                            {
                                jQuery.Select("#horzThumbnailTemplate").Plugin <jQueryTemplateObject>()
                                .RenderTemplate(photo)
                                .AppendTo(thumbnailList);
                            }
                            else
                            {
                                jQuery.Select("#vertThumbnailTemplate").Plugin <jQueryTemplateObject>()
                                .RenderTemplate(photo)
                                .AppendTo(thumbnailList);
                            }

                            photoIndex++;
                        }

                        GridsterOptions gridOptions = new GridsterOptions();
                        gridOptions.Margins         = new int[] { 10, 10 };
                        gridOptions.BaseDimensions  = new int[] { 140, 140 };

                        thumbnailList.Plugin <jQueryGridsterObject>().Gridster(gridOptions)
                        .Find("a")
                        .Plugin <jQueryLightBoxObject>().LightBox();

                        GridsterObject gridster =
                            (GridsterObject)thumbnailList.GetDataValue("gridster");
                        gridster.DisableDragging();
                    });

                    jQuery.FromElement(Document.Body).Focus();
                    e.PreventDefault();
                });
            });
        }
Beispiel #15
0
        private static void Arrange(jQueryObject element)
        {
#if DEBUG
            if (!element.Is("." + CssClassNameAdvancedLayout))
            {
                throw new Exception("Element not marked for advanced layout.");
            }
#endif
            // does element have its al state parsed?
            AdvancedLayoutState elementState = (AdvancedLayoutState)element.GetDataValue(DataNameLayoutState);
            if (elementState == null)
            {
                element.Data(DataNameLayoutState, elementState = ParseAdvancedLayout(element));
            }

            // grab parents
            jQueryObject parent = element.Parent();
            jQueryObject offsetParent = element.OffsetParent();
            if (offsetParent.Length == 0 || parent.Length == 0)
            {
                return;
            }

            bool parentIsOffsetParent = offsetParent[0] == parent[0];
#if DEBUG
            if (!parentIsOffsetParent && element.Is(":visible"))
            {
                throw new Exception("Parent must use position:absolute|fixed|relative;.");
            }
#endif
            if (!parentIsOffsetParent)
            {
                return;
            }

            // gather parent padding and client dimensions
            DimensionsAndPadding parentDimensions = null;
            parentDimensions = GetDimensionsAndPadding(parent);

            // detect parent's coordinates in offset-parent frame.
            float contentStartInOffsetSpaceX, contentStartInOffsetSpaceY;
            {
                if (parentIsOffsetParent)
                { // parent is offset parent. we know our local frame.
                    contentStartInOffsetSpaceX = 0;
                    contentStartInOffsetSpaceY = 0;
                }
                else
                { // experimental support for staticly positioned parent.

                    parent.Prepend(_frameDetector);

                    jQueryPosition parentContentFrameInDocumentSpace = _frameDetector.GetOffset();
                    jQueryPosition offsetParentFrameInDocumentSpace = offsetParent.GetOffset();
                    if (parentContentFrameInDocumentSpace != null && offsetParentFrameInDocumentSpace != null)
                    {
                        contentStartInOffsetSpaceX = parentContentFrameInDocumentSpace.Left - offsetParentFrameInDocumentSpace.Left - parentDimensions.PaddingLeft;
                        contentStartInOffsetSpaceY = parentContentFrameInDocumentSpace.Top - offsetParentFrameInDocumentSpace.Top - parentDimensions.PaddingTop;
                    }
                    else
                    {
                        jQueryPosition contentStartInOffsetSpace = _frameDetector.Position();
                        if (contentStartInOffsetSpace != null)
                        {
                            contentStartInOffsetSpaceX = contentStartInOffsetSpace.Left - parentDimensions.PaddingLeft;
                            contentStartInOffsetSpaceY = contentStartInOffsetSpace.Top - parentDimensions.PaddingTop;
                        }
                        else
                        {
                            contentStartInOffsetSpaceX = 0;
                            contentStartInOffsetSpaceY = 0;
                        }
                    }

                    _frameDetector.Remove();
                }

            }

            double topBoundary = contentStartInOffsetSpaceY + parentDimensions.PaddingTop + elementState.Margin.Top;
            double bottomBoundary = contentStartInOffsetSpaceY + parentDimensions.ClientHeight - parentDimensions.PaddingBottom - elementState.Margin.Bottom;
            double leftBoundary = contentStartInOffsetSpaceX + parentDimensions.PaddingLeft + elementState.Margin.Left;
            double rightBoundary = contentStartInOffsetSpaceX + parentDimensions.ClientWidth - parentDimensions.PaddingRight - elementState.Margin.Right;


            // determine where to position
            int top = 0;
            int left = 0;
            int width = 0;
            int height = 0;
            switch (elementState.VerticalAlignment)
            {
                case VerticalAlignment.Top:
                    height = Math.Round(elementState.Height - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(topBoundary);
                    break;

                case VerticalAlignment.Center:
                    height = Math.Round(elementState.Height - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(topBoundary * 0.5 + bottomBoundary * 0.5 - height * 0.5);
                    break;

                case VerticalAlignment.Bottom:
                    height = Math.Round(elementState.Height - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(contentStartInOffsetSpaceY + parentDimensions.ClientHeight - parentDimensions.PaddingBottom - elementState.Margin.Bottom - elementState.Height);
                    break;

                case VerticalAlignment.Stretch:
                    height = Math.Round(bottomBoundary - topBoundary - elementState.Padding.Top - elementState.Padding.Bottom);
                    top = Math.Round(topBoundary);
                    break;

            }
            switch (elementState.HorizontalAlignment)
            {
                case HorizontalAlignment.Left:
                    width = Math.Round(elementState.Width - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(leftBoundary);
                    break;

                case HorizontalAlignment.Center:
                    width = Math.Round(elementState.Width - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(leftBoundary * 0.5 + rightBoundary * 0.5 - width * 0.5);
                    break;

                case HorizontalAlignment.Right:
                    width = Math.Round(elementState.Width - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(contentStartInOffsetSpaceX + parentDimensions.ClientWidth - parentDimensions.PaddingRight - elementState.Margin.Right - elementState.Width);
                    break;

                case HorizontalAlignment.Stretch:
                    width = Math.Round(rightBoundary - leftBoundary - elementState.Padding.Left - elementState.Padding.Right);
                    left = Math.Round(leftBoundary);
                    break;
            }

            if (width <= 0)
            {
                width = 0;
            }
            if (height <= 0)
            {
                height = 0;
            }

            element.CSS(
                new Dictionary(
                    "position", "absolute",
                    "top", top,
                    "left", left,
                    "width", width,
                    "height", height,
                    "padding-top", elementState.Padding.Top,
                    "padding-right", elementState.Padding.Right,
                    "padding-bottom", elementState.Padding.Bottom,
                    "padding-left", elementState.Padding.Left
                )
            );
        }