Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions assets/js/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function(win, undef){
var CONSTANTS = {
JS_VERSION : '0.3.0'
},
CONS_REG = {}
;

function parseConstants(text) {
Object.each(CONSTANTS, function(value, key) {
var reg = CONS_REG[key] || (CONS_REG[key] = new RegExp('{{' + key + '}}', 'g'))
;

text = text.replace(reg, value);
});

return text;
}

win['parseConstants'] = parseConstants;
})(window);
100 changes: 59 additions & 41 deletions assets/js/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@
type : 'GET',
success : function(text) {
if (hasMarked){
var lexer, parsed;
var lexer;

if (parseHandler) {
lexer = marked.lexer(text);
parsed = marked.parser(parseHandler(lexer));
text = marked.parser(parseHandler(lexer));
} else {
parsed = marked(text);
text = marked(text);
}

successHandler(parsed);
} else {
successHandler(text);
}

successHandler(parseConstants(text));

callback && callback();
},
error : function() {
Expand Down Expand Up @@ -168,7 +166,7 @@
if (!(matches = linkReg.exec(text))) {
title = text;
id = baseId + headerMenu.length;
text = '[' + text + '](' + headerMenu.length + ')';
//text = '[' + text + '](' + headerMenu.length + ')';
} else {
title = matches[1];
id = matches[2].replace('#', baseId);
Expand Down Expand Up @@ -249,11 +247,6 @@
dom = $('<div>' + html + '</div>')
;

// // use new window to open
// dom.find('a[href^="http"]').each(function() {
// $(this).attr('target', '_blank');
// });

articleEl.html(html);
}

Expand All @@ -266,7 +259,7 @@
init();
} else if (hash.page !== hashParam.page) {
hashParam.page = hash.page;
loadContent();
loadContent(done);
}
});

Expand Down Expand Up @@ -328,41 +321,66 @@
});

loadCategory(function() {
loadContent(function() {
var path = $.joinPath(name, page, section)
;
loadContent(done);
});
}

articleEl.find('a.top').each(function() {
var el = this,
anchor = $(el),
id = anchor.attr('id')
;
function done() {
var hash = parseHash(),
name = hash.name,
page = hash.page,
section = hash.section,
path = $.joinPath(name, page, section)
;

if (id === path) {
win.scrollTo(0, anchor.offset().top);
}
cateUl.find('a.link').each(function() {
var el = this,
anchor = $(el),
href = anchor.attr('href')
;

if (href.indexOf('#' + name + '/' + page) === 0) {
var li = anchor.parent('li'),
groupLi = li.parent('ul').parent('li')
;

[li, groupLi].forEach(function(e) {
e.addClass('active')
.siblings('.active').removeClass('active');
});
}
});

dropdownUl = $('section.dropdown ul.dropdown-menu');
articleEl.find('a.top').each(function() {
var el = this,
anchor = $(el),
id = anchor.attr('id')
;

dropdownUl.on('mousemove', function(e) {
dropdownUl.attr('open', 'true');
}).on('mouseout', function(e) {
dropdownUl.attr('open', 'false');
if (id === path) {
win.scrollTo(0, anchor.offset().top);
}
});

winEl.one('scroll', function() {
if (dropdownUl.attr('open') !== 'true') {
dropdownUl.parent().removeClass('open');
}
});
}).prev('a').on('click', function(e) {
var el = this,
anchor = $(el)
;
anchor.parent().toggleClass('open');
});
dropdownUl = $('section.dropdown ul.dropdown-menu');

dropdownUl.on('mousemove', function(e) {
dropdownUl.attr('open', 'true');
}).on('mouseout', function(e) {
dropdownUl.attr('open', 'false');

winEl.one('scroll', function() {
if (dropdownUl.attr('open') !== 'true') {
dropdownUl.parent().removeClass('open');
}
});
}).prev('a').on('click', function(e) {
var el = this,
anchor = $(el)
;
anchor.parent().toggleClass('open');
});

}

$(function() {
Expand Down
1 change: 1 addition & 0 deletions content.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<script src="assets/js/libs/zepto.min.js"></script>
<script src="assets/js/libs/marked.min.js"></script>
<script src="assets/js/reset.js"></script>
<script src="assets/js/constant.js"></script>
<script src="assets/js/content.js"></script>
</body>
</html>
163 changes: 163 additions & 0 deletions pages/js/api/core_base_class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# core.base.Class **api**

提供简洁高效的 OO 实现。

## 依赖

* [mix/core/{{JS_VERSION}}/base/reset](#js/api/core_base_reset)

## 引用(获取)

`require('mix/core/{{JS_VERSION}}/base/class')`

## 类方法

### create(parent, properties)

* @param {Klass} parent
* @param {object} properties
* @return {Klass} the class object

### create(properties)

* @param {object} properties
* @return {Klass} the class object

创建类。

举例:

var Pig = Class.create({
initialize: function(name) {
this.name = name;
},

talk: function() {
console.log('I\'m' + this.name + '.');
}
});

## 实例方法

### extend(properties)

* @param {object} properties
* @return {Klass} the class object

继承类。

举例:

var RedPig = Pig.extend({
initialize: function(name) {
RedPig.superclass.initialize.call(this, name);
},

color: 'red'
});

### implement(properties)

* @param {object} properties

混合方法。

举例:

RedPig.implement({
swim: function() {
console.log('I can swim!');
}
});



## properties中的几个关键key

### initialize

构造方法。

访问父类的构造方法,可以通过:


someClass.supperclass.initialize.call(this, params*);


### Extends

从某个类继承。

举例:

var RedPig = Class.create({
Extends : Pig,

initialize: function(name) {
RedPig.superclass.initialize.call(this, name);
},

color: 'red'
});

### Implements

混合方法。

举例:

var FlyableRedPig = RedPig.extend({
Implements: {
fly : function() {
console.log('I can fly!');
}
},

initialize: function(name) {
FlyableRedPig.superclass.initialize.call(this, name);
}
});

### Statics

设置类静态方法。

举例:

var Pig = Class.create({
Statics : {
pigs : [],

add : function(name) {
var pig = new Pig(name);
this.pigs.push(pig);

return pig;
}
}

initialize: function(name) {
this.name = name;
},

talk: function() {
console.log('I\'m' + this.name + '.');
}
});

## 调用父类中的方法

### someClass.superclass.initialize
### someClass.superclass.methodName

举例:

var MyPig = Pig.extend({
initialize: function(name) {
MyPig.superclass.initialize.call(this, name);
}

talk : function() {
MyPig.superclass.talk.call(this) + ' who are you?';
}
})
Loading