Skip to content

Commit 8c09174

Browse files
committed
renamed jquery.prompt
1 parent 255cca7 commit 8c09174

File tree

10 files changed

+637
-3
lines changed

10 files changed

+637
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Gruntfile.coffee

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
fs = require("fs")
2+
3+
#global module:false
4+
module.exports = (grunt) ->
5+
6+
7+
# Project configuration.
8+
grunt.initConfig
9+
pkg: grunt.file.readJSON('component.json')
10+
banner:
11+
"/** <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today(\"yyyy/mm/dd\") %>\n"+
12+
" * <%= pkg.homepage %>\n" +
13+
" * Copyright (c) <%= grunt.template.today(\"yyyy\") %> <%= pkg.author.name %> - MIT\n"+
14+
" */"
15+
16+
coffee:
17+
options:
18+
bare: true
19+
compile:
20+
files:
21+
'dist/<%= pkg.name %>.js': 'src/<%= pkg.name %>.coffee'
22+
23+
wrap:
24+
dist:
25+
src: ['dist/<%= pkg.name %>.js']
26+
dest: '.'
27+
wrapper: ["<%= banner %>\n(function(window,document,undefined) {\n","\n}(window,document));"]
28+
29+
uglify:
30+
options:
31+
stripBanners: true
32+
banner: '<%= banner %>'
33+
34+
dist:
35+
src: "dist/<%= pkg.name %>.js"
36+
dest: "dist/<%= pkg.name %>.min.js"
37+
38+
watch:
39+
scripts:
40+
files: 'src/*.coffee'
41+
tasks: 'default'
42+
43+
grunt.loadNpmTasks "grunt-contrib-watch"
44+
grunt.loadNpmTasks "grunt-contrib-uglify"
45+
grunt.loadNpmTasks "grunt-contrib-coffee"
46+
grunt.loadNpmTasks "grunt-wrap"
47+
48+
# Default task.
49+
grunt.registerTask "default", "coffee wrap uglify".split(' ')

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
notifyjs
2-
========
31

4-
Notify.js - A robust, customizable notification library
2+
### Notify.js - A robust, customizable notification library
3+
4+
## http://notifyjs.com

component.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"title": "Notify.js",
3+
"name": "notify",
4+
"version": "0.0.1",
5+
"author": {
6+
"name": "Jaime Pillora"
7+
},
8+
"homepage": "http://notifyjs.com/",
9+
"license": "MIT"
10+
}

dist/notify.js

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/** Notify.js - v0.0.1 - 2013/04/04
2+
* http://notifyjs.com/
3+
* Copyright (c) 2013 Jaime Pillora - MIT
4+
*/
5+
(function(window,document,undefined) {
6+
'use strict';
7+
8+
var Options, Prompt, arrowDirs, className, coreStyle, create, getAnchorElement, pluginName, pluginOptions, userStyles;
9+
10+
pluginName = 'notify';
11+
12+
className = '__notify';
13+
14+
arrowDirs = {
15+
top: 'bottom',
16+
bottom: 'top',
17+
left: 'right',
18+
right: 'left'
19+
};
20+
21+
coreStyle = {
22+
html: "<div class=\"" + className + "Wrapper\">\n <div class=\"" + className + "Main\">\n <div class=\"" + className + "Content\">\n </div>\n </div>\n</div>",
23+
css: "." + className + "Wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n." + className + "Main {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n." + className + "Content {\n background: #fff;\n position: relative;\n font-size: 11px;\n box-shadow: 0 0 6px #000;\n -moz-box-shadow: 0 0 6px #000;\n -webkit-box-shadow: 0 0 6px #000;\n padding: 4px 10px 4px 8px;\n border-radius: 6px;\n border-style: solid;\n border-width: 2px;\n -moz-border-radius: 6px;\n -webkit-border-radius: 6px;\n white-space: nowrap;\n}"
24+
};
25+
26+
userStyles = {
27+
"default": {
28+
html: "<span>test</span>",
29+
css: "body {\n test: 42\n}"
30+
},
31+
bootstrap: {
32+
html: "<span>test</span>",
33+
css: "body {\n test: 42\n}"
34+
}
35+
};
36+
37+
pluginOptions = {
38+
autoHidePrompt: false,
39+
autoHideDelay: 10000,
40+
arrowShow: true,
41+
arrowSize: 5,
42+
arrowPosition: 'top',
43+
color: 'red',
44+
colors: {
45+
red: '#ee0101',
46+
green: '#33be40',
47+
black: '#393939',
48+
blue: '#00f'
49+
},
50+
showAnimation: 'fadeIn',
51+
showDuration: 200,
52+
hideAnimation: 'fadeOut',
53+
hideDuration: 600,
54+
gap: 2
55+
};
56+
57+
create = function(tag) {
58+
return $(document.createElement(tag));
59+
};
60+
61+
Options = function(options) {
62+
if ($.isPlainObject(options)) {
63+
return $.extend(this, options);
64+
}
65+
};
66+
67+
Options.prototype = pluginOptions;
68+
69+
getAnchorElement = function(element) {
70+
var fBefore, radios;
71+
if (element.is('[type=radio]')) {
72+
radios = element.parents('form:first').find('[type=radio]').filter(function(i, e) {
73+
return $(e).attr('name') === element.attr('name');
74+
});
75+
element = radios.first();
76+
}
77+
fBefore = element.prev();
78+
if (fBefore.is('span.styled,span.OBS_checkbox')) {
79+
element = fBefore;
80+
}
81+
return element;
82+
};
83+
84+
Prompt = (function() {
85+
86+
function Prompt(elem, node, options) {
87+
if ($.type(options) === 'string') {
88+
options = {
89+
color: options
90+
};
91+
}
92+
this.options = new Options($.isPlainObject(options) ? options : {});
93+
this.elementType = elem.attr('type');
94+
this.originalElement = elem;
95+
this.elem = getAnchorElement(elem);
96+
this.elem.data(pluginName, this);
97+
this.wrapper = $(coreStyle.html);
98+
this.main = this.wrapper.find("." + className + "Main");
99+
this.content = this.main.find("." + className + "Content");
100+
this.elem.before(this.wrapper);
101+
this.main.css(this.calculateCSS());
102+
this.run(node);
103+
}
104+
105+
Prompt.prototype.buildArrow = function() {
106+
var alt, d, dir, showArrow, size;
107+
dir = this.options.arrowPosition;
108+
size = this.options.arrowSize;
109+
alt = arrowDirs[dir];
110+
this.arrow = create("div");
111+
this.arrow.addClass(className + 'Arrow').css({
112+
'margin-top': 2 + (document.documentMode === 5 ? size * -4 : 0),
113+
'position': 'relative',
114+
'z-index': '2',
115+
'margin-left': 10,
116+
'width': 0,
117+
'height': 0
118+
}).css('border-' + alt, size + 'px solid ' + this.getColor());
119+
for (d in arrowDirs) {
120+
if (d !== dir && d !== alt) {
121+
this.arrow.css('border-' + d, size + 'px solid transparent');
122+
}
123+
}
124+
showArrow = this.options.arrowShow && this.elementType !== 'radio';
125+
if (showArrow) {
126+
return this.arrow.show();
127+
} else {
128+
return this.arrow.hide();
129+
}
130+
};
131+
132+
Prompt.prototype.showMain = function(show) {
133+
var hidden;
134+
hidden = this.main.parent().parents(':hidden').length > 0;
135+
if (hidden && show) {
136+
this.main.show();
137+
}
138+
if (hidden && !show) {
139+
this.main.hide();
140+
}
141+
if (!hidden && show) {
142+
this.main[this.options.showAnimation](this.options.showDuration);
143+
}
144+
if (!hidden && !show) {
145+
return this.main[this.options.hideAnimation](this.options.hideDuration);
146+
}
147+
};
148+
149+
Prompt.prototype.calculateCSS = function() {
150+
var elementPosition, height, left, mainPosition;
151+
elementPosition = this.elem.position();
152+
mainPosition = this.main.parent().position();
153+
height = this.elem.outerHeight();
154+
left = elementPosition.left - mainPosition.left;
155+
if (!navigator.userAgent.match(/MSIE/)) {
156+
height += elementPosition.top - mainPosition.top;
157+
}
158+
return {
159+
top: height + this.options.gap,
160+
left: left
161+
};
162+
};
163+
164+
Prompt.prototype.getColor = function() {
165+
return this.options.colors[this.options.color] || this.options.color;
166+
};
167+
168+
Prompt.prototype.run = function(node, options) {
169+
var t;
170+
if ($.isPlainObject(options)) {
171+
$.extend(this.options, options);
172+
} else if ($.type(options) === 'string') {
173+
this.options.color = options;
174+
}
175+
if (this.main && !node) {
176+
this.showMain(false);
177+
return;
178+
} else if (!this.main && !node) {
179+
return;
180+
}
181+
if ($.type(node) === 'string') {
182+
this.content.html(node.replace('\n', '<br/>'));
183+
} else {
184+
this.content.empty().append(node);
185+
}
186+
this.content.css({
187+
'color': this.getColor(),
188+
'border-color': this.getColor()
189+
});
190+
if (this.arrow) {
191+
this.arrow.remove();
192+
}
193+
this.buildArrow();
194+
this.content.before(this.arrow);
195+
this.showMain(true);
196+
if (this.options.autoHidePrompt) {
197+
clearTimeout(this.elem.data('mainTimer'));
198+
t = setTimeout(function() {
199+
return this.showMain(false);
200+
}, this.options.autoHideDelay);
201+
return this.elem.data('mainTimer', t);
202+
}
203+
};
204+
205+
return Prompt;
206+
207+
})();
208+
209+
$(function() {
210+
$("head").append(create("style").html(coreStyle.css));
211+
return $(document).on('click', "." + className, function() {
212+
var inst;
213+
inst = getAnchorElement($(this)).data(pluginName);
214+
if (inst != null) {
215+
return inst.showMain(false);
216+
}
217+
});
218+
});
219+
220+
$[pluginName] = function(elem, node, options) {
221+
return $(elem)[pluginName](node, options);
222+
};
223+
224+
$[pluginName].options = function(options) {
225+
return $.extend(pluginOptions, options);
226+
};
227+
228+
$[pluginName].addStyle = function(s) {
229+
return $.extend(true, userStyles, s);
230+
};
231+
232+
$.fn[pluginName] = function(node, options) {
233+
return $(this).each(function() {
234+
var inst;
235+
inst = getAnchorElement($(this)).data(pluginName);
236+
if (inst != null) {
237+
return inst.run(node, options);
238+
} else {
239+
return new Prompt($(this), node, options);
240+
}
241+
});
242+
};
243+
244+
}(window,document));

