├── .editorconfig ├── css ├── jDatepicker.css └── style.css ├── index.php ├── js ├── jDatepicker.js ├── jFloatTop.js ├── jPaginate.js └── jReplenish.js ├── paging-ajax-demo.php └── readme.md /.editorconfig: -------------------------------------------------------------------------------- 1 | ; http://editorconfig.org 2 | ; 3 | ; Sublime: https://github.com/sindresorhus/editorconfig-sublime 4 | ; Phpstorm: https://plugins.jetbrains.com/plugin/7294-editorconfig 5 | 6 | root = true 7 | 8 | [*] 9 | indent_style = space 10 | indent_size = 2 11 | end_of_line = lf 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | 16 | [{*.md,*.php,composer.json,composer.lock}] 17 | indent_size = 4 18 | -------------------------------------------------------------------------------- /css/jDatepicker.css: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery-NepaliDatepicker-plugin CSS 3 | * 4 | * @author Jitendra Adhikari 5 | * @email jiten.adhikary@gmail.com 6 | * 7 | */ 8 | .jDatepicker-div { 9 | padding:3px; 10 | background:#fff; 11 | border:1px solid #e3e3e3; 12 | border-radius:5px; 13 | width:198px; 14 | display:none; 15 | z-index:2; 16 | position:absolute; 17 | } 18 | 19 | .jDatepicker-table { 20 | margin-top:0px; 21 | width:160px; 22 | } 23 | 24 | .jDatepicker-table thead tr { 25 | border:1px solid #bbb; 26 | } 27 | 28 | .jDatepicker-table th { 29 | background:#d4d4d4; 30 | font-family:Verdana, Geneva, sans-serif; 31 | font-size:14px; 32 | padding:5px 8px; 33 | } 34 | 35 | .jDatepicker-table th.disabled { 36 | background:#bbb; 37 | color:#888; 38 | } 39 | 40 | .jDatepicker-nav { 41 | background:#bbb; 42 | cursor:pointer; 43 | height:24px; 44 | border-radius:3px 3px 0 0; 45 | margin-bottom:0; 46 | width:198px; 47 | } 48 | 49 | .jDatepicker-nav span { 50 | text-align:center; 51 | width:15px; 52 | } 53 | 54 | .jDatepicker-nav span.disabled { 55 | color:#888; 56 | } 57 | 58 | .jDatepicker-prevnav { 59 | float:left; 60 | width:50px; 61 | } 62 | 63 | .jDatepicker-prevnav span { 64 | float:left; 65 | } 66 | 67 | .jDatepicker-label { 68 | text-align:center; 69 | float:left; 70 | width:90px; 71 | font-size:14px; 72 | font-weight:bold; 73 | padding-top:2px; 74 | } 75 | 76 | .jDatepicker-nextnav { 77 | display:inline; 78 | float:right; 79 | width:50px; 80 | } 81 | 82 | .jDatepicker-days td { 83 | font-weight:bold; 84 | font-size:12px; 85 | } 86 | 87 | .jDatepicker-nextnav span { 88 | float:right; 89 | } 90 | 91 | .jDatepicker-table td { 92 | background:#eee; 93 | font-size:12px; 94 | text-align:center; 95 | padding:4px auto; 96 | } 97 | 98 | .jDatepicker-table td.jDatepicker-click { 99 | cursor:pointer; 100 | border:1px solid #ddd; 101 | } 102 | 103 | .jDatepicker-table td.jDatepicker-hover { 104 | border:1px solid #aaa; 105 | } 106 | 107 | .jDatepicker-table td.jDatepicker-selected, 108 | .jDatepicker-table td.jDatepicker-today { 109 | font-weight:bold; 110 | background:none; 111 | } 112 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | /* common */ 2 | body{font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;margin:0; padding:0;} 3 | #ground{width:90%;margin:0 auto;} 4 | fieldset,legend {border:1px solid #DDD;} 5 | legend{padding:2px 8px;} 6 | legend.slide{cursor:pointer;} 7 | fieldset{margin:10px 0;} 8 | 9 | /* pagination */ 10 | .jq-pagination-wrap{width:95%;float:left;} 11 | .jq-pagination-nav{margin-top:15px;float:left;} 12 | .jq-pagination-nav a{cursor:pointer;background:#CCC;margin:0 1px;text-align:center; padding:2px 5px;font-size:14px;border-radius:3px 0;} 13 | .jq-pagination-nav a.jq-pagination-current-key{background:#DDD;color:#AAA;cursor:default;} 14 | .item{width:25%;margin:5px 0;float:left;} 15 | 16 | /* floattop */ 17 | .boxwrap{width:99%;padding:5px;} 18 | .box{border:1px solid #AAA;background:#FFF;margin:10px;padding:10px;} 19 | .box span{background:#EEE;border:1px solid #EEE;display:block;padding:5px;font-family:"Comic Sans MS", cursive;} 20 | 21 | /* replenish */ 22 | .input,.label{width:33%;float:left;} 23 | .input input,textarea,select{font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif;width:50%;} 24 | input[type="submit"]{display:none;} 25 | textarea{padding:5px;resize:none;} 26 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JavaScript jQuery plugin Demos | Adhocore » Jitendra Adhikari 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Click on the title to expand or collapse block

