This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

修复各项bug及优化组件结构

old
宇天 2017-09-04 01:02:25 +08:00
parent e5aee134f3
commit aca7d5f8ce
11 changed files with 145 additions and 886 deletions

View File

@ -810,7 +810,7 @@ Renderer.prototype.code = function(code, lang, escaped) {
// + '</section>'
}
return '<pre class="do-ui-blockcode">'
return '<pre :skip class="do-ui-blockcode">'
+ output
+ '</pre>';
};
@ -888,7 +888,7 @@ Renderer.prototype.em = function(text) {
Renderer.prototype.codespan = function(txt) {
txt = txt.replace(/&amp;/g, '&')
return '<code class="do-ui-inlinecode">' + txt + '</code>';
return '<code :skip class="do-ui-inlinecode">' + txt + '</code>';
};
Renderer.prototype.br = function() {

View File

@ -1,3 +1,10 @@
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2017-08-02 21:50:34
* @version $Id$
*/
define(['css!./highlight'], function() {
var _self = window;

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,11 @@
define(['./core', 'css!./highlight'], function(Prism) {
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2017-08-02 21:50:34
* @version $Id$
*/
define(['./base', 'css!./highlight'], function(Prism) {
Prism.languages.actionscript = Prism.languages.extend('javascript', {
'keyword': /\b(?:as|break|case|catch|class|const|default|delete|do|else|extends|finally|for|function|if|implements|import|in|instanceof|interface|internal|is|native|new|null|package|private|protected|public|return|super|switch|this|throw|try|typeof|use|var|void|while|with|dynamic|each|final|get|include|namespace|native|override|set|static)\b/,

View File

@ -1,32 +0,0 @@
@charset "UTF-8";
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2017-02-13 13:53:38
*
*/
/*代码块*/
.do-ui-blockcode {position:relative;border:1px solid #ddd;margin:15px 0;}
.do-ui-blockcode::before {position:relative;display:block;width:100%;height:25px;padding:0 8px;background:#eee;border-bottom:1px solid #ddd;line-height:25px;content:"代码示例";box-sizing: border-box;}
.do-ui-blockcode section {position:relative;}
.do-ui-blockcode .linenum {display:block;position:absolute;z-index:1;left:0;top:0;width:40px;height:100%;background:#eee;border-right:1px solid #ddd;text-align:center;}
/*语法高亮*/
.do-ui-blockcode .lang {position:relative;display:block;overflow-x:auto;z-index:0;padding:0 8px 0 50px;color:#383a42;background:#fafafa;word-wrap:break-word;white-space:pre-wrap;}
.do-ui-blockcode .lang .c-comment{color: #8e908c;font-style:italic;}
.do-ui-blockcode .lang .c-smartyx {color: #607d8b;}
.do-ui-blockcode .lang .c-important {color: #f5871f;font-style:italic;}
.do-ui-blockcode .lang .c-punctuation {color: #986756;}
.do-ui-blockcode .lang .c-regex {color: #c82829;}
.do-ui-blockcode .lang .c-boolean,.do-ui-blockcode .lang .c-number {color: #f5871f;}
.do-ui-blockcode .lang .c-function {color:#009688;}
.do-ui-blockcode .lang .c-class-name,.do-ui-blockcode .lang .c-build-in {color:#3aa9f3;}
.do-ui-blockcode .lang .c-class-name,.do-ui-blockcode .lang .c-build-in {font-style:italic;font-weight:bold;}
.do-ui-blockcode .lang .c-attr-name {color: #eab700;}
.do-ui-blockcode .lang .c-string,.do-ui-blockcode .lang .c-attr-value {color: #5ab302;}
.do-ui-blockcode .lang .c-tag,.do-ui-blockcode .lang .c-keyword,.do-ui-blockcode .lang .c-operator {color: #d81406;}
.do-ui-blockcode .lang .c-keyword {font-style:italic;}
/*行内代码*/
.do-ui-inlinecode {margin:0 2px;padding:0 5px;color:#d14;border:1px solid #ddd;border-radius:3px;}

View File

@ -0,0 +1,49 @@
@charset "UTF-8";
/**
*
* @authors yutent (yutent@doui.cc)
* @date 2017-02-13 13:53:38
*
*/
/*代码块*/
.do-ui-blockcode {position: relative;border: 1px solid #ddd;margin: 15px 0;padding: 8px 0;line-height: 1.5;background: #fafafa;
/*语法高亮*/
.lang {position: relative;display: block;padding: 0 8px;color: #383a42;word-wrap: break-word;white-space: pre-wrap;font-family: Courier;
.c-comment{color: #8e908c;font-style:italic;}
.c-smartyx {color: #607d8b;}
.c-important {color: #f5871f;font-style:italic;}
.c-punctuation {color: #986756;}
.c-regex {color: #c82829;}
.c-boolean,
.c-number {color: #f5871f;}
.c-function {color:#009688;}
.c-class-name,
.c-build-in {color:#3aa9f3;}
.c-class-name,
.c-build-in {font-style:italic;font-weight:bold;}
.c-attr-name,
.c-property {color: #c79f0f;font-weight:bold;}
.c-property {font-style:italic;}
.c-string,
.c-attr-value {color: #5ab302;}
.c-tag,
.c-keyword,
.c-selector,
.c-operator {color: #d81406;}
.c-keyword {font-style:italic;}
}
}
/*行内代码*/
.do-ui-inlinecode {margin:0 2px;padding:0 5px;color:#d14;border:1px solid #ddd;border-radius:3px;}

View File

@ -0,0 +1 @@
define(["yua"],function(){function t(){this.table={get:[]},this.errorFn=null,this.history=null,this.hash="",this.started=!1,this.init={}}function e(t){return!t||t===window.name||"_self"===t||"top"===t&&window==window.top}var r={prefix:/^(#!|#)[\/]?/,historyOpen:!0,allowReload:!0},i=!0,a=/(:id)|(\{id\})|(\{id:([A-z\d\,\[\]\{\}\-\+\*\?\!:\^\$]*)\})/g;return t.prototype={error:function(t){this.errorFn=t},config:function(t){if(this.started)return console.error("Router config has been set");this.started=!0,t.allowReload||(t.historyOpen=!0),this.init=yua.mix({},r,t)},_getRegExp:function(t,e){var r=t.replace(a,function(t,e,r,i,a){var n="([\\w.-]";return e||r?n+"+)":(/^\{[\d\,]+\}$/.test(a)||(n="("),n+a+")")});return r=r.replace(/(([^\\])([\/]+))/g,"$2\\/").replace(/(([^\\])([\.]+))/g,"$2\\.").replace(/(([^\\])([\-]+))/g,"$2\\-").replace(/(\(.*)(\\[\-]+)(.*\))/g,"$1-$3"),r="^"+r+"$",e.regexp=new RegExp(r),e},_add:function(t,e,r){this.started||this.config({});var i=this.table[t.toLowerCase()];if("/"===e.charAt(0)){e=e.replace(/^[\/]+|[\/]+$|\s+/g,"");var a={};a.rule=e,a.callback=r,yua.Array.ensure(i,this._getRegExp(e,a))}else console.error('char "/" must be in front of router rule')},_route:function(t,e){var e=e.trim(),r=this.table[t],i=this.init;if(i.allowReload||e!==this.history){i.historyOpen&&(this.history=e,yua.ls&&yua.ls("lastHash",e));for(var a,n=0;a=r[n++];){var o=e.match(a.regexp);if(o)return o.shift(),a.callback.apply(a,o)}this.errorFn&&this.errorFn(e)}},on:function(t,e){var r=this;Array.isArray(t)?t.forEach(function(t){r._add("get",t,e)}):this._add("get",t,e)}},yua.bind(window,"load",function(){if(yua.router.started){var t=yua.router.init.prefix,e=location.hash;e=e.replace(t,"").trim(),yua.router._route("get",e)}}),"onhashchange"in window&&window.addEventListener("hashchange",function(t){if(i){var e=yua.router.init.prefix,r=location.hash.replace(e,"").trim();yua.router._route("get",r)}}),yua.bind(document,"mousedown",function(t){if(!(("defaultPrevented"in t?t.defaultPrevented:!1===t.returnValue)||t.ctrlKey||t.metaKey||2===t.which)){for(var r=t.target;"A"!==r.nodeName;)if(!(r=r.parentNode)||"BODY"===r.tagName)return;if(e(r.target)){if(!yua.router.started)return;var a=r.getAttribute("href")||r.getAttribute("xlink:href"),n=yua.router.init.prefix;if(null===a||!n.test(a))return;yua.router.hash=a.replace(n,"").trim(),t.preventDefault(),location.hash=a,i=!1}}}),yua.bind(document,"mouseup",function(){i||(yua.router._route("get",yua.router.hash),i=!0)}),yua.ui.router="0.0.1",yua.router=new t});

View File

@ -10,7 +10,7 @@
define(['yua', 'css!./skin/def.css'], function(){
//储存版本信息
yua.ui.tree = '0.0.1'
yua.ui.tree = '0.0.2'
var box = '<ul>{li}</ul>',
ul = '<ul :class="{open: {it}.open}">{li}</ul>',
@ -18,6 +18,7 @@ define(['yua', 'css!./skin/def.css'], function(){
+ '<em :click="$toggle({it})"></em>'
+ '<span :click="$select({it})" :class="{active: {it}.id === currItem}" :text="{it}.name"></span>'
+ '{child}</li>';
var keyPath = {};
function repeat(arr, name){
@ -44,17 +45,17 @@ define(['yua', 'css!./skin/def.css'], function(){
})
arr.forEach(function(it){
tmp[it.id] = it
keyPath[it.id] = ''
var parentItem = tmp[it.pid]
delete it.pid
if(!parentItem){
return farr.push(tmp[it.id])
}
keyPath[it.id] += keyPath[parentItem.id] + parentItem.id + ','
parentItem.open = !!parentItem.open
parentItem.children = parentItem.children || []
parentItem.children.push(it)
})
tmp = arr = null
return farr
}
@ -67,12 +68,44 @@ define(['yua', 'css!./skin/def.css'], function(){
vm.$onClick(obj)
}
}
vm.$update = function(arr){
vm.$reset = function(arr){
vm.treeArr.clear()
vm.treeHTML = ''
vm.treeArr.pushArray(format(arr))
vm.currItem = -1
var tpl = repeat(vm.treeArr.$model, 'treeArr')
yua.nextTick(function(){
vm.treeHTML = box.replace('{li}', tpl)
})
}
vm.$update = function(id, obj){
var path = keyPath[id],
tmpid = null,
tmpobj = null
path += id
path = path.split(',')
while(tmpid = +path.shift()){
if(!tmpobj){
tmpobj = vm.treeArr
}else{
tmpobj = tmpobj.children
}
for(var i = 0, it; it = tmpobj[i++];){
if(it.id === tmpid){
tmpobj = it
break
}
}
}
for(var j in obj){
tmpobj[j] = obj[j]
}
}
},
$ready: function(vm){
@ -84,6 +117,7 @@ define(['yua', 'css!./skin/def.css'], function(){
treeArr: [],
$select: yua.noop,
$update: yua.noop,
$reset: yua.noop,
$onSuccess: yua.noop,
$onClick: yua.noop,
$toggle: function(obj){

View File

@ -160,10 +160,6 @@ yua.type = function (obj) { //取得目标的类型
typeof obj
}
yua.isFunction = function (fn) {
return serialize.call(fn) === "[object Function]"
}
/*判定是否是一个朴素的javascript对象Object不是DOM对象不是BOM对象不是自定义类的实例*/
yua.isPlainObject = function (obj) {
@ -208,7 +204,7 @@ yua.mix = yua.fn.mix = function () {
}
//确保接受方为一个复杂的数据类型
if (typeof target !== "object" && !yua.isFunction(target)) {
if (typeof target !== "object" && yua.type(target) !== 'function') {
target = {}
}
@ -445,7 +441,7 @@ if(!Date.prototype.format){
{
value: function(str){
str = str || 'Y-m-d H:i:s'
var week = ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
var week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
dt = {
'fullyear': this.getFullYear(),
'year': this.getYear(),
@ -3051,7 +3047,7 @@ function scanAttr(elem, vmodels, match) {
uuid: "_" + (++bindingID),
priority: (directives[type].priority || type.charCodeAt(0) * 10) + (Number(param.replace(/\D/g, "")) || 0)
}
if (type === "html" || type === "text") {
if (type === "html" || type === "text" || type === "attr") {
var filters = getToken(value).filters
binding.expr = binding.expr.replace(filters, "")
@ -3661,9 +3657,10 @@ var attrDir = yua.directive("attr", {
//类名定义, :class="xx:yy" :class="{xx: yy}" :class="xx" :class="{{xx}}"
yua.directive("class", {
init: function (binding) {
var expr = [];
if(!/^\{.*\}$/.test(binding.expr)){
var expr = binding.expr.split(':')
expr = binding.expr.split(':')
expr[1] = expr[1] && expr[1].trim() || 'true'
var arr = expr[0].split(/\s+/)
binding.expr = '{' + arr.map(function(it){
@ -3686,16 +3683,16 @@ yua.directive("class", {
activate = "mousedown"
abandon = "mouseup"
var fn0 = $elem.bind("mouseleave", function () {
binding.toggleClass && $elem.removeClass(binding.newClass)
$elem.removeClass(expr[0])
})
}
}
var fn1 = $elem.bind(activate, function () {
binding.toggleClass && $elem.addClass(binding.newClass)
$elem.addClass(expr[0])
})
var fn2 = $elem.bind(abandon, function () {
binding.toggleClass && $elem.removeClass(binding.newClass)
$elem.removeClass(expr[0])
})
binding.rollback = function () {
$elem.unbind("mouseleave", fn0)
@ -3707,6 +3704,9 @@ yua.directive("class", {
},
update: function (val) {
if(this.type !== 'class'){
return
}
var obj = val
if(!obj || this.param)
return log('class指令语法错误 %c %s="%s"', 'color:#f00', this.name, this.expr)
@ -4993,8 +4993,8 @@ yua.directive("repeat", {
elem.removeAttribute(binding.name)
effectBinding(elem, binding)
binding.param = binding.param || "el"
binding.sortedCallback = getBindingCallback(elem, "data-with-sorted", binding.vmodels)
var rendered = getBindingCallback(elem, "data-" + type + "-rendered", binding.vmodels)
binding.sortedCallback = getBindingCallback(elem, "data-repeat-sortby", binding.vmodels)
var rendered = getBindingCallback(elem, "data-repeat-rendered", binding.vmodels)
var signature = generateID(type)
var start = DOC.createComment(signature + ":start")
@ -5002,19 +5002,12 @@ yua.directive("repeat", {
binding.signature = signature
binding.start = start
binding.template = yuaFragment.cloneNode(false)
if (type === "repeat") {
var parent = elem.parentNode
parent.replaceChild(end, elem)
parent.insertBefore(start, end)
binding.template.appendChild(elem)
} else {
while (elem.firstChild) {
binding.template.appendChild(elem.firstChild)
}
elem.appendChild(start)
elem.appendChild(end)
parent = elem
}
binding.element = end
if (rendered) {

View File

@ -160,10 +160,6 @@ yua.type = function (obj) { //取得目标的类型
typeof obj
}
yua.isFunction = function (fn) {
return serialize.call(fn) === "[object Function]"
}
/*判定是否是一个朴素的javascript对象Object不是DOM对象不是BOM对象不是自定义类的实例*/
yua.isPlainObject = function (obj) {
@ -207,7 +203,7 @@ yua.mix = yua.fn.mix = function () {
}
//确保接受方为一个复杂的数据类型
if (typeof target !== "object" && !yua.isFunction(target)) {
if (typeof target !== "object" && yua.type(target) !== 'function') {
target = {}
}
@ -444,7 +440,7 @@ if(!Date.prototype.format){
{
value: function(str){
str = str || 'Y-m-d H:i:s'
var week = ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'],
var week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
dt = {
'fullyear': this.getFullYear(),
'year': this.getYear(),
@ -3050,7 +3046,7 @@ function scanAttr(elem, vmodels, match) {
uuid: "_" + (++bindingID),
priority: (directives[type].priority || type.charCodeAt(0) * 10) + (Number(param.replace(/\D/g, "")) || 0)
}
if (type === "html" || type === "text") {
if (type === "html" || type === "text" || type === "attr") {
var filters = getToken(value).filters
binding.expr = binding.expr.replace(filters, "")
@ -3665,9 +3661,10 @@ var attrDir = yua.directive("attr", {
//类名定义, :class="xx:yy" :class="{xx: yy}" :class="xx" :class="{{xx}}"
yua.directive("class", {
init: function (binding) {
var expr = [];
if(!/^\{.*\}$/.test(binding.expr)){
var expr = binding.expr.split(':')
expr = binding.expr.split(':')
expr[1] = expr[1] && expr[1].trim() || 'true'
var arr = expr[0].split(/\s+/)
binding.expr = '{' + arr.map(function(it){
@ -3690,16 +3687,16 @@ yua.directive("class", {
activate = "mousedown"
abandon = "mouseup"
var fn0 = $elem.bind("mouseleave", function () {
binding.toggleClass && $elem.removeClass(binding.newClass)
$elem.removeClass(expr[0])
})
}
}
var fn1 = $elem.bind(activate, function () {
binding.toggleClass && $elem.addClass(binding.newClass)
$elem.addClass(expr[0])
})
var fn2 = $elem.bind(abandon, function () {
binding.toggleClass && $elem.removeClass(binding.newClass)
$elem.removeClass(expr[0])
})
binding.rollback = function () {
$elem.unbind("mouseleave", fn0)
@ -3711,6 +3708,9 @@ yua.directive("class", {
},
update: function (val) {
if(this.type !== 'class'){
return
}
var obj = val
if(!obj || this.param)
return log('class指令语法错误 %c %s="%s"', 'color:#f00', this.name, this.expr)
@ -4997,8 +4997,8 @@ yua.directive("repeat", {
elem.removeAttribute(binding.name)
effectBinding(elem, binding)
binding.param = binding.param || "el"
binding.sortedCallback = getBindingCallback(elem, "data-with-sorted", binding.vmodels)
var rendered = getBindingCallback(elem, "data-" + type + "-rendered", binding.vmodels)
binding.sortedCallback = getBindingCallback(elem, "data-repeat-sortby", binding.vmodels)
var rendered = getBindingCallback(elem, "data-repeat-rendered", binding.vmodels)
var signature = generateID(type)
var start = DOC.createComment(signature + ":start")
@ -5006,19 +5006,12 @@ yua.directive("repeat", {
binding.signature = signature
binding.start = start
binding.template = yuaFragment.cloneNode(false)
if (type === "repeat") {
var parent = elem.parentNode
parent.replaceChild(end, elem)
parent.insertBefore(start, end)
binding.template.appendChild(elem)
} else {
while (elem.firstChild) {
binding.template.appendChild(elem.firstChild)
}
elem.appendChild(start)
elem.appendChild(end)
parent = elem
}
binding.element = end
if (rendered) {