Skip to content

Instantly share code, notes, and snippets.

@edorcutt
Created December 20, 2010 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edorcutt/749097 to your computer and use it in GitHub Desktop.
Save edorcutt/749097 to your computer and use it in GitHub Desktop.
KRL_Scope_Safari_Entity_Variables
ruleset a169x195 {
meta {
name "KRL_Scope_Safari_Entity_Variables"
description <<
Demo Persistent Entity Variables
>>
author "Ed Orcutt"
logging on
}
dispatch {
domain "kynetx.aculis.net"
}
global {
SafariHeader = <<
<div id="SafariHeader">
KRL Scope Safari: Entity Variables
<hr class="safarititlehr" />
</div>
>>;
SafariContent = <<
<div id="SafariContent">
no content :(
</div>
>>;
SafariCurrentValue = <<
Current Value:
<span id="SafariCurrentValue">no value yet</span>
<hr class="safarihr"/>
>>;
SafariSubmit = <<
<form id="SafariSubmitForm" onsubmit="return false">
<input id="SafariFormValue"
type="text"
name="SafariInputValue"
value="Enter a new value" />
<input type="submit" value="Mutate">
</form>
>>;
SafariClear = <<
<form id="SafariClearForm" onsubmit="return false">
<input type="submit" value="Clear">
</form>
>>;
css <<
.safarititlehr {
height:2px;
border-width:0;
background-color:white;
}
.safarihr {
height: 1px;
border-width: 0;
background-color: gray;
}
#SafariSubmitForm {
float: left;
}
#SafariCurrentValue {
font-weight: bold;
}
>>
}
rule Safari_Initialize {
select when pageview ".*"
pre {
SafariValue = ent:safari_entity || "Just Born!";
}
{
notify(SafariHeader, SafariContent) with
background_color = "#222" and
opacity = 1.0 and
width = "320px" and
sticky = true;
replace_inner("#SafariContent", SafariCurrentValue);
replace_inner("#SafariCurrentValue", SafariValue);
append("#SafariContent", SafariSubmit);
watch("#SafariSubmitForm", "submit");
append("#SafariContent", SafariClear);
watch("#SafariClearForm", "submit");
}
fired {
set ent:safari_entity SafariValue;
}
}
rule Safari_Respond_Submit {
select when web submit "#SafariSubmitForm"
pre {
newValue = page:param("SafariInputValue");
}
{
replace_inner("#SafariCurrentValue", newValue);
emit <<
$K("input#SafariFormValue").val("Thanks, again?");
>>
}
fired {
set ent:safari_entity newValue;
}
}
rule Safari_Respond_Clear {
select when web submit "#SafariClearForm"
{
replace_inner("#SafariCurrentValue", "all clear");
emit <<
$K("input#SafariFormValue").val("Cleared!");
>>
}
fired {
clear ent:safari_entity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment