`

Extjs4 Css美工相关

 
阅读更多

转: http://www.sencha.com/learn/theming/#!/guide/theming-section-2

 

 

This Guide is most relevant to Ext JS, 4.x.

Ext JS 4 has a brand new theming system to customize the look of your application while still supporting all browsers.

A Brief Introduction to SASS & Compass

SASS is a pre-processor which adds new syntax to CSS allowing for things like variables, mixins, nesting, and math/color functions. For example, in SASS we can write:

 

$blue: #3bbfce;
$margin: 16px;
 
.content-navigation {
    border-color: $blue;
    color: darken($blue, 9%);
}
 
.border {
    padding: $margin / 2;
    margin: $margin / 2;
    border-color: $blue;
}

And it will compile to:

.content-navigation {
    border-color: #3bbfce;
    color: #2b9eab;
}
 
.border {
    padding: 8px;
    margin: 8px;
    border-color: #3bbfce;
}

To see the wide variety of other features available in SASS, please see http://sass-lang.com/. Compass extends SASS by adding a variety of CSS3 mixins and providing the extension system that Ext JS leverages. With Compass, one can include rules like:

$boxheight: 10em;
 
.mybox {
    @include border-radius($boxheight/4);
}

Which compiles into:

.mybox {
    -webkit-border-radius: 2.5em;
    -moz-border-radius: 2.5em;
    -o-border-radius: 2.5em;
    -ms-border-radius: 2.5em;
    -khtml-border-radius: 2.5em;
    border-radius: 2.5em;
}

You can learn more about the pre-included mixins with Compass and the other tools it provides here: http://compass-style.org/docs/.

Requirements

Ruby

Mac OSX

XCode installs Ruby and all necessary dependencies to your Mac when installed.

Xcode can be found on the Apple Developer Website: http://developer.apple.com/xcode/

Windows

Visit http://rubyinstaller.org/ and download the latest packaged version of Ruby (1.9.2 at the time of writing)

Compass/SASS gem

Mac OSX

In /Applications/Utilities/Terminal.app, run the following code (you will be asked for your password):

sudo gem install compass

You can verify you have Compass and Sass installed by running the following in Terminal.app:

compass -v
 
sass -v

At the time of writing, the latest version of Compass is 0.11.1 (Antares). The latest version of Sass is 3.1.1 (Brainy Betty)

Windows

Select Start Command Prompt with Ruby from the new Start Menu option.

Type the following:

gem install compass

You can verify you have Compass and Sass installed by running the following in Terminal.app:

compass -v
sass -v

At the time of writing, the latest version of Compass is 0.11.1 (Antares). The latest version of Sass is 3.1.1 (Brainy Betty)

Directory Structure

The Ext JS SDK comes with a template which can be used as a base for your new theme. If you followed the Getting Started guide, you should have a directory for your application with a subfolder extjs containing the Ext JS SDK. It should look something like this:

appname/
appname/extjs/
appname/app.js
appname/index.html

Copy the template resources folder from appname/extjs/resources/themes/templates/resource to your root application folder:

appname/
appname/resources/
appname/resources/css/
appname/resources/sass/
appname/resources/sass/config.rb
appname/resources/sass/my-ext-theme.sass

You will also need to copy the images from appname/extjs/resources/themes/images/default to appname/resources/images.

Ensure the path to your Ext JS folder is correct in appname/resources/sass/config.rb:

# $ext_path: This should be the path of the Ext JS SDK relative to this file
$ext_path = "../../extjs"

Due to a bug in Ext JS 4.0.2a you will also need to edit line 62 of appname/extjs/resources/themes/lib/utils.rb from this:

images_path = File.join($ext_path, 'resources', 'themes', 'images', theme)

to this:

images_path = relative_path

This ensures images will be served from appname/resources/images rather than appname/extjs/resources/images

Compiling your CSS

Compiling your CSS is a simple process using Compass.

First, change to your sass directory in appname/resources/sass, then run the following command in Terminal.app on Mac OSX or Command Prompt on Windows:

> compass compile

This should output the following:

> create ../css/my-ext-theme.css

Your minified css file should now be in appname/resources/css/my-ext-theme.css.

Changing global SASS variables

The Ext JS theming system comes with global SASS variables which you can use to change the look of your application with a few lines of code.

These SASS variables can be added to your appname/resources/sass/my-ext-theme.scss file, but they must be inserted before the call to @import 'ext4/default/all'. You can see an example commented out at the top of your my-ext-theme.scss file:

// Insert your custom variables here.
// $base-color: #aa0000;

Try uncommenting this line and changing the base-color to something else, perhaps the green #a1c148.

Now regenerate your theme by navigating to appname/resources/sass and running compass compile

Available Variables

Navigate to appname/extjs/resources/themes/stylesheets/ext4/default/variables directory. This directory contains all defined variables for each component in Ext JS 4.

The naming convention for variables follows CSS property names, prepends by the component name. For example:

  • Panel border radius

    • CSS Property: border-radius
    • Variable: $panel-border-radius
  • Panel body background color

    • CSS Property: background-color
    • Variable: $panel-body-background-color
  • Toolbar background color

    • CSS Property: background-color
    • Variable: $toolbar-background-color

You can copy any of these variables and add them to your appname/resources/sass/my-ext-theme.scss file before the @import 'ext4/default/all' line.

View the Results

To view your new theme, lets overwrite app.js with the Theme example from the main SDK. This example shows most Ext JS components on a single page. Copy appname/extjs/examples/themes/themes.js to appname/app.js.

Update appname/index.html to the following:

<html>
<head>
    <title>Ext Theme</title>
 
    <link rel="stylesheet" type="text/css" href="resources/css/my-ext-theme.css">
    <script type="text/javascript" src="extjs/ext-debug.js"></script>
    <script type="text/javascript" src="app.js"></script>
</head>
<body></body>
</html>

Now open index.html in your browser and you should see your new theme in action. Try updating the base color in my-ext-theme.sass to something else, recompile your sass, and refresh your browser to see the change. Also try experimenting with other sass variables.

Component UIs

Every component in the Ext JS framework has a ui configuration (which defaults to default). This property can be changed to allow components in your application to have different styles.

The ui of any component can be changed at any time, even after render, by using the setUI method. An example of this can be found in examples/panel/bubble-panel.html.

Creating new Ext JS UIs

Some Ext JS components have SASS @mixin's which allow you to quickly generate new UIs. These include: Ext.panel.Panel, Ext.button.Button, Ext.Toolbar and Ext.window.Window.

Creating these new UIs is simple. Simply call the associated @mixin (found in the documentation) for the component you want to create a new UI for.

Lets look at the Panel @mixin as an example (which can be found in examples/panel/bubble-panel/sass/bubble-panel.scss):

@include extjs-panel-ui(
    'bubble',
 
    $ui-header-font-size: 12px,
    $ui-header-font-weight: bold,
    $ui-header-color: #0D2A59,
    $ui-header-background-color: #fff,
    $ui-header-background-gradient: null,
 
    $ui-border-color: #fff,
    $ui-border-radius: 4px,
    $ui-body-background-color: #fff,
    $ui-body-font-size: 14px
);

The above code will create a new ui for any Ext.panel.Panel component, which you can then use in your application by specifying the ui configuration:

Ext.create('widget.panel', {
    ui: 'bubble',
    width: 300,
    height: 300,
    title: 'Panel with a bubble UI!'
});

Supporting Legacy Browsers

In most cases when creating new UI's, you will want to include background gradients or rounded corners. Unfortunately legacy browsers do not support the corresponding CSS3 properties, so we must use images instead.

With Ext JS 4, we have included a Slicing tool which does the hard work for you. Simply pass it a manifest file of your new UI's (if you have created any) and run the tool from the command line.

How it works

The slicing tool creates a new browser instance, which loads Ext JS and a specified CSS file. Once loaded, it parses a JavaScript file which includes every Ext JS component that needs styling (panel, window, toolbar, etc.). It then analyzes each of those components and determines the size and location of each image that needs to be sliced. It then slices each of the images, sprites them together and saves them in the location defined in the manifest.

The slicer too itself can be run from the command line and is installed as part of the SDK Tools package. It can be run by calling sencha slice theme. Example usage (assuming you are in your application root directory):

sencha slice theme -d extjs -c resources/css/my-ext-theme.css -o resources/images -v

It accepts several arguments:

  • --css[=]value, -c[=]value

    The path to your theme's complete CSS file, e.g., ext-all-access.css. Uses the default Ext JS 4 theme CSS if not provided.

  • --ext-dir[=]value, -d[=]value (required)

    The path to the root of your Ext JS 4 SDK directory.

  • --manifest[=]value, -m[=]value

    The path to your Theme Generator JSON manifest file, e.g., manifest.json. Uses the default packaged manifest if not provided.

  • --output-dir[=]value, -o[=]value

    The destination path to save all generated theme images. This should be inside the resources/themes/images/<themename>/ directory. Defaults to the current working directory.

  • --verbose, -v

    Display a message for every image that is generated.

Usage

  1. Compile your CSS

    You must ensure your SASS theme file has been compiled as this is used for the slicer. Passing no CSS file would result in the slicer to revert to the default ext-all.css file, which would be pointless in most cases.

  2. Creating your manifest file (optional)

    The manifest file is a simple JavaScript file which tells the Slicing tool which custom UI's you would like to slice. This step is only necessary when you have created new UI's.

    Let's look at the bubble panel example again:

    Ext.onReady(function() {
        Ext.manifest = {
            widgets: [
                {
                    xtype: 'widget.header',
                    ui   : 'bubble'
                },
                {
                    xtype: 'widget.panel',
                    ui   : 'bubble'
                }
            ]
        };
    });

    As you can see, you define an Object called Ext.manifest and give it an Array property called widgets. In this Array you should insert an object containing the xtype and ui of the component you want to generate the images for.

    It is important that the Ext.manifest Object is defined inside the Ext.onReady method.

  3. Generating your images

    Now all that is left is to run the command, including the arguments to the Ext JS SDK folder, your theme CSS file and the output directory of the sliced images.

    sencha slice theme -d extjs -c resources/css/my-ext-theme.css -o resources/images -v

FAQ

  • I am getting a 'error resources/sass/my-ext-theme.scss (Line 8: File to import not found or unreadable: ext4/default/all)' error when I compile?

    This is because Compass cannot file the Ext JS 4 theme files. Ensure the $ext_path in the sass/config.rb file is correct.

<!-- AddThis Button BEGIN -->
分享到:
评论

相关推荐

    ExtJS主题CSS

    4. **绿叶色主题**:绿色代表生机与活力,可能适合环保、健康或者户外相关的应用。 5. **粉红主题**:多用于女性向或年轻人口味的产品,营造出温馨、可爱的氛围。 6. **紫色主题**:紫色通常与奢华和高贵相关联,...

    extjs4.0引用的JS和CSS

    Neptune是ExtJS 4的一个内置主题,提供了一套现代且扁平化的界面设计。如果使用了中立主题,可能需要额外引入这个文件来应用主题样式。 3. **ext-theme-neptune-overrides.css**:Neptune主题的覆盖样式文件,通常...

    extJs3升级extjs4方案

    在 ExtJS 3 里生成表的几个框架组件,ExtJS4 大多生成 div,这使得 CSS classes 将会失败。ExtJS4 已完全重新写 grid 组件,tree 也被更新,所以从版本 3 到 4 大部分的属性改变了。 在 ExtJS4 中,API 也发生了很...

    extjs4学习文档

    EXTJS4 是一款强大的JavaScript框架,用于构建富客户端Web应用程序。EXTJS4的学习文档旨在帮助开发者掌握这一框架,尤其对于初学者来说,提供了宝贵的资源。文档中包含了从环境配置到实际应用开发的基础步骤。 首先...

    css.rar_FAC657、COM_c2ecb2;color:_extjs4_extjs的库_html aef css包装

    在提供的压缩包“css.rar”中,我们关注的是与ExtJS 4主题相关的CSS资源。 标题中的“FAC657、COM_c2ecb2;color:_extjs4_extjs的库_html aef css包装”可能是指一种特定的颜色代码(FAC657和C2ECB2)在ExtJS 4的库...

    包含各种类型的extjs小图标,Extjs4小图标

    - ExtJS 4允许开发者自定义图标,可以通过编写CSS来设置新的背景图片,或者使用Icon类并传入自定义的SVG代码或数据URL。 6. **响应式设计**: - 在移动设备上,图标可能需要调整大小或样式以适应不同的屏幕尺寸。...

    Extjs4的demo

    在本例中,我们假设你已经在MyEclipse中创建了一个新的Web项目,并命名为"Extjs4"。将ExtJS 4.0.7的文件放入Webroot目录,以便于访问。 接下来,你需要设置一个学习环境。确保你的机器上已经安装了MyEclipse和...

    extjs4-教程

    ### ExtJS4基础教程知识点 #### 1. ExtJS4开发环境搭建 ExtJS4是使用JavaScript进行开发的框架,专门用于构建富互联网应用(RIA)。搭建ExtJS开发环境需要预先安装一些软件和配置开发环境。以下步骤详细介绍了如何...

    ExtJS4之初体验

    ### ExtJS4之初体验 #### 一、准备工作 在开始使用ExtJS4进行开发之前,我们需要做一些基础的准备工作,确保开发环境已经搭建好,并且能够顺利地运行第一个ExtJS4程序。 ##### 1. 浏览器兼容性 ExtJS4支持大部分...

    extjs4自定义深蓝色主题

    `ext-ux-all.css`可能包含了一些ExtJS4的扩展组件(UX components)的样式,这些组件通常是社区开发的,提供额外的功能或视觉效果。而`fixed.css`可能是对某些组件或全局样式的微调,以实现固定定位或其他特定布局...

    extjs4中文文档

    EXTJS4是一个强大的JavaScript框架,主要用于构建富客户端Web应用程序。这个中文文档是EXTJS4的官方文档...同时,文档还可能涵盖了EXTJS4的升级、调试、性能优化等相关内容,帮助开发者解决实际开发过程中遇到的问题。

    extjs4完整下载

    ExtJS4正式版(官方完整下载包):含所有的源代码,html,api文档,示例。官方网站下载现在需要注册,这个仅供爱好者个人学习使用,如果项目中使用请至官方网站购买。

    ExtJS4多文件上传,带进度条及管理

    本文将详细解析"ExtJS4多文件上传,带进度条及管理"这一主题,涵盖其核心概念、实现方式以及相关技术。 **一、ExtJS4概述** ExtJS4是Sencha公司推出的一个前端框架,它提供了丰富的组件库和强大的数据绑定机制,...

    EXTJS4自学手册

    EXTJS4自学手册——EXT文件目录,本地加载文档,命名规范 EXTJS4自学手册——EXT基本方法、属性(onReady、define、create) EXTJS4自学手册——EXT基本方法、属性(apply、applyIf、constructor) EXTJS4自学手册...

    extjs4环境搭建

    1. `\extjs-4.x\resources`:这个文件夹包含所有CSS样式文件和图片资源,它们用于定义组件的外观。 2. `\extjs-4.x\ext-all.js`:这是ExtJS的核心文件,包含了所有的组件、事件处理和其他核心功能。 3. `\extjs-4.x\...

    ExtJs 4 API中文

    ExtJs 4 API 中文

    extjs4-slate 主题

    总的来说,ExtJS 4 Slate 主题为开发者提供了一个现代、美观的界面设计,通过合理的 CSS 样式和资源管理,可以帮助构建出专业级别的 web 应用程序。同时,它的易定制性和响应式设计使其在各种项目中都具有很高的实用...

    extjs4学习资源大全

    在"ext"目录下,你可以找到ExtJS4的核心库文件,包括JS文件和CSS样式表。这些文件是构建ExtJS应用的基础,其中`ext-all.js`是包含所有组件和功能的完整版本,而`ext-debug.js`则是带有调试信息的版本,便于在开发...

    ExtJs4.rar

    在本文中,我们将深入探讨ExtJS4这一版本的重要特性、改进以及它如何扩展了先前版本的功能。 首先,ExtJS4在组件化方面有了显著提升。在之前的版本中,组件系统就已经是其核心优势,而ExtJS4进一步优化了这一系统,...

Global site tag (gtag.js) - Google Analytics