1

どの質問をすればよいか 100% 確信が持てません。これを行うための最善の方法について確信が持てないためです。そこから。

任意の HTML 要素 (IMG、A、TD など) があります。CSS を介して、HTML 動作が割り当てられます

.BoldSelection { 
    behavior: url(SelectBold.htc); 
    border: thin solid black;  
}

ビヘイビアーは、要素がクリックされたときに要素の周りに太い境界線を配置するだけですが、以前に選択した要素を通常の境界線で設定する必要があります。

これがHTCソースです。これは、CurrentlyFocusedElementID が動作のすべてのインスタンス間で静的である場合に機能します。しかし、そうではありません。

<Public:Attach Event="onContentReady" onEvent="LoadInit" />

    <Script Language="VBScript" type="Text/VBScript">

        Sub LoadInit
            element.onClick = getRef("setFocusedElement")
        End Sub

        Sub setFocusedElement
            set ele = document.getElementByID(CurrentlyFocusedElementID)
            ele.style.border = "thin solid black"
            CurrentlyFocusedElementID = element.id
            element.style.border = "thick solid black"
        End Sub

    </Script>

また、含まれているドキュメントの DOM 内に任意のプロパティまたは属性を格納できれば、最後のアクティブな要素を探すための共通の場所としてそれを使用できると考えました ... 残念ながら、それなしではそれを行う方法がわかりませんある種のハックを使用する (つまり、ボディのクラス値をハイジャックする)

コードをすべて HTC 内に保持したいと考えています。私はこのようにそれを行うモジュール式の方法が好きです..その方法で、CSS 動作を割り当てるだけで完了します-コールバックなし..親属性なし..宣言する HTML コンポーネントはありません。

私がこれを行うことをどのように提案しますか?

前もって感謝します。

4

1 に答える 1

1

パズルの欠けている部分は..expandosでした。カスタムの任意の属性。これが完成した.HTCです

<Public:Attach Event="onContentReady" onEvent="LoadInit" />

  <Script Language="VBScript" type="Text/VBScript">

    ' This is an example HTC only.   If we were only setting borders, it'd make more sense to store
    ' the previous element's border type and keep the rest of the formatting.  For simplicity we are
    ' swapping out the class name

    Sub LoadInit

      ' No ID defined for this element.  Highlight it for the developer
      If element.id = "" Then
        element.style.bordercolor = "rgb(200,50,10)"
        element.style.borderwidth = "thin"
        element.style.borderstyle = "dashed"
        Exit Sub
      End If

      ' Attach our Click Events
      element.onClick = getRef("BoldIt")
      element.onDblClick = getRef("BoldItMore")

    End Sub


    ' Changes the Class Name for the current element, and if a previously
    ' selected element exists, restore its original classname
    Sub changeClass(newCSSClass)
      ' Storing the Expando on the document.body element
      Set ele = window.document.body

      ' Retrieve our two custom attributes - the ID of the element, and what its original ClassName was.
      LastEle = ele.getAttribute("LastHighlightedEle")
      LastEleClass = ele.getAttribute("LastHighlightedEleClass")

      ' If there was in fact a previously selected element - restore the classname
      If not isnull(LastEle) then
        set oldEle = window.document.getElementByID(LastEle)
        oldEle.className = LastEleClass
        set oldEle =  Nothing
      End If

      ' Set our two custom attributes to this element and adjust this element's CSS ClassName
      LastEle = element.id
      LastEleClass = element.className
      ele.setAttribute "LastHighlightedEle",LastEle
      ele.setAttribute "LastHighlightedEleClass",LastEleClass
      element.className = newCSSClass
    End Sub

    ' Single Click Event - 'Thick' is a CSS Style for a 3px border
    Sub BoldIt
      changeClass("Thick")
    End Sub

    ' Double Click Event - 'Thicker' is a CSS Style for a 4px border
    Sub BoldItMore
      changeClass("Thicker")
    End Sub

  </Script>
于 2009-10-22T15:32:30.850 に答える