15 | 16 | 36 | 37 |
38 | 39 |
40 |
41 | Nepali(BS) jDatepicker Demo 42 |
43 |
Nepali Date:
44 |
English Date:
45 |
46 |
47 |
48 | 49 |
50 |
51 | Replenish Demo 52 |
53 |
54 | 1. without HTML5 55 |
56 |
Text
57 |
URL
58 |
Date
59 |
60 |
Email
61 |
Number
62 |
Combo 66 |
67 |
68 | Textarea 69 |
70 | 71 |
72 |
73 | 74 |
75 | 2. with HTML5 76 |
77 |
Text
78 |
URL
79 |
Date
80 |
81 |
Email
82 |
Number
83 |
Combo 87 |
88 |
89 | Textarea 90 |
91 | 92 |
93 |
94 |
95 |
96 |
97 | 98 |
99 |
100 | FloatTop Demo 101 |
102 |

The boxes for this demo are dynamically generated (by PHP script) and have varying heights

103 |
104 | 107 |
108 | strlen($str) ) 113 | $str .= substr($pool, mt_rand(0, 25), 1) . " "; 114 | 115 | echo " {$str} "; 116 | ?> 117 |
118 | 119 |
120 |
121 |
122 | 123 |
124 |
125 |
126 | 127 |

© 2012 - 2013 — adhocore | Jitendra Adhikari

128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /js/jDatepicker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery Plugin - Enables to pick date in BikramSambat and gives equivalent English Date 3 | * 4 | * @author adhocore | Jitendra Adhikari 5 | * @email jiten.adhikary@gmail.com 6 | */ 7 | ; 8 | (function($) { 9 | 'use strict'; 10 | $.fn.jDatepicker = function(opts) { 11 | opts = $.extend({ 12 | separator: '-', 13 | format: 'yyyy-mm-dd', 14 | ADelm: '', 15 | ADformat: 'yyyy-mm-dd' 16 | }, opts || {}); 17 | 18 | var ref = new Date(), 19 | dpElm = this, 20 | adElm = null, 21 | ADbase = [1944, 1, 1, 7], 22 | BSbase = [2000, 1, 1, 4], 23 | ADtoBS = [2000, 9, 16, 6], 24 | BStoAD = [1943, 4, 13, 3], 25 | npDates = [ 26 | [2, 4, 3, 4, 3, 2, 2, 2, 1, 2, 1, 3], 27 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 28 | [3, 3, 4, 4, 3, 2, 2, 1, 2, 1, 2, 2], 29 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 3], 30 | [2, 4, 3, 4, 3, 2, 2, 2, 1, 2, 1, 3], 31 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 32 | [3, 3, 4, 4, 3, 2, 2, 1, 2, 1, 2, 2], 33 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 3], 34 | [3, 3, 3, 4, 3, 3, 1, 2, 2, 1, 1, 3], 35 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 36 | [3, 3, 4, 4, 3, 2, 2, 1, 2, 1, 2, 2], 37 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 3], 38 | [3, 3, 3, 4, 3, 3, 1, 2, 2, 1, 2, 2], 39 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 40 | [3, 3, 4, 4, 3, 2, 2, 1, 2, 1, 2, 2], 41 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 3], 42 | [3, 3, 3, 4, 3, 3, 1, 2, 2, 1, 2, 2], 43 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 44 | [3, 4, 3, 4, 3, 2, 2, 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 2, 3], 96 | [3, 3, 3, 4, 3, 3, 1, 2, 2, 1, 2, 2], 97 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 98 | [3, 4, 3, 4, 3, 2, 2, 1, 2, 1, 2, 2], 99 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 3], 100 | [3, 3, 3, 4, 3, 3, 2, 1, 2, 1, 2, 2], 101 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 102 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 2], 103 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 2, 1, 3], 104 | [3, 3, 3, 4, 3, 3, 2, 1, 2, 1, 2, 2], 105 | [3, 3, 4, 3, 3, 3, 2, 1, 2, 1, 2, 2], 106 | [3, 4, 3, 4, 3, 2, 2, 2, 1, 1, 2, 2], 107 | [3, 3, 4, 4, 3, 2, 2, 2, 1, 2, 2, 2], 108 | [2, 4, 3, 4, 3, 2, 2, 2, 1, 2, 2, 2], 109 | [3, 3, 4, 3, 3, 2, 2, 2, 1, 2, 2, 2], 110 | [3, 3, 4, 3, 3, 2, 2, 2, 1, 2, 2, 2], 111 | [3, 4, 3, 4, 2, 3, 2, 2, 1, 2, 2, 2], 112 | [2, 4, 3, 4, 3, 2, 2, 2, 1, 2, 2, 2], 113 | [3, 3, 4, 3, 3, 3, 2, 2, 1, 2, 2, 2], 114 | [2, 3, 4, 4, 2, 3, 2, 2, 1, 2, 2, 2], 115 | [2, 4, 3, 4, 3, 2, 2, 2, 1, 2, 2, 2], 116 | [2, 4, 3, 4, 3, 2, 2, 2, 1, 2, 2, 2] 117 | ], 118 | npNums = ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'], 119 | monthNames = ['चैत्र', 'बैशाख', 'जेष्ठ', 'आषाढ', 'श्रावण', 'भाद्र', 'आश्विन', 'कार्तिक', 'मंसिर', 'पौष', 'माघ', 'फाल्गुन', 'चैत्र'], 120 | dayNames = ['श', 'आ', 'सो', 'म', 'बु', 'बि', 'शु', 'श'], 121 | lngDayNames = ['शनिबार', 'आइतबार', 'सोमबार', 'मंगलबार', 'बुधबार', 'बिहिबार', 'शुक्रबार', 'शनिबार'], 122 | defaults = toBS(ref.getFullYear(), ref.getMonth() + 1, ref.getDate()), 123 | uid = Math.ceil(Math.random() * 10000), 124 | dpuid = '.jDp-' + uid; 125 | 126 | $('
').appendTo('body'); 127 | 128 | if (opts.ADelm) { 129 | adElm = opts.ADelm.replace(/^[#]+/, ''); 130 | if ($('#' + adElm).length < 1) { 131 | $('') 132 | .attr('name', adElm).attr('id', adElm) 133 | .data('elmID', uid).insertAfter(dpElm); 134 | }; 135 | adElm = $('#' + adElm); 136 | }; 137 | 138 | $(dpuid).html(calendar()); 139 | dpElm.data('elmID', uid).addClass('jDatepicker-element'); 140 | reFmt(); 141 | 142 | dpElm.focus(function() { 143 | dpuid = '.jDp-' + $(this).data('elmID'); 144 | $(dpuid).css('top', (num(dpElm.offset().top) + num(dpElm.height()) + num(dpElm.css('marginTop')) + 5) + 'px') 145 | .css('left', (num(dpElm.offset().left) + num(dpElm.css('marginLeft')) - 3) + 'px') 146 | .css('position', dpElm.css('position') == 'fixed' ? 'fixed' : 'absolute') 147 | .attr('elmID', uid); 148 | if ($(dpuid).is(':hidden')) $(dpuid).html(calendar()).show(); 149 | }); 150 | 151 | $(dpuid).delegate('.jDatepicker-click', 'click', function() { 152 | var t = $('.jDatepicker-table', $(dpuid)), 153 | y = t.data('year'), 154 | m = t.data('month'), 155 | d = $(this).data('day'), 156 | ad = toAD(y, m, d), 157 | sep = opts.separator; 158 | 159 | dpElm.val(y + sep + m + sep + d); 160 | adElm.val(ad[0] + sep + ad[1] + sep + ad[2]); 161 | 162 | $(dpuid).hide(); 163 | }); 164 | 165 | $(dpuid).delegate('.jDatepicker-div', 'mouseenter', function() { 166 | dpuid = '.np-dp-' + $(this).data('elmID'); 167 | }); 168 | 169 | $(dpuid).delegate('.jDatepicker-click', 'mouseenter', function() { 170 | $(this).addClass('jDatepicker-hover'); 171 | }); 172 | 173 | $(dpuid).delegate('.jDatepicker-click', 'mouseleave', function() { 174 | $(this).removeClass('jDatepicker-hover'); 175 | }); 176 | 177 | $(dpuid).delegate('.jDatepicker-next', 'click', function() { 178 | var a = attr(), 179 | y = a[0], 180 | m = a[1] + 1; 181 | if (m > 12) { 182 | m = 1; 183 | y = y + 1; 184 | }; 185 | $(dpuid).html(calendar(y, m)); 186 | }); 187 | 188 | $(dpuid).delegate('.jDatepicker-prev', 'click', function() { 189 | var a = attr(), 190 | y = a[0], 191 | m = a[1] - 1; 192 | if (m < 1) { 193 | m = 12; 194 | y = y - 1; 195 | }; 196 | $(dpuid).html(calendar(y, m)); 197 | }); 198 | 199 | $(dpuid).delegate('.jDatepicker-nextyear', 'click', function() { 200 | var a = attr(); 201 | $(dpuid).html(calendar(a[0] + 1, a[1])); 202 | }); 203 | 204 | $(dpuid).delegate('.jDatepicker-prevyear', 'click', function() { 205 | var a = attr(); 206 | $(dpuid).html(calendar(a[0] - 1, a[1])); 207 | }); 208 | 209 | $(document).click(function(event) { 210 | if ($(dpuid).is(':visible')) { 211 | var target = event.target || event.srcElement || event.currentTarget; 212 | if ($(dpuid).find(target).length < 1) { 213 | if ($(target).hasClass('jDatepicker-controls') || $(target).hasClass('jDatepicker-element')) 214 | $.noop(); 215 | else $(dpuid).hide(); 216 | }; 217 | }; 218 | }); 219 | 220 | function num(n) { 221 | return parseInt(n, 10); 222 | } 223 | 224 | function pad(n) { 225 | if (n < 10) { 226 | return '0' + n; 227 | } 228 | 229 | return n + ''; 230 | } 231 | 232 | function calendar(y, m) { 233 | var f = dtFmt(), 234 | yy = f[0] || num(defaults[0]), 235 | mm = f[1] || num(defaults[1]), 236 | dd = f[2] || num(defaults[2]); 237 | 238 | if (!y) y = yy; 239 | if (!m) m = mm; 240 | 241 | var nd = npDay(y, m) - 1, 242 | max = (npDates[y - 2000][m - 1] + 28), 243 | limit = (nd + max > 35) ? 42 : 35; 244 | 245 | var out = '
\ 246 |
«\ 247 |
\ 248 |
' + npNum(y) + ' ' + monthNames[m] + '
»\ 249 |
\ 250 |
', 251 | i = 0, 252 | j = 0, 253 | tr = false; 254 | 255 | out += ''; 256 | out += ''; 257 | 258 | while (i++ < 7) { 259 | out += ""; 260 | }; 261 | 262 | out += ''; 263 | 264 | for (i = 0, j = 0; i < limit; i++) { 265 | tr = false; 266 | if (i % 7 == 0) { 267 | tr = true; 268 | out += ''; 269 | } 270 | if (i == nd) j = 1; 271 | out += "'; 272 | if (j > 0) j++; 273 | if (j == max + 1) j = 0; 274 | if (i % 7 == 0 && !tr) { 275 | out += ''; 276 | }; 277 | }; 278 | 279 | out += '
" + dayNames[i] + "
" + ((j > 0 && j <= max) ? npNum(j) : '') + '
'; 280 | 281 | return out; 282 | }; 283 | 284 | function npDay(y, m) { 285 | var days = 0; 286 | y = y - 2000; 287 | 288 | while (1) { 289 | if (y == 0 && m == 1) break; 290 | if (m-- < 1) { 291 | m = 12; 292 | y--; 293 | }; 294 | 295 | if (m > 0) days = (days + 28 + npDates[y][m - 1]); 296 | }; 297 | 298 | return ((days + 4) % 7 != 0) ? (days + 4) % 7 : 7; 299 | }; 300 | 301 | function npNum(n) { 302 | var n = n + '', 303 | nep = '', 304 | d = ''; 305 | for (var k = 0; k < n.length; k++) { 306 | d = n.substr(k, 1); 307 | nep += (d == '0' || num(d) < 10) ? npNums[d] : d; 308 | }; 309 | 310 | return nep; 311 | }; 312 | 313 | /** Reformat date with 0 padding and separator */ 314 | function reFmt() { 315 | var f = dtFmt(), 316 | sep = opts.separator; 317 | if (f.length) dpElm.val(f[0] + sep + pad(f[1]) + sep + pad(f[2])); 318 | }; 319 | 320 | /** Format date */ 321 | function dtFmt() { 322 | var v = dpElm.val(); 323 | if (v && /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[012])$/.test(v)) { 324 | var vv = v.split(/[\/\-]/); 325 | 326 | return [num(vv[0]), num(vv[1]), num(vv[2])]; 327 | } 328 | 329 | return []; 330 | }; 331 | 332 | function attr() { 333 | var t = $('.jDatepicker-table', $(dpuid)); 334 | 335 | return [num(t.data('year')), num(t.data('month'))]; 336 | }; 337 | 338 | function toBS(y, m, d) { 339 | // if ( y < 1944 || y > 2090 ) return [0000,0,0,0]; 340 | var enDays = d, 341 | nDay, nDay, year, month, day; 342 | for (year = ADbase[0], month = ADbase[1];; month++) { 343 | if (y == year && m == month) break; 344 | if (month > 12) { 345 | month = 1; 346 | year += 1; 347 | if (y == year && m == month) break; 348 | } 349 | 350 | enDays = num(enDays) + enMonDays(year, month); 351 | } 352 | 353 | nDay = (ADtoBS[3] + enDays) % 7; 354 | nDay = nDay == 0 ? 7 : nDay; 355 | 356 | for (year = ADtoBS[0], month = ADtoBS[1], day = ADtoBS[2];; enDays--, day++) { 357 | if (day > npMonDays(year, month)) { 358 | day = 1; 359 | month = num(month) + 1; 360 | } 361 | if (month > 12) { 362 | month = 1; 363 | year = num(year) + 1; 364 | } 365 | if (enDays == 0) break; 366 | } 367 | 368 | return [year, pad(month), pad(day), nDay]; 369 | }; 370 | 371 | function toAD(y, m, d) { 372 | // if ( y < 2001 || y > 2090 ) return [0000,0,0,0]; 373 | var npDays = d, 374 | nDay, year, month, day; 375 | 376 | for (year = BSbase[0], month = BSbase[1];; month++) { 377 | if (y == year && m == month) break; 378 | if (month > 12) { 379 | month = 1; 380 | year = num(year) + 1; 381 | if (y == year && m == month) break; 382 | } 383 | npDays = num(npDays) + npMonDays(year, month); 384 | } 385 | 386 | nDay = (BStoAD[3] + npDays) % 7; 387 | nDay = nDay == 0 ? 7 : nDay; 388 | 389 | for (year = BStoAD[0], month = BStoAD[1], day = BStoAD[2];; npDays--, day++) { 390 | if (day > enMonDays(year, month)) { 391 | day = 1; 392 | month = num(month) + 1; 393 | } 394 | if (month > 12) { 395 | month = 1; 396 | year = num(year) + 1; 397 | } 398 | if (npDays == 0) break; 399 | }; 400 | 401 | return [year, pad(month), pad(day), nDay]; 402 | }; 403 | 404 | function enMonDays(y, m) { 405 | var max = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 406 | if (m < 1 || m > 12) return 0; 407 | if (m == 2 && isLeap(y)) return 29; 408 | 409 | return max[m - 1]; 410 | }; 411 | 412 | function npMonDays(y, m) { 413 | return 28 + npDates[y - 2000][m - 1]; 414 | }; 415 | 416 | function isLeap(y) { 417 | return (y % 100 != 0 || y % 400 == 0) && y % 4 == 0; 418 | }; 419 | 420 | return dpElm; // chaining 421 | }; 422 | })(jQuery); 423 | -------------------------------------------------------------------------------- /js/jFloatTop.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery plugin - jFloatTop | simulates CSS float:top; 3 | * 4 | * @author adhocore | Jitendra Adhikari 5 | * @email jiten.adhikary@gmail.com 6 | */ 7 | Array.prototype.max = function() { 8 | return Math.max.apply(Math, this); 9 | }; 10 | Array.prototype.min = function() { 11 | return Math.min.apply(Math, this); 12 | }; 13 | Array.prototype.maxi = function() { 14 | return this.indexOf(this.max()); 15 | }; 16 | Array.prototype.mini = function() { 17 | return this.indexOf(this.min()); 18 | }; 19 | 20 | (function($) { 21 | 'use strict'; 22 | $.fn.jFloatTop = function(opts) { 23 | opts = $.extend({ 24 | itemClass: 'box', 25 | col: 4, 26 | gap: 4 27 | }, opts || {}); 28 | 29 | var wrap = $(this), 30 | hh = [], 31 | minH = 0, 32 | boxes = wrap.find('.' + opts.itemClass), 33 | box = $(boxes[0]), 34 | minW = Math.floor( 35 | ( 36 | ( 37 | num(wrap.width()) - (offsetWidth(wrap) / 2) - 38 | (opts.gap - num(box.css('marginLeft')) - num(box.css('marginRight'))) 39 | * (opts.col - 1) 40 | ) / opts.col 41 | ) 42 | - offsetWidth(box) 43 | ); 44 | 45 | function num(n) { 46 | return parseInt(n, 10); 47 | }; 48 | 49 | function offsetWidth(el) { 50 | return (num(el.css('marginLeft')) + num(el.css('marginRight')) + num(el.css('paddingRight')) + num(el.css('paddingLeft')) + num(el.css('borderLeftWidth')) + num(el.css('borderRightWidth'))); 51 | }; 52 | 53 | wrap.css('position', 'relative'); 54 | 55 | boxes.each(function(i, e) { 56 | $(this).width(minW); 57 | 58 | var h = num($(this).outerHeight()); 59 | var j = i % opts.col, m = 0; 60 | 61 | if (i == 0) { 62 | m = h; 63 | for (var k = 0; k < opts.col; k++) { 64 | hh.push(0); 65 | } 66 | } else { 67 | m = hh.min(); 68 | } 69 | 70 | minH = minH == 0 ? m : Math.min(m, minH); 71 | 72 | if ((hh.max() - m) > minH) { 73 | j = hh.mini(); 74 | }; 75 | 76 | $(this).css({ 77 | top: hh[j], 78 | left: j * ($(this).outerWidth() + opts.gap), 79 | position: 'absolute' 80 | }); 81 | 82 | hh[j] += h + opts.gap; 83 | }); 84 | 85 | wrap.height(num(hh.max())); 86 | 87 | $(window).resize(function() { 88 | wrap.floattop(opts); 89 | }); 90 | 91 | return wrap; // chaining 92 | } 93 | })(jQuery); 94 | -------------------------------------------------------------------------------- /js/jPaginate.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery plugin - jPaginate | paginates preloaded items or lazy ajax loaded ones 3 | * 4 | * @author adhocore | Jitendra Adhikari 5 | * @email jiten.adhikary@gmail.com 6 | */ 7 | ; 8 | (function($) { 9 | 'use strict'; 10 | $.fn.jPaginate = function(option) { 11 | var defaults = { 12 | itemClass: 'item', 13 | offset: 0, 14 | startPage: 1, 15 | perPage: 10, 16 | ajax: { 17 | baseurl: '', 18 | format: '?currpage&offset&perpage', 19 | total: 0, 20 | offset: 'offset', // get variable name 21 | perpage: 'perpage', // get variable name 22 | currpage: 'currpage' // get variable name 23 | }, 24 | nextLabel: 'Next ›', 25 | prevLabel: '‹ Prev', 26 | navPos: 'bottom', 27 | navLinks: 'max', 28 | showCurrent: false, 29 | maxPageLinks: 0, 30 | navTitle: { 31 | prev: 'go to previous page', 32 | next: 'go to next page', 33 | first: 'go to first page', 34 | last: 'go to last page', 35 | page: 'go to page %i', 36 | current: 'current page %i' 37 | } 38 | }; 39 | 40 | option = option || {}; 41 | option.offset = 0; 42 | option.ajax = $.extend(defaults.ajax, option.ajax); 43 | 44 | var handle = $(this), 45 | isAjax = typeof option.ajax == 'object' && option.ajax.baseurl != '' && option.ajax.total > 0, 46 | option = $.extend(defaults, option), 47 | numPages, 48 | currPage, 49 | count, 50 | wrap; 51 | 52 | if (option.itemClass == '') { 53 | handle.append('

