Skip to content

Instantly share code, notes, and snippets.

@davinmsu
Created October 9, 2014 11:37
Show Gist options
  • Select an option

  • Save davinmsu/b0b03081dbddf462fd7d to your computer and use it in GitHub Desktop.

Select an option

Save davinmsu/b0b03081dbddf462fd7d to your computer and use it in GitHub Desktop.
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
function extend(Child, Parent)
{
var F = function () { };
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.super = Parent.prototype;
}
function Table(){
var obj = this;
this.el = $('<table><thead><tr><td>№</td><td>Название</td><td>Цена</td><td>макс. скорость</td></tr></thead><tbody></tbody></table>');
this.rows = [];
this.render = function(container){
$(container).append(this.el);
};
this.remove = function(){
this.el.remove();
};
this.add = function(data){
if(Row.prototype.isPrototypeOf(data))
data = [data];
$.each(data, function(i, e){
obj.el.find('tbody').append(e.el)
});
};
this.getRows = function(){
};
}
function Row(data){
this.el = $('<tr><td>'+data[0]+'</td><td>'+data[1]+'</td><td>'+data[2]+'</td><td>'+data[3]+'</td></tr>');
this.hide = function(){
this.el.hide()
};
this.show = function(){
this.el.show()
};
}
function RowDel(data){
Row.call(this, data);
this.remove = function(){
this.el.remove();
}
}
extend(RowDel,Row);
t = new Table();
r1 = new Row([1,'Nissan', '$5000', '200 km/h']);
r2 = new Row([2,'Audi', '$7000', '220 km/h']);
r3 = new Row([3,'BMW', '$9500', '230 km/h']);
r4 = new RowDel([4,'Toyota', '$5000', '200 km/h']);
r5 = new RowDel([5,'Chrysler', '$7000', '220 km/h']);
r6 = new RowDel([6,'Honda', '$9500', '230 km/h']);
rows = [r1,r2,r3];
rows2 = [r4,r5,r6];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment