コード例 #1
0
        private void UpdateImageLink(string href, IHTMLElement ImgElement, ILinkOptions defaultOptions)
        {
            MshtmlMarkupServices markupServices = new MshtmlMarkupServices((IMarkupServicesRaw)ImgElement.document);
            IHTMLElement         parentElement  = ImgElement.parentElement;

            if (!(parentElement is IHTMLAnchorElement))
            {
                parentElement = markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_A, null);
                MarkupRange range = markupServices.CreateMarkupRange();
                range.MoveToElement(ImgElement, true);
                markupServices.InsertElement(parentElement, range.Start, range.End);

                //set the default target attribute for the new element
                string             target            = defaultOptions.ShowInNewWindow ? "_blank" : null;
                IHTMLAnchorElement htmlAnchorElement = (parentElement as IHTMLAnchorElement);
                if (htmlAnchorElement.target != target) //don't set the target to null if its already null (avoids adding empty target attr)
                {
                    htmlAnchorElement.target = target;
                }

                ImageViewer viewer = DhtmlImageViewers.GetImageViewer(DhtmlImageViewer);
                if (viewer != null)
                {
                    if (defaultOptions.UseImageViewer)
                    {
                        viewer.Apply(htmlAnchorElement, defaultOptions.ImageViewerGroupName);
                    }
                }
            }
            parentElement.setAttribute("href", href, 0);
        }
コード例 #2
0
        protected override void LoadEditor()
        {
            base.LoadEditor();
            HtmlImageTargetSettings = new HtmlImageTargetDecoratorSettings(EditorContext.Settings, EditorContext.ImgElement);
            LoadLinkTargetsCombo();

            string imgUrl = (string)EditorContext.ImgElement.getAttribute("src", 2);

            LinkToSourceImageEnabled = UrlHelper.IsFileUrl(imgUrl) && GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs);

            if (ImageEditingContext.EditorOptions.DhtmlImageViewer != null)
            {
                imageViewer = DhtmlImageViewers.GetImageViewer(ImageEditingContext.EditorOptions.DhtmlImageViewer);
            }
        }