itemClass not defined

'); 54 | 55 | return false; 56 | } 57 | 58 | if (isAjax) { 59 | option.ajax.baseurl = option.ajax.baseurl.replace(/[\/]+$/, '') + '/'; 60 | count = option.ajax.total; 61 | } else { 62 | var items = handle.find('.' + option.itemClass); 63 | count = items.length; 64 | 65 | if (count == 0) { 66 | handle.append('jQueryPagination error: items with class "' + option.itemClass + '" not found.'); 67 | return false; 68 | } 69 | 70 | items.wrapAll('
'); 71 | wrap = $('.jq-pagination-wrap', handle); 72 | 73 | if (option.navPos == 'top') { 74 | wrap.before('
'); 75 | } else { 76 | if (option.navPos == 'both') { 77 | wrap.before('
'); 78 | wrap.after('
'); 79 | } else { 80 | wrap.after('
'); 81 | }; 82 | }; 83 | }; 84 | 85 | numPages = Math.ceil(count / option.perPage); 86 | 87 | if (option.startPage > 0 && option.startPage < Math.ceil(count / option.perPage)) { 88 | option.offset = (option.startPage - 1) * option.perPage; 89 | }; 90 | 91 | render(); 92 | 93 | $(handle).delegate('.jq-pagination-prev-key', 'click', function() { 94 | option.offset -= (option.perPage); 95 | render(); 96 | }); 97 | 98 | $(handle).delegate('.jq-pagination-next-key', 'click', function() { 99 | option.offset += (option.perPage); 100 | render(); 101 | }); 102 | 103 | $(handle).delegate('.jq-pagination-nav-key', 'click', function() { 104 | option.offset = parseInt($(this).data('pageoffset')); 105 | render(); 106 | }); 107 | 108 | function render() { 109 | var currPage = Math.floor(option.offset - option.perPage) / option.perPage + 2; 110 | 111 | if (isAjax) { 112 | $.ajax({ 113 | type: 'GET', 114 | url: option.ajax.baseurl + parseFormat(option.ajax.format), 115 | success: function(res) { 116 | (handle.find('.jq-pagination-wrap').length < 1) ? 117 | handle.append(res): handle.find('.jq-pagination-wrap').html(res); 118 | items = handle.find('.' + option.itemClass); 119 | if (items.length == 0) { 120 | handle.append('