dist/notify.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
2+
3+
<!-- jQuery Prompt -->
4+
<script src="dist/jquery.prompt.js"></script>
5+
6+
<form>
7+
<input id="one" value="42" data-validate="number"/>
8+
<input id="two" value="abc" data-validate="number"/>
9+
<input type="submit"/>
10+
</form>
11+
12+
<script>
13+
$(function() {
14+
15+
setTimeout(function() {
16+
$("#one").prompt("hello");
17+
}, 300);
18+
setTimeout(function() {
19+
$.prompt($("#two"),"world", {color: 'black'});
20+
}, 600);
21+
setTimeout(function() {
22+
$.prompt($("#two"),$("<strong/>").html("WORLD!"), {color: 'blue'});
23+
}, 2800);
24+
25+
});
26+
</script>

notify.jquery.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "notify",
3+
"version": "0.0.1",
4+
"title": "notify",
5+
"description": "A robust, customizable notification library",
6+
"bugs": "https://github.com/jpillora/notifyjs/issues",
7+
"homepage": "http://notifyjs.com",
8+
"docs": "http://notifyjs.com",
9+
"download": "http://notifyjs.com#download",
10+
"author": {
11+
"name": "Jaime Pillora"
12+
},
13+
"licenses": [
14+
{
15+
"type": "MIT",
16+
"url": "http://opensource.org/licenses/MIT"
17+
}
18+
],
19+
"keywords": [
20+
"notify",
21+
"notification",
22+
"prompt",
23+
"popup"
24+
],
25+
"dependencies": {
26+
"jquery": ">=1.8"
27+
}
28+
}

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "notify",
3+
"devDependencies": {
4+
"grunt": "~0.4.x",
5+
"grunt-contrib-watch": "~0.1.4",
6+
"grunt-contrib-uglify": "~0.1.1rc6",
7+
"grunt-contrib-jshint": "~0.1.0",
8+
"grunt-contrib-concat": "~0.1.1",
9+
"grunt-contrib-coffee": "~0.4.0rc7",
10+
"grunt-wrap": "~0.2.0"
11+
}
12+
}

0 commit comments

Comments
 (0)