<klip>
   <identity>
      <title>
         API: TextField
      </title>
   </identity>
   <locations>
      <contentsource>
         http://news.com.com/2547-1_3-0-5.xml
      </contentsource>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
   </locations>
   <klipscript>
   <![CDATA[

// Globals
var textfield_URL;


function onLoad()
{
	var tab = Setup.addTab ("Setup");	

	// Enable user to enter URL for source
	tab.addText( "Enter URL: " );
	textfield_URL = tab.addTextField();
	if (Prefs.getPref( "textfield_URL" ) == "" ) {
		Prefs.setPref( "textfield_URL", Prefs.contentsource );
	}
	textfield_URL.value = Prefs.getPref( "textfield_URL" );

	Setup.onClose = Setup_onClose;
}


function onRefresh()
{
	Setup_saveTextFields ();

	var result = Engines.Data.process ( textfield_URL.value );

	return result;
}


//
// Support functions -----------------------------------------------
//

function Setup_onClose()
{
	if (Setup_saveTextFields ())
	{
		// Neet to refresh the Klip with new data	
		Klip.requestRefresh ();
	}
}

function Setup_saveTextFields()
{
	var request_refresh = false;

	// Check if the user changed the text field URL
	if (Prefs.getPref( "textfield_URL" ) != textfield_URL.value) {
		Prefs.setPref( "textfield_URL", textfield_URL.value ); 

		// Clear everything and request a refresh
		Items.clear (true);
		Items.Deleted.clear (true);

		request_refresh = true;
	}

	return request_refresh;
}	

  
   ]]>
   </klipscript>
</klip>

