| | 43 | * |
| | 44 | * @param string CSS |
| | 45 | * |
| | 46 | * @param hash Alternate descriptive names for your classes |
| | 47 | * { '.fooclass': 'Foo Description' } |
| | 48 | * |
| | 49 | * @param bool If set true then @import rules in the stylesheet are skipped, |
| | 50 | * otherwise they will be incorporated if possible. |
| | 51 | * |
| | 52 | * @param string If skip_imports is false, this string should contain |
| | 53 | * the "URL" of the stylesheet these styles came from (doesn't matter |
| | 54 | * if it exists or not), it is used when resolving relative URLs etc. |
| | 55 | * If not provided, it defaults to Xinha.css in the Xinha root. |
| 468 | | var RE_atimport = '@import\\s*(url\\()?["\'](.*)["\'].*'; |
| 469 | | var imports = css.match(new RegExp(RE_atimport,'ig')); |
| 470 | | var m, file, re = new RegExp(RE_atimport,'i'); |
| 471 | | |
| 472 | | if (imports) |
| 473 | | { |
| 474 | | var path = URL.replace(/\?.*$/,'').split("/"); |
| 475 | | path.pop(); |
| 476 | | path = path.join('/'); |
| 477 | | for (var i=0;i<imports.length;i++) |
| 478 | | { |
| 479 | | m = imports[i].match(re); |
| 480 | | file = m[2]; |
| 481 | | if (!file.match(/^([^:]+\:)?\//)) |
| 482 | | { |
| 483 | | file = Xinha._resolveRelativeUrl(path,file); |
| 484 | | } |
| 485 | | css += Xinha._geturlcontent(file); |
| 486 | | } |
| 487 | | } |
| 488 | | |
| 489 | | return Xinha.ripStylesFromCSSString(css); |
| 490 | | }; |
| 491 | | |
| 492 | | Xinha.ripStylesFromCSSString = function(css) |
| 493 | | { |
| | 489 | |
| | 490 | return Xinha.ripStylesFromCSSString(css, skip_imports, URL); |
| | 491 | }; |
| | 492 | |
| | 493 | Xinha.ripStylesFromCSSString = function(css, skip_imports, imports_relative_to) |
| | 494 | { |
| | 495 | if(!skip_imports) |
| | 496 | { |
| | 497 | if(!imports_relative_to) |
| | 498 | { |
| | 499 | imports_relative_to = _editor_url + 'Xinha.css' |
| | 500 | } |
| | 501 | |
| | 502 | var seen = { }; |
| | 503 | |
| | 504 | function resolve_imports(css, url) |
| | 505 | { |
| | 506 | seen[url] = true; // protects against infinite recursion |
| | 507 | |
| | 508 | var RE_atimport = '@import\\s*(url\\()?["\'](.*)["\'].*'; |
| | 509 | var imports = css.match(new RegExp(RE_atimport,'ig')); |
| | 510 | var m, file, re = new RegExp(RE_atimport,'i'); |
| | 511 | |
| | 512 | if (imports) |
| | 513 | { |
| | 514 | var path = url.replace(/\?.*$/,'').split("/"); |
| | 515 | path.pop(); |
| | 516 | path = path.join('/'); |
| | 517 | for (var i=0;i<imports.length;i++) |
| | 518 | { |
| | 519 | m = imports[i].match(re); |
| | 520 | file = m[2]; |
| | 521 | if (!file.match(/^([^:]+\:)?\//)) |
| | 522 | { |
| | 523 | file = Xinha._resolveRelativeUrl(path,file); |
| | 524 | } |
| | 525 | |
| | 526 | if(seen[file]) continue; |
| | 527 | |
| | 528 | css += resolve_imports(Xinha._geturlcontent(file), file); |
| | 529 | } |
| | 530 | } |
| | 531 | |
| | 532 | return css; |
| | 533 | } |
| | 534 | |
| | 535 | css = resolve_imports(css, imports_relative_to); |
| | 536 | } |
| | 537 | |