-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsimple-javascript-popup.html
156 lines (89 loc) · 8.58 KB
/
simple-javascript-popup.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!-- https://github.com/ttodua/useful-javascript/ -->
<h1>1) Simplest Popups:</h1>
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------SCRIPT 1 ---------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<a href="javascript:show_my_popup('Hello, simple message here');"> 1)Message is got directly</a> (cant use full formatting)<br/>
<a href="javascript:show_my_popup('#mymessg');"> 2)Message is got from ELEMENT</a> (supports full formatting)
<div id="mymessg" style="display:none;">
<div style="color:red;">Here are styled elements! </br><span style="color:blue">And inside it,here is a styled span</span></div>
</div>
<script type="text/javascript">
//######################## simple POPUP ############################# https://github.com/ttodua/useful-javascript/ ###############
function show_my_popup(TEXTorID,AdditionalStyles='' ){
TEXTorID=TEXTorID.trim(); var FirstChar= TEXTorID.charAt(0); var eName = TEXTorID.substr(1); if ('#'==FirstChar || '.'==FirstChar){ if('#'==FirstChar){var x=document.getElementById(eName);} else{var x=document.getElementsByClassName(eName)[0];}} else { var x=document.createElement('div');x.innerHTML=TEXTorID;} var randm_id=Math.floor((Math.random()*100000000));
var DivAA = document.createElement('div'); DivAA.id = "blkBackgr_"+randm_id; DivAA.className = "MyJsBackg"; DivAA.setAttribute("style", 'background:black; height:5000px; left:0px; opacity:0.9; position:fixed; top:0px; width:100%; z-index:9599;'); document.body.appendChild(DivAA);
var DivBB = document.createElement('div'); DivBB.id = 'popupp_'+randm_id; DivBB.className = "MyJsPopup"; DivBB.setAttribute("style",'background-color:white; border:6px solid white; border-radius:10px; display:block; min-height:1%; min-width:350px; width:auto; overflow:auto; max-height:80%; max-width:800px; padding:15px; position:fixed; text-align:left; top:10%; z-index:9599; left:0px; right:0px; margin-left:auto; margin-right:auto; width:80%;'+ AdditionalStyles); DivBB.innerHTML = '<div style="background-color:#C0BCBF; border-radius:55px; padding:5px; font-family:arial; float:right; font-weight:700; margin:-15px -10px 0px 0px;"><a href="javascript:my_popup_closee('+randm_id+');" style="display:block;margin:-5px 0 0 0;font-size:1.6em;">x</a></div>'; document.body.appendChild(DivBB);z=x.cloneNode(true);DivBB.appendChild(z); if(z.style.display=="none"){z.style.display="block";} } function my_popup_closee(RandomIDD) { var x=document.getElementById("blkBackgr_"+RandomIDD); x.parentNode.removeChild(x); var x=document.getElementById('popupp_'+RandomIDD); x.parentNode.removeChild(x);
}
//#####################################################################################################################################
</script>
<br/><br/> p.s.
<br/>1) to use special characters in simple popup, use HTML entities (<a href="http://dev.w3.org/html5/html-author/charref">1</a> or <a href="http://www.elizabethcastro.com/html/extras/entities.html">2</a>)
<br/>2) to popup YOUTUBE videos, see: http://jsfiddle.net/8cqox13z/2/
<br/>3) If you wish (in your custom projects) to only make Bacgkround black, use these functions: <b>SHOW_blackGROUND()</b> and <b>HIDE_blackGROUND()</b>
<script type="text/javascript">
//######################## separate BLACKening background #################(NOTE: on your over element, use z-index:9600 ) ###############
function SHOW_blackGROUND(){ var AAADIV = document.createElement('div'); AAADIV.id = "my_black_bck_123"; var stl='background:black; height:5000px; left:0px; opacity:0.9; position:fixed; top:0px; width:100%; z-index:9503;'; AAADIV.setAttribute("style", stl ); if (mybodyyy = document.body) {mybodyyy.insertBefore(AAADIV, mybodyyy.childNodes[0]);} else {document.write('<div style="'+stl+'"></div>');}}
function REMOVE_blackGROUND(){ var AAADIV = document.getElementById('my_black_bck_123'); AAADIV.parentNode.removeChild(AAADIV); }
//###################################################################################
</script>
<br/><br/><h1>2) Faded Popup:</h1>
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------SCRIPT 2 ---------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<a href="javascript:FadeShowHide('.mydiiv', 'show');">1) Show FADED POPUP</a>
<script type="text/javascript">
function FadeShowHide(TEXTorID , my_action) {
var ActAMOUNT = 20; // amount of actions
var movement_interval = 6; // 1000/ActAMOUNT = DURATION of each step(miliseconds)
var HIDE_INSTANTLY_ENABLED = false;
var SHOW_INSTANTLY_ENABLED = false;
//Make Background Black
if ('undefined'== typeof MyFadBackg){MyFadBackg = document.createElement('div'); MyFadBackg.id = "MyFADBackg"; MyFadBackg.setAttribute("style", 'z-index:9254; visibility:hidden; background:black; height:3000px; width:4000px; left:-1000px; opacity:0.8; position:fixed; top:-600px; transition:all 0.2s ease-out;-webkit-transition:opacity 0.2s; transition:opacity 0.2s; -moz-transition:all 0.2s ease-out; -o-transition:all 0.2s ease-out;'); document.body.appendChild(MyFadBackg);}
var FirstChar= TEXTorID.trim().charAt(0); var eName=TEXTorID.substr(1); var x= ('#'==FirstChar) ? document.getElementById(eName): document.getElementsByClassName(eName)[0];
if (my_action=='show') { if (SHOW_INSTANTLY_ENABLED) {x.style.opacity = '1'; x.style.visibility = "visible"; return; }
var PlusOrMinus = 1; MyFadBackg.style.visibility='visible'; x.style.visibility = 'visible'; var counte = ActAMOUNT*2 /3; }
else if (my_action=='hide') { if (HIDE_INSTANTLY_ENABLED) {x.style.opacity = '0'; x.style.visibility = "hidden"; return; }
var PlusOrMinus = -1;MyFadBackg.style.visibility='hidden'; x.style.visibility = 'hidden'; var counte = ActAMOUNT/1; }
setTimeout(function looooperrr(){ counte = counte + 1*PlusOrMinus; //Increases or decreases
if ( counte >= 0 && counte <= ActAMOUNT ) {
var opacitRATIO = counte/ActAMOUNT; var zoomRATIO = counte/ActAMOUNT;
x.style.opacity =opacitRATIO; x.style.transform = 'scale('+zoomRATIO+')'; x.style.webkitTransform='scale('+zoomRATIO+')'; x.style.MozTransform='scale('+zoomRATIO +')'; x.style.msTransform='scale('+zoomRATIO+')'; x.style.OTransform = 'scale('+zoomRATIO+')';
if ( my_action=='hide' && zoomRATIO < 2/3){ x.style.visibility = "hidden"; return;}
} setTimeout(looooperrr,movement_interval);
}, movement_interval );
}
</script>
<div class="mydiiv" style="visibility:hidden; z-index:9255; position:absolute; top:50%; left:40%; opacity:0; height:100px; width:200px; margin:0 auto; background:#FFFFFF; box-shadow:0px 1px 10px 0px rgba(0, 0, 0, 0.506); overflow:hidden; padding:10px; border-radius:3px; color:#555555; ">
<div class="buttns_inside_line" style="color:red;">Something hereeeeeeee</div> <a href="javascript:FadeShowHide('.mydiiv', 'hide'); " style="float:right;">X</a>
</div>
<br/><br/><h2>3) during request show "loading" message: - <a href="https://github.com/ttodua/useful-javascript/blob/master/during-request-show-%22WAIT%22">https://github.com/ttodua/useful-javascript/blob/master/during-request-show-%22WAIT%22</a></h2>
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------SCRIPT 3 ---------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<br/><br/><br/><h2>4) Open new window:</h1>
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------SCRIPT 4 ---------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<!-- ------------------------- -->
<a href="javascript:void(0);" onclick="window.open('http://www.youtube.com', 'windowname1', 'width=500, height=300'); return false;">using window.open() method</a>
<!-- ======================some my personal JUNK, not usable for others======================== -->
<!-- function, to To hide(DISPLAY:NONE) all divs, which has class="My_TARGET_Hiddens" -->
<script type="text/javascript">window.onload = function(){ hide_popuping_divs("My_TARGET_Hiddens"); }; function hide_popuping_divs(classnameee){ var elmnts = document.getElementsByClassName(classnameee); for (var index = 0; index < elmnts.length; ++index) { elmnts[index].style.display= "none"; }}</script>