Skip to content

Commit

Permalink
Added a js version of the string plugin for krpanoJS
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldOfView committed Apr 4, 2011
1 parent ce6565f commit acfb1cb
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h2><a name="plugins" href="#plugins" class="selflink">Plugins</a></h2>
<dd>A plugin that adds a doubleclick event to krpano.</dd>
<dt><a name="gyro" href="gyro/plugin.html">gyro</a><span class="flashhtml5">for HTML5</span></dt>
<dd>A plugin that uses the gyroscope in devices such as the iPhone 4 and iPad2 to control the view.</dd>
<dt><a name="string" href="string/plugin.html">string</a><span class="flashhtml5">for Flash</span></dt>
<dt><a name="string" href="string/plugin.html">string</a><span class="flashhtml5">for Flash & HTML5</span></dt>
<dd>A plugin that adds vector-math calculations to krpano.</dd>
<dt><a name="vectormath" href="vectormath/plugin.html">vectormath</a><span class="flashhtml5">for Flash</span></dt>
<dd>A plugin that adds string manipulation functions to krpano.</dd>
Expand Down
10 changes: 10 additions & 0 deletions string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
string plugin for KRPano
by Aldo Hoeben / fieldOfView.com
http://fieldofview.github.com/krpano_fovplugins/string/plugin.html
This software can be used free of charge and the source code is available under a Creative Commons Attribution license:
http://creativecommons.org/licenses/by/3.0/
*/

var krpanoplugin=function(){var c=this,f=null,d=null;c.registerplugin=function(i,h,j){f=i;d=j;if(f.version<"1.0.8.14"||f.build<"2011-03-30"){f.trace(3,"gyro plugin - too old krpano version (min. 1.0.8.14)");return}d.txtlength=a;d.txtchunk=g;d.txtfind=b;d.txtreplace=e};c.unloadplugin=function(){d=null;f=null};function a(i,h){f.set(i,h.length)}function g(k,h,j,i){f.set(k,h.substr(j,i))}function b(j,h,i){f.set(j,h.indexOf(i))}function e(m,j,l,i,h){var k=new RegExp(l,h);f.set(m,j.replace(k,i))}};
4 changes: 2 additions & 2 deletions string/plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ <h2><a name="description" href="#description" class="selflink">Description</a></
</div>
<div class="paragraph">
<h2><a name="download" href="#download" class="selflink">Download</a></h2>
<div class="dlitem"> <a href="http://fieldofview.github.com/krpano_fovplugins/clipboard.swf">string.swf</a>&nbsp; <small>(plugin only)</small></div>
<div class="dlitem"> <a href="http://fieldofview.github.com/krpano_fovplugins/clipboard.js">string.js</a>&nbsp; <small>(plugin only)</small></div>
<div class="dlitem"> <a href="http://fieldofview.github.com/krpano_fovplugins/string.swf">string.swf</a>&nbsp; <small>(plugin only)</small></div>
<div class="dlitem"> <a href="http://fieldofview.github.com/krpano_fovplugins/string.js">string.js</a>&nbsp; <small>(plugin only)</small></div>
<p>The string <a href="https://github.com/fieldOfView/krpano_fovplugins/tree/master/string">sources and examples</a> are available as part of the fovplugins package</p>
<div class="dlitem"> <a href="https://github.com/fieldOfView/krpano_fovplugins/zipball/master">fovplugins.zip</a>&nbsp; <small>(plugin, source code &amp; examples)</small><br/>
</div>
Expand Down
72 changes: 72 additions & 0 deletions string/source/string.source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
string plugin for KRPanoJS
by Aldo Hoeben / fieldOfView.com
http://fieldofview.github.com/krpano_fovplugins/string/plugin.html
This software can be used free of charge and the source code is available under a Creative Commons Attribution license:
http://creativecommons.org/licenses/by/3.0/
*/

var krpanoplugin = function()
{
var local = this,
krpano = null, plugin = null;

////////////////////////////////////////////////////////////
// plugin management

local.registerplugin = function(krpanointerface, pluginpath, pluginobject)
{
krpano = krpanointerface;
plugin = pluginobject;

if (krpano.version < "1.0.8.14" || krpano.build < "2011-03-30")
{
krpano.trace(3,"gyro plugin - too old krpano version (min. 1.0.8.14)");
return;
}

// register methods
plugin.txtlength = txtlength;
plugin.txtchunk = txtchunk;
plugin.txtfind = txtfind;
plugin.txtreplace = txtreplace;
}


local.unloadplugin = function()
{
plugin = null;
krpano = null;
}


////////////////////////////////////////////////////////////
// public methods

function txtlength(varName, subject)
{
// return the length of the supplied text
krpano.set(varName, subject.length);
}

function txtchunk(varName, subject, start, length)
{
// return a substring of the supplied text
krpano.set(varName, subject.substr(start, length));
}

function txtfind(varName, subject, find)
{
// find a needle in a haystack and return its position
krpano.set(varName, subject.indexOf(find));
}

function txtreplace(varName, subject, find, replace, flags)
{
// find and replace a needle in a haystack
var pattern = new RegExp(find, flags);
krpano.set(varName, subject.replace(pattern, replace) );
}

}

0 comments on commit acfb1cb

Please sign in to comment.