Sha256: 04eb0206c1b525dde81c50b0c3a96489501844dc99d743daea9234c85d3a9cba

Contents?: true

Size: 1.76 KB

Versions: 33

Compression:

Stored size: 1.76 KB

Contents

/*!
 * Stylus - Media
 * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var Node = require('./node')
  , nodes = require('./');

/**
 * Initialize a new `Media` with the given `val`
 *
 * @param {String} val
 * @api public
 */

var Media = module.exports = function Media(val){
  Node.call(this);
  this.val = val;
};

/**
 * Inherit from `Node.prototype`.
 */

Media.prototype.__proto__ = Node.prototype;

/**
 * Clone this node.
 *
 * @return {Media}
 * @api public
 */

Media.prototype.clone = function(parent){
  var clone = new Media;
  clone.val = this.val.clone(parent, clone);
  clone.block = this.block.clone(parent, clone);
  clone.lineno = this.lineno;
  clone.filename = this.filename;
  return clone;
};

/**
 * Return a JSON representation of this node.
 *
 * @return {Object}
 * @api public
 */

Media.prototype.toJSON = function(){
  return {
    __type: 'Media',
    val: this.val,
    block: this.block,
    lineno: this.lineno,
    filename: this.filename
  };
};

/**
 * Check if media block has properties.
 *
 * @return {Boolean}
 * @api public
 */

Media.prototype.__defineGetter__('hasProperties', function(){
  return hasProperties(this.block);
});

/**
 * Return @media "val".
 *
 * @return {String}
 * @api public
 */

Media.prototype.toString = function(){
  return '@media ' + this.val;
};

function hasProperties(block) {
  for (var i = 0, len = block.nodes.length; i < len; i++) {
    var node = block.nodes[i];
    switch (node.nodeName) {
      case 'property':
        return true;
      case 'group':
        return !node.hasOnlyPlaceholders && hasProperties(node.block);
      case 'block':
        return hasProperties(node);
      default:
        if (node.block) return hasProperties(node.block);
    }
  }
}

Version data entries

33 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.6 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.1.5 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.5 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.1.4 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.1.4 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.3 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.3 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.1.2 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.2 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.1.1 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.1 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.1.0 node_modules/poised/node_modules/stylus/lib/nodes/media.js
ela-4.1.0 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-4.0.0 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-3.4.3 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-3.4.2 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-3.4.0 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-3.3.1 node_modules/codo/node_modules/nib/node_modules/stylus/lib/nodes/media.js
ela-3.3.0 node_modules/poised.old/node_modules/stylus/lib/nodes/media.js