Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > b3a1f4d91c26f535919e39e25606614a > files > 1429

wt-doc-3.2.3-1.fc18.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt: Wt::JSlot Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Wt
   &#160;<span id="projectnumber">3.2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="namespaceWt.html">Wt</a>      </li>
      <li class="navelem"><a class="el" href="classWt_1_1JSlot.html">JSlot</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">Wt::JSlot Class Reference<div class="ingroups"><a class="el" href="group__signalslot.html">Signal/slot system</a></div></div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="Wt::JSlot" -->
<p>A slot that is only implemented in client side JavaScript code.  
 <a href="classWt_1_1JSlot.html#details">More...</a></p>

<p><code>#include &lt;Wt/WJavaScript&gt;</code></p>

<p><a href="classWt_1_1JSlot-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#a0d7d51d1bfe2c1fe86fd0da1aa6100a2">JSlot</a> (<a class="el" href="classWt_1_1WWidget.html">WWidget</a> *parent=0)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a JavaScript-only slot within the parent scope.  <a href="#a0d7d51d1bfe2c1fe86fd0da1aa6100a2"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#a5a029953497443c38ba50514194a7925">JSlot</a> (const std::string &amp;javaScript, <a class="el" href="classWt_1_1WWidget.html">WWidget</a> *parent=0)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a JavaScript-only and sets the JavaScript code.  <a href="#a5a029953497443c38ba50514194a7925"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ade213c06a4ee987a4ec39446e6954e21"></a><!-- doxytag: member="Wt::JSlot::~JSlot" ref="ade213c06a4ee987a4ec39446e6954e21" args="()" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#ade213c06a4ee987a4ec39446e6954e21">~JSlot</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Destructor. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#a4e28a8ef6d2965aeaac0c5dcf587bbbb">setJavaScript</a> (const std::string &amp;javaScript)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Sets or modify the JavaScript code associated with the slot.  <a href="#a4e28a8ef6d2965aeaac0c5dcf587bbbb"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#a3d65b00a8015e556580527b52750ef87">exec</a> (const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Executes the JavaScript code.  <a href="#a3d65b00a8015e556580527b52750ef87"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">std::string&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1JSlot.html#a520731f1245cb9a757675a93372c761c">execJs</a> (const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a JavaScript statement that executes the slot.  <a href="#a520731f1245cb9a757675a93372c761c"></a><br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>A slot that is only implemented in client side JavaScript code. </p>
<p>This class provides a hook for adding your own JavaScript to respond to events.</p>
<p>Carefully consider the use of this. Not only is writing cross-browser JavaScript hard and tedious, but one must also be aware of possible security problems (see further), and ofcourse, the event handling will not be available when JavaScript is disabled or not present at all.</p>
<p>If you wish to add client side event handling, with automatic fall-back to server-side event handling and without writing JavaScript code with the associated risks and problems, consider using stateless slot implementations instead (see <a class="el" href="classWt_1_1WObject.html#adaa163b9e92933f3b2ff4ec58e2734c6" title="Declares a slot to be stateless and learn client-side behaviour on first invocation.">WObject::implementStateless()</a>)</p>
<p>For some purposes, stateless slot implementations are not sufficient, since they do not allow state inspection. At the same time, the non-availability in case of disabled JavaScript may also be fine for some non-essential functionality (see for example the <a class="el" href="classWt_1_1WSuggestionPopup.html" title="A widget which popups to assist in editing a textarea or lineedit.">WSuggestionPopup</a> widget), or when you simply do not care. For these situations a JSlot can be used to add client-side event handling.</p>
<p>The JavaScript code may be set (or changed) using the <a class="el" href="classWt_1_1JSlot.html#a4e28a8ef6d2965aeaac0c5dcf587bbbb" title="Sets or modify the JavaScript code associated with the slot.">setJavaScript()</a> method which takes a string that implements a JavaScript function with the following signature:</p>
<div class="fragment"><pre class="fragment"> <span class="keyword">function</span>(sender, event) {
   <span class="comment">// handle the event, and sender is a reference to the DOM element</span>
   <span class="comment">// which captured the event (and holds the signal). Therefore it</span>
   <span class="comment">// equivalent to the sender for a normal %Wt slot.</span>

   <span class="comment">// You can prevent the default action using:</span>
   ${WT_CLASS}.cancelEvent(event);
   <span class="comment">// (where ${WT_CLASS} should be the value of the WT_CLASS define</span>
 }
