Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.findNext = function(selector, steps, scope)
- {
- // Steps given? Then parse to int
- if (steps)
- {
- steps = Math.floor(steps);
- }
- else if (steps === 0)
- {
- // Stupid case :)
- return this;
- }
- else
- {
- // Else, try the easy way
- var next = this.next(selector);
- if (next.length)
- return next;
- // Easy way failed, try the hard way :)
- steps = 1;
- }
- // Set scope to document or user-defined
- scope = (scope) ? $(scope) : $(document);
- // Find kids that match selector: used as exclusion filter
- var kids = this.find(selector);
- // Find in parent(s)
- hay = $(this);
- while(hay[0] != scope[0])
- {
- // Move up one level
- hay = hay.parent();
- // Select all kids of parent
- // - excluding kids of current element (next != inside),
- // - add current element (will be added in document order)
- var rs = hay.find(selector).not(kids).add($(this));
- // Move the desired number of steps
- var id = rs.index(this) + steps;
- // Result found? then return
- if (id > -1 && id < rs.length)
- return $(rs[id]);
- }
- // Return empty result
- return $([]);
- }
- $(".card-title").each(function() {
- var cartTitleHieght = $(this).height();
- var cartDestHieght = $(this).findNext('.card-dest').height();
- // console.log('title: ' + cartTitleHieght);
- // console.log('dest: ' + cartDestHieght);
- descLen = $(this).findNext('.max-text').text().length;
- if(cartTitleHieght + cartDestHieght <= 48) {
- $(this).findNext(".max-text").text($(this).findNext(".max-text").text().substr(0,200)+'...');
- } else if (cartTitleHieght + cartDestHieght <= 72) {
- $(this).findNext(".max-text").text($(this).findNext(".max-text").text().substr(0,130)+'...');
- } else if (cartTitleHieght + cartDestHieght <= 96) {
- $(this).findNext(".max-text").text($(this).findNext(".max-text").text().substr(0,80)+'...');
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement