Fixed adding genres, start of edit/delete

This commit is contained in:
Timothy Warren 2012-09-10 15:45:39 +00:00
parent e316378dad
commit 3f70cbb20b
23 changed files with 650 additions and 38 deletions

View File

@ -34,6 +34,7 @@ return [
'default_controller' => 'welcome', 'default_controller' => 'welcome',
'default_module' => 'meta', 'default_module' => 'meta',
'genre' => 'meta/genre/index', 'genre' => 'meta/genre/index',
'genre/add' => 'meta/genre/add',
'genre/add_category' => 'meta/genre/add_category', 'genre/add_category' => 'meta/genre/add_category',
'category' => 'meta/category/index', 'category' => 'meta/category/index',
'category/add_section' => 'meta/category/add_section', 'category/add_section' => 'meta/category/add_section',

View File

@ -74,7 +74,7 @@ class category extends meta\controller {
$this->page->set_message('error', 'Section already exists for this category'); $this->page->set_message('error', 'Section already exists for this category');
} }
$this->detail($id); $this->index($id);
} }
} }

View File

@ -97,6 +97,9 @@ class genre extends meta\controller {
$this->load_view('genre_detail', $data); $this->load_view('genre_detail', $data);
} }
/**
* Adds a category to the current genre
*/
public function add_category() public function add_category()
{ {
// Strip away tags for the sake of security // Strip away tags for the sake of security

View File

@ -62,7 +62,10 @@ class section extends meta\controller {
$keys = filter_var_array($_POST['name'], FILTER_SANITIZE_STRING); $keys = filter_var_array($_POST['name'], FILTER_SANITIZE_STRING);
$vals = filter_var_array($_POST['val'], FILTER_SANITIZE_STRING);
// Raw to allow use of HTML formatting
// Prepared statements keep the database safe here.
$vals = $_POST['val'];
$data = array_combine($keys, $vals); $data = array_combine($keys, $vals);

View File

@ -106,8 +106,8 @@ class model extends \miniMVC\Model {
// Fetch the data as a workaround // Fetch the data as a workaround
// for databases that do not support // for databases that do not support
// grabbing result counts (SQLite / Firebird) // grabbing result counts (SQLite / Firebird)
$array = $query->fetchAll(); $array = $query->fetchAll(\PDO::FETCH_ASSOC);
if (empty($array)) if (count($array) < 1)
{ {
$this->db->set('genre', $genre) $this->db->set('genre', $genre)
->insert('genre'); ->insert('genre');

View File

@ -13,7 +13,7 @@
<input type="text" name="section" id="section" /></dd> <input type="text" name="section" id="section" /></dd>
<dt><input type="hidden" name="category_id" value="<?= $category_id ?>" /></dt><dd> <dt><input type="hidden" name="category_id" value="<?= $category_id ?>" /></dt><dd>
<button type="submit">Add Section</button></dd> <button type="submit" class="save">Add Section</button></dd>
</dl> </dl>
</fieldset> </fieldset>
</form> </form>
@ -23,6 +23,10 @@
<?php if (is_array($section)) list($section, $d) = $section ?> <?php if (is_array($section)) list($section, $d) = $section ?>
<li> <li>
<h4><a href="<?= miniMVC\site_url("section/detail/{$id}") ?>"><?= $section ?></a></h4> <h4><a href="<?= miniMVC\site_url("section/detail/{$id}") ?>"><?= $section ?></a></h4>
<span class="modify" id="section_<?=$id ?>">
<button class="edit">Edit</button>
<button class="delete">Delete</button>
</span>
<?php if ( ! empty($d)): ?> <?php if ( ! empty($d)): ?>
@ -30,7 +34,10 @@
<?php $class = (strpos($v, "<br />") !== FALSE) ? 'multiline' : 'pair' ?> <?php $class = (strpos($v, "<br />") !== FALSE) ? 'multiline' : 'pair' ?>
<dl class="<?= $class ?>"> <dl class="<?= $class ?>">
<dt><?= $k ?></dt> <dt>
<?= $k ?>
</dt>
<dd><?= $v ?></dd> <dd><?= $v ?></dd>
</dl> </dl>

View File

@ -13,14 +13,20 @@
<input type="text" name="category" id="category" /></dd> <input type="text" name="category" id="category" /></dd>
<dt><input type="hidden" name="genre_id" value="<?= $genre_id ?>" /></dt><dd> <dt><input type="hidden" name="genre_id" value="<?= $genre_id ?>" /></dt><dd>
<button type="submit">Add Category</button></dd> <button type="submit" class="save">Add Category</button></dd>
</dl> </dl>
</fieldset> </fieldset>
</form> </form>
<ul> <ul>
<?php foreach($categories as $id => $cat): ?> <?php foreach($categories as $id => $cat): ?>
<li><a href="<?= miniMVC\site_url("category/detail/{$id}") ?>"><?= $cat ?></a></li> <li>
<a href="<?= miniMVC\site_url("category/detail/{$id}") ?>"><?= $cat ?></a>
<span class="modify" id="category_<?=$id ?>">
<button class="edit">Edit</button>
<button class="delete">Delete</button>
</span>
</li>
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>

View File

@ -9,13 +9,21 @@
<input type="text" name="genre" id="genre" /></dd> <input type="text" name="genre" id="genre" /></dd>
<dt>&nbsp;</dt><dd> <dt>&nbsp;</dt><dd>
<button type="submit">Add Genre</button></dd> <button type="submit" class="save">Add Genre</button></dd>
</dl> </dl>
</fieldset> </fieldset>
</form> </form>
<ul> <ul>
<?php foreach($genres as $id => $name): ?> <?php foreach($genres as $id => $name): ?>
<li><a href="<?= miniMVC\site_url("genre/{$id}") ?>"><?= $name ?></a></li> <li>
<a href="<?= miniMVC\site_url("genre/{$id}") ?>">
<?= $name ?>
</a>
<span class="modify" id="genre_<?=$id ?>">
<button class="edit">Edit</button>
<button class="delete">Delete</button>
</span>
</li>
<?php endforeach ?> <?php endforeach ?>
</ul> </ul>

View File

@ -16,10 +16,10 @@
<input type="text" name="name[]" id="section" /></dd> <input type="text" name="name[]" id="section" /></dd>
<dt><label for="val">Value:</label></dt><dd> <dt><label for="val">Value:</label></dt><dd>
<textarea name="val[]" rows="5" cols="40"></textarea></dd> <textarea id="input" name="val[]" rows="5" cols="40"></textarea></dd>
<dt><input type="hidden" name="section_id" value="<?= $section_id ?>" /></dt><dd> <dt><input type="hidden" name="section_id" value="<?= $section_id ?>" /></dt><dd>
<button type="submit">Save Data</button></dd> <button type="submit" class="save">Save Data</button></dd>
</dl> </dl>
</fieldset> </fieldset>
</form> </form>

View File

@ -13,6 +13,7 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* Asset management configuration file * Asset management configuration file
* *
@ -53,7 +54,7 @@ $css_root = $document_root. 'css/';
| Path fragment to rewrite in css files | Path fragment to rewrite in css files
| |
*/ */
$path_from = ''; $path_from = './images/';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -63,7 +64,7 @@ $path_from = '';
| The path fragment replacement for the css files | The path fragment replacement for the css files
| |
*/ */
$path_to = ''; $path_to = '//github.timshomepage.net/meta/assets/images/';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -23,7 +23,8 @@ return array(
'css' => array( 'css' => array(
'normalize.css', 'normalize.css',
'message.css', 'message.css',
'theme.css' 'theme.css',
'tinyeditor.css'
) )
); );
// End of css_groups.php // End of css_groups.php

View File

@ -28,6 +28,7 @@ return array(
'js' => array( 'js' => array(
'kis-lite-dom-min.js', 'kis-lite-dom-min.js',
'tinyeditor.js',
'meta.js' 'meta.js'
), ),
); );

View File

@ -113,6 +113,10 @@ if ($last_modified === $requested_time)
exit(); exit();
} }
// Correct paths that have changed due to concatenation
// based on rules in the config file
$css = str_replace($path_from, $path_to, $css);
if (!isset($_GET['debug'])) if (!isset($_GET['debug']))
{ {
$css = compress($css); $css = compress($css);

View File

@ -11,6 +11,10 @@ html, body {
button { button {
color:#312; color:#312;
padding:5px;
border:1px solid #555;
border-radius:5px;
box-shadow:1px 1px #a98;
} }
a { a {
@ -30,7 +34,6 @@ legend:hover {
} }
h1,h2 { h1,h2 {
display:-moz-inline-box;
display:inline-block; display:inline-block;
vertical-align:middle; vertical-align:middle;
width:25%; width:25%;
@ -43,8 +46,8 @@ fieldset dl {
/* form styles */ /* form styles */
form dt, form dd { form dt, form dd {
display:-moz-inline-box; /* For older versions of Mozilla/Firefox */
display:inline-block; display:inline-block;
vertical-align:top;
padding:0.25em 0; padding:0.25em 0;
} }
@ -60,7 +63,40 @@ form dd {
padding-left:.25em; padding-left:.25em;
} }
/* Outline styles */ /* ! Edit buttons */
.modify {
position:absolute;
display:none;
margin-left:1em;
}
li:hover .modify, dt:hover .modify {
display:inline-block;
}
button.save {
background:#797;
color:#eee;
}
button.save:hover {
background:#595;
}
button.edit {
}
button.delete {
background:#977;
color:#eee;
}
button.delete:hover {
background:#955;
}
/* ! Outline styles */
.list { .list {
padding:0; padding:0;
margin:0; margin:0;
@ -74,7 +110,11 @@ form dd {
list-style:none; list-style:none;
} }
/* Data listing styles */ li h4 {
display:inline;
}
/* ! Data listing styles */
dl.multiline, dl.pair { dl.multiline, dl.pair {
border-bottom:1px dotted #312; border-bottom:1px dotted #312;
} }
@ -92,7 +132,6 @@ dl.multiline dd {
} }
dl.pair dt, dl.pair dd { dl.pair dt, dl.pair dd {
display:-moz-inline-block;
display:inline-block; display:inline-block;
padding:0.25em 0; padding:0.25em 0;
} }

57
assets/css/tinyeditor.css Executable file
View File

@ -0,0 +1,57 @@
.te {
border: 1px solid #bbb;
padding: 0 1px 1px;
font: 12px Verdana,Arial;
}
.te iframe { border: none }
.teheader {
height: 31px;
border-bottom: 1px solid #bbb;
background: url(./images/header-bg.gif) repeat-x;
padding-top: 1px;
overflow: hidden;
}
.testyle { margin-right: 12px }
.tedivider {
float: left;
width: 1px;
height: 30px;
background: #ccc;
}
.tecontrol {
float: left;
width: 34px;
height: 30px;
cursor: pointer;
background-image: url(./images/icons.png);
}
.tecontrol:hover {
background-color: #fff;
background-position: 30px 0;
}
.tefooter {
height: 32px;
border-top: 1px solid #bbb;
background: #f5f5f5;
}
.toggle {
float: left;
background: url(./images/icons.png) -34px 2px no-repeat;
padding: 9px 13px 0 31px;
height: 23px;
border-right: 1px solid #ccc;
cursor: pointer;
color: #666;
}
.toggle:hover { background-color: #fff }
.resize {
float: right;
height: 32px;
width: 32px;
background: url(./images/resize.gif) 15px 15px no-repeat;
cursor: s-resize;
}
#editor {
cursor: text;
margin: 10px;
}

BIN
assets/images/header-bg.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 B

BIN
assets/images/icons.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
assets/images/resize.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

51
assets/js/cache/js vendored
View File

@ -1,17 +1,34 @@
(function(){if("undefined"!==typeof document.querySelector){var d,e,b,c;d=function(a){c="undefined"===typeof a?"undefined"!==typeof d.el?d.el:document.documentElement:"object"!==typeof a?e(a):a;d.prototype.el=c;var a=b(d),f;for(f in a)"object"===typeof a[f]&&(a[f].el=c);a.el=c;return a};e=function(a,f){var b;if("string"!=typeof a||"undefined"===typeof a)return a;b=null!=f&&1===f.nodeType?f:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a); (function(){if("undefined"!==typeof document.querySelector){var f,e,d,c;f=function(a){c="undefined"===typeof a?"undefined"!==typeof f.el?f.el:document.documentElement:"object"!==typeof a?e(a):a;f.prototype.el=c;var a=d(f),b;for(b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};e=function(a,b){var c;if("string"!=typeof a||"undefined"===typeof a)return a;c=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);c=c.querySelectorAll(a);
return 1===b.length?b[0]:b};b=function(a){var f;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);f=typeof a;if(!("object"!==f&&"function"!==f))return f=function(){},f.prototype=a,new f}};d.ext=function(a,f){f.el=c;d[a]=f};d.ext("each",function(a){if("undefined"!==typeof c.length&&c!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(c,a);else{var f=c.length;if(0!==f)for(var b,d=0;d<f;d++)b=c.item(d)?c.item(d):c[d],a.call(b,b)}else a.call(c, return 1===c.length?c[0]:c};d=function(a){var b;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);b=typeof a;if(!("object"!==b&&"function"!==b))return b=function(){},b.prototype=a,new b}};f.ext=function(a,b){b.el=c;f[a]=b};f.ext("each",function(a){if("undefined"!==typeof c.length&&c!==window)if("undefined"!==typeof Array.prototype.forEach)[].forEach.call(c,a);else{var b=c.length;if(0!==b)for(var d,e=0;e<b;e++)d=c.item(e)?c.item(e):c[e],a.call(d,d)}else a.call(c,
c)});d.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};d=window.$_=window.$_||d;d.$=e}})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")}); c)});f.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};f=window.$_=window.$_||f;f.$=e}})();"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});
"undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event&&(Event.prototype.preventDefault=function(){window.event.returnValue=!1},Event.prototype.stopPropagation=function(){window.event.cancelBubble=!0});"undefined"===typeof Array.isArray&&(Array.isArray=function(d){return"[object Array]"===Object.prototype.toString.apply(d)}); "undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event&&(Event.prototype.preventDefault=function(){window.event.returnValue=!1},Event.prototype.stopPropagation=function(){window.event.cancelBubble=!0});"undefined"===typeof Array.isArray&&(Array.isArray=function(f){return"[object Array]"===Object.prototype.toString.apply(f)});
(function(){if("undefined"!==typeof window.XMLHttpRequest){var d={_do:function(d,b,c,a,f){var g=new XMLHttpRequest;"undefined"===typeof c&&(c=function(){});f=f?"POST":"GET";d+="GET"===f?"?"+this._serialize(b):"";g.open(f,d);g.onreadystatechange=function(){4===g.readyState&&(200===g.status?c.call(g.responseText,g.responseText):"undefined"!==typeof a&&a.call(g.status,g.status))};"POST"===f?(g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.send(this._serialize(b))):g.send(null)}, (function(){if("undefined"!==typeof window.XMLHttpRequest){var f={_do:function(e,d,c,a,b){var l=new XMLHttpRequest;"undefined"===typeof c&&(c=function(){});b=b?"POST":"GET";e+="GET"===b?"?"+this._serialize(d):"";l.open(b,e);l.onreadystatechange=function(){4===l.readyState&&(200===l.status?c.call(l.responseText,l.responseText):"undefined"!==typeof a&&a.call(l.status,l.status))};"POST"===b?(l.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),l.send(this._serialize(d))):l.send(null)},
_serialize:function(d){var b,c,a=[];for(b in d)d.hasOwnProperty(b)&&"function"!==typeof d[b]&&(c=d[b].toString(),b=encodeURIComponent(b),c=encodeURIComponent(c),a.push(b+"="+c));return a.join("&")}};$_.ext("get",function(e,b,c,a){d._do(e,b,c,a,!1)});$_.ext("post",function(e,b,c,a){d._do(e,b,c,a,!0)});$_.ext("sse",function(d,b){var c;"undefined"!==typeof EventSource&&(c=new EventSource(d),c.onmessage=function(a){b.call(a.data,a.data)})})}})(); _serialize:function(e){var d,c,a=[];for(d in e)e.hasOwnProperty(d)&&"function"!==typeof e[d]&&(c=e[d].toString(),d=encodeURIComponent(d),c=encodeURIComponent(c),a.push(d+"="+c));return a.join("&")}};$_.ext("get",function(e,d,c,a){f._do(e,d,c,a,!1)});$_.ext("post",function(e,d,c,a){f._do(e,d,c,a,!0)});$_.ext("sse",function(e,d){var c;"undefined"!==typeof EventSource&&(c=new EventSource(e),c.onmessage=function(a){d.call(a.data,a.data)})})}})();
(function(){var d,e,b,c;"undefined"!==typeof document.addEventListener?(d=function(a,b,c){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,c,!1)},e=function(a,b,c){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,c,!1)}):"undefined"!==typeof document.attachEvent&&(d=function(a,b,c){function d(a){c.apply(a)}"undefined"!==typeof a.attachEvent&&(e(b,c),a.attachEvent("on"+b,d),a=a.KIS_0_6_0=a.KIS_0_6_0||{},a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||[],a.listeners[b].push({callback:c, (function(){var f,e,d,c;"undefined"!==typeof document.addEventListener?(f=function(a,b,c){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,c,!1)},e=function(a,b,c){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,c,!1)}):"undefined"!==typeof document.attachEvent&&(f=function(a,b,c){function d(a){c.apply(a)}"undefined"!==typeof a.attachEvent&&(e(b,c),a.attachEvent("on"+b,d),a=a.KIS_0_6_0=a.KIS_0_6_0||{},a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||[],a.listeners[b].push({callback:c,
_listener:d}))},e=function(a,b,c){if("undefined"!==typeof a.detachEvent){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[b])for(var e=d.listeners[b],k=e.length,i=0;i<k;i++)if(e[i].callback===c){a.detachEvent("on"+b,e[i]._listener);e.splice(i,1);0===e.length&&delete d.listeners[b];break}}});b=function(a,c,g,h){var j,k;if(typeof a==="undefined")return null;if(c.match(/^([\w\-]+)$/))h===true?d(a,c,g):e(a,c,g);else{c=c.split(" ");k=c.length;for(j=0;j<k;j++)b(a,c[j],g,h)}};c=function(a,c,d,e){b(a,d,function(b){var d, _listener:d}))},e=function(a,b,c){if("undefined"!==typeof a.detachEvent){var d=a.KIS_0_6_0;if(d&&d.listeners&&d.listeners[b])for(var e=d.listeners[b],f=e.length,g=0;g<f;g++)if(e[g].callback===c){a.detachEvent("on"+b,e[g]._listener);e.splice(g,1);0===e.length&&delete d.listeners[b];break}}});d=function(a,b,c,i){var j,o;if(typeof a==="undefined")return null;if(b.match(/^([\w\-]+)$/))i===true?f(a,b,c):e(a,b,c);else{b=b.split(" ");o=b.length;for(j=0;j<o;j++)d(a,b[j],c,i)}};c=function(a,b,c,e){d(a,c,function(c){var d,
i,g,b=b||window.event;i=$_.$(c,a);for(d in i){g=b.target||b.srcElement;if(g==i[d]){e.call(i[d],b);b.stopPropagation()}}},true)};$_.ext("event",{add:function(a,c){$_.each(function(d){b(d,a,c,true)})},remove:function(a,c){$_.each(function(d){b(d,a,c,false)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(e){c(e,a,b,d)})}})})(); g,f,c=c||window.event;g=$_.$(b,a);for(d in g){f=c.target||c.srcElement;if(f==g[d]){e.call(g[d],c);c.stopPropagation()}}},true)};$_.ext("event",{add:function(a,b){$_.each(function(c){d(c,a,b,true)})},remove:function(a,b){$_.each(function(c){d(c,a,b,false)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(e){c(e,a,b,d)})}})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(d){var d=(d.HTMLElement||d.Element).prototype,e=Object,b=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},f=function(b,d){if(""===d)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(d))throw new a("INVALID_CHARACTER_ERR", "undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(f){var f=(f.HTMLElement||f.Element).prototype,e=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1},a=function(a,b){this.name=a;this.code=DOMException[a];this.message=b},b=function(b,d){if(""===d)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(d))throw new a("INVALID_CHARACTER_ERR",
"String contains an invalid character");return c.call(b,d)},g=function(a){for(var c=b.call(a.className),c=c?c.split(/\s+/):[],d=0,f=c.length;d<f;d++)this.push(c[d]);this._updateClassName=function(){a.className=this.toString()}},h=g.prototype=[],j=function(){return new g(this)};a.prototype=Error.prototype;h.item=function(a){return this[a]||null};h.contains=function(a){return-1!==f(this,a+"")};h.add=function(a){a+="";-1===f(this,a)&&(this.push(a),this._updateClassName())};h.remove=function(a){a=f(this, "String contains an invalid character");return c.call(b,d)},l=function(a){for(var b=d.call(a.className),b=b?b.split(/\s+/):[],c=0,e=b.length;c<e;c++)this.push(b[c]);this._updateClassName=function(){a.className=this.toString()}},i=l.prototype=[],j=function(){return new l(this)};a.prototype=Error.prototype;i.item=function(a){return this[a]||null};i.contains=function(a){return-1!==b(this,a+"")};i.add=function(a){a+="";-1===b(this,a)&&(this.push(a),this._updateClassName())};i.remove=function(a){a=b(this,
a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};h.toggle=function(a){a+="";-1===f(this,a)?this.add(a):this.remove(a)};h.toString=function(){return this.join(" ")};if(e.defineProperty){h={get:j,enumerable:!0,configurable:!0};try{e.defineProperty(d,"classList",h)}catch(k){-2146823252===k.number&&(h.enumerable=!1,e.defineProperty(d,"classList",h))}}else e.prototype.__defineGetter__&&d.__defineGetter__("classList",j)}(self); a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};i.toggle=function(a){a+="";-1===b(this,a)?this.add(a):this.remove(a)};i.toString=function(){return this.join(" ")};if(e.defineProperty){i={get:j,enumerable:!0,configurable:!0};try{e.defineProperty(f,"classList",i)}catch(o){-2146823252===o.number&&(i.enumerable=!1,e.defineProperty(f,"classList",i))}}else e.prototype.__defineGetter__&&f.__defineGetter__("classList",j)}(self);
(function(){function d(b,c,a){var d,e;"undefined"!==typeof b.hasAttribute?(b.hasAttribute(c)&&(d=b.getAttribute(c)),e=!0):"undefined"!==typeof b[c]?(d=b[c],e=!1):"class"===c&&"undefined"!==typeof b.className&&(c="className",d=b.className,e=!1);if("undefined"===typeof d&&("undefined"===typeof a||null===a))return null;if("undefined"===typeof a)return d;"undefined"!==typeof a&&null!==a?!0===e?b.setAttribute(c,a):b[c]=a:null===a&&(!0===e?b.removeAttribute(c):delete b[c]);return"undefined"!==typeof a? (function(){function f(d,c,a){var b,e;"undefined"!==typeof d.hasAttribute?(d.hasAttribute(c)&&(b=d.getAttribute(c)),e=!0):"undefined"!==typeof d[c]?(b=d[c],e=!1):"class"===c&&"undefined"!==typeof d.className&&(c="className",b=d.className,e=!1);if("undefined"===typeof b&&("undefined"===typeof a||null===a))return null;if("undefined"===typeof a)return b;"undefined"!==typeof a&&null!==a?!0===e?d.setAttribute(c,a):d[c]=a:null===a&&(!0===e?d.removeAttribute(c):delete d[c]);return"undefined"!==typeof a?
a:d}function e(b,c,a){var d,c=c.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")});d={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof a&&"undefined"!==b.style[c])return b.style[c];if("undefined"===typeof a&&"undefined"!==b.style[d[c]])return b.style[d[c]];if("undefined"!==typeof b.style[c])return b.style[c]=a,null;if(b.style[d[c]])return b.style[d[c]]=a,null}$_.ext("dom",{addClass:function(b){$_.each(function(c){c.classList.add(b)})}, a:b}function e(d,c,a){var b,c=c.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")});b={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof a&&"undefined"!==d.style[c])return d.style[c];if("undefined"===typeof a&&"undefined"!==d.style[b[c]])return d.style[b[c]];if("undefined"!==typeof d.style[c])return d.style[c]=a,null;if(d.style[b[c]])return d.style[b[c]]=a,null}$_.ext("dom",{addClass:function(d){$_.each(function(c){c.classList.add(d)})},
removeClass:function(b){$_.each(function(c){c.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){"undefined"===typeof b&&(b="block");this.css("display",b)},attr:function(b,c){var a=this.el;if(1<a.length&&"undefined"===typeof c)return null;if(1<a.length&&"undefined"!==typeof c)$_.each(function(a){return d(a,b,c)});else return d(a,b,c)},text:function(b){var c,a,d;d=this.el;a="undefined"!==typeof d.textContent?"textContent":"undefined"!==typeof d.innerText?"innerText": removeClass:function(d){$_.each(function(c){c.classList.remove(d)})},hide:function(){this.css("display","none")},show:function(d){"undefined"===typeof d&&(d="block");this.css("display",d)},attr:function(d,c){var a=this.el;if(1<a.length&&"undefined"===typeof c)return null;if(1<a.length&&"undefined"!==typeof c)$_.each(function(a){return f(a,d,c)});else return f(a,d,c)},text:function(d){var c,a,b;b=this.el;a="undefined"!==typeof b.textContent?"textContent":"undefined"!==typeof b.innerText?"innerText":
"innerHTML";c=d[a];return"undefined"!==typeof b?d[a]=b:c},css:function(b,c){if("undefined"===typeof c)return e(this.el,b);$_.each(function(a){e(a,b,c)})},append:function(b){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",b):this.el.innerHTML+=b},prepend:function(b){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("afterbegin",b):this.el.innerHTML=b+this.el.innerHTML},html:function(b){"undefined"!==typeof b&&(this.el.innerHTML=b);return this.el.innerHTML}})})(); "innerHTML";c=b[a];return"undefined"!==typeof d?b[a]=d:c},css:function(d,c){if("undefined"===typeof c)return e(this.el,d);$_.each(function(a){e(a,d,c)})},append:function(d){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",d):this.el.innerHTML+=d},prepend:function(d){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("afterbegin",d):this.el.innerHTML=d+this.el.innerHTML},html:function(d){"undefined"!==typeof d&&(this.el.innerHTML=d);return this.el.innerHTML}})})();
(function(){$_("fieldset dl").dom.hide();$_("fieldset legend").event.add("click",function(){var d=$_("fieldset dl").dom;"none"==d.css("display").trim()?d.show():d.hide()})})(); var TINY={};function T$(f){return document.getElementById(f)}function T$$$(){return document.all?1:0}
TINY.editor=function(){function f(c,a){this.n=c;window[c]=this;this.t=T$(a.id);this.obj=a;this.xhtml=a.xhtml;var b=document.createElement("div"),f=document.createElement("div"),i=document.createElement("div"),j=a.controls.length,o=0;this.i=document.createElement("iframe");this.i.frameBorder=0;this.i.width=a.width||"500";this.i.height=a.height||"250";this.ie=T$$$();i.className=a.rowclass||"teheader";b.className=a.cssclass||"te";b.style.width=this.i.width+"px";b.appendChild(i);for(o;o<j;o++){var g=
a.controls[o];if("n"==g)i=document.createElement("div"),i.className=a.rowclass||"teheader",b.appendChild(i);else if("|"==g){var h=document.createElement("div");h.className=a.dividerclass||"tedivider";i.appendChild(h)}else if("font"==g){var g=document.createElement("select"),k=a.fonts||["Verdana","Arial","Georgia"],m=k.length,h=0;g.className="tefont";g.onchange=new Function(this.n+'.ddaction(this,"fontname")');g.options[0]=new Option("Font","");for(h;h<m;h++){var n=k[h];g.options[h+1]=new Option(n,
n)}i.appendChild(g)}else if("size"==g){g=document.createElement("select");m=a.sizes||[1,2,3,4,5,6,7];k=m.length;h=0;g.className="tesize";g.onchange=new Function(this.n+'.ddaction(this,"fontsize")');for(h;h<k;h++)n=m[h],g.options[h]=new Option(n,n);i.appendChild(g)}else if("style"==g){g=document.createElement("select");m=a.styles||[["Style",""],["Paragraph","<p>"],["Header 1","<h1>"],["Header 2","<h2>"],["Header 3","<h3>"],["Header 4","<h4>"],["Header 5","<h5>"],["Header 6","<h6>"]];k=m.length;h=0;
g.className="testyle";g.onchange=new Function(this.n+'.ddaction(this,"formatblock")');for(h;h<k;h++)n=m[h],g.options[h]=new Option(n[0],n[1]);i.appendChild(g)}else e[g]&&(k=document.createElement("div"),h=e[g],n=h[2],m=h[0]*d,k.className=a.controlclass,k.style.backgroundPosition="0px "+m+"px",k.title=h[1],h="a"==n?'.action("'+h[3]+'",0,'+(h[4]||0)+")":'.insert("'+h[4]+'","'+h[5]+'","'+h[3]+'")',k.onclick=new Function(this.n+("print"==g?".print()":h)),k.onmouseover=new Function(this.n+".hover(this,"+
m+",1)"),k.onmouseout=new Function(this.n+".hover(this,"+m+",0)"),i.appendChild(k),this.ie&&(k.unselectable="on"))}this.t.parentNode.insertBefore(b,this.t);this.t.style.width=this.i.width+"px";f.appendChild(this.t);f.appendChild(this.i);b.appendChild(f);this.t.style.display="none";a.footer&&(f=document.createElement("div"),f.className=a.footerclass||"tefooter",a.toggle&&(i=a.toggle,j=document.createElement("div"),j.className=i.cssclass||"toggle",j.innerHTML=a.toggletext||"source",j.onclick=new Function(this.n+
".toggle(0,this);return false"),f.appendChild(j)),a.resize&&(i=a.resize,j=document.createElement("div"),j.className=i.cssclass||"resize",j.onmousedown=new Function("event",this.n+".resize(event);return false"),j.onselectstart=function(){return false},f.appendChild(j)),b.appendChild(f));this.e=this.i.contentWindow.document;this.e.open();b="<html><head>";f=a.bodyid?' id="'+a.bodyid+'"':"";a.cssfile&&(b+='<link rel="stylesheet" href="'+a.cssfile+'" />');a.css&&(b+='<style type="text/css">'+a.css+"</style>");
b+="</head><body"+f+">"+(a.content||this.t.value);this.e.write(b+"</body></html>");this.e.close();this.e.designMode="on";this.d=1;if(this.xhtml)try{this.e.execCommand("styleWithCSS",0,0)}catch(p){try{this.e.execCommand("useCSS",0,1)}catch(q){}}}var e=[],d=-30;e.cut=[1,"Cut","a","cut",1];e.copy=[2,"Copy","a","copy",1];e.paste=[3,"Paste","a","paste",1];e.bold=[4,"Bold","a","bold"];e.italic=[5,"Italic","a","italic"];e.underline=[6,"Underline","a","underline"];e.strikethrough=[7,"Strikethrough","a","strikethrough"];
e.subscript=[8,"Subscript","a","subscript"];e.superscript=[9,"Superscript","a","superscript"];e.orderedlist=[10,"Insert Ordered List","a","insertorderedlist"];e.unorderedlist=[11,"Insert Unordered List","a","insertunorderedlist"];e.outdent=[12,"Outdent","a","outdent"];e.indent=[13,"Indent","a","indent"];e.leftalign=[14,"Left Align","a","justifyleft"];e.centeralign=[15,"Center Align","a","justifycenter"];e.rightalign=[16,"Right Align","a","justifyright"];e.blockjustify=[17,"Block Justify","a","justifyfull"];
e.undo=[18,"Undo","a","undo"];e.redo=[19,"Redo","a","redo"];e.image=[20,"Insert Image","i","insertimage","Enter Image URL:","http://"];e.hr=[21,"Insert Horizontal Rule","a","inserthorizontalrule"];e.link=[22,"Insert Hyperlink","i","createlink","Enter URL:","http://"];e.unlink=[23,"Remove Hyperlink","a","unlink"];e.unformat=[24,"Remove Formatting","a","removeformat"];e.print=[25,"Print","a","print"];f.prototype.print=function(){this.i.contentWindow.print()};f.prototype.hover=function(c,a,b){c.style.backgroundPosition=
(b?"34px ":"0px ")+a+"px"};f.prototype.ddaction=function(c,a){this.action(a,c.options[c.selectedIndex].value)};f.prototype.action=function(c,a,b){b&&!this.ie?alert("Your browser does not support this function."):this.e.execCommand(c,0,a||null)};f.prototype.insert=function(c,a,b){c=prompt(c,a);null!=c&&""!=c&&this.e.execCommand(b,0,c)};f.prototype.setfont=function(){execCommand("formatblock",0,hType)};f.prototype.resize=function(c){this.mv&&this.freeze();this.i.bcs=TINY.cursor.top(c);this.mv=new Function("event",
this.n+".move(event)");this.sr=new Function(this.n+".freeze()");this.ie?(document.attachEvent("onmousemove",this.mv),document.attachEvent("onmouseup",this.sr)):(document.addEventListener("mousemove",this.mv,1),document.addEventListener("mouseup",this.sr,1))};f.prototype.move=function(c){c=TINY.cursor.top(c);this.i.height=parseInt(this.i.height)+c-this.i.bcs;this.i.bcs=c};f.prototype.freeze=function(){this.ie?(document.detachEvent("onmousemove",this.mv),document.detachEvent("onmouseup",this.sr)):(document.removeEventListener("mousemove",
this.mv,1),document.removeEventListener("mouseup",this.sr,1))};f.prototype.toggle=function(c,a){if(this.d){if(b=this.e.body.innerHTML,this.xhtml&&(b=b.replace(/<span class="apple-style-span">(.*)<\/span>/gi,"$1"),b=b.replace(/ class="apple-style-span"/gi,""),b=b.replace(/<span style="">/gi,""),b=b.replace(/<br>/gi,"<br />"),b=b.replace(/<br ?\/?>$/gi,""),b=b.replace(/^<br ?\/?>/gi,""),b=b.replace(/(<img [^>]+[^\/])>/gi,"$1 />"),b=b.replace(/<b\b[^>]*>(.*?)<\/b[^>]*>/gi,"<strong>$1</strong>"),b=b.replace(/<i\b[^>]*>(.*?)<\/i[^>]*>/gi,
"<em>$1</em>"),b=b.replace(/<u\b[^>]*>(.*?)<\/u[^>]*>/gi,'<span style="text-decoration:underline">$1</span>'),b=b.replace(/<(b|strong|em|i|u) style="font-weight: normal;?">(.*)<\/(b|strong|em|i|u)>/gi,"$2"),b=b.replace(/<(b|strong|em|i|u) style="(.*)">(.*)<\/(b|strong|em|i|u)>/gi,'<span style="$2"><$4>$3</$4></span>'),b=b.replace(/<span style="font-weight: normal;?">(.*)<\/span>/gi,"$1"),b=b.replace(/<span style="font-weight: bold;?">(.*)<\/span>/gi,"<strong>$1</strong>"),b=b.replace(/<span style="font-style: italic;?">(.*)<\/span>/gi,
"<em>$1</em>"),b=b.replace(/<span style="font-weight: bold;?">(.*)<\/span>|<b\b[^>]*>(.*?)<\/b[^>]*>/gi,"<strong>$1</strong>")),a&&(a.innerHTML=this.obj.toggletext||"wysiwyg"),this.t.value=b,!c)this.t.style.height=this.i.height+"px",this.i.style.display="none",this.t.style.display="block",this.d=0}else{var b=this.t.value;a&&(a.innerHTML=this.obj.toggletext||"source");this.xhtml&&!this.ie&&(b=b.replace(/<strong>(.*)<\/strong>/gi,'<span style="font-weight: bold;">$1</span>'),b=b.replace(/<em>(.*)<\/em>/gi,
'<span style="font-weight: italic;">$1</span>'));this.e.body.innerHTML=b;this.t.style.display="none";this.i.style.display="block";this.d=1}};f.prototype.post=function(){this.d&&this.toggle(1)};return{edit:f}}();TINY.cursor=function(){return{top:function(f){return T$$$()?window.event.clientY+document.documentElement.scrollTop+document.body.scrollTop:f.clientY+window.scrollY}}}();
(function(){$_("fieldset dl").dom.hide();$_("fieldset legend").event.add("click",function(){var f=$_("fieldset dl").dom;"none"==f.css("display").trim()?f.show():f.hide()});$_("button.delete").event.add("click",function(){var f=this.parentNode.id,f=f.split("_");confirm("Are you sure you want to delete this "+f[0]+"? Deleting this item will delete all items under it. There is no undo.")});new TINY.editor.edit("editor",{id:"input",width:450,height:175,cssclass:"te",controlclass:"tecontrol",rowclass:"teheader",
dividerclass:"tedivider",controls:"bold italic underline | subscript superscript | orderedlist unorderedlist | leftalign centeralign rightalign | unformat | undo redo n image hr link unlink | cut copy paste print".split(" "),footer:!0,xhtml:!0,cssfile:"//github.timshomepage.net/meta/assets/css.php/g/css",bodyid:"editor",footerclass:"tefooter",toggle:{text:"source",activetext:"wysiwyg",cssclass:"toggle"},resize:{cssclass:"resize"}})})();

View File

@ -2,7 +2,7 @@
"use strict"; "use strict";
// Show/hide forms based on use // ! Show/hide forms based on use
$_("fieldset dl").dom.hide(); $_("fieldset dl").dom.hide();
$_("fieldset legend").event.add('click', function(e){ $_("fieldset legend").event.add('click', function(e){
var form = $_("fieldset dl").dom; var form = $_("fieldset dl").dom;
@ -12,4 +12,59 @@
: form.hide(); : form.hide();
}); });
var meta = {};
/**
* Deletes a genre/category/section/data item
* based on the current page context
*/
meta.delete_item = function(e) {
// Get the type/id of the item
var item_id = this.parentNode.id;
item_id = item_id.split('_');
var id = item_id[1];
var type = item_id[0];
// Confirm deletion
var confirm_string = "Are you sure you want to delete this "+type+"? Deleting this item will delete all items under it. There is no undo.";
var do_delete = confirm(confirm_string);
// Call the appropriate deletion method
// Show status message
};
// -------------------------------------------------
// ! Event binding
// -------------------------------------------------
// Delete Button functionality
$_("button.delete").event.add('click', meta.delete_item);
// WYSIWYG
new TINY.editor.edit('editor',{
id:'input',
width:450,
height:175,
cssclass:'te',
controlclass:'tecontrol',
rowclass:'teheader',
dividerclass:'tedivider',
controls:['bold','italic','underline','|','subscript','superscript','|',
'orderedlist','unorderedlist','|','leftalign',
'centeralign','rightalign','|','unformat','|','undo','redo','n',
'image','hr','link','unlink','|','cut','copy','paste','print'],
footer:true,
//fonts:['Verdana','Arial','Georgia','Trebuchet MS'],
xhtml:true,
cssfile:'//github.timshomepage.net/meta/assets/css.php/g/css',
bodyid:'editor',
footerclass:'tefooter',
toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'},
resize:{cssclass:'resize'}
});
}()); }());

