You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by br...@apache.org on 2014/02/14 18:24:35 UTC
svn commit: r1568367 [5/13] - in /jspwiki/trunk: ./ jspwiki-war/
jspwiki-war/src/main/config/wro/ jspwiki-war/src/main/java/org/apache/wiki/
jspwiki-war/src/main/scripts/dynamic-styles/
jspwiki-war/src/main/scripts/lib/ jspwiki-war/src/main/scripts/moo...
Added: jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Request.File.js
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Request.File.js?rev=1568367&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Request.File.js (added)
+++ jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Request.File.js Fri Feb 14 17:24:32 2014
@@ -0,0 +1,79 @@
+/*
+---
+
+name: Request.File
+description: Uploading files with FormData
+license: MIT-style license.
+authors: [Arian Stolwijk, Djamil Legato]
+requires: [Request]
+provides: Request.File
+credits: https://gist.github.com/a77b537e729aff97429c
+
+...
+*/
+
+(function(){
+
+var progressSupport = ('onprogress' in new Browser.Request());
+
+Request.File = new Class({
+
+ Extends: Request,
+
+ options: {
+ emulation: false,
+ urlEncoded: false
+ },
+
+ initialize: function(options){
+ this.xhr = new Browser.Request();
+ this.formData = new FormData();
+ this.setOptions(options);
+ this.headers = this.options.headers;
+ },
+
+ append: function(key, value){
+ this.formData.append(key, value);
+ return this.formData;
+ },
+
+ reset: function(){
+ this.formData = new FormData();
+ },
+
+ send: function(options){
+ if (!this.check(options)) return this;
+//console.log(this.formData);
+ this.options.isSuccess = this.options.isSuccess || this.isSuccess;
+ this.running = true;
+
+ var xhr = this.xhr;
+ if (progressSupport){
+ xhr.onloadstart = this.loadstart.bind(this);
+ xhr.onprogress = this.progress.bind(this);
+ xhr.upload.onprogress = this.progress.bind(this);
+ }
+
+ xhr.open('POST', this.options.url, true);
+ xhr.onreadystatechange = this.onStateChange.bind(this);
+
+ Object.each(this.headers, function(value, key){
+ try {
+ xhr.setRequestHeader(key, value);
+ } catch (e){
+ this.fireEvent('exception', [key, value]);
+ }
+ }, this);
+
+ this.fireEvent('request');
+ xhr.send(this.formData);
+
+ if (!this.options.async) this.onStateChange();
+ if (this.options.timeout) this.timer = this.timeout.delay(this.options.timeout, this);
+ return this;
+ }
+
+});
+
+})();
+
Propchange: jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Request.File.js
------------------------------------------------------------------------------
svn:executable = *
Added: jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/String.Extend.js
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/String.Extend.js?rev=1568367&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/String.Extend.js (added)
+++ jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/String.Extend.js Fri Feb 14 17:24:32 2014
@@ -0,0 +1,184 @@
+/*
+Mootools Extension: String.Extend.js
+ String-extensions: capitalize,() deCamelize(), trunc(), xsubs()
+*/
+String.implement({
+
+ /*
+ Function: capitalize
+ Converts the first letter of each word in a string to uppercase.
+
+ Example:
+ > "i like cookies".capitalize() === 'I Like Cookies'
+ > "je vais à l'école".capitalize() === 'Je Vais à L'école' //not "Je Vais à L'éCole"
+ */
+ capitalize: function(){
+ //fix mootools implementation , supporting i18n chars such as éà è, not matched by \b
+ //return String(this).replace(/\b[a-z]/g, function(match){
+ return this.replace(/(\s|^)\S/g, function(match){
+ return match.toUpperCase();
+ });
+ },
+
+ /*
+ Function: deCamelize
+ Convert camelCase string to space-separated set of words.
+
+ Example:
+ > "CamelCase".deCamelize() === "Camel Case";
+ */
+ deCamelize: function(){
+ //return this.replace(/([a-z])([A-Z])/g,"$1 $2");
+ //return this.replace(/([a-zà -ý])([A-ZÃ-Ã])/g,"$1 $2");
+ return this.replace(/([a-z\xe0-\xfd])([A-Z\xc0-\xdd])/g,"$1 $2");
+ },
+
+ /*
+ Function: trunc
+ Truncate a string to a maximum length
+
+ Arguments:
+ size - maximum length of the string, excluding the length of the elips
+ elips - (optional) replaces the truncated part (defaults to '...')
+
+ Alternative
+ Use css propoerty
+ white-space:nowrap;
+ overflow:hidden;
+ text-overflow:ellipsis;
+
+ Example:
+ > "this is a long string".trunc(7) === "this is..."
+ > "this is a long string".trunc(7,'__') === "this is__"
+ */
+ trunc: function (size, elips){
+
+ return this.slice(0, size-1) + ((this.length<size) ? '' : (elips||'â¦'));
+
+ },
+
+
+ /*
+ Function: localize
+ Localize a string with optional parameters. (indexed or named)
+
+ Require:
+ I18N - (global hash) repository of {{name:value}} pairs
+ name - starts with a prefix {{javascript.}}
+ value - (server generated) localized string, with optional {parameters}
+ in curly braces
+
+ Examples:
+ (start code)
+ //initialize the translation strings
+ String.I18N = {
+ "javascript.moreInfo":"More",
+ "javascript.imageInfo":"Image {0} of {1}", //indexed parms
+ "javascript.imageInfo2":Image {imgCount} of {totalCount}" //named parms
+ "javascript.curlyBraces":"Show \{Curly Braces}", //escaped curly braces
+ }
+ String.I18N.PREFIX="javascript.";
+
+ "moreInfo".localize() === "More";
+ "imageInfo".localize(2,4) === "Image 2 of 4"
+ "imageInfo2".localize({totalCount:4, imgCount:2}) === "Image 2 of 4"
+ "curlyBraces".localize() === "Show {Curly Braces}"
+
+ (end)
+
+ */
+ localize: function( params ){
+
+ var I18N = String.I18N;
+
+ return ( I18N[I18N.PREFIX + this] || this ).substitute(
+
+ ( typeOf(params) == 'object' ) ? params : Array.from(arguments)
+
+ );
+
+ },
+
+ /*
+ Function: xsubs (extended Substitute)
+ Equal to substitute(), but also supports anonymous arguments.
+
+ Named arguments:
+ > "Hello {text}".xsubs({text:"world"}) ==> "Hello world"
+ Anonymous arguments:
+ > "Hello {0}{1}".xsubs("world", "!") === "Hello world!"
+ */
+ xsubs: function(object, regexp){
+
+ if( typeOf(object) != 'object' ){
+ object = Array.from(arguments);
+ regexp = null;
+ }
+ return this.substitute(object, regexp);
+ },
+
+ /*
+ Function:slick(props)
+ Convert css selector into a new DOM Element
+
+ Example:
+ > "input#someID.someClass1.someClass2[disabled=true]".slick({text:"Hi"});
+ */
+ slick:function(props){
+
+ return new Element(this+"", props);
+
+ },
+
+ /*
+ Function: sliceArgs
+ Parse the command arguments of a string or an element's class-name.
+ Pattern: <command>(-arg1)(-arg2)...
+ Returns an array of arguments.
+
+ > <command>.sliceArgs( args (, regexp) );
+
+ Arguments:
+ args : (string) or dom-element with classname
+ regexp : (optional string) pattern match for the arguments, defaults (-\w+)*
+
+ Example
+ > "zebra".sliceArgs( "zebra-eee-ffa" ); //returns ['eee','ffa']
+ > "zebra".sliceArgs( "horse" ); //returns null
+ > "zebra".sliceArgs( "zebra" ); //returns []
+
+ */
+ sliceArgs: function(element, regexp){
+
+ var args = element.grab /*isElement*/ ? element.className : element;
+
+ if( !regexp) regexp = "(^|\\s)"+this+"(-\\w+)*(?:\\s|$)"; //default '-' separated arguments
+
+ args = args.match( regexp );
+ return args && args[0].split('-').slice(1);
+
+ },
+
+ /*
+ Function: fetchContext
+ Match an elements classname or string against one of the bootstrap contextual patterns.
+ Supported contexts: default, primary, success, info, warning, danger
+
+ Return a (string) classname to invoke the contextual colors.
+
+ Example
+ > 'panel'.fetchContext( 'accordion-danger') => 'panel panel-danger'
+ > 'panel'.fetchContext( 'commentbox-success') => 'panel panel-success'
+
+ */
+ fetchContext : function(element){
+
+ var name = element.grab /*isElement*/ ? element.className : element;
+
+ name = (name.match( /\b(default|primary|success|info|warning|danger)(\b|$)/ )||[,'default'])[1];
+
+ return this+' '+this+'-'+name ;
+
+ }
+
+});
\ No newline at end of file
Added: jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Textarea.js
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Textarea.js?rev=1568367&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Textarea.js (added)
+++ jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Textarea.js Fri Feb 14 17:24:32 2014
@@ -0,0 +1,340 @@
+/*
+Class: Textarea
+ The textarea class enriches a TEXTAREA element, and provides cross browser
+ support to handle text selection: get and set the selected text,
+ changing the selection, etc.
+ It also provide support to retrieve and validate the caret/cursor position.
+
+Example:
+ (start code)
+ <script>
+ var txta = new Textarea( "mainTextarea" );
+ </script>
+ (end)
+*/
+var Textarea = new Class({
+
+ Implements: [Options,Events],
+
+ //options: { onChange:function(e){} );
+
+ initialize: function(el,options){
+
+ var self = this,
+ txta = self.ta = $(el),
+
+ lastValue,
+ lastLength = -1,
+ changeFn = function(e){
+ var v = txta.value;
+ if( v.length != lastLength || v !== lastValue ){
+ self.fireEvent('change', e);
+ lastLength = v.length;
+ lastValue = v;
+ }
+ };
+
+ self.setOptions(options);
+
+ txta.addEvents({ change:changeFn, keyup:changeFn });
+
+ //Create shadow div to support pixel measurement of the caret in the textarea
+ //self.taShadow = new Element('div',{
+ // styles: { position:'absolute', visibility:'hidden', overflow:'auto'/*,top:0, left:0, zIndex:1, white-space:pre-wrap*/ }
+ //})
+ self.taShadow = new Element('div[style=position:absolute;visibility:hidden;overflow:auto]')
+ .inject(txta,'before')
+ .setStyles( txta.getStyles(
+ 'font-family0font-size0line-height0text-indent0padding-top0padding-right0padding-bottom0padding-left0border-left-width0border-right-width0border-left-style0border-right-style0white-space0word-wrap'
+ .split(0)
+ ));
+
+ return this;
+ },
+
+ /*
+ Function: toElement
+ Return the DOM textarea element.
+ This allows the dollar function to return
+ the element when passed an instance of the class. (mootools 1.2.x)
+
+ Example:
+ > var txta = new Textarea('textarea-element');
+ > $('textarea-element') == txta.toElement();
+ > $('textarea-element') == $(txta); //mootools 1.2.x
+ */
+ toElement: function(){
+ return this.ta;
+ },
+
+ /*
+ Function: getValue
+ Returns the value (text content) of the textarea.
+ */
+ getValue: function(){
+ return this.ta.value;
+ },
+ /*
+ Function: slice
+ Mimics the string slice function on the value (text content) of the textarea.
+ Arguments:
+ Ref. javascript slice function
+ */
+ slice: function(start,end){
+ return this.ta.value.slice(start,end);
+ },
+
+
+ /*
+ Function: getFromStart
+ Returns the first not selected part of the textarea, till the start of the selection.
+ */
+ getFromStart: function(){
+ return this.slice( 0, this.getSelectionRange().start );
+ },
+
+ /*
+ Function: getTillEnd
+ Returns the last not selected part of the textarea, starting from the end of the selection.
+ */
+ getTillEnd: function(){
+ return this.slice( this.getSelectionRange().end );
+ },
+
+ /*
+ Function: getSelection
+ Returns the selected text as a string
+
+ Note:
+ IE fixme: this may return any selection, not only selected text in this textarea
+ //if(Browser.Engine.trident) return document.selection.createRange().text;
+ */
+ getSelection: function(){
+
+ var cur = this.getSelectionRange();
+ return this.slice(cur.start, cur.end);
+
+ },
+
+ /*
+ Function: setSelectionRange
+ Selects the selection range of the textarea from start to end
+
+ Arguments:
+ start - start position of the selection
+ end - (optional) end position of the seletion (default == start)
+
+ Returns:
+ Textarea object
+ */
+ setSelectionRange: function(start, end){
+
+ var txta = this.ta,
+ value,diff,range;
+
+ if(!end){ end = start; }
+
+ if( txta.setSelectionRange ){
+
+ txta.setSelectionRange(start, end);
+
+ } else {
+
+ value = txta.value;
+ diff = value.slice(start, end - start).replace(/\r/g, '').length;
+ start = value.slice(0, start).replace(/\r/g, '').length;
+
+ range = txta.createTextRange();
+ range.collapse(1 /*true*/);
+ range.moveEnd('character', start + diff);
+ range.moveStart('character', start);
+ range.select();
+ //textarea.scrollTop = scrollPosition;
+ //textarea.focus();
+
+ }
+ return this;
+ },
+
+ /*
+ Function: getSelectionRange
+ Returns an object describing the textarea selection range.
+
+ Returns:
+ {{ { 'start':number, 'end':number, 'thin':boolean } }}
+ start - coordinate of the selection
+ end - coordinate of the selection
+ thin - boolean indicates whether selection is empty (start==end)
+ */
+
+/* ffs
+ getIERanges: function(){
+ this.ta.focus();
+ var txta = this.ta,
+ range = document.selection.createRange(),
+ re = this.createTextRange(),
+ dupe = re.duplicate();
+ re.moveToBookmark(range.getBookmark());
+ dupe.setEndPoint('EndToStart', re);
+ return { start: dupe.text.length, end: dupe.text.length + range.text.length, length: range.text.length, text: range.text };
+ },
+*/
+ getSelectionRange: function(){
+
+ var txta = this.ta,
+ caret = { start: 0, end: 0 /*, thin: true*/ },
+ range, dup, value, offset;
+
+ if( txta.selectionStart!=null ){
+
+ caret = { start: txta.selectionStart, end: txta.selectionEnd };
+
+ } else {
+
+ range = document.selection.createRange();
+ //if (!range || range.parentElement() != txta){ return caret; }
+ if ( range && range.parentElement() == txta ){
+ dup = range.duplicate();
+ value = txta.value;
+ offset = value.length - value.match(/[\n\r]*$/)[0].length;
+
+ dup.moveToElementText(txta);
+ dup.setEndPoint('StartToEnd', range);
+ caret.end = offset - dup.text.length;
+ dup.setEndPoint('StartToStart', range);
+ caret.start = offset - dup.text.length;
+ }
+ }
+
+ caret.thin = (caret.start==caret.end);
+
+ return caret;
+ },
+
+ /*
+ Function: setSelection
+ Replaces the selection with a new value (concatenation of arguments).
+ On return, the selection is set to the replaced text string.
+
+ Arguments:
+ string - string to be inserted in the textarea.
+ If multiple arguments are passed, all strings will be concatenated.
+
+ Returns:
+ Textarea object, with a new selection
+
+ Example:
+ > txta.setSelection("new", " value"); //replace selection by 'new value'
+ */
+ setSelection: function(){
+
+ var value = Array.from(arguments).join('').replace(/\r/g, ''),
+ txta = this.ta,
+ scrollTop = txta.scrollTop, //cache top
+ start,end,v,range;
+
+ if( txta.selectionStart!=null ){
+
+ start = txta.selectionStart;
+ end = txta.selectionEnd;
+ v = txta.value;
+ //txta.value = v.substr(0, start) + value + v.substr(end);
+ txta.value = v.slice(0, start) + value + v.substr(end);
+ txta.selectionStart = start;
+ txta.selectionEnd = start + value.length;
+
+ } else {
+
+ txta.focus();
+ range = document.selection.createRange();
+ range.text = value;
+ range.collapse(1 /*true*/);
+ range.moveStart("character", -value.length);
+ range.select();
+
+ }
+ txta.focus();
+ txta.scrollTop = scrollTop;
+ txta.fireEvent('change');
+ return this;
+
+ },
+
+ /*
+ Function: insertAfter
+ Inserts the arguments after the selection, and puts caret after inserted value
+
+ Arguments:
+ string( one or more) - string to be inserted in the textarea.
+
+ Returns:
+ Textarea object
+ */
+ insertAfter: function(){
+
+ var value = Array.from(arguments).join('');
+
+ return this.setSelection( value )
+ .setSelectionRange( this.getSelectionRange().start + value.length );
+
+ },
+
+ /*
+ Function: isCaretAtStartOfLine
+ Returns boolean indicating whether caret is at the start of a line.
+ */
+ isCaretAtStartOfLine: function(){
+
+ var i = this.getSelectionRange().start;
+ return( (i<1) || ( this.ta.value.charAt( i-1 ).test( /[\n\r]/ ) ) );
+
+ },
+
+ /*
+ Function: getCoordinates
+ Returns the absolute coordinates (px) of the character at a certain offset in the textarea.
+ Default returns pixel coordinates of the selection.
+
+ Credits:
+ Inspired by http://github.com/sergeche/tx-content-assist.
+
+ Arguments:
+ offset - character index
+ If omitted, the pixel position of the caret is returned.
+
+ Returns:
+ {{ { top, left, width, height, right, bottom } }}
+ */
+ getCoordinates: function( offset ){
+
+ var txta = this.ta,
+ taShadow = this.taShadow,
+ delta = 0,
+ el,css,style,t,l,w,h;
+
+ //prepare taShadow
+ css = txta.getStyles(['padding-left','padding-right','border-left-width','border-right-width']);
+ for(style in css){ delta +=css[style].toInt() }
+
+ //default offset is the position of the caret
+ if( !offset ){ offset = this.getSelectionRange().end; }
+
+ el = taShadow.set({
+ styles: {
+ width: txta.offsetWidth - delta,
+ height: txta.getStyle('height') //ensure proper handling of scrollbars - if any
+ },
+ //FIXME: should we put the full selection inside the <i></i> bracket ? (iso a single char)
+ html: txta.value.slice(0, offset) + '<i>A</i>' + txta.value.slice(offset+1)
+ }).getElement('i');
+
+ t = txta.offsetTop + el.offsetTop - txta.scrollTop;
+ l = txta.offsetLeft + el.offsetLeft - txta.scrollLeft;
+ w = el.offsetWidth;
+ h = el.offsetHeight;
+ return {top:t, left:l, width:w, height:h, right:l+w, bottom:t+h}
+
+ }
+
+});
+
Added: jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Tips.js
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Tips.js?rev=1568367&view=auto
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Tips.js (added)
+++ jspwiki/trunk/jspwiki-war/src/main/scripts/moo-extend/Tips.js Fri Feb 14 17:24:32 2014
@@ -0,0 +1,73 @@
+/*
+Dynamic Style: Tips
+ Add Tip behavior to a set of DOM Elements
+
+Bootstrap
+(start code)
+ //tip anchors
+ <element> Caption
+ <body> ...body... </body>
+ </element>
+
+ //layout of the tip, with absolute position
+ div.tooltip(.active)(.top|.left|.right|.bottom)
+ div.tooltip-inner
+ <body> ... </body>
+ div.tooltip-arrow
+(end)
+*/
+var Tips = function Tips(elements,options){
+
+ var tt = 'div.tooltip',
+ TheTip = [tt,[tt+'-inner'/*,tt+'-arrow'*/]].slick().inject(document.body),
+ inner = TheTip.getFirst();
+
+ $$(elements).addEvents({
+
+ mousemove: function(e){
+ TheTip.setStyles({ top:e.page.y +10, left:e.page.x + 10 });
+ },
+
+ mouseenter: function(e){
+ inner.adopt( this.getFirst() ) ;
+ TheTip.addClass('in'); //.fade('in');
+ },
+
+ mouseleave: function(e){
+ TheTip.removeClass('in'); //.fade('out');
+ this.adopt( inner.getFirst() );
+ }
+ });
+}
+
+
+
+/*TIP position logic
+ position: function(event){
+
+ var windowPadding={x:0, y:0};
+
+ var size = window.getSize(),
+ scroll = window.getScroll(),
+ tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight},
+ props = {x: 'left', y: 'top'},
+ bounds = {y: false, x2: false, y2: false, x: false},
+ obj = {};
+
+ for (var z in props){
+
+ obj[props[z]] = event.page[z] + this.options.offset[z];
+
+ if (obj[props[z]] < 0) bounds[z] = true;
+
+ if ((obj[props[z]] + tip[z] - scroll[z]) > size[z] - windowPadding[z]){
+
+ obj[props[z]] = event.page[z] - this.options.offset[z] - tip[z];
+ bounds[z+'2'] = true;
+ }
+ }
+
+ this.tip.setStyles(obj);
+ },
+
+*/
\ No newline at end of file