<!DOCTYPE HTML PUBLIC "-//IETF//DAREA HTML//EN">
<html id=MyPage>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="Microsoft Theme" content="none">
<meta name="Microsoft Border" content="none">
<meta name="GENERATOR" content="Microsoft FrontPage 2.0">
<title>ComboText Scriptlet</title>
</head>
<body>
<script language="JavaScript">
</script>
<script language="VBscript" for="window" event="onload">
InitComboText
</script>
<script language="VBscript" for="document" event="onclick">
if window.event.srcElement.id = "push" then
DoInsertText
else
if window.event.srcElement.id = "pop" then
DoRemoveText
end if
end if
</script>
<script language="VBscript">
' utility for quoting
' -------------------------------------------------------
Function Quote( s )
s = Chr(34) + s + Chr(34)
Quote = s
End Function
' Prepare the HTML string for Title
' -------------------------------------------------------
Function FormatText
sPrefix = "<DIV id=text>"
sSuffix = " " + "<br></DIV>"
if mButtonPosition = "Right" then
sBody = mText + " " + mPushImage
else
sBody = mPushImage + " " + mText
end if
FormatText = sPrefix + sBody + sSuffix
End Function
' Prepare the HTML string for Memo
' -------------------------------------------------------
Function FormatMemo
sPrefix = "<DIV id=memo>"
sSuffix = " " + "</DIV>"
if mButtonPosition = "Right" then
sBody = mMemo + " " + sImage
else
sBody = sPopImage + " " + mMemo
end if
FormatMemo = sPrefix + sBody + sSuffix
End Function
' Initialize the control
' -------------------------------------------------------
Sub InitComboText
' save some standard settings
document.body.style.setAttribute "marginTop", "0"
document.body.style.setAttribute "marginBottom", "0"
document.body.style.setAttribute "marginLeft", "0"
document.body.style.setAttribute "marginRight", "0"
' put text
DoPutText mText
document.fgColor = mTextColor
document.bgColor = mBkgndColor
' make selectable the scriplet content
if InScriptlet then
window.external.selectableContent = mSelectable
end if
End Sub
' Add new text
' -------------------------------------------------------
Sub DoInsertText
document.body.insertAdjacentHTML "BeforeEnd", FormatMemo
DoModify "memo", "fontFamily", mMemoFont
DoModify "memo", "fontSize", mMemoFontSize
DoModify "memo", "fontWeight", mMemoFontWeight
DoModify "memo", "color", mMemoColor
DoModify "memo", "marginLeft", 5
' change image
Set coll = document.images
Set elem = coll.item(0)
elem.outerHTML = mPopImage
MyPage.style.pixelHeight = MyPage.style.pixelHeight + mExpandBy
if InScriptlet then
window.external.scrollbar = True
end if
mExpanded = True
if InScriptlet then
window.external.RaiseEvent "OnExpand", window.document
end if
End Sub
' Remove new text
' -------------------------------------------------------
Sub DoRemoveText
Set coll = document.images
Set elem = coll.item(0)
elem.outerHTML = mPushImage
' remove DIV tag
Set e = GetElemById( "DIV", "memo" )
e.outerHTML = ""
MyPage.style.pixelHeight = MyPage.style.pixelHeight - mExpandBy
if InScriptlet then
window.external.scrollbar = False
end if
mExpanded = False
if InScriptlet then
window.external.RaiseEvent "OnCollapse", window.document
end if
End Sub
' Search for the given tag and id
' ----------------------------------
Function GetElemById( tagName, idName )
Set GetElemById = Nothing
Set coll = document.all.tags( tagName )
for i=0 to coll.length-1
if coll.item(i).id = idName then
Set GetElemById = coll.item(i)
Exit Function
end if
next
Set coll = Nothing
End Function
' Set text
' ----------------------------------
Sub DoPutText( sText )
if mExpanded then
DoRemoveText
end if
mText = sText
Set e = GetElemById( "DIV", "text" )
if Not e is Nothing then
e.outerHTML = FormatText
end if
DoModify "text", "fontFamily", mTextFont
DoModify "text", "fontSize", mTextFontSize
DoModify "text", "fontWeight", mTextFontWeight
DoModify "text", "marginLeft", 5
End Sub
' Set memo text
' ----------------------------------
Sub DoPutMemo( sMemo )
if mExpanded then
DoRemoveText
end if
mMemo = sMemo
Set e = GetElemById( "DIV", "memo" )
if Not e is Nothing then
e.outerHTML = FormatMemo
end if
Set e = Nothing
End Sub
' Change the element styles
' ----------------------------------
Sub DoModify( idName, attrib, value )
Set e = GetElemById( "DIV", idName )
if Not e is Nothing then
e.style.setAttribute attrib, value
else
Exit Sub
end if
Set e = Nothing
' this way it works fine...
if attrib="color" And idName="memo" then
Set coll = document.all.tags("DIV")
coll.item(1).style.color = mMemoColor
end if
End Sub
</script>
<script language="JavaScript">
// declare the object interface
public_description = new CreateComboText;
var InScriptlet = (typeof(window.external.version) == "string")
// Vars that match properties
/*---------------------------------*/
mExpandBy = 50;
mSelectable = 0;
mMemo = "";
mText = "";
mButtonPosition = "Left";
mTextFont = "Tahoma";
mTextFontSize = "12pt";
mTextFontWeight = "700";
mMemoFont = "Tahoma";
mMemoFontSize = "10pt";
mMemoFontWeight = "400";
mMemoColor = "Black";
mTextColor = "Blue";
mBkgndColor = "gainsboro"
mCancelEvent = 0
mExpanded = 0;
// Internals
/*---------------------------------*/
mPushImage = "<img id=" + Quote("push") + " src=push.gif align=middle alt="+Quote("Expand text")+">";
mPopImage = "<img id=" + Quote("pop") + " src=pop.gif align=middle alt="+Quote("Collapse")+">";
/*---------------------------------*/
function CreateComboText() {
// This function define the scriptlet interface in terms of
// properties, methods and events.
// Properties
this.put_CancelEvent = put_CancelEvent;
this.get_Expanded = get_Expanded;
this.put_Text = put_Text;
this.get_Text = get_Text;
this.put_Memo = put_Memo;
this.get_Memo = get_Memo;
this.put_ExpandBy = put_ExpandBy;
this.get_ExpandBy = get_ExpandBy;
this.put_ButtonPosition = put_ButtonPosition;
this.get_ButtonPosition = get_ButtonPosition;
this.put_Selectable = put_Selectable;
this.get_Selectable = get_Selectable;
this.put_TextFont = put_TextFont;
this.put_TextFontSize = put_TextFontSize;
this.put_TextFontWeight = put_TextFontWeight;
this.put_TextColor = put_TextColor;
this.get_TextColor = get_TextColor;
this.put_BkgndColor = put_BkgndColor;
this.get_BkgndColor = get_BkgndColor;
this.put_MemoFont = put_MemoFont;
this.put_MemoFontSize = put_MemoFontSize;
this.put_MemoFontWeight = put_MemoFontWeight;
this.put_MemoColor = put_MemoColor;
this.get_MemoColor = get_MemoColor;
// Methods
this.Expand = InsertMemoText;
this.Collapse = RemoveMemoText;
// Events
this.event_OnExpand = "";
this.event_OnCollapse = "";
}
/*---------------------------------*/
function InsertMemoText() {
// This function expands the document by inserting the memo text
DoInsertText();
return 1;
}
/*---------------------------------*/
function RemoveMemoText() {
// This function collapses the document by removing the memo text
DoRemoveText();
return 1;
}
/*---------------------------------*/
function put_CancelEvent( bYes ) {
mCancelEvent = bYes
return 1;
}
/*---------------------------------*/
function get_Expanded() {
return mExpanded;
}
/*---------------------------------*/
function put_Text( sText ) {
DoPutText( sText );
return 1;
}
/*---------------------------------*/
function get_Text() {
return mText;
}
/*---------------------------------*/
function put_Memo( sMemo ) {
DoPutMemo( sMemo );
return 1;
}
/*---------------------------------*/
function get_Memo() {
return mMemo;
}
/*---------------------------------*/
function put_Selectable( b ) {
mSelectable = b;
if( InScriptlet ) {
window.external.selectableContent = mSelectable;
}
return 1;
}
/*---------------------------------*/
function get_Selectable() {
return mSelectable;
}
/*---------------------------------*/
function put_ButtonPosition( pos ) {
mButtonPosition = pos;
DoPutText( mText );
return 1;
}
/*---------------------------------*/
function get_ButtonPosition() {
return mButtonPosition;
}
/*---------------------------------*/
function put_ExpandBy( pixel ) {
if( mExpanded ) {
DoRemoveText();
}
mExpandBy = pixel;
return 1;
}
/*---------------------------------*/
function get_ExpandBy() {
return mExpandBy;
}
/*---------------------------------*/
function put_TextFont( font ) {
mTextFont = font
DoModify( "text", "fontFamily", mTextFont );
return 1;
}
/*---------------------------------*/
function put_TextFontSize( size ) {
mTextFontSize = size;
DoModify( "text", "fontSize", mTextFontSize );
return 1;
}
/*---------------------------------*/
function put_TextFontWeight( bold ) {
mTextFontWeight = bold;
DoModify( "text", "fontWeight", mTextFontWeight );
return 1;
}
/*---------------------------------*/
function put_TextColor( color ) {
mTextColor = color;
document.fgColor = mTextColor;
return 1;
}
/*---------------------------------*/
function get_TextColor( ) {
return mTextColor;
}
/*---------------------------------*/
function put_MemoFont( font ) {
mMemoFont = font
DoModify( "memo", "fontFamily", mMemoFont );
return 1;
}
/*---------------------------------*/
function put_MemoFontSize( size ) {
mMemoFontSize = size
DoModify( "memo", "fontSize", mMemoFontSize );
return 1;
}
/*---------------------------------*/
function put_MemoFontWeight( bold ) {
mMemoFontWeight = bold;
DoModify( "memo", "fontWeight", mMemoFontWeight );
return 1;
}
/*---------------------------------*/
function put_MemoColor( color ) {
mMemoColor = color;
DoModify( "memo", "color", mMemoColor );
return 1;
}
/*---------------------------------*/
function get_MemoColor() {
return mMemoColor;
}
/*---------------------------------*/
function put_BkgndColor( color ) {
mBkgndColor = color;
document.bgColor = mBkgndColor
return 1;
}
/*---------------------------------*/
function get_BkgndColor() {
return mBkgndColor;
}
</script>
<DIV id=text><br></DIV>
</body>
</html>

Tidak ada komentar:
Posting Komentar