Вход Регистрация
Файл: mg-core/script/toggles.js
Строк: 105
<?php
(function( $ ){

  $.
fn.toggles = function(opts) {
    
opts opts || {};
    var 
= $.extend({
      
dragabletrue,
      
clickabletrue,
      
ontext'Вкл',
      
offtext'Выкл',
      
ontrue,
      
animtime300
    
},opts);
    var 
transition 'margin-left '+o.animtime/1000+'s ease-in-out';
    var 
transitions = {
      
'-webkit-transition'transition,
      
'-moz-transition'transition,
      
'transition'transition
    
};
    var 
notrans = {
      
'-webkit-transition''',
      
'-moz-transition''',
      
'transition'''
    
};
    var 
toggle = function(slide,w,h) {
      var 
inner slide.find('.inner');
      
inner.css(transitions);
      var 
active slide.toggleClass('active').hasClass('active');
      
inner.css({
        
marginLeft: (active) ? : -w+h
      
});
      if (
o.checkbox) $(o.checkbox).attr('checked',active);
      
setTimeout(function() {
        
inner.css({
          
marginLeft: (active) ? : -w+h
        
});
        
inner.css(notrans);
      },
o.animtime);
    };

    return 
this.each(function() {
      var 
self = $(this);

      
// we dont want the click handler to go on all the elements
      
o.click opts.click || self;


      var 
self.height(), wself.width();
      if (
=== || w===0) {
        
self.height(20);
        
self.width(50);
      }
      var 
slide = $('<div class="slide" />'), inner = $('<div class="inner" />'),on = $('<div class="on" />'), off = $('<div class="off" />'), blob = $('<div class="blob" />');
      
on
      
.css({
        
height:h,
        
widthw-h/2,
        
textAlign'center',
        
textIndent: -h/2,
        
lineHeighth+'px'
      
})
      .
text(o.ontext);
      
off
      
.css({
        
height:h,
        
widthw-h/2,
        
marginLeft: -h/2,
        
textAlign'center',
        
textIndenth/2,
        
lineHeighth+'px'
      
})
      .
text(o.offtext);
      
blob.css({
        
heighth,
        
widthh,
        
marginLeft: -h/2
      
});
      
inner.css({
        
widthw*2-h,
        
marginLeft: (o.on) ? : -w+h
      
});
      if (
o.on) {
        
slide.addClass('active');
        if (
o.checkbox) $(o.checkbox).attr('checked',true);
      }
      
self.html('');
      
self.append(slide.append(inner.append(on,blob,off)));
      var 
diff 0time;
      
self.on('toggle', function() {
        
toggle(slide,w,h);
      });
      if (
o.clickable) {
        
o.click.click(function(e) {
          if (
e.target !=  blob[0] || !o.dragable) {
            
self.trigger('toggle');
          }
        });
      }


    });
};
})( 
jQuery );
?>
Онлайн: 0
Реклама