Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Properly extend rules, parse each import sheet separately, widget fix…

…es, rendering fix
  • Loading branch information...
commit bb779b6161f4127b993250d4cf465f2d70df0709 1 parent 0e919ad
@kriszyp authored
View
190 LICENSE
@@ -0,0 +1,190 @@
+xstyle is available under *either* the terms of the modified BSD license *or* the
+Academic Free License version 2.1. As a recipient of xstyle, you may choose which
+license to receive this code under.
+
+The text of the AFL and BSD licenses is reproduced below.
+
+-------------------------------------------------------------------------------
+The "New" BSD License:
+**********************
+
+Copyright (c) 2010-2011, The Dojo Foundation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the Dojo Foundation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------------------------------------------------
+The Academic Free License, v. 2.1:
+**********************************
+
+This Academic Free License (the "License") applies to any original work of
+authorship (the "Original Work") whose owner (the "Licensor") has placed the
+following notice immediately following the copyright notice for the Original
+Work:
+
+Licensed under the Academic Free License version 2.1
+
+1) Grant of Copyright License. Licensor hereby grants You a world-wide,
+royalty-free, non-exclusive, perpetual, sublicenseable license to do the
+following:
+
+a) to reproduce the Original Work in copies;
+
+b) to prepare derivative works ("Derivative Works") based upon the Original
+Work;
+
+c) to distribute copies of the Original Work and Derivative Works to the
+public;
+
+d) to perform the Original Work publicly; and
+
+e) to display the Original Work publicly.
+
+2) Grant of Patent License. Licensor hereby grants You a world-wide,
+royalty-free, non-exclusive, perpetual, sublicenseable license, under patent
+claims owned or controlled by the Licensor that are embodied in the Original
+Work as furnished by the Licensor, to make, use, sell and offer for sale the
+Original Work and Derivative Works.
+
+3) Grant of Source Code License. The term "Source Code" means the preferred
+form of the Original Work for making modifications to it and all available
+documentation describing how to modify the Original Work. Licensor hereby
+agrees to provide a machine-readable copy of the Source Code of the Original
+Work along with each copy of the Original Work that Licensor distributes.
+Licensor reserves the right to satisfy this obligation by placing a
+machine-readable copy of the Source Code in an information repository
+reasonably calculated to permit inexpensive and convenient access by You for as
+long as Licensor continues to distribute the Original Work, and by publishing
+the address of that information repository in a notice immediately following
+the copyright notice that applies to the Original Work.
+
+4) Exclusions From License Grant. Neither the names of Licensor, nor the names
+of any contributors to the Original Work, nor any of their trademarks or
+service marks, may be used to endorse or promote products derived from this
+Original Work without express prior written permission of the Licensor. Nothing
+in this License shall be deemed to grant any rights to trademarks, copyrights,
+patents, trade secrets or any other intellectual property of Licensor except as
+expressly stated herein. No patent license is granted to make, use, sell or
+offer to sell embodiments of any patent claims other than the licensed claims
+defined in Section 2. No right is granted to the trademarks of Licensor even if
+such marks are included in the Original Work. Nothing in this License shall be
+interpreted to prohibit Licensor from licensing under different terms from this
+License any Original Work that Licensor otherwise would have a right to
+license.
+
+5) This section intentionally omitted.
+
+6) Attribution Rights. You must retain, in the Source Code of any Derivative
+Works that You create, all copyright, patent or trademark notices from the
+Source Code of the Original Work, as well as any notices of licensing and any
+descriptive text identified therein as an "Attribution Notice." You must cause
+the Source Code for any Derivative Works that You create to carry a prominent
+Attribution Notice reasonably calculated to inform recipients that You have
+modified the Original Work.
+
+7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
+the copyright in and to the Original Work and the patent rights granted herein
+by Licensor are owned by the Licensor or are sublicensed to You under the terms
+of this License with the permission of the contributor(s) of those copyrights
+and patent rights. Except as expressly stated in the immediately proceeding
+sentence, the Original Work is provided under this License on an "AS IS" BASIS
+and WITHOUT WARRANTY, either express or implied, including, without limitation,
+the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU.
+This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No
+license to Original Work is granted hereunder except under this disclaimer.
+
+8) Limitation of Liability. Under no circumstances and under no legal theory,
+whether in tort (including negligence), contract, or otherwise, shall the
+Licensor be liable to any person for any direct, indirect, special, incidental,
+or consequential damages of any character arising as a result of this License
+or the use of the Original Work including, without limitation, damages for loss
+of goodwill, work stoppage, computer failure or malfunction, or any and all
+other commercial damages or losses. This limitation of liability shall not
+apply to liability for death or personal injury resulting from Licensor's
+negligence to the extent applicable law prohibits such limitation. Some
+jurisdictions do not allow the exclusion or limitation of incidental or
+consequential damages, so this exclusion and limitation may not apply to You.
+
+9) Acceptance and Termination. If You distribute copies of the Original Work or
+a Derivative Work, You must make a reasonable effort under the circumstances to
+obtain the express assent of recipients to the terms of this License. Nothing
+else but this License (or another written agreement between Licensor and You)
+grants You permission to create Derivative Works based upon the Original Work
+or to exercise any of the rights granted in Section 1 herein, and any attempt
+to do so except under the terms of this License (or another written agreement
+between Licensor and You) is expressly prohibited by U.S. copyright law, the
+equivalent laws of other countries, and by international treaty. Therefore, by
+exercising any of the rights granted to You in Section 1 herein, You indicate
+Your acceptance of this License and all of its terms and conditions.
+
+10) Termination for Patent Action. This License shall terminate automatically
+and You may no longer exercise any of the rights granted to You by this License
+as of the date You commence an action, including a cross-claim or counterclaim,
+against Licensor or any licensee alleging that the Original Work infringes a
+patent. This termination provision shall not apply for an action alleging
+patent infringement by combinations of the Original Work with other software or
+hardware.
+
+11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this
+License may be brought only in the courts of a jurisdiction wherein the
+Licensor resides or in which Licensor conducts its primary business, and under
+the laws of that jurisdiction excluding its conflict-of-law provisions. The
+application of the United Nations Convention on Contracts for the International
+Sale of Goods is expressly excluded. Any use of the Original Work outside the
+scope of this License or after its termination shall be subject to the
+requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et
+seq., the equivalent laws of other countries, and international treaty. This
+section shall survive the termination of this License.
+
+12) Attorneys Fees. In any action to enforce the terms of this License or
+seeking damages relating thereto, the prevailing party shall be entitled to
+recover its costs and expenses, including, without limitation, reasonable
+attorneys' fees and costs incurred in connection with such action, including
+any appeal of such action. This section shall survive the termination of this
+License.
+
+13) Miscellaneous. This License represents the complete agreement concerning
+the subject matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent necessary to
+make it enforceable.
+
+14) Definition of "You" in This License. "You" throughout this License, whether
+in upper or lower case, means an individual or a legal entity exercising rights
+under, and complying with all of the terms of, this License. For legal
+entities, "You" includes any entity that controls, is controlled by, or is
+under common control with you. For purposes of this definition, "control" means
+(i) the power, direct or indirect, to cause the direction or management of such
+entity, whether by contract or otherwise, or (ii) ownership of fifty percent
+(50%) or more of the outstanding shares, or (iii) beneficial ownership of such
+entity.
+
+15) Right to Use. You may use the Original Work in all ways not otherwise
+restricted or conditioned by this License or by law, and Licensor promises not
+to interfere with or be responsible for such uses by You.
+
+This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved.
+Permission is hereby granted to copy and distribute this license without
+modification. This license may not be modified without the express written
+permission of its copyright owner.
View
1  elemental.js
@@ -63,6 +63,7 @@ define([], function(){
for(var i = 0; i < renderQueue.length; i++){
var element = renderQueue[i];
var renderings = element.renderings, currentStyle = element.elementalStyle;
+ delete element.renderings;
for(var j = 0; j < renderings.length; j++){
var rendering = renderings[j];
var renderer = rendering.renderer;
View
2  ext.css
@@ -10,6 +10,6 @@ x-property {
-x-widget: require(xstyle/ext/widget);
-x-content: require(xstyle/ext/generate);
bind: require(xstyle/ext/bind);
- to: require(xstyle/ext/bind);
+ from: require(xstyle/ext/bind);
onclick: require(xstyle/ext/event);
}
View
26 ext/event-delegate.js
@@ -0,0 +1,26 @@
+define([], function(){
+ var module, hasAddEventListener = !!document.addEventListener,
+ div = document.createElement('div')
+ matchesSelector = div.matchesSelector || div.webkitMatchesSelector || div.msMatchesSelector || div.mozMatchesSelector;
+ return module = {
+ // TODO: do an onCall function version for adding events that don't get overriden?
+ onProperty: function(name, value, rule){
+ var selector;
+ // TODO: We could do a neat optimization of event handling with webkitMatchesRules, and delegating to the appropriate rule based on a hash map
+ // we use event delegation
+ this.on(document, name.slice(2), rule.fullSelector(), value);
+ },
+ on: function(target, event, selector, listener){
+ // this function can be overriden to provide better event handling
+ hasAddEventListener ?
+ target.addEventListener(event, select, false) :
+ target.attachEvent(event, select);
+ function select(event){
+ selector = selector || rule.fullSelector();
+ if(matchesSelector.call(event.target, selector)){
+ console.log("execute event", listener);
+ }
+ }
+ }
+ };
+});
View
2  ext/generate.js
@@ -1,4 +1,4 @@
-// TODO: eventually can probably get rid of put-selector dependency
+// TODO: eventually maybe we can probably get rid of put-selector dependency
define(['../elemental', 'put-selector/put'], function(elemental, put){
var nextId = 0;
return {
View
4 ext/widget.js
@@ -44,6 +44,8 @@ define(['../elemental'], function(elemental){
new Class(props, element);
});
}
+ }else{
+ console.error("No type defined for widget");
}
}else if(value.splice){
// an array
@@ -103,7 +105,7 @@ define(['../elemental'], function(elemental){
// }
return {
then: function(callback){
- parse(value.eachProperty ? value : rule, function(renderer){
+ parse(value[1].eachProperty ? value[1] : rule, function(renderer){
elemental.addRenderer(name, value, rule, renderer);
callback();
}, typeof value == "string" && value);
View
2  load-imports.js
@@ -187,6 +187,8 @@ define([], function(){
sourceSheet.localSource = text;
finishedModule();
});
+ }else{
+ sheet.localSource = link.innerHTML;
}
var cssRules = sheet.rules || sheet.cssRules;
for(var i = 0; i < cssRules.length; i++){
View
31 test/testDijit.css
@@ -25,28 +25,29 @@ button {
}
dijit-text {
width: 100px;
- -x-widget: dijit/form/TextBox;
+ widget: dijit/form/TextBox;
height: 30px;
display: block;
background-color: red;
}
red-dijit-text {
- =dijit-text(200px);
+ extends(dijit-text);/*dijit-text(200px)*/
height: 50px;
}
-form.edit-object { =>
- label 'Some label',
- input[type=number] {
- to: content.price;
- background-color: green;
- },
- input[type=number] {
- to: content.quantity;
- },
- div {
- to: content.price*content.quantity;
- },
- red-dijit-text;
+form.edit-object {
+ =>
+ label 'Some label',
+ input[type=number] {
+ from: content.price;
+ background-color: green;
+ },
+ input[type=number] {
+ from: content.quantity;
+ },
+ div {
+ from: content.price*content.quantity;
+ },
+ red-dijit-text 'red-dijit-text';
background-color: blue;
}
View
308 xstyle.js
@@ -66,12 +66,16 @@ define("xstyle/xstyle", ["require"], function (require) {
if(rule.selectorText && rule.selectorText.substring(0,2) == "x-"){
// an extension is used, needs to be parsed
needsParsing = true;
+ if(/^'/.test(rule.style.content)){
+ // this means we are in a built sheet, and can directly parse it
+ // TODO: parse here
+ }
}
}
}
if(needsParsing){
// ok, determined that CSS extensions are in the CSS, need to get the source and really parse it
- parse(sheet.source || sheet.ownerElement.innerHTML, sheet, callback);
+ parse(sheet.localSource || sheet.ownerElement.innerHTML, sheet, callback);
}
}
function parse(textToParse, styleSheet, callback) {
@@ -85,6 +89,8 @@ define("xstyle/xstyle", ["require"], function (require) {
if(!styleSheet.deleteRule){
styleSheet.deleteRule = sheet.removeRule;
}
+
+
var handlers = {property:{}};
function addHandler(type, name, module){
var handlersForType = handlers[type] || (handlers[type] = {});
@@ -126,16 +132,16 @@ define("xstyle/xstyle", ["require"], function (require) {
});
}
}while(asString = parts[2]);
-/* var ifUnsupported = value.charAt(value.length - 1) == "?";
- value = value.replace(/require\s*\(|\)\??/g, '');
- if(!ifUnsupported || typeof testDiv.style[name] != "string"){ // if conditioned on support, test to see browser has that style
- // not supported as a standard property, now let's check to see if we can support it with vendor prefixing
- if(ifUnsupported && typeof testDiv.style[vendorPrefix + name] == "string"){
- // it does support vendor prefixing, fix it with that
- value = 'xstyle/xstyle';
- }
- addHandler(type, name, value);
- }*/
+ /* var ifUnsupported = value.charAt(value.length - 1) == "?";
+ value = value.replace(/require\s*\(|\)\??/g, '');
+ if(!ifUnsupported || typeof testDiv.style[name] != "string"){ // if conditioned on support, test to see browser has that style
+ // not supported as a standard property, now let's check to see if we can support it with vendor prefixing
+ if(ifUnsupported && typeof testDiv.style[vendorPrefix + name] == "string"){
+ // it does support vendor prefixing, fix it with that
+ value = 'xstyle/xstyle';
+ }
+ addHandler(type, name, value);
+ }*/
});
}
});
@@ -180,17 +186,17 @@ define("xstyle/xstyle", ["require"], function (require) {
newCall: function(name){
return new Call(name);
},
- add: function(selector, cssText){
-console.log("add", selector, cssText);
+ add: function(cssText){
+console.log("add", this.selector, cssText);
if(cssText){
styleSheet.addRule ?
- styleSheet.addRule(selector, cssText) :
- styleSheet.insertRule(selector + '{' + cssText + '}', styleSheet.cssRules.length);
+ styleSheet.addRule(this.selector, cssText) :
+ styleSheet.insertRule(this.selector + '{' + cssText + '}', styleSheet.cssRules.length);
}
},
onRule: function(){
if(!this.parent.root){
- this.add(this.selector, this.cssText);
+ this.add(this.cssText);
}
},
addProperty: function(name, property){
@@ -223,10 +229,10 @@ console.log("onProperty", name, value);
}while(name);
}
}
- function onCall(identifier, name, value){
+ function onCall(identifier, value){
var handlerForName = handlers['function'][identifier];
if(handlerForName){
- handler(handlerForName, "onCall", name, value);
+ handler(handlerForName, "onCall", identifier, value, value.args);
}
}
function onRule(selector, rule){
@@ -288,132 +294,143 @@ console.log("onProperty", name, value);
typeof module == "string" ? require([module], onLoad) : onLoad(module);
}
}
- function addInSequence(operand){
- if(sequence){
- // we had a string so we are accumulated sequences now
- sequence.push ? operand && sequence.push(operand) : typeof sequence == 'string' && typeof operand == 'string' ? sequence += operand : sequence = arrayWithoutCommas([sequence, operand]);
- }else{
- sequence = operand;
- }
- }
var stack = [target];
- // parse the CSS, finding each rule
- cssScan.lastIndex = 0; // start at zero
- while(true){
- var match = cssScan.exec(textToParse);
- var operator = match[3],
- first = match[1].trim(),
- value = match[2],
- name, sequence, assignNextName;
- value = value && value.trim();
- if(assignNextName){
- // first part of a property
- name = value && first;
- sequence = value = value || first;
- assignNextName = false;
- }else{
- // subsequent part of a property
- value = value ? first + ':' + value : first;
- addInSequence(value);
+ function parseSheet(textToParse, styleSheet){
+ // parse the CSS, finding each rule
+ function addInSequence(operand){
+ if(sequence){
+ // we had a string so we are accumulated sequences now
+ sequence.push ? operand && sequence.push(operand) : typeof sequence == 'string' && typeof operand == 'string' ? sequence += operand : sequence = arrayWithoutCommas([sequence, operand]);
+ }else{
+ sequence = operand;
+ }
}
- switch(operator){
- case "'": case '"':
- var quoteScan = operator == "'" ? singleQuoteScan : doubleQuoteScan;
- quoteScan.lastIndex = cssScan.lastIndex;
- var str = quoteScan.exec(textToParse)[1];
- cssScan.lastIndex = quoteScan.lastIndex;
- // push the string on the current value and keep parsing
- addInSequence(new String(str));
- continue;
- case '/':
- // we parse these in case it is a comment
- if(textToParse[cssScan.lastIndex + 1] == '*'){
- // it's a comment, scan to the end of the comment
- commentScan.lastIndex = cssScan.lastIndex + 1;
- commentScan.exec(textToParse);
- cssScan.lastIndex = commentScan.lastIndex;
- }else{
- // not a comment, keep the operator in the accumulating string
- addInSequence('/');
+ cssScan.lastIndex = 0; // start at zero
+ var ruleIndex = 0;
+ while(true){
+ var match = cssScan.exec(textToParse);
+ var operator = match[3],
+ first = match[1].trim(),
+ value = match[2],
+ name, sequence, assignNextName;
+ value = value && value.trim();
+ if(assignNextName){
+ // first part of a property
+ name = typeof value == 'string' && first;
+ sequence = value = value || first;
+ if(name || operator != '/'){
+ // as long we haven't hit an initial comment, we have the assigned property name now, and don't need to assign again
+ assignNextName = false;
}
- continue;
- case '\\':
- // escaping sequence
- var lastIndex = quoteScan.lastIndex++;
- addInSequence(textToParse.charAt(lastIndex));
- continue;
- case '(': case '{':
- var newTarget;
- assignNextName = true;
- if(operator == '{'){
- addInSequence(newTarget = target.newRule(value));
- }else{
- addInSequence(newTarget = target.newCall(value));
- }
- newTarget.parent = target;
- if(sequence[0].charAt(0) == '='){
- sequence.creating = true;
- }
- if(sequence.creating){
- newTarget.selector = '.x-generated-' + nextId++;
- }else{
- newTarget.selector = target.root ? value : target.selector + ' ' + value;
- }
- target.currentName = name;
- target.currentSequence = sequence;
- stack.push(target = newTarget);
- target.operator = operator;
- target.start = cssScan.lastIndex,
- target.selector && target.selector.replace(/:([-\w]+)/, function(t, pseudo){
- onPseudo(pseudo, target);
- });
- name = null;
- sequence = null;
- continue;
- }
- /*if(assignmentOperator == "@"){
- // directive
- if(sequence[0].slice(0,6) == "import"){
-console.log("found import", value[1]);
- /*return sheet.request(value[1], function(importedSheet){
- importedSheet.sheet = sheet.sheet;
- parse(importedSheet, target, function(){
- continueParsing(text.slice(cssScan.lastIndex), callback)
+ }else{
+ // subsequent part of a property
+ value = value ? first + ':' + value : first;
+ addInSequence(value);
+ }
+ switch(operator){
+ case "'": case '"':
+ var quoteScan = operator == "'" ? singleQuoteScan : doubleQuoteScan;
+ quoteScan.lastIndex = cssScan.lastIndex;
+ var str = quoteScan.exec(textToParse)[1];
+ cssScan.lastIndex = quoteScan.lastIndex;
+ // push the string on the current value and keep parsing
+ addInSequence(new String(str));
+ continue;
+ case '/':
+ // we parse these in case it is a comment
+ if(textToParse[cssScan.lastIndex] == '*'){
+ // it's a comment, scan to the end of the comment
+ commentScan.lastIndex = cssScan.lastIndex + 1;
+ commentScan.exec(textToParse);
+ cssScan.lastIndex = commentScan.lastIndex;
+ }else{
+ // not a comment, keep the operator in the accumulating string
+ addInSequence('/');
+ }
+ continue;
+ case '\\':
+ // escaping sequence
+ var lastIndex = quoteScan.lastIndex++;
+ addInSequence(textToParse.charAt(lastIndex));
+ continue;
+ case '(': case '{':
+ var newTarget;
+ if(operator == '{'){
+ assignNextName = true;
+ addInSequence(newTarget = target.newRule(value));
+ }else{
+ addInSequence(newTarget = target.newCall(value));
+ }
+ newTarget.parent = target;
+ if(target.root){
+ newTarget.cssRule = styleSheet.cssRules[ruleIndex++];
+ }
+ if(sequence[0].charAt(0) == '='){
+ sequence.creating = true;
+ }
+ if(sequence.creating){
+ newTarget.selector = '.x-generated-' + nextId++;
+ }else{
+ newTarget.selector = target.root ? value : target.selector + ' ' + value;
+ }
+ target.currentName = name;
+ target.currentSequence = sequence;
+ stack.push(target = newTarget);
+ target.operator = operator;
+ target.start = cssScan.lastIndex,
+ target.selector && target.selector.replace(/:([-\w]+)/, function(t, pseudo){
+ onPseudo(pseudo, target);
});
- });
+ name = null;
+ sequence = null;
+ continue;
}
- }else{*/
- if(sequence){
- target.addProperty(name, sequence);
- }
- name = null;
-// }
- switch(operator){
- case '}': case ')':
- var ruleText = textToParse.slice(target.start, cssScan.lastIndex - 1);
- target.cssText = ruleText;
- if(operator == '}'){
- onRule(target.selector, target);
- if(target.selector.slice(0,2) != "x-"){
- target.eachProperty(onProperty);
+ if(sequence){
+ if(sequence[0].charAt(0) == "@"){
+ // directive
+ if(sequence[0].slice(1,7) == "import"){
+ console.log("found import", sequence);
+ var importedSheet = styleSheet.cssRules[ruleIndex++].styleSheet;
+ waiting++;
+ // preserve the current index, as we are using a single regex to be shared by all parsing executions
+ var currentIndex = cssScan.lastIndex;
+ parseSheet(importedSheet.localSource, importedSheet);
+ cssScan.lastIndex = currentIndex;
}
- }else{
- onCall(target.selector, target);
+ }else{
+ target.addProperty(name, sequence);
}
- stack.pop();
- target = stack[stack.length - 1];
- sequence = target.currentSequence;
- name = target.currentName;
- break;
- case "":
- // no operator means we have reached the end
- callback && callback();
- return finishedLoad(target);
- case ';':
- sequence = null;
- assignNextName = true;
+ }
+ name = null;
+ // }
+ switch(operator){
+ case '}': case ')':
+ var ruleText = textToParse.slice(target.start, cssScan.lastIndex - 1);
+ target.cssText = ruleText;
+ if(operator == '}'){
+ onRule(target.selector, target);
+ if(target.selector.slice(0,2) != "x-"){
+ target.eachProperty(onProperty);
+ }
+ }else{
+ onCall(target.caller, target);
+ }
+ stack.pop();
+ target = stack[stack.length - 1];
+ sequence = target.currentSequence;
+ name = target.currentName;
+ break;
+ case "":
+ // no operator means we have reached the end
+ callback && callback();
+ return;
+ case ';':
+ sequence = null;
+ assignNextName = true;
+ }
}
}
+ parseSheet(textToParse,styleSheet);
function finishedLoad(){
if(--waiting == 0){
if(callback){
@@ -435,16 +452,27 @@ console.log("found import", value[1]);
}
return vendorPrefix + name + ':' + value + ';';
},
- onCall: function(name, args, rule){
+ onCall: function(name, rule){
// handle extends(selector)
-
-console.log("extends", value);
+ var args = rule.args;
+console.log("extends", args);
var extendingRule = rule.parent;
- var baseRule = extendingRule.parent.rules[args[0]];
+ var parentRule = extendingRule;
+ do{
+ var baseRule = parentRule.rules && parentRule.rules[args[0]];
+ parentRule = parentRule.parent;
+ }while(!baseRule);
var newText = baseRule.cssText;
extendingRule.cssText += newText;
extendingRule.properties = Object.create(baseRule.properties);
- extendingRule.add(extendingRule.fullSelector(), newText);
+ baseRule.eachProperty(function(name, value){
+ if(name){
+ var ruleStyle = extendingRule.cssRule.style;
+ if(!ruleStyle[name]){
+ ruleStyle[name] = value;
+ }
+ }
+ });
},
parse: parse
};
Please sign in to comment.
Something went wrong with that request. Please try again.