Skip to content

Commit 5209cd7

Browse files
committed
c
1 parent c11f334 commit 5209cd7

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,39 @@ angular为基础的一些组件
55

66
> 依赖于angular requireJS
77
8-
有一些是在别人的代码基础上做了修改,根据需求做了进一步的修改:
8+
> src下的:
9+
>> lang.js: 做了一些基对angular的扩展
10+
11+
>> browserPrefix.js: 浏览器前缀的一些检测
12+
13+
### 目前主要包含的组件有: ###
14+
15+
> deledates: angular的事件代理
16+
17+
> dialog: dialog弹框
18+
>> confirm: 基于dialog的confirm框
19+
20+
> flow: 文件上传(对于支持文件夹上传的浏览器会将文件夹整合到一块,看起来可以是一个文件夹在上传)
21+
22+
> imageViewer: 多个图片预览查看,支持鼠标键盘快捷键切换,可拖拽图片预览(有待进一步优化)
23+
24+
> keydown: 键盘按键指令,需要在属性上指定key-code(默认13 enter键),可以指定在任意元素上(已添加tab-index)
25+
26+
> mousewheel: 鼠标滚轮指令,做了firefox兼容处理
27+
28+
> placeholder: 针对不支持placeholder的浏览器做的指令兼容
29+
30+
> scrollLoad: 滚动加载指令,也支持某一区域元素的滚动加载
31+
32+
> selection: 选择指令,选择input类元素中的内容,支持选择部分内容,通过属性指定选择区域(sln-start:开始位置-默认0,sln-end: 结束位置-默认最后末尾)
33+
34+
PS: 有一些是在别人的代码基础上做了修改,根据需求做了进一步的修改:
935
> dialog: [modal](https://github.com/angular-ui/bootstrap/tree/master/src/modal)
1036
1137
> flow: [ng-flow](https://github.com/flowjs/ng-flow)
1238
1339
> scrollLoad: [ngInfiniteScroll](https://github.com/sroze/ngInfiniteScroll)
1440
1541
> ...
42+
43+
暂时这么多,后续更新中...

src/placeholder/placeholder.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,52 @@ define(['angular'], function(angular) {
66
var supportPlaceHoder = 'placeholder' in document.createElement('input');
77

88
if (!supportPlaceHoder) {
9+
var changeInputType = function(oldObject, oType) {
10+
var newObject = document.createElement('input');
11+
newObject.type = oType;
12+
if(oldObject.className) newObject.className = oldObject.className;
13+
oldObject.parentNode.insertBefore(newObject, oldObject);
14+
return newObject;
15+
}
916
md.directive('placeholder', ['$timeout', function($timeout) {
1017

1118
return function(scope, elem, attrs) {
1219
var txt = attrs.placeholder;
1320
if (!txt) return;
21+
var newInput;
22+
newInput = angular.element(changeInputType(elem[0], 'text'));
23+
newInput.val(txt);
24+
newInput.on('focus', function() {
25+
newInput.css('display', 'none');
26+
elem.css('display', 'inline-block')[0].focus();
27+
});
28+
elem.css('display', 'none');
29+
1430
var modelT = attrs.ngModel;
31+
1532
elem.on('focus', function() {
16-
if (modelT ? !scope.$eval(modelT) : (elem.val() === txt)) {
33+
if (modelT ? !scope.$eval(modelT) : !elem.val()) {
1734
elem.val('');
1835
}
1936
scope.$apply();
2037
});
2138

2239
elem.on('blur', function() {
2340
if (elem.val() === '') {
24-
elem.val(txt);
41+
newInput.css('display', 'inline-block');
42+
elem.css('display', 'none');
2543
}
2644
scope.$apply();
2745
});
2846

2947
$timeout(function() {
30-
if (!elem.val()) elem.val(txt);
48+
if (!elem.val()) {
49+
newInput.css('display', 'inline-block');
50+
elem.css('display', 'none');
51+
} else {
52+
newInput.css('display', 'none');
53+
elem.css('display', 'inline-block');
54+
}
3155
scope.$apply();
3256
});
3357
}

0 commit comments

Comments
 (0)