373
assets/js/tinyeditor.js Executable file
View File

@ -0,0 +1,373 @@
var TINY = {};
function T$(i)
{
return document.getElementById(i)
}
function T$$$()
{
return document.all ? 1 : 0
}
TINY.editor = function ()
{
var c = [],
offset = -30;
c['cut'] = [1, 'Cut', 'a', 'cut', 1];
c['copy'] = [2, 'Copy', 'a', 'copy', 1];
c['paste'] = [3, 'Paste', 'a', 'paste', 1];
c['bold'] = [4, 'Bold', 'a', 'bold'];
c['italic'] = [5, 'Italic', 'a', 'italic'];
c['underline'] = [6, 'Underline', 'a', 'underline'];
c['strikethrough'] = [7, 'Strikethrough', 'a', 'strikethrough'];
c['subscript'] = [8, 'Subscript', 'a', 'subscript'];
c['superscript'] = [9, 'Superscript', 'a', 'superscript'];
c['orderedlist'] = [10, 'Insert Ordered List', 'a', 'insertorderedlist'];
c['unorderedlist'] = [11, 'Insert Unordered List', 'a', 'insertunorderedlist'];
c['outdent'] = [12, 'Outdent', 'a', 'outdent'];
c['indent'] = [13, 'Indent', 'a', 'indent'];
c['leftalign'] = [14, 'Left Align', 'a', 'justifyleft'];
c['centeralign'] = [15, 'Center Align', 'a', 'justifycenter'];
c['rightalign'] = [16, 'Right Align', 'a', 'justifyright'];
c['blockjustify'] = [17, 'Block Justify', 'a', 'justifyfull'];
c['undo'] = [18, 'Undo', 'a', 'undo'];
c['redo'] = [19, 'Redo', 'a', 'redo'];
c['image'] = [20, 'Insert Image', 'i', 'insertimage', 'Enter Image URL:', 'http://'];
c['hr'] = [21, 'Insert Horizontal Rule', 'a', 'inserthorizontalrule'];
c['link'] = [22, 'Insert Hyperlink', 'i', 'createlink', 'Enter URL:', 'http://'];
c['unlink'] = [23, 'Remove Hyperlink', 'a', 'unlink'];
c['unformat'] = [24, 'Remove Formatting', 'a', 'removeformat'];
c['print'] = [25, 'Print', 'a', 'print'];
function edit(n, obj)
{
this.n = n;
window[n] = this;
this.t = T$(obj.id);
this.obj = obj;
this.xhtml = obj.xhtml;
var p = document.createElement('div'),
w = document.createElement('div'),
h = document.createElement('div'),
l = obj.controls.length,
i = 0;
this.i = document.createElement('iframe');
this.i.frameBorder = 0;
this.i.width = obj.width || '500';
this.i.height = obj.height || '250';
this.ie = T$$$();
h.className = obj.rowclass || 'teheader';
p.className = obj.cssclass || 'te';
p.style.width = this.i.width + 'px';
p.appendChild(h);
for (i; i < l; i++)
{
var id = obj.controls[i];
if (id == 'n')
{
h = document.createElement('div');
h.className = obj.rowclass || 'teheader';
p.appendChild(h)
}
else if (id == '|')
{
var d = document.createElement('div');
d.className = obj.dividerclass || 'tedivider';
h.appendChild(d)
}
else if (id == 'font')
{
var sel = document.createElement('select'),
fonts = obj.fonts || ['Verdana', 'Arial', 'Georgia'],
fl = fonts.length,
x = 0;
sel.className = 'tefont';
sel.onchange = new Function(this.n + '.ddaction(this,"fontname")');
sel.options[0] = new Option('Font', '');
for (x; x < fl; x++)
{
var font = fonts[x];
sel.options[x + 1] = new Option(font, font)
}
h.appendChild(sel)
}
else if (id == 'size')
{
var sel = document.createElement('select'),
sizes = obj.sizes || [1, 2, 3, 4, 5, 6, 7],
sl = sizes.length,
x = 0;
sel.className = 'tesize';
sel.onchange = new Function(this.n + '.ddaction(this,"fontsize")');
for (x; x < sl; x++)
{
var size = sizes[x];
sel.options[x] = new Option(size, size)
}
h.appendChild(sel)
}
else if (id == 'style')
{
var sel = document.createElement('select'),
styles = obj.styles || [
['Style', ''],
['Paragraph', '<p>'],
['Header 1', '<h1>'],
['Header 2', '<h2>'],
['Header 3', '<h3>'],
['Header 4', '<h4>'],
['Header 5', '<h5>'],
['Header 6', '<h6>']
],
sl = styles.length,
x = 0;
sel.className = 'testyle';
sel.onchange = new Function(this.n + '.ddaction(this,"formatblock")');
for (x; x < sl; x++)
{
var style = styles[x];
sel.options[x] = new Option(style[0], style[1])
}
h.appendChild(sel)
}
else if (c[id])
{
var div = document.createElement('div'),
x = c[id],
func = x[2],
ex, pos = x[0] * offset;
div.className = obj.controlclass;
div.style.backgroundPosition = '0px ' + pos + 'px';
div.title = x[1];
ex = func == 'a' ? '.action("' + x[3] + '",0,' + (x[4] || 0) + ')' : '.insert("' + x[4] + '","' + x[5] + '","' + x[3] + '")';
div.onclick = new Function(this.n + (id == 'print' ? '.print()' : ex));
div.onmouseover = new Function(this.n + '.hover(this,' + pos + ',1)');
div.onmouseout = new Function(this.n + '.hover(this,' + pos + ',0)');
h.appendChild(div);
if (this.ie)
{
div.unselectable = 'on'
}
}
}
this.t.parentNode.insertBefore(p, this.t);
this.t.style.width = this.i.width + 'px';
w.appendChild(this.t);
w.appendChild(this.i);
p.appendChild(w);
this.t.style.display = 'none';
if (obj.footer)
{
var f = document.createElement('div');
f.className = obj.footerclass || 'tefooter';
if (obj.toggle)
{
var to = obj.toggle,
ts = document.createElement('div');
ts.className = to.cssclass || 'toggle';
ts.innerHTML = obj.toggletext || 'source';
ts.onclick = new Function(this.n + '.toggle(0,this);return false');
f.appendChild(ts)
}
if (obj.resize)
{
var ro = obj.resize,
rs = document.createElement('div');
rs.className = ro.cssclass || 'resize';
rs.onmousedown = new Function('event', this.n + '.resize(event);return false');
rs.onselectstart = function ()
{
return false
};
f.appendChild(rs)
}
p.appendChild(f)
}
this.e = this.i.contentWindow.document;
this.e.open();
var m = '<html><head>',
bodyid = obj.bodyid ? " id=\"" + obj.bodyid + "\"" : "";
if (obj.cssfile)
{
m += '<link rel="stylesheet" href="' + obj.cssfile + '" />'
}
if (obj.css)
{
m += '<style type="text/css">' + obj.css + '</style>'
}
m += '</head><body' + bodyid + '>' + (obj.content || this.t.value);
m += '</body></html>';
this.e.write(m);
this.e.close();
this.e.designMode = 'on';
this.d = 1;
if (this.xhtml)
{
try
{
this.e.execCommand("styleWithCSS", 0, 0)
}
catch (e)
{
try
{
this.e.execCommand("useCSS", 0, 1)
}
catch (e)
{}
}
}
};
edit.prototype.print = function ()
{
this.i.contentWindow.print()
},
edit.prototype.hover = function (div, pos, dir)
{
div.style.backgroundPosition = (dir ? '34px ' : '0px ') + (pos) + 'px'
},
edit.prototype.ddaction = function (dd, a)
{
var i = dd.selectedIndex,
v = dd.options[i].value;
this.action(a, v)
},
edit.prototype.action = function (cmd, val, ie)
{
if (ie && !this.ie)
{
alert('Your browser does not support this function.')
}
else
{
this.e.execCommand(cmd, 0, val || null)
}
},
edit.prototype.insert = function (pro, msg, cmd)
{
var val = prompt(pro, msg);
if (val != null && val != '')
{
this.e.execCommand(cmd, 0, val)
}
},
edit.prototype.setfont = function ()
{
execCommand('formatblock', 0, hType)
},
edit.prototype.resize = function (e)
{
if (this.mv)
{
this.freeze()
}
this.i.bcs = TINY.cursor.top(e);
this.mv = new Function('event', this.n + '.move(event)');
this.sr = new Function(this.n + '.freeze()');
if (this.ie)
{
document.attachEvent('onmousemove', this.mv);
document.attachEvent('onmouseup', this.sr)
}
else
{
document.addEventListener('mousemove', this.mv, 1);
document.addEventListener('mouseup', this.sr, 1)
}
},
edit.prototype.move = function (e)
{
var pos = TINY.cursor.top(e);
this.i.height = parseInt(this.i.height) + pos - this.i.bcs;
this.i.bcs = pos
},
edit.prototype.freeze = function ()
{
if (this.ie)
{
document.detachEvent('onmousemove', this.mv);
document.detachEvent('onmouseup', this.sr)
}
else
{
document.removeEventListener('mousemove', this.mv, 1);
document.removeEventListener('mouseup', this.sr, 1)
}
},
edit.prototype.toggle = function (post, div)
{
if (!this.d)
{
var v = this.t.value;
if (div)
{
div.innerHTML = this.obj.toggletext || 'source'
}
if (this.xhtml && !this.ie)
{
v = v.replace(/<strong>(.*)<\/strong>/gi, '<span style="font-weight: bold;">$1</span>');
v = v.replace(/<em>(.*)<\/em>/gi, '<span style="font-weight: italic;">$1</span>')
}
this.e.body.innerHTML = v;
this.t.style.display = 'none';
this.i.style.display = 'block';
this.d = 1
}
else
{
var v = this.e.body.innerHTML;
if (this.xhtml)
{
v = v.replace(/<span class="apple-style-span">(.*)<\/span>/gi, '$1');
v = v.replace(/ class="apple-style-span"/gi, '');
v = v.replace(/<span style="">/gi, '');
v = v.replace(/<br>/gi, '<br />');
v = v.replace(/<br ?\/?>$/gi, '');
v = v.replace(/^<br ?\/?>/gi, '');
v = v.replace(/(<img [^>]+[^\/])>/gi, '$1 />');
v = v.replace(/<b\b[^>]*>(.*?)<\/b[^>]*>/gi, '<strong>$1</strong>');
v = v.replace(/<i\b[^>]*>(.*?)<\/i[^>]*>/gi, '<em>$1</em>');
v = v.replace(/<u\b[^>]*>(.*?)<\/u[^>]*>/gi, '<span style="text-decoration:underline">$1</span>');
v = v.replace(/<(b|strong|em|i|u) style="font-weight: normal;?">(.*)<\/(b|strong|em|i|u)>/gi, '$2');
v = v.replace(/<(b|strong|em|i|u) style="(.*)">(.*)<\/(b|strong|em|i|u)>/gi, '<span style="$2"><$4>$3</$4></span>');
v = v.replace(/<span style="font-weight: normal;?">(.*)<\/span>/gi, '$1');
v = v.replace(/<span style="font-weight: bold;?">(.*)<\/span>/gi, '<strong>$1</strong>');
v = v.replace(/<span style="font-style: italic;?">(.*)<\/span>/gi, '<em>$1</em>');
v = v.replace(/<span style="font-weight: bold;?">(.*)<\/span>|<b\b[^>]*>(.*?)<\/b[^>]*>/gi, '<strong>$1</strong>')
}
if (div)
{
div.innerHTML = this.obj.toggletext || 'wysiwyg'
}
this.t.value = v;
if (!post)
{
this.t.style.height = this.i.height + 'px';
this.i.style.display = 'none';
this.t.style.display = 'block';
this.d = 0
}
}
},
edit.prototype.post = function ()
{
if (this.d)
{
this.toggle(1)
}
};
return {
edit: edit
}
}();
TINY.cursor = function ()
{
return {
top: function (e)
{
return T$$$() ? window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop : e.clientY + window.scrollY
}
}
}();

35
assets/js/tinyeditor/index.html Executable file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TinyEditor - JavaScript WYSIWYG Editor</title>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="tinyeditor.js"></script>
</head>
<body>
<textarea id="input" style="width:400px; height:200px"></textarea>
<script type="text/javascript">
new TINY.editor.edit('editor',{
id:'input',
width:584,
height:175,
cssclass:'te',
controlclass:'tecontrol',
rowclass:'teheader',
dividerclass:'tedivider',
controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|',
'orderedlist','unorderedlist','|','outdent','indent','|','leftalign',
'centeralign','rightalign','blockjustify','|','unformat','|','undo','redo','n',
'font','size','style','|','image','hr','link','unlink','|','cut','copy','paste','print'],
footer:true,
fonts:['Verdana','Arial','Georgia','Trebuchet MS'],
xhtml:true,
cssfile:'style.css',
bodyid:'editor',
footerclass:'tefooter',
toggle:{text:'source',activetext:'wysiwyg',cssclass:'toggle'},
resize:{cssclass:'resize'}
});
</script>
</body>
</html>

1
assets/js/tinyeditor/packed.js Executable file

File diff suppressed because one or more lines are too long