/*
* cloneattr — plugin based on jQuery for platform SCAD7
*
* Copyright (c) 2019 Dobrynin P. Yu.
*
* Version: 1.0.0
*
* home page link:
* http://http://platforma.scad7.ru
*
* Копировать коллекцию атрибутов элементов в другие элементы той же строки таблицы
* try {
* $([selector]).cloneattr({to : ‘.col01’});
* } catch(err) {
* console.log(err);
* }
* try {
* $([selector]).cloneattr({attr: ‘onclick’, to : ‘.col01’});
* } catch(err) {
* console.log(err);
* }
* Уничтожить атрибут
* $([selector]).cloneattr(‘destroy’);
*/
(function( $ ){
var methods = {
init : function( options ) {
var settings =$.extend({
‘attr’ : ‘onclick’
,’attrto’ : ‘onclick’
,’to’ : ‘.col01’
}, options);
return this.each(function(index){
var $this = $(this)
, data = $this.data(‘cloneattr’)
, elem = $(settings.to)
, attr = settings.attr
, attrto = settings.attrto
;
if ( ! data) {
$(this).data(‘cloneattr’, {
target : $this
, elem : elem
, attr : attr
, attrto : attrto
});
}
// — клонирование атрибута —
//console.log(‘PLUGIN_CLONEATTR: index=’+index+’ settings.to=’+ settings.to );
//console.log(‘PLUGIN_CLONEATTR: parent class=’+ $(this).parent(‘.headtable’).attr(‘class’) );
//console.log(‘PLUGIN_CLONEATTR: parent class=’+ $(this).parent(‘.headtable’).parent(‘.rowmenu_open’).attr(‘class’)
// + ‘ id=’+ $(this).parent(‘.headtable’).parent(‘.rowmenu_open’).attr(‘id’));
//console.log(‘PLUGIN_CLONEATTR: class=’+ $(this).parent(‘.headtable’).parent(‘.rowmenu_open’).nextAll(settings.to).attr(‘class’) );
var to_elem = $(this).parent(‘.headtable’).parent(‘.rowmenu_open’).nextAll(settings.to);
to_elem.attr(settings.attrto, $( this ).attr(settings.attr) );
to_elem.hover(function(){$(this).css(‘background-color’,’#dedede’)},function(){$(this).css(‘background-color’,»)});
}); //return
}
, destroy : function() {
return this.each(function(){
var $this = $(this), data = $this.data(‘cloneattr’);
$(window).unbind(‘.cloneattr’);
data.elem.removeAttr( data.attrto);
$this.removeData(‘cloneattr’);
}); //return
}
, run : function run() {
return this.each(function() {
return this;
}); //return
}
};
$.fn.cloneattr = function( method ) {
if ( methods[method] ) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if ( typeof method === ‘object’ || ! method) {
return methods.init.apply( this, arguments );
} else {
$.error( ‘Метод с именем ‘ + method + ‘ не существует для jQuery.cloneattr’ );
}
};
})( jQuery )