Greetings,
I can see that when I set htmlText in a textarea control, the text property contains the html free version of the text. So there is a parser somewhere that is ripping of html from the content, which would be very usefull for my purposes.
However, based on the flex source code, the setting of html is done in UITextField.as, which is the type of the textfield member of TextArea. The line that does the work is:
super.htmlText = value;
in function
override public function set htmlText(value:String):void
Trying to follow the class hieararchy, I end up in FlexTextField class, which extends flash player's textfield class.
It appears the functionality I am after is in flash player. So is there any way of accessing this html cleaning function? Am I missing something here?
Best Regards
Seref
In case regex fails you, here is something you might want to check out:
var t:String = "asd <span>This is <font>some</font> text <b> :) </b> </span> \nand more";
function stripTags(x:XML):String {
var t:String = "";
var children:XMLList = x.children();
var child:XML;
for(var i:Number = 0; i < children.length(); i++){
child = children[i];
if(child.nodeKind() == "text")
t += child.toString();
else if(child.nodeKind() == "element")
t += stripTags(child);
}
return t;
}
var x:XML = new XML("<root>" + t + "</root>");
XML.ignoreWhitespace = false;
var s:String = stripTags(x);
trace(s);
PS: I haven't tested this ActionScript code, here is the equivalent JavaScript code that I tested and found working. I assume it would work in ActionScript since both follow ECMAScript.
var t = "asd <span>This is <font>some</font> text <b> :) </b> </span> \nand more";
function stripTags(str){
function strip(x){
var t = "";
var children = x.children();
var child;
for(var i = 0; i < children.length(); i++){
child = children[i];
if(child.nodeKind() == "text")
t += child.toString();
else if(child.nodeKind() == "element")
t += strip(child);
}
return t;
}
var xml = new XML("<root>" + str + "</root>");
XML.ignoreWhitespace = false;
return strip(xml);
}
var s = stripTags(t);
console.log(s);
output:
asd This is some text :)
and more
Nope, there is no way to access code in the Flash Player native classes.
However, you should be able to use a Regex to easily parse out all HTML Tags in your content.
Although, not tested, here is one option that came up in Google. You can just use that in Flex. So, you can probably do something like this:
var regEx : RegExp = new RegExp('<(.|\n)*?>');
var noHTMLText = htmlText.replace(regEx , '');
Of course, this was written in the browser. More info on Regex in Flex.
Related
Given I have contained within a string an entire HTML document, how can I launch a new browser window, and then inject the html into that instance so that the new window renders the document?
I've found so many examples on the web that simply do not work. I'm a middle tier guy, so I'm weak on the web/javascript stuff.
UPDATE: Here's a snippet of code that shows what I'm trying to do
void Display()
{
string javascript = string.Empty;
javascript += "<script type='text/javascript'>";
javascript += "var win = window.open('', '', '');";
javascript += "win.document.open();";
javascript += "win.document.write('{0}');"; //<------Notice I have a format parameter placed within the call to document.Write
javascript += "win.document.close();";
javascript += "win.focus();";
javascript += "</script" + ">";
// this.DisplayableDocumentation is an IEnumerable of strings. Each string contains an entire
// HTML document. Ultimately, I want to launch a new window for each document.
this.DisplayableDocumentation
.ForEach(document =>
{
HttpContext.Current.Response.Write(string.Format(javascript, document));
});
}
void Display() {
var i = 0;
var javascript = "<script type='text/javascript'>";
DisplayableDocumentation
.ForEach(document =>
{
i++;
Response.Write(String.Format("<input id='txt{1}' type='text' value='{0}' style='display:none;'/>", Server.HtmlEncode(document), i));
javascript += String.Format(#"
var win{1} = window.open('', '', '');
win{1}.document.open();
win{1}.document.write(document.getElementById('txt{1}').value);
win{1}.document.close();
win{1}.focus();
", document, i);
});
javascript += "</" + "script>";
RegisterStartupScript("javascript", javascript);
}
Put the string somewhere so you can reference it from another page... or rather, another handler. Then set the address of your new window to use this handler as it's href.
I am a complete ASP.NET newbie, so this will probably be simple.
I have a label which text is set dynamically in the code behind using the following pseudo code
label.Text = string.Format(SOME-DYNAMIC-MESSAGE(ID,1), name, day);
The SOME-DYNAMIC-MESSAGE has a form of, where {0} and {1} refers to variables name and day.
Hello {0}, today is {1}.
I need to make those variables bold. I am trying to wrap them in span, so I can access them from CSS using this code
HtmlGenericControl bold = new HtmlGenericControl("span");
bold.InnerText = name;
bold.Attributes.Add("class", "bold");
label.Text = string.Format(SOME-DYNAMIC-MESSAGE(ID,1), bold, day);
but it doesn't work, no extra wrapper added. It even stopped to show me the the content of the variable.
Anybody knows how to fix this?
Try :
label.Text = string.Format(SOME-DYNAMIC-MESSAGE(ID,1), "<span style=\"font-weight:bold\">" + bold + "</span>", "<span style=\"font-weight:bold\">" + day + "</span>");
Here is a quick sample app (Console app) to demonstrate an approach. I think you are trying to format the input string for String.Format and make the font-weight of the token ({0}, {1}, etc...) bold.
use this Func<string,string> to format the input string. then add the following CSS to your html page:
class Program
{
static void Main(string[] args)
{
var input = #"Hello {0}, today is {1}.";
Func<string, string> SomeDynamicMessage = s => {
var val = s;
val = val.Replace("{", "<span class='bold-token'>{");
val = val.Replace("}", "}</span>");
return val;
};
Console.WriteLine(SomeDynamicMessage(input));
// output: Hello <span class='bold-token'>{0}</span>, today is <span class='bold-token'>{1}</span>.
var final = Console.ReadLine();
}
}
Css snippet:
.bold-token { font-weight: bold; }
Final output:
Hello <span class='bold-token'>{0}</span>, today is <span class='bold-token'>{1}</span>
EDIT -- MORE INFO
Here is how you should use it:
var input = #"Hello {0}, today is {1}.";
label.Text = string.Format(SomeDynamicMessage(input), "test", "Thursday");
and the output would be:
Hello <span class='bold-token'>test</span>, today is <span class='bold-token'>Thursday</span>
I hope someone will be able to help here, so first of all though let's take a look at exactly what my problem is ...
I would have liked to insert a movieclip from an external swf into my textarea but I think it isn't as easy as I thought... because the Textarea,TextFlow components are unfortunately almost unusable to me in this respect ..
I have read the API of Textarea and TextFlow , and I searched a lot on Google and some forums, but I have not found the solution to my problem.
I have found similar topics to this one like as :
Using symbol from library in htmlText <img> tag in ActionScript 3
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000322.html
I have tried several ways to refer to the symbol but to no avail...
Here is my code :
[Bindable]
/**
* The text which will be displayed
**/
public var pblMessages:String = "";
<s:TextArea id="pblArea" left="10" right="242" top="241" bottom="55" editable="false"
textFlow="{TextConverter.importToFlow(pblMessages,TextConverter.TEXT_FIELD_HTML_FORMAT)}"
valueCommit="pblAreaCommitHandler(event)">
</s:TextArea>
Method for adding new line :
private function submitText(keyPress:Boolean=false) :void {
if (pblInput.text=="") {
pblInput.setFocus();
return;
}
var format:ElementFormat = new ElementFormat();
var fontDescription:FontDescription = new FontDescription("Arial");
format.fontSize = 11;
format.fontDescription = fontDescription;
var s:String = pblInput.text;
var re: RegExp = new RegExp("\r|\n","gi");
s = s.replace(re,"");
var inlineGraphicElement:InlineGraphicElement = new InlineGraphicElement();
inlineGraphicElement.source = Smileys.smi_kiss;
var p:ParagraphElement = new ParagraphElement();
p.addChild(inlineGraphicElement);
//pblArea.textFlow.addChild(p);
pblMessages += "<font color='#000000'>" + s + "</font><img src='assets/testmovie.swf#smi_kiss' width='20' height='20'/><br/>";
pblInput.text="";
}
If the smiley is displayed on the first frame in the swf, then it displayed (without symbol) too in the TextArea of course.. but I don't want to make 100 different swf file.. I'm quite sure that the smileys can be displayed by using symbols.
Thank you in advance for your help.
Try to create complete TextFlow without using TextConverter.importToFlow. After adding inlineGraphicElement to p, you should add a SpanElement to p, and then add text to SpanElement.text, and then assign a textFlow to pblArea.textFlow.
I'm using the AJAX Control Toolkit control "TextBoxWaterMarkExtender". The problem originally was that in Firefox, setting the text with javascript like so:
var getDateField = document.getElementById('soandso');
getDateField.value = 'someandsome';
Would be cleared on submit/post because the Extender control thought that nobody had edited it, so it was clearing the "watermark".
I followed this workaround: http://www.mindfiresolutions.com/Workaround-for-TextBoxWatermarkExtender-of-AjaxControlToolkit--855.php
and it works great in Firefox, but IE says "'null' is null or not an object" on this line:
var dateIdentified = $find("Beh" + sender).get_Text();
Anything obvious that I'm missing?
Edit: Sorry guys, I thought $find was a jQuery function.
Edit: More code:
function dateToday(sender)
{
var dateIdentified = $find("Beh" + sender).get_Text();
if (dateIdentified.length == 0)
{
var todaydate = new Date();
var smonth = todaydate.getMonth() + 1;
var sday = todaydate.getDate();
var syear = todaydate.getFullYear();
$find("Beh" + sender).set_Text(smonth.toString() + '/' + sday.toString() + '/' + syear.toString());
}
}
WaterMark:
<toolkit:TextBoxWatermarkExtender BehaviorID="BehSTART_DATE" ID="WaterMarkSTART_DATE" runat="server"
TargetControlID="dcSTART_DATE"
WaterMarkText="mm/dd/yyyy" WaterMarkCssClass="searchHint" />
For anyone interested to know, I switched from using body onLoad to call my javascript function to
Sys.Application.add_load(MyFunction);
as this article suggested: http://blogs.telerik.com/dimodimov/posts/08-12-13/don_t_use_body_onload_in_asp_net_ajax_websites.aspx
Now IE, Firefox and Chrome all see a value for the $find.
Try this:
$("Beh" + sender).text();
find() is used when you've already looked up an element or elements and you want to find child elements inside of them. For example, you grab a table and then want to find all elements inside the table with a class of foo, like so:
var myTable = $('#myTable');
// more code
myTable.find('.foo');
How to style parts of the tooltip e.g. bold? I’m generating a tooltip in an itemrenderer for an datagrid, displaying the column name and then the value: I want to display the value bold…
public override function set data(value:Object):void
{
var dg:DataGrid = this.listData.owner as DataGrid;
var dataField:String = (dg.columns[this.listData.columnIndex] as DataGridColumn).dataField;
var toolString:String = “”;
for(var i:int = 0; i < dg.columns.length; i++)
{
var fieldName:String = (dg.columns[i] as DataGridColumn).dataField;
toolString = StringUtil.substitute("{0}{1}: {2}\n", toolString, fieldName, displayString(value[fieldName]));
}
this.toolTip = toolString;
super.data = value;
this.text = displayString(value[dataField]);
}
If you want to change all tooltips in your application, you can do so w/ CSS, as described in the docs herelink text.
I have found that to often be limiting, so it is more common I would create a custom toolTip.
The documentation is a bit confusing if memory serves me, so to create a custom toolTip you listen to the toolTipCreate method and replace the event.toolTip with your new toolTip. Toi position the new toolTip something other than the default, you must do that in a toolTipShow listener.
Just use custom simple HTMLToolTip class for your tooltips
http://flexscript.wordpress.com/2008/08/19/flex-html-tooltip-component/