r57963 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57962‎ | r57963 | r57964 >
Date:00:23, 21 October 2009
Author:dale
Status:deferred
Tags:
Comment:
* html5 file api drag drop file stubs
Modified paths:
  • /trunk/phase3/js2/editPage.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/dragDropFile.js (added) (history)
  • /trunk/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /trunk/phase3/js2/mwEmbed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/phase3/js2/editPage.js
@@ -24,6 +24,11 @@
2525 var amwConf = $j.extend( true, defaultAddMediaConfig, mwAddMediaConfig );
2626 // kind of tricky, it would be nice to use run on ready "loader" call here
2727 var didWikiEditorBind = false;
 28+
 29+ //setup the drag drop binding (will only work for html5 upload browsers)
 30+ //$j( 'textarea#wpTextbox1' ).dragFileUpload();
 31+
 32+ //set up the add-media-wizard binding:
2833 if( typeof $j.wikiEditor != 'undefined' ) {
2934 $j( 'textarea#wpTextbox1' ).bind( 'wikiEditor-toolbar-buildSection-main',
3035 function( e, section ) {
Index: trunk/phase3/js2/mwEmbed/libAddMedia/dragDropFile.js
@@ -0,0 +1,75 @@
 2+/* firefox 3.6 drag-drop uploading
 3+*/
 4+var TCNDDU = TCNDDU || {};
 5+
 6+(function( $ ) {
 7+ $.dragDropFile = function ( selector ) {
 8+ //setup drag binding and highlight
 9+ var dC = $j( selector ).get(0);
 10+ dC.addEventListener("dragenter",
 11+ function(event){
 12+ $j(dC).css('border', 'solid red');
 13+ event.stopPropagation();
 14+ event.preventDefault();
 15+ }, false);
 16+ dC.addEventListener("dragleave",
 17+ function(event){
 18+ //default textbox css (should be an easy way to do this)
 19+ $j(dC).css('border', '');
 20+ event.stopPropagation();
 21+ event.preventDefault();
 22+ }, false);
 23+ dC.addEventListener("dragover",
 24+ function(event){
 25+ event.stopPropagation();
 26+ event.preventDefault();
 27+ }, false);
 28+ dC.addEventListener("drop",
 29+ function( event ){
 30+ //for some reason scope does not persist for events so here we go:
 31+ doDrop( event );
 32+ //handle the drop loader and call event
 33+
 34+ }, false);
 35+ function doDrop(event){
 36+ var dt = event.dataTransfer,
 37+ files = dt.files,
 38+ imgPreviewFragment = document.createDocumentFragment(),
 39+ count = files.length,
 40+ domElements;
 41+
 42+ event.stopPropagation();
 43+ event.preventDefault();
 44+ // ( error out if they dragged multiple files for now)
 45+ if( files.length > 1 ){
 46+ js_log( 'errro multiple files');
 47+
 48+ return false;
 49+ }
 50+ for (var i = 0; i < count; i++) {
 51+ if(files[i].fileSize < 1048576) {
 52+ domElements = [
 53+ document.createElement('li'),
 54+ document.createElement('a'),
 55+ document.createElement('img')
 56+ ];
 57+
 58+ domElements[2].src = files[i].getAsDataURL(); // base64 encodes local file(s)
 59+ domElements[2].width = 300;
 60+ domElements[2].height = 200;
 61+ domElements[1].appendChild(domElements[2]);
 62+ domElements[0].id = "item"+i;
 63+ domElements[0].appendChild(domElements[1]);
 64+
 65+ imgPreviewFragment.appendChild(domElements[0]);
 66+
 67+ dropListing.appendChild(imgPreviewFragment);
 68+
 69+ TCNDDU.processXHR(files.item(i), i);
 70+ } else {
 71+ alert("file is too big, needs to be below 1mb");
 72+ }
 73+ }
 74+ }
 75+
 76+})(window.$mw);
Index: trunk/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -508,23 +508,20 @@
509509 //grab the extension:
510510 var sf = _this.fogg.sourceFilename;
511511 var ext = '';
512 - if( sf.lastIndexOf('.') != -1){
513 - ext = sf.substring( sf.lastIndexOf('.')+1 ).toLowerCase();
514 - }
 512+ if( sf.lastIndexOf('.') != -1)
 513+ ext = sf.substring( sf.lastIndexOf('.')+1 ).toLowerCase();
515514
516515 //set to passthrough to true by default (images, arbitrary files that we want to send with http chunks)
517516 this.encoder_settings['passthrough'] = true;
518517
519518 //see if we have video or audio:
520 - if( _this.isSourceAudio() || _this.isSourceVideo() ){
521 - _this.encoder_settings['passthrough'] = false;
522 - }
 519+ if( _this.isSourceAudio() || _this.isSourceVideo() )
 520+ _this.encoder_settings['passthrough'] = false;
523521
524522 //special case see if we already have ogg video:
525 - if( _this.isOggFormat() ){
 523+ if( _this.isOggFormat() )
526524 _this.encoder_settings['passthrough'] = true;
527 - }
528 -
 525+
529526 js_log('base autoEncoderSettings::' + _this.sourceFileInfo.contentType + ' passthrough:' + _this.encoder_settings['passthrough']);
530527 },
531528 isUnknown:function(){
Index: trunk/phase3/js2/mwEmbed/mv_embed.js
@@ -451,7 +451,7 @@
452452 },
453453 updateText : function( wikiText ){
454454 this.wikiText = wikiText;
455 - //invalidate the output (will force a reparse)
 455+ //invalidate the output (will force a re-parse )
456456 this.pOut = '';
457457 },
458458 parse : function(){
@@ -530,7 +530,7 @@
531531 }
532532 function getMagicTxtFromTempNode( node ){
533533 node.tObj = parseTmplTxt ( node.t );
534 - //do magic swap if templet key found in pMagicSet
 534+ //do magic swap if template key found in pMagicSet
535535 if( node.tObj.name in pMagicSet){
536536 var nt = pMagicSet[ node.tObj.name ]( node.tObj );
537537 return nt;
@@ -575,7 +575,7 @@
576576 //strip out the parent from the root
577577 this.pNode['p'] = null;
578578
579 - //do the recusrive magic swap text:
 579+ //do the recursive magic swap text:
580580 this.pOut = recurse_magic_swap( this.pNode );
581581
582582 },
@@ -613,10 +613,10 @@
614614 /**
615615 * Returns the transformed wikitext
616616 *
617 - * Build output from swapable index
618 - * (all transforms must be expanded in parse stage and linerarly rebuilt)
619 - * Alternativly we could build output using a placeholder & replace system
620 - * (this lets us be slightly more slopty with ordering and indexes, but probably slower)
 617+ * Build output from swappable index
 618+ * (all transforms must be expanded in parse stage and linearly rebuilt)
 619+ * Alternatively we could build output using a place-holder & replace system
 620+ * (this lets us be slightly more slopy with ordering and indexes, but probably slower)
621621 *
622622 * Ideal: we build a 'wiki DOM'
623623 * When editing you update the data structure directly
@@ -641,11 +641,6 @@
642642 var loadRS = $mw.lang.loadRS;
643643 var gM = $mw.lang.gM;
644644
645 -//if some no-js2 script defined and loaded gMsg in global space:
646 -if( _global['gMsg'] ){
647 - loadGM( _global['gMsg'] );
648 -}
649 -
650645 // All default messages in [English] should be overwritten by the CMS language message system.
651646 $mw.lang.loadGM({
652647 "mwe-loading_txt" : "loading ...",
@@ -656,11 +651,11 @@
657652 "mwe-size-bytes" : "$1 B",
658653 "mwe-error_load_lib" : "Error: JavaScript $1 was not retrievable or does not define $2",
659654 "mwe-loading-add-media-wiz": "Loading add media wizard",
660 - "mwe-apiproxy-setup" : " Setting up API proxy"
 655+ "mwe-apiproxy-setup" : "Setting up API proxy",
 656+ "mwe-load-drag-item" : "Loading draged item",
 657+ "mwe-ok" : "Ok"
661658 });
662659
663 -
664 -
665660 /**
666661 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
667662 * Any file _not_ listed here won't be auto-loadable
@@ -757,6 +752,7 @@
758753 "$j.ui.draggable" : "jquery/jquery.ui/ui/ui.draggable.js",
759754 "$j.ui.selectable" : "jquery/jquery.ui/ui/ui.selectable.js",
760755
 756+ "$mw.dragDropFile" : "libAddMedia/dragDropFile.js",
761757 "mvFirefogg" : "libAddMedia/mvFirefogg.js",
762758 "mvAdvFirefogg" : "libAddMedia/mvAdvFirefogg.js",
763759 "mvBaseUploadInterface" : "libAddMedia/mvBaseUploadInterface.js",
@@ -1133,8 +1129,6 @@
11341130 document.getElementsByTagName( "playlist" )
11351131 ];
11361132 if( e[0].length != 0 || e[1].length != 0 || e[2].length != 0 ) {
1137 - js_log( 'we have items to rewrite' );
1138 - setSwappableToLoading( e );
11391133 // Load libs and process them
11401134 mvJsLoader.embedVideoCheck( function() {
11411135 // Run any queued global events:
@@ -1148,16 +1142,9 @@
11491143 mvJsLoader.runQueuedFunctions();
11501144 }
11511145 }
1152 -// A quick function that sets the initial text of swappable elements to "loading".
1153 -// jQuery might not be ready. Does not destroy inner elements.
1154 -function setSwappableToLoading( e ) {
1155 - //for(var i =0)
1156 - //for(var j = 0; i < j.length; j++){
1157 - //}
1158 -}
 1146+
11591147 //js2AddOnloadHook: ensure jQuery and the DOM are ready
1160 -function js2AddOnloadHook( func ) {
1161 - js_log("js2AddOnloadHook::" + mvJsLoader.doneReadyEvents);
 1148+function js2AddOnloadHook( func ) {
11621149 // If we have already run the DOM-ready function, just run the function directly:
11631150 if( mvJsLoader.doneReadyEvents ) {
11641151 // Make sure jQuery is there:
@@ -1204,8 +1191,8 @@
12051192 * Store all the mwEmbed jQuery-specific bindings
12061193 * (set up after jQuery is available).
12071194 *
1208 - * These functions are genneraly are loaders that do the dynamic mapping of
1209 - * dependencies for a given compoent
 1195+ * These functions are generaly are loaders that do the dynamic mapping of
 1196+ * dependencies for a given componet
12101197 *
12111198 *
12121199 */
@@ -1213,6 +1200,18 @@
12141201 js_log( 'mv_jqueryBindings' );
12151202 (function( $ ) {
12161203 /*
 1204+ * dragDrop file loader
 1205+ */
 1206+ $.fn.dragFileUpload = function ( conf ){
 1207+ if( this.selector ){
 1208+ var _this = this;
 1209+ //load the dragger and "setup"
 1210+ $mw.load( ['$mw.dragDropFile'], function(){
 1211+ $mw.dragDropFile( _this.selector );
 1212+ });
 1213+ }
 1214+ }
 1215+ /*
12171216 * apiProxy Loader loader:
12181217 *
12191218 * @param mode is either 'server' or 'client'
@@ -1491,7 +1490,13 @@
14921491 //append the style free loader ontop:
14931492 $('body').append('<div id="mwe_tmp_loader" style="display:none" title="' + title + '" >' +
14941493 msg_txt +
1495 - '</div>');
 1494+ '</div>');
 1495+ //special btn == ok gives empty give a single "oky" -> "close"
 1496+ if( btn == 'ok' ){
 1497+ btn[ gM('mwe-ok') ] = function(){
 1498+ $j('#mwe_tmp_loader').close();
 1499+ }
 1500+ }
14961501 //turn the loader into a real dialog loader:
14971502 mvJsLoader.doLoadDepMode([
14981503 [

Status & tagging log