コード例 #3
0
        /// <summary>
        /// Any setting that is derived from the homepage html needs to be in this function.  This function is turned
        /// on and off when detecting blog settings through the IncludeHomePageSettings.  None of these checks will be run
        /// if the internet is not active.  As each check is made, it does not need to be applied back the _content until the end
        /// at which time it will write the settings back to the registry.
        /// </summary>
        private void DetectHomePageSettings()
        {
            if (_homepageAccessor.HtmlDocument == null)
            {
                return;
            }

            IDictionary homepageSettings = new Hashtable();

            Debug.Assert(!UseManifestCache, "This code will not run correctly under the manifest cache, due to option overrides not being set");

            LightWeightHTMLMetaData metaData = new LightWeightHTMLMetaData(_homepageAccessor.HtmlDocument);

            if (metaData.Charset != null)
            {
                try
                {
                    homepageSettings.Add(BlogClientOptions.CHARACTER_SET, metaData.Charset);
                }
                catch (NotSupportedException)
                {
                    //not an actual encoding
                }
            }

            string docType = new LightWeightHTMLMetaData(_homepageAccessor.HtmlDocument).DocType;

            if (docType != null)
            {
                bool xhtml = docType.IndexOf("xhtml", StringComparison.OrdinalIgnoreCase) >= 0;
                if (xhtml)
                {
                    homepageSettings.Add(BlogClientOptions.REQUIRES_XHTML, true.ToString(CultureInfo.InvariantCulture));
                }
            }

            //checking whether blog is rtl
            HtmlExtractor extractor = new HtmlExtractor(_homepageAccessor.HtmlDocument.RawHtml);

            if (extractor.Seek(new OrPredicate(
                                   new SmartPredicate("<html dir>"),
                                   new SmartPredicate("<body dir>"))).Success)
            {
                BeginTag tag = (BeginTag)extractor.Element;
                string   dir = tag.GetAttributeValue("dir");
                if (String.Compare(dir, "rtl", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    homepageSettings.Add(BlogClientOptions.TEMPLATE_IS_RTL, true.ToString(CultureInfo.InvariantCulture));
                }
            }

            if (_homepageAccessor.HtmlDocument != null)
            {
                string      html   = _homepageAccessor.OriginalHtml;
                ImageViewer viewer = DhtmlImageViewers.DetectImageViewer(html, _context.HomepageUrl);
                if (viewer != null)
                {
                    homepageSettings.Add(BlogClientOptions.DHTML_IMAGE_VIEWER, viewer.Name);
                }
            }

            _context.HomePageOverrides = homepageSettings;
        }
コード例 #4
0
        private void LoadTargetSummaryLabel()
        {
            if (HtmlImageTargetSettings.LinkTarget == LinkTargetType.IMAGE)
            {
                linkToSummaryText = Path.GetFileName(EditorContext.SourceImageUri.LocalPath);
                linkToSizeText    = String.Format(CultureInfo.CurrentCulture, Res.Get(StringId.DimensionsFormat), HtmlImageTargetSettings.ImageSize.Width, HtmlImageTargetSettings.ImageSize.Height);
                linkToImageViewer = "";
                if (HtmlImageTargetSettings.DhtmlImageViewer != null && HtmlImageTargetSettings.DhtmlImageViewer == ImageEditingContext.EditorOptions.DhtmlImageViewer)
                {
                    if (HtmlImageTargetSettings.LinkOptions.UseImageViewer && HtmlImageTargetSettings.DhtmlImageViewer != "Windows Live Spaces")
                    {
                        string viewerName = DhtmlImageViewers.GetLocalizedName(HtmlImageTargetSettings.DhtmlImageViewer);

                        if (!string.IsNullOrEmpty(HtmlImageTargetSettings.LinkOptions.ImageViewerGroupName))
                        {
                            linkToImageViewer =
                                string.Format(CultureInfo.InvariantCulture,
                                              Res.Get(StringId.ImageViewerDisplayFormatGroup),
                                              viewerName,
                                              HtmlImageTargetSettings.LinkOptions.ImageViewerGroupName);
                        }
                        else
                        {
                            linkToImageViewer =
                                string.Format(CultureInfo.InvariantCulture,
                                              Res.Get(StringId.ImageViewerDisplayFormatSingle),
                                              viewerName);
                        }
                    }
                }
            }
            else if (HtmlImageTargetSettings.LinkTarget == LinkTargetType.URL)
            {
                linkToImageViewer = String.Empty;
                linkToSummaryText = HtmlImageTargetSettings.LinkTargetUrl;
                if (UrlHelper.IsUrl(linkToSummaryText))
                {
                    try
                    {
                        //attempt to shorten the URI string into a path-ellipsed format.
                        Uri sourceUri = new Uri(HtmlImageTargetSettings.LinkTargetUrl);
                        linkToSummaryText = String.Format(CultureInfo.InvariantCulture, "{0}://{1}", sourceUri.Scheme, sourceUri.Host);
                        string[] segments = sourceUri.Segments;
                        if (segments.Length > 2)
                        {
                            linkToSummaryText += "/...";
                            if (segments[segments.Length - 2].EndsWith("/"))
                            {
                                linkToSummaryText += "/";
                            }
                            linkToSummaryText += segments[segments.Length - 1];
                        }
                        else
                        {
                            linkToSummaryText += String.Join("", segments);
                        }

                        if (sourceUri.Query != null)
                        {
                            linkToSummaryText += sourceUri.Query;
                        }
                    }
                    catch (Exception) { }
                }

                linkToSizeText = null;
            }
            else
            {
                linkToSummaryText = null;
                linkToSizeText    = null;
            }

            PerformLayout();
            Invalidate();
        }