Sha256: de1e3613d075ccc259e30d9f6f8dd8b2f27b88f6bd746eee0be24dcffeeeb5ae

Contents?: true

Size: 1.8 KB

Versions: 12

Compression:

Stored size: 1.8 KB

Contents

(function(window,jQuery) {
  
  var $ = jQuery;
  
  function getData(string) {
    var data = {};
    
    $.each(string.match(/data-(.*?)="(.*?)"/g) || [], function(index, value) {
      var match = value.match(/data-(.*?)="(.*?)"/);
      data[match[1]] = match[2];
    });
    
    return data;
  }
  
  window.snippets = function() {
    
    var snippets = {names:[],snippets:{}};
    
    var snippetComments = $("*:not(iframe)").contents().filter(function() {
      try {
        return this.nodeType === 8 && this.data.match(/snippet data-type=\"start\"/);
      } catch (e) {
        // Yay for not being allow to look at dom elements with external content, aka iframes
        return false;
      }
    });
    
    snippetComments.each(function() {
      
      var data = getData(this.data);
      
      snippets.names.push(data['name']);
      
      snippets.snippets[data['name']] = {
        pageId:data['page-id'],
        data:data,
        comment:this,
        elements:function() {
          
          var snippetElements = [];
          var element = this.comment;
          while(element.nextSibling) {
            element = element.nextSibling;
            if(element.nodeType === 8 && element.data.match(/snippet data-type=\"end\"/)) {
              break;
            }
            snippetElements.push(element);
          }
          
          return $(snippetElements);
        },
        update:function(newElements) {
          this.elements().remove();
          $(newElements).insertAfter(this.comment);
        },
        prepend:function(newElements) {
          $(newElements).insertAfter(this.comment);
        },
        append:function(newElements) {
          $(newElements).insertAfter(this.elements().last());
        }
        
      };
    });
    
    return snippets;
  };
  
}(window,jQuery));

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
burp_cms-1.7.1 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.7.0 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.6.0 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.13 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.12 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.11 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.10 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.9 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.8 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.7 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.6 app/assets/packages/burp/editing/js/snippets.js
burp_cms-1.5.5 app/assets/packages/burp/editing/js/snippets.js