mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 04:53:26 +00:00
Prod JS
This commit is contained in:
196
www/include/js/jquery.Selection.js
Normal file
196
www/include/js/jquery.Selection.js
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
/*
|
||||||
|
* Selection Object
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function( window ) {
|
||||||
|
|
||||||
|
var Selectable = function(options) {
|
||||||
|
|
||||||
|
var defaults = {
|
||||||
|
allow_multiple : false,
|
||||||
|
container : window.document,
|
||||||
|
selector : '*',
|
||||||
|
callbackSelection : null,
|
||||||
|
selectStart : null,
|
||||||
|
selectStop : null
|
||||||
|
},
|
||||||
|
options = (typeof options == 'object') ? options : {};
|
||||||
|
|
||||||
|
this.options = jQuery.extend(defaults, options);
|
||||||
|
this.datas = new Array();
|
||||||
|
|
||||||
|
var $container = jQuery(this.options.container),
|
||||||
|
$this = this;
|
||||||
|
|
||||||
|
if(jQuery($container).hasClass('selectionnable'))
|
||||||
|
{
|
||||||
|
/* this container is already selectionnable */
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery($container).addClass('selectionnable');
|
||||||
|
|
||||||
|
jQuery(this.options.selector, $container)
|
||||||
|
.live('mousedown', function(event){
|
||||||
|
|
||||||
|
if(typeof $this.options.selectStart === 'function')
|
||||||
|
{
|
||||||
|
$this.options.selectStart(jQuery.extend(jQuery.Event('selectStart'), event), $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
var $that = jQuery(this);
|
||||||
|
|
||||||
|
var k = get_value($that, $this);
|
||||||
|
|
||||||
|
if(is_shift_key(event) && jQuery('.last_selected', $container).filter($this.options.selector).length != 0)
|
||||||
|
{
|
||||||
|
var lst = jQuery($this.options.selector, $container);
|
||||||
|
|
||||||
|
var index1 = jQuery.inArray( jQuery('.last_selected', $container).filter($this.options.selector)[0], lst );
|
||||||
|
var index2 = jQuery.inArray( $that[0], lst );
|
||||||
|
|
||||||
|
if(index2<index1)
|
||||||
|
{
|
||||||
|
var tmp = index1;
|
||||||
|
index1 = (index2 - 1) < 0 ? index2 : (index2 - 1);
|
||||||
|
index2 = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(index2 != -1 && index1 != -1)
|
||||||
|
{
|
||||||
|
var exp = $this.options.selector + ':gt(' + index1 + '):lt(' + (index2-index1) + ')';
|
||||||
|
|
||||||
|
$.each(jQuery(exp, $container),function(i,n){
|
||||||
|
if(!jQuery(n).hasClass('selected'))
|
||||||
|
{
|
||||||
|
$this.push(jQuery(n).attr('id').split('_').slice(2,4).join('_'));
|
||||||
|
jQuery(n).addClass('selected');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this.has(k) === false)
|
||||||
|
{
|
||||||
|
$this.push(k);
|
||||||
|
$that.addClass('selected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!is_ctrl_key(event))
|
||||||
|
{
|
||||||
|
$this.empty().push(k);
|
||||||
|
jQuery('.selected', $container).filter($this.options.selector).removeClass('selected');
|
||||||
|
$that.addClass('selected');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if($this.has(k) === true)
|
||||||
|
{
|
||||||
|
$this.remove(k);
|
||||||
|
$that.removeClass('selected');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this.push(k);
|
||||||
|
$that.addClass('selected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery('.last_selected', $container).removeClass('last_selected');
|
||||||
|
$that.addClass('last_selected');
|
||||||
|
|
||||||
|
|
||||||
|
if(typeof $this.options.selectStop === 'function')
|
||||||
|
{
|
||||||
|
$this.options.selectStop(jQuery.extend(jQuery.Event('selectStop'), event), $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
function get_value(element, Selectable)
|
||||||
|
{
|
||||||
|
if(typeof Selectable.options.callbackSelection === 'function')
|
||||||
|
{
|
||||||
|
return Selectable.options.callbackSelection(jQuery(element));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return jQuery('input[name="id"]', jQuery(element)).val();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Selectable.prototype = {
|
||||||
|
push : function(element){
|
||||||
|
if(window.console)
|
||||||
|
{
|
||||||
|
window.console.log('pushing ',element);
|
||||||
|
}
|
||||||
|
if(this.options.allow_multiple === true || !this.has(element))
|
||||||
|
{
|
||||||
|
this.datas.push(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
remove : function(element){
|
||||||
|
this.datas = jQuery.grep(this.datas, function(n){
|
||||||
|
return(n !== element);
|
||||||
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
has : function(element){
|
||||||
|
|
||||||
|
return jQuery.inArray(element,this.datas) >= 0;
|
||||||
|
},
|
||||||
|
get : function(){
|
||||||
|
|
||||||
|
return this.datas;
|
||||||
|
},
|
||||||
|
empty : function(){
|
||||||
|
this.datas = new Array();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
length : function(){
|
||||||
|
|
||||||
|
return this.datas.length;
|
||||||
|
},
|
||||||
|
size : function(){
|
||||||
|
|
||||||
|
return this.datas.length;
|
||||||
|
},
|
||||||
|
serialize : function(separator){
|
||||||
|
|
||||||
|
separator = separator || ';';
|
||||||
|
|
||||||
|
return this.datas.join(separator);
|
||||||
|
},
|
||||||
|
selectAll : function(separator){
|
||||||
|
var $this = this;
|
||||||
|
|
||||||
|
jQuery(this.optionsthis.options.selector, $container).not('.selected').filter(':visible').each(function(){
|
||||||
|
$this.push(get_value(this, $this));
|
||||||
|
$(this).addClass('selected');
|
||||||
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('SELECTABALE to be declare');
|
||||||
|
|
||||||
|
window.Selectable = Selectable;
|
||||||
|
console.log('SELECTABALE declared');
|
||||||
|
})(window);
|
58
www/include/js/tests/jquery.Selection.js.html
Normal file
58
www/include/js/tests/jquery.Selection.js.html
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title></title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<script src="http://code.jquery.com/jquery-latest.js"></script>
|
||||||
|
<script src="/include/vendor/qunit/qunit/qunit.js"></script>
|
||||||
|
<script src="/include/js/jquery.Selection.js"></script>
|
||||||
|
<link type="text/css" rel="stylesheet" href="/include/vendor/qunit/qunit/qunit.css"/>
|
||||||
|
<script> $(document).ready(function(){
|
||||||
|
|
||||||
|
|
||||||
|
test("Selection instanciation", function() {
|
||||||
|
var sel = new Selection();
|
||||||
|
var array = new Array();
|
||||||
|
equal( typeof array, typeof sel.get(), "We expect the selection to be an Array" );
|
||||||
|
equal( array.length, sel.get().length, "We expect the selection to be empty" );
|
||||||
|
});
|
||||||
|
|
||||||
|
module("Add datas");
|
||||||
|
|
||||||
|
test("first test within module", function() {
|
||||||
|
var sel = new Selection();
|
||||||
|
sel.push('a');
|
||||||
|
equal( 1, sel.get().length, "We expect the selection to be empty" );
|
||||||
|
equal( 'a', sel.get().pop(), "We expect the selection to be empty" );
|
||||||
|
});
|
||||||
|
|
||||||
|
module("Multiple selections");
|
||||||
|
|
||||||
|
test("first test within module", function() {
|
||||||
|
var sel1 = new Selection();
|
||||||
|
var sel2 = new Selection();
|
||||||
|
|
||||||
|
sel1.push('a');
|
||||||
|
sel2.push('b');
|
||||||
|
|
||||||
|
equal( 1, sel1.get().length, "We expect the selection to be empty" );
|
||||||
|
equal( 'a', sel1.get().pop(), "We expect the selection to be empty" );
|
||||||
|
|
||||||
|
equal( 1, sel2.get().length, "We expect the selection to be empty" );
|
||||||
|
equal( 'b', sel2.get().pop(), "We expect the selection to be empty" );
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 id="qunit-header">QUnit example</h1>
|
||||||
|
<h2 id="qunit-banner"></h2>
|
||||||
|
<div id="qunit-testrunner-toolbar"></div>
|
||||||
|
<h2 id="qunit-userAgent"></h2>
|
||||||
|
<ol id="qunit-tests"></ol>
|
||||||
|
<div id="qunit-fixture">test markup, will be hidden</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -79,7 +79,12 @@ $groups = array(
|
|||||||
, '//login/geonames.js'
|
, '//login/geonames.js'
|
||||||
, '//include/jslibs/jquery.form.2.49.js'
|
, '//include/jslibs/jquery.form.2.49.js'
|
||||||
, '//include/jslibs/jquery.vertical.buttonset.js'
|
, '//include/jslibs/jquery.vertical.buttonset.js'
|
||||||
|
, '//include/js/jquery.Selection.js'
|
||||||
|
, '//prod/jquery.Prod.js'
|
||||||
|
, '//prod/jquery.Results.js'
|
||||||
, '//prod/page0.js'
|
, '//prod/page0.js'
|
||||||
|
, '//prod/jquery.WorkZone.js'
|
||||||
|
, '//prod/jquery.Alerts.js'
|
||||||
, '//prod/publicator.js'
|
, '//prod/publicator.js'
|
||||||
, '//prod/jquery.order.js'
|
, '//prod/jquery.order.js'
|
||||||
, '//include/jslibs/jquery.sprintf.1.0.3.js'
|
, '//include/jslibs/jquery.sprintf.1.0.3.js'
|
||||||
|
Reference in New Issue
Block a user