summaryrefslogtreecommitdiff
path: root/lib/scripts/script.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2006-05-19 18:50:23 +0200
committerAndreas Gohr <andi@splitbrain.org>2006-05-19 18:50:23 +0200
commit3df72098bbc205fa4bd4735d52d2626baad93548 (patch)
tree105ca14ca3ff596ad4c7d20a1985aeb02c5f7caa /lib/scripts/script.js
parenta219c1f00349b720d262939fec3e7baf19a63402 (diff)
downloadrpg-3df72098bbc205fa4bd4735d52d2626baad93548.tar.gz
rpg-3df72098bbc205fa4bd4735d52d2626baad93548.tar.bz2
new mediamanager
This patch adds a completely rewritten media popup. The following noteworthy changes were made: - media manager uses a collapsible namespace tree - media manager uses AJAX if available - media manager popup can be kept open when selecting a media file - only one template is used for the media manager :!: Template - Editable image metadata is configured in conf/mediameta.php now - The JS cookie mechanism was enhanced to store key/value pairs - Language strings can be exported to JS in js.php darcs-hash:20060519165023-7ad00-4932b4553fc919aa4a8b8187958b823acf4f8cee.gz
Diffstat (limited to 'lib/scripts/script.js')
-rw-r--r--lib/scripts/script.js130
1 files changed, 45 insertions, 85 deletions
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index bd7af48da..df12a29fb 100644
--- a/lib/scripts/script.js
+++ b/lib/scripts/script.js
@@ -78,6 +78,30 @@ function isset(varname){
}
/**
+ * Select elements by their class name
+ *
+ * @author Dustin Diaz <dustin [at] dustindiaz [dot] com>
+ * @link http://www.dustindiaz.com/getelementsbyclass/
+ */
+function getElementsByClass(searchClass,node,tag) {
+ var classElements = new Array();
+ if ( node == null )
+ node = document;
+ if ( tag == null )
+ tag = '*';
+ var els = node.getElementsByTagName(tag);
+ var elsLen = els.length;
+ var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
+ for (i = 0, j = 0; i < elsLen; i++) {
+ if ( pattern.test(els[i].className) ) {
+ classElements[j] = els[i];
+ j++;
+ }
+ }
+ return classElements;
+}
+
+/**
* Get the X offset of the top left corner of the given object
*
* @link http://www.quirksmode.org/index.html?/js/findpos.html
@@ -186,31 +210,6 @@ function hideLoadBar(id){
if(obj) obj.style.display="none";
}
-/*
- * Insert the selected filename and close the window
- *
- * @see http://www.alexking.org/index.php?content=software/javascript/content.php
- */
-function mediaSelect(file){
- opener.insertTags('wiki__text','{{'+file+'|','}}','');
- window.close();
-}
-
-/**
- * For the upload Dialog. Prefills the wikiname.
- */
-function suggestWikiname(){
- var form = $('dw__upload');
- if(!form) return;
-
- var file = form.elements.upload.value;
-
- file = file.substr(file.lastIndexOf('/')+1);
- file = file.substr(file.lastIndexOf('\\')+1);
-
- form.elements.id.value = file;
-}
-
/**
* Adds the toggle switch to the TOC
*/
@@ -255,55 +254,6 @@ function toggleToc() {
}
/*
- * This sets a cookie by JavaScript
- *
- * @see http://www.webreference.com/js/column8/functions.html
- */
-function setCookie(name, value, expires, path, domain, secure) {
- var curCookie = name + "=" + escape(value) +
- ((expires) ? "; expires=" + expires.toGMTString() : "") +
- ((path) ? "; path=" + path : "") +
- ((domain) ? "; domain=" + domain : "") +
- ((secure) ? "; secure" : "");
- document.cookie = curCookie;
-}
-
-/*
- * This reads a cookie by JavaScript
- *
- * @see http://www.webreference.com/js/column8/functions.html
- */
-function getCookie(name) {
- var dc = document.cookie;
- var prefix = name + "=";
- var begin = dc.indexOf("; " + prefix);
- if (begin == -1) {
- begin = dc.indexOf(prefix);
- if (begin !== 0){ return null; }
- } else {
- begin += 2;
- }
- var end = document.cookie.indexOf(";", begin);
- if (end == -1){
- end = dc.length;
- }
- return unescape(dc.substring(begin + prefix.length, end));
-}
-
-/*
- * This is needed for the cookie functions
- *
- * @see http://www.webreference.com/js/column8/functions.html
- */
-function fixDate(date) {
- var base = new Date(0);
- var skew = base.getTime();
- if (skew > 0){
- date.setTime(date.getTime() - skew);
- }
-}
-
-/*
* This enables/disables checkboxes for acl-administration
*
* @author Frank Schubert <frank@schokilade.de>
@@ -374,24 +324,25 @@ function fnt(id, e, evt) {
* Add the edit window size controls
*/
function initSizeCtl(ctlid,edid){
- if(!document.getElementById){ return; }
+ if(!document.getElementById){ return; }
var ctl = $(ctlid);
var textarea = $(edid);
+ if(!ctl || !textarea) return;
- var hgt = getCookie('DokuWikisizeCtl');
- if(hgt === null || hgt === ''){
- textarea.style.height = '300px';
- }else{
+ var hgt = DokuCookie.getValue('sizeCtl');
+ if(hgt){
textarea.style.height = hgt;
+ }else{
+ textarea.style.height = '300px';
}
var l = document.createElement('img');
var s = document.createElement('img');
l.src = DOKU_BASE+'lib/images/larger.gif';
s.src = DOKU_BASE+'lib/images/smaller.gif';
- addEvent(l,'click',function(){sizeCtl(edid,100);});
- addEvent(s,'click',function(){sizeCtl(edid,-100);});
+ addEvent(l,'click',function(){sizeCtl(edid,100);});
+ addEvent(s,'click',function(){sizeCtl(edid,-100);});
ctl.appendChild(l);
ctl.appendChild(s);
}
@@ -405,10 +356,7 @@ function sizeCtl(edid,val){
height += val;
textarea.style.height = height+'px';
- var now = new Date();
- fixDate(now);
- now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); //expire in a year
- setCookie('DokuWikisizeCtl',textarea.style.height,now);
+ DokuCookie.setValue('sizeCtl',textarea.style.height);
}
/**
@@ -432,3 +380,15 @@ function scrollToMarker(){
var obj = $('scroll__here');
if(obj) obj.scrollIntoView();
}
+
+/**
+ * Remove messages
+ */
+function cleanMsgArea(){
+ var elems = getElementsByClass('(success|info|error)',document,'div');
+ if(elems){
+ for(var i=0; i<elems.length; i++){
+ elems[i].style.display = 'none';
+ }
+ }
+}