From a9cfe01a284c48b245a40ff3d02ebd2183fcba66 Mon Sep 17 00:00:00 2001 From: Pierre Spring Date: Fri, 24 Sep 2010 01:14:16 +0200 Subject: started jQueryfying media manager --- lib/scripts/media.js | 495 +++++++++++++++++++++++++-------------------------- 1 file changed, 240 insertions(+), 255 deletions(-) (limited to 'lib/scripts') diff --git a/lib/scripts/media.js b/lib/scripts/media.js index 6a5107fcc..9338ae078 100644 --- a/lib/scripts/media.js +++ b/lib/scripts/media.js @@ -2,6 +2,10 @@ /*global jQuery, window, DOKU_BASE*/ "use strict"; +// TODO +// * fix the css to have pointers on the +/- images in the tree when JS is enabled +// * fix the css to have pointers on a.select when JS is enabled + /** * JavaScript functionalitiy for the media management popup * @@ -9,34 +13,56 @@ * @author Pierre Spring */ (function ($) { + var toggle, list, cleanup_content; + + /** + * Prefills the wikiname. + * + * @author Andreas Gohr + */ + suggest = function(){ + var file, name, text; + + file = $(this); + name = $('#upload__name'); + if(!file.size() || !name.size()) return; + + text = file.val(); + text = text.substr(text.lastIndexOf('/')+1); + text = text.substr(text.lastIndexOf('\\')+1); + name.val(text); + }; + /** * Open or close a subtree using AJAX * * @author Andreas Gohr + * @author Pierre Spring */ toggle = function (event) { var clicky, listitem, sublist, link, ul; - + + event.preventDefault(); // TODO: really here? + var clicky = $(this); var listitem = clicky.parent(); // if already open, close by removing the sublist - var sublist = listitem.find('ul').first(); + sublist = listitem.find('ul').first(); if(sublist.size()){ sublist.remove(); // TODO: really? we could just hide it, right? clicky.attr('src', DOKU_BASE + 'lib/images/plus.gif'); - event.preventDefault(); // TODO: really here? return; } // get the enclosed link (is always the first one) link = listitem.find('a').first(); - + //prepare the new ul ul = $('
    '); //fixme add classname here - + $.post( DOKU_BASE + 'lib/exe/ajax.php', link.attr('search').substr(1) + '&call=medians', @@ -46,77 +72,230 @@ }, 'html' ); - + clicky.attr('src', DOKU_BASE + 'lib/images/minus.gif'); }; - - $(function () { - $('#media__tree').delegate('img', 'click', toggle); - }); -}(jQuery)); - -var media_manager = { - keepopen: false, - hide: false, - align: false, - popup: false, - id: false, - display: false, - link: false, - size: false, - ext: false, /** - * Attach event handlers to all "folders" below the given element + * list the content of a namespace using AJAX * * @author Andreas Gohr + * @author Pierre Spring */ - treeattach: function(obj){ - if(!obj) return; + list = function (event) { + var link, content; + link = $(this); - var items = obj.getElementsByTagName('li'); - for(var i=0; i'); - // attach action load folder list via AJAX - var link = elem.getElementsByTagName('a')[0]; - link.style.cursor = 'pointer'; - addEvent(link,'click',function(event){ return media_manager.list(event,this); }); - } - }, + // fetch the subtree + $.post( + DOKU_BASE + 'lib/exe/ajax.php', + link.attr('search').substr(1)+'&call=medialist', + function (data) { + content.html(data); + cleanup_content(content); - /** - * Attach the image selector action to all links below the given element - * also add the action to autofill the "upload as" field - * - * @author Andreas Gohr - */ - selectorattach: function(obj){ - if(!obj) return; - var items = getElementsByClass('select',obj,'a'); - for(var i=0; i - */ - list: function(event,link){ - // prepare an AJAX call to fetch the subtree - var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php'); - ajax.AjaxFailedAlert = ''; - ajax.encodeURIString = false; - if(ajax.failed) return true; - - cleanMsgArea(); - - var content = $('media__content'); - content.innerHTML = '...'; - - ajax.elementObj = content; - ajax.afterCompletion = function(){ - media_manager.selectorattach(content); - media_manager.confirmattach(content); - media_manager.updatehide(); - media_manager.initFlashUpload(); - }; - ajax.runAJAX(link.search.substr(1)+'&call=medialist'); - return false; - }, - - /** - * Prefills the wikiname. - * - * @author Andreas Gohr - */ - suggest: function(){ - var file = $('upload__file'); - var name = $('upload__name'); - if(!file || !name) return; - - var text = file.value; - text = text.substr(text.lastIndexOf('/')+1); - text = text.substr(text.lastIndexOf('\\')+1); - name.value = text; - }, - - initFlashUpload: function(){ if(!hasFlash(8)) return; var oform = $('dw__upload'); @@ -785,7 +771,6 @@ var media_manager = { addInitEvent(function(){ //media_manager.treeattach($('media__tree')); - media_manager.selectorattach($('media__content')); media_manager.confirmattach($('media__content')); media_manager.attachoptions($('media__opts')); media_manager.initpopup(); -- cgit v1.2.3