</pre></div><p>In the JavaScript code, you may use <a class="el" href="classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7" title="Returns a JavaScript expression to the corresponding DOM node.">WWidget::jsRef()</a> to obtain the DOM element corresponding to any <a class="el" href="classWt_1_1WWidget.html" title="The abstract base class for a user-interface component.">WWidget</a>, or <a class="el" href="classWt_1_1WObject.html#a5c5cc1d7aada99baf97d0dc203e42154" title="Returns the (unique) identifier for this object.">WWidget::id()</a> to obtain the DOM id. In addition you may trigger server-side events using the JavaScript WtSignalEmit function (see <a class="el" href="classWt_1_1JSignal.html" title="A signal to relay JavaScript to C++ calls.">JSignal</a> documentation). That's how far we can help you. For the rest you are left to yourself, buggy browsers and quirky JavaScript (<a href="http://www.quirksmode.org/">http://www.quirksmode.org/</a> was a reliable companion to me) -- good luck.</p>
<p>Note that the slot object needs to live as long as you want the JavaScript to be executed by connected signals: when the slot is destroyed, the connection is destroyed just as with other signal/slot connections where the target object is deleted. This means that it is (almost?) always a bad idea to declare a <a class="el" href="classWt_1_1JSlot.html" title="A slot that is only implemented in client side JavaScript code.">JSlot</a> on the stack. </p>
</div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a0d7d51d1bfe2c1fe86fd0da1aa6100a2"></a><!-- doxytag: member="Wt::JSlot::JSlot" ref="a0d7d51d1bfe2c1fe86fd0da1aa6100a2" args="(WWidget *parent=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::JSlot::JSlot </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&#160;</td>
          <td class="paramname"><em>parent</em> = <code>0</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Constructs a JavaScript-only slot within the parent scope. </p>
<p>The JavaScript code block will reside within the scope of the given widget. By picking a long-lived parent, one may reuse a single block of JavasCript code for multiple widgets.</p>
<p>When <code>parent</code> = <code>0</code>, then the JavaScript will be inlined in each caller (possibly replicating the same JavaScript). </p>

</div>
</div>
<a class="anchor" id="a5a029953497443c38ba50514194a7925"></a><!-- doxytag: member="Wt::JSlot::JSlot" ref="a5a029953497443c38ba50514194a7925" args="(const std::string &amp;javaScript, WWidget *parent=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Wt::JSlot::JSlot </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>javaScript</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="classWt_1_1WWidget.html">WWidget</a> *&#160;</td>
          <td class="paramname"><em>parent</em> = <code>0</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Constructs a JavaScript-only and sets the JavaScript code. </p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1JSlot.html#a0d7d51d1bfe2c1fe86fd0da1aa6100a2" title="Constructs a JavaScript-only slot within the parent scope.">JSlot(WWidget *)</a>, <a class="el" href="classWt_1_1JSlot.html#a4e28a8ef6d2965aeaac0c5dcf587bbbb" title="Sets or modify the JavaScript code associated with the slot.">setJavaScript()</a> </dd></dl>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a3d65b00a8015e556580527b52750ef87"></a><!-- doxytag: member="Wt::JSlot::exec" ref="a3d65b00a8015e556580527b52750ef87" args="(const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::JSlot::exec </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>object</em> = <code>&quot;null&quot;</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>event</em> = <code>&quot;null&quot;</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Executes the JavaScript code. </p>
<p>This executes the JavaScript code in the same way as when triggered by a <a class="el" href="classWt_1_1EventSignal.html" title="A signal that conveys user-interface events.">EventSignal</a>. This function returns immediately, and execution of the JavaScript code is deferred until after the event handling.</p>
<p>The arguments are the <code>"object, event"</code> arguments of the JavaScript event callback function.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1JSlot.html#a4e28a8ef6d2965aeaac0c5dcf587bbbb" title="Sets or modify the JavaScript code associated with the slot.">setJavaScript()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a520731f1245cb9a757675a93372c761c"></a><!-- doxytag: member="Wt::JSlot::execJs" ref="a520731f1245cb9a757675a93372c761c" args="(const std::string &amp;object=&quot;null&quot;, const std::string &amp;event=&quot;null&quot;)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">std::string Wt::JSlot::execJs </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>object</em> = <code>&quot;null&quot;</code>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>event</em> = <code>&quot;null&quot;</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Returns a JavaScript statement that executes the slot. </p>
<p>This returns the JavaScript code to execute the slot.</p>
<p>The arguments are the <code>"object, event"</code> arguments of the JavaScript event callback function.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1JSlot.html#a3d65b00a8015e556580527b52750ef87" title="Executes the JavaScript code.">exec()</a> </dd></dl>

</div>
</div>
<a class="anchor" id="a4e28a8ef6d2965aeaac0c5dcf587bbbb"></a><!-- doxytag: member="Wt::JSlot::setJavaScript" ref="a4e28a8ef6d2965aeaac0c5dcf587bbbb" args="(const std::string &amp;javaScript)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::JSlot::setJavaScript </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&#160;</td>
          <td class="paramname"><em>javaScript</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Sets or modify the JavaScript code associated with the slot. </p>
<p>When the slot is triggered, the corresponding function defined by <code>javaScript</code> is executed.</p>
<p>The JavaScript function takes two parameters and thus should look like: </p>
<div class="fragment"><pre class="fragment">     <span class="keyword">function</span>(obj, event) {
       <span class="comment">// ...</span>
     }
</pre></div><p>The first parameter <code>obj</code> is a reference to the DOM element that generates the event. The <code>event</code> refers to the JavaScript event object.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WWidget.html#aa2b7078b3b43d53a85e5244b45d504f7" title="Returns a JavaScript expression to the corresponding DOM node.">WWidget::jsRef()</a> </dd></dl>

</div>
</div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Thu Nov 1 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by&nbsp;<a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>