jPaginate error: items with class "' + option.itemClass + '" not found.

'); 121 | return false; 122 | } 123 | if (handle.find('.jq-pagination-wrap').length < 1) { 124 | items.wrapAll('
'); 125 | wrap = $('.jq-pagination-wrap', handle); 126 | if (option.navPos == 'top') wrap.before('
'); 127 | else { 128 | if (option.navPos == 'both') { 129 | wrap.before('
'); 130 | wrap.after('
'); 131 | } else { 132 | wrap.after('
'); 133 | }; 134 | }; 135 | }; 136 | navLinks(); 137 | }, 138 | error: function(res) { 139 | handle.append('

Error Loading Content.

'); 140 | } 141 | }); 142 | } else { 143 | navLinks(); 144 | items.each(function() { 145 | ($(this).index() < option.offset || $(this).index() > (option.offset + option.perPage - 1)) ? 146 | $(this).hide(): $(this).show(); 147 | }); 148 | }; 149 | }; 150 | 151 | function navLinks() { 152 | var nav = $('.jq-pagination-nav', handle), 153 | i, j, title; 154 | 155 | nav.empty(); 156 | if (option.navLinks != 'min' && currPage != 1) { 157 | nav.append('« First'); 158 | }; 159 | 160 | if (option.offset > 0) 161 | nav.append('' + option.prevLabel + ''); 162 | 163 | if (option.showCurrent && (option.navLinks == 'min' || option.navLinks == 'mod')) { 164 | title = (option.navTitle.current).replace('%i', currPage); 165 | nav.append('' + currPage + ''); 166 | }; 167 | 168 | if (option.navLinks == 'max') { 169 | if (option.maxPageLinks == 0 || numPages <= option.maxPageLinks) { 170 | for (i = 0, j = 1; i < count; i += option.perPage, j++) { 171 | if (i == option.offset) { 172 | title = (option.navTitle.current).replace('%i', j); 173 | nav.append('' + j + ''); 174 | } else { 175 | title = (option.navTitle.page).replace('%i', j); 176 | nav.append('' + j + ''); 177 | }; 178 | }; 179 | } else { 180 | var maxlc = Math.ceil(option.maxPageLinks / 2); 181 | var maxlf = Math.floor(option.maxPageLinks / 2); 182 | var left = (currPage - maxlf) > 0 ? currPage - maxlf : 1; 183 | var right = (currPage + maxlc) < numPages ? currPage + maxlc - 1 : numPages; 184 | 185 | for (i = left; i <= right; i++) { 186 | if (i == currPage) { 187 | title = (option.navTitle.current).replace('%i', i); 188 | nav.append('' + i + '') 189 | } else { 190 | title = (option.navTitle.page).replace('%i', i); 191 | nav.append('' + i + ''); 192 | }; 193 | }; 194 | }; 195 | }; 196 | 197 | if (option.offset < (count - option.perPage)) { 198 | nav.append('' + option.nextLabel + ''); 199 | } 200 | 201 | if (option.navLinks != 'min' && currPage != numPages) { 202 | nav.append('Last »'); 203 | }; 204 | }; 205 | 206 | function parseFormat(format) { 207 | format = format.replace(/^[\/]+/, ''); 208 | if (format.indexOf('&') > -1 && format[0] != '?') format = '?' + format; 209 | 210 | var isget = format.indexOf('&') > -1 && format.indexOf('/') == -1, 211 | os = (option.ajax.offset && isget) ? option.ajax.offset + '=' + option.offset : option.offset, 212 | ps = (option.ajax.perpage && isget) ? option.ajax.perpage + '=' + option.perPage : option.perPage, 213 | cs = (option.ajax.currpage && isget) ? option.ajax.currpage + '=' + currPage : currPage; 214 | 215 | return format.replace('offset', os).replace('perpage', ps).replace('currpage', cs); 216 | }; 217 | }; 218 | })(jQuery); 219 | -------------------------------------------------------------------------------- /js/jReplenish.js: -------------------------------------------------------------------------------- 1 | /** 2 | * jQuery plugin - jReplenish | Replenishes the form with relevant data, made for testers ;) 3 | * 4 | * @author adhocore | Jitendra Adhikari 5 | * @email jiten.adhikary@gmail.com 6 | */ 7 | ; 8 | (function($) { 9 | 'use strict'; 10 | $.fn.jReplenish = function(options) { 11 | options = $.extend({ 12 | allFields: true, 13 | minLen: 10, 14 | maxLen: 25, 15 | dashDot: true 16 | }, options || {}); 17 | 18 | var form = this, 19 | toFill = form.find('input, textarea').not(':submit, :button, :reset'), 20 | toSelect = form.find('select'), 21 | number = '0123456789', 22 | alpha = 'abcdefghijklmnopqrstuvwxyz', 23 | upalpha = alpha.toUpperCase(), 24 | dashdot = '.-_'; 25 | 26 | if (!options.allFields) { 27 | toFill = toFill.filter(function() { 28 | var reqd = $(this).attr('required'); 29 | return $(this).hasClass('required') || (typeof reqd !== 'undefined' && reqd !== false); 30 | }); 31 | toSelect = toSelect.filter(function() { 32 | var reqd = $(this).attr('required'); 33 | return $(this).hasClass('required') || (typeof reqd !== 'undefined' && reqd !== false); 34 | }); 35 | }; 36 | 37 | if (toFill.length + toSelect.length > 0) { 38 | var undoBtn = form.find('input[type="reset"]'); 39 | form.find('input:submit').before(''); 40 | 41 | if (undoBtn.length < 1) { 42 | form.find('input:submit').after(''); 43 | } else { 44 | undoBtn.addClass('undo-form-replenish').attr('title', 'Undo Fill'); 45 | } 46 | } 47 | 48 | function doFill() { 49 | toFill.each(function(i, e) { 50 | var minLen = $(this).attr('minlength'), 51 | maxLen = $(this).attr('maxlength'), 52 | itype = $(this).attr('type'); 53 | minLen = (typeof minLen !== 'undefined' && minLen !== false) ? 54 | minLen : options.minLen; 55 | maxLen = (typeof maxLen !== 'undefined' && maxLen !== false && maxLen != -1 && 56 | maxLen != 524288 && maxLen != 2147483647) ? maxLen : options.maxLen; 57 | 58 | if ($(this).hasClass('date') || itype == 'date') { 59 | $(this).val(date()); 60 | } else if ($(this).hasClass('url') || itype == 'url') { 61 | $(this).val(url(minLen)); 62 | } else if ($(this).hasClass('email') || itype == 'email') { 63 | $(this).val(email(minLen)); 64 | } else if ($(this).hasClass('number') || itype == 'number') { 65 | $(this).val(val('number', false, minLen, maxLen)); 66 | } else { 67 | $(this).val(val('alphanum', true, minLen, maxLen)); 68 | }; 69 | }); 70 | 71 | toSelect.each(function(i, e) { 72 | var j = 1; 73 | if ($(this).find('option[value!=""]').length == (optCount = $(this).find('option').length)) { 74 | j = 0; 75 | } 76 | $(this).find('option').eq(rand(j, optCount - 1)).attr('selected', true); 77 | }); 78 | }; 79 | 80 | $('.replenish-form-btn', form).click(function() { 81 | doFill(); 82 | $(this).val('Refill'); 83 | $('.undo-form-replenish', form).show(); 84 | }); 85 | 86 | $('.undo-form-replenish', form).click(function() { 87 | if ($(this).hasClass('replenish-undo-btn')) $(this).hide(); 88 | $('.replenish-form-btn', form).val('Fill'); 89 | }); 90 | 91 | function val(type, dash, min, max) { 92 | var ret = '', 93 | pool = '', 94 | len = rand(min, max); 95 | 96 | if (!type) type = 'alphanum'; 97 | if (type == 'alphanum') pool = number + alpha + upalpha; 98 | if (type == 'alpha') pool = alpha; 99 | if (type == 'upalpha') pool = alpha + upalpha; 100 | if (type == 'number') pool = number; 101 | if (options.dashDot && pool != number && dash) pool += dashdot; 102 | 103 | while (ret.length < len) { 104 | ret += pool[Math.floor(Math.random() * pool.length)]; 105 | }; 106 | 107 | return ret; 108 | }; 109 | 110 | function email(min) { 111 | return val('alpha', true, 5, min) + '@' + val('alpha', false, min - 5, min - 5) + '.' + val('alpha', false, 3, 4); 112 | }; 113 | 114 | function url(min) { 115 | return 'https://' + val('alpha', false, min - 3, min) + '.' + val('alpha', false, 3, 4); 116 | }; 117 | 118 | function date() { 119 | var m = rand(1, 12), 120 | d = rand(1, 28); 121 | if (m < 10) m = '0' + m; 122 | if (d < 10) d = '0' + d; 123 | 124 | return rand(1900, 2100) + '-' + m + '-' + d; 125 | }; 126 | 127 | function rand(min, max) { 128 | return Math.floor(Math.random() * (max - min + 1)) + parseInt(min, 10); 129 | }; 130 | 131 | return form; // chaining 132 | } 133 | })(jQuery); 134 | -------------------------------------------------------------------------------- /paging-ajax-demo.php: -------------------------------------------------------------------------------- 1 | ajax loaded item {$i}
\n"; 12 | } 13 | 14 | echo $o; 15 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # adhocore/jquery-plugins 2 | 3 | some cool jQuery plugins for you 4 | 5 | ### What's included: 6 | 7 | - [jDatepicker](./js/jDatepicker.js) - Bikram Sambat Calendar and Date picker 8 | - [jFloatTop](./js/jFloatTop.js) - CSS Grid Float top (Simulates `float: top;`) 9 | - [jPaginate](./js/jPaginate.js) - Client side pagination with preloaded or ajax loaded items 10 | - [jReplenish](./js/jReplenish.js) - Automate filling up forms, great for rapid testing forms heavy apps 11 | 12 | #### Demo 13 | 14 | > [adhocore.github.io/jquery-plugins](https://adhocore.github.io/jquery-plugins) 15 | --------------------------------------------------------------------------------