trivial: remove unused copy of bgiframe.js and related files (#43241)

This commit is contained in:
Frédéric Péters 2020-05-23 22:58:29 +02:00
parent 692d275a6b
commit be985a8acf
19 changed files with 0 additions and 1484 deletions

9
README
View File

@ -147,15 +147,6 @@ WYSIWYG - jQuery plugin 0.3
#
# Dual licensed under the MIT and GPL licenses:
jQuery Date Picker:
# Copyright (c) 2007 Kelvin Luck (http://www.kelvinluck.com/)
# Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
# and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
bgiframe:
# Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
# Licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
svg-pan-zoom:
# Copyright 2009-2010 Andrea Leofreddi <a.leofreddi@itcharm.com>
# Licensed under the BSD 2-clause license (http://opensource.org/licenses/BSD-2-Clause)

View File

@ -1,33 +0,0 @@
# bgiframe Change Log
## 3.0.0
* Rewrite of the plugin
* New conditional option (no longer restricted to IE6 only)
* No longer uses CSS Expressions
* Supoprts AMD loaders
## 2.1.2
* Fixed visual test (test.html)
* Small optimization to only check for IE once
## 2.1.1
* Removed $.browser.version for jQuery < 1.1.3
## 2.1
* Updated to work with jQuery 1.1.3
* Added $.browser.version for jQuery < 1.1.3
* Optimized duplication check by using child selector and using .length test
## 2.0
* Added ability change settings like width, height, src and more.
## 1.0
* Only adds iframe once per an element
* Works with SSL enabled pages

View File

@ -1,20 +0,0 @@
Copyright 2013, Brandon Aaron (http://brandonaaron.net/)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,47 +0,0 @@
# bgiframe
Plugin has been rewritten to remove the use of CSS Expressions and to lift the restriction to IE6 only. The IE6 limitation is on by default but is now configurable by passing the `conditional` option. You may want to do this for instance if you are trying to layer on top of Silverlight in later IE versions. As a result of removing the CSS Expressions, you'll now need to re-run the bgiframe on elements that change their width, height, and/or borders after they are changed.
The bgiframe plugin is chainable and applies the iframe hack to get around zIndex issues. It will only apply itself in IE6 (by default) and adds a class to the iframe called 'bgiframe'. The iframe is appended as the first child of the matched element(s) with a tabIndex and zIndex of -1.
By default the plugin will take borders, sized with pixel units, into account. If a different unit is used for the border's width, then you will need to use the top and left settings as explained below.
## How do I use it?
The usage is simple. Just call bgiframe on a jQuery collection of elements.
$('.fix-z-index').bgiframe();
If your element changes width, height, or border widths then you'll need to call bgiframe on those elements after the change.
Here is an example of using a different conditional and recalling `bgiframe` on the manipulated element.
var settings = { conditional: /MSIE/.test(navigator.userAgent) },
$testing = $('#testing');
$testing
.bgiframe(settings)
.bind('click', function(e) {
$testing
.width( $testing.width() + 10 )
.height( $testing.height() + 10 )
.bgiframe(settings);
});
### Settings
The plugin tries its best to handle most situations but sometimes some configuration is necessary. The following is a list of available settings.
* `top` *(String|Number)*: The iframe must be offset to the top by the width of the top border. This should be a negative number representing the border-top-width. If a number is used here, pixels will be assumed. Otherwise, be sure to specify a unit. An expression could also be used. By default the value is "auto" which will use the elements border top width as calculated by jQuery.
* `left` *(String|Number)*: The iframe must be offset to the left by the width of the left border. This should be a negative number representing the border-left-width. If a number is is used here, pixels will be assumed. Otherwise, be sure to specify a unit. An expression could also be used. By default the value is "auto" which will use the elements border left width as calculated by jQuery.
* `width` *(String|Number)*: This is the width of the iframe. If a number is used here, pixels will be assume. Otherwise, be sure to specify a unit. An expression could also be used. By default the value is "auto" which will the offsetWidth of the element.
* `height` *(String|Number)*: This is the height of the iframe. If a number is used here, pixels will be assume. Otherwise, be sure to specify a unit. An expression could also be used. By default the value is "auto" which will use the offsetHeight of the element.
* `opacity` *(Boolean)*: This is a boolean representing whether or not to use opacity. If set to true, the opacity of 0 is applied. If set to false, the opacity filter is not applied. Default: true.
* `src` *(String)*: This setting is provided so that one could change the src of the iframe to whatever they need. Default: "javascript:false;"
* `conditional` *(Boolean|Function)*: Turn on or off the injection of the iFrame. `true` to turn on the iFrame and `false` to turn it off. Default is IE6 only conditional.
## License
The bgiframe plugin is licensed under the MIT License (LICENSE.txt).
Copyright (c) 2013 [Brandon Aaron](http://brandonaaron.net)

View File

@ -1,64 +0,0 @@
/*! Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Version 3.0.0
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.fn.bgiframe = function(s) {
s = $.extend({
top : 'auto', // auto == borderTopWidth
left : 'auto', // auto == borderLeftWidth
width : 'auto', // auto == offsetWidth
height : 'auto', // auto == offsetHeight
opacity : true,
src : 'javascript:false;',
conditional : /MSIE 6.0/.test(navigator.userAgent) // expresion or function. return false to prevent iframe insertion
}, s);
// wrap conditional in a function if it isn't already
if (!$.isFunction(s.conditional)) {
var condition = s.conditional;
s.conditional = function() { return condition; };
}
var $iframe = $('<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
'style="display:block;position:absolute;z-index:-1;"/>');
return this.each(function() {
var $this = $(this);
if ( s.conditional(this) === false ) { return; }
var existing = $this.children('iframe.bgiframe');
var $el = existing.length === 0 ? $iframe.clone() : existing;
$el.css({
'top': s.top == 'auto' ?
((parseInt($this.css('borderTopWidth'),10)||0)*-1)+'px' : prop(s.top),
'left': s.left == 'auto' ?
((parseInt($this.css('borderLeftWidth'),10)||0)*-1)+'px' : prop(s.left),
'width': s.width == 'auto' ? (this.offsetWidth + 'px') : prop(s.width),
'height': s.height == 'auto' ? (this.offsetHeight + 'px') : prop(s.height),
'opacity': s.opacity === true ? 0 : undefined
});
if ( existing.length === 0 ) {
$this.prepend($el);
}
});
};
// old alias
$.fn.bgIframe = $.fn.bgiframe;
function prop(n) {
return n && n.constructor === Number ? n + 'px' : n;
}
}));

View File

@ -1,6 +0,0 @@
/*! Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Version 3.0.0
*/
(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{a(jQuery)}}(function(a){a.fn.bgiframe=function(c){c=a.extend({top:"auto",left:"auto",width:"auto",height:"auto",opacity:true,src:"javascript:false;",conditional:/MSIE 6.0/.test(navigator.userAgent)},c);if(!a.isFunction(c.conditional)){var e=c.conditional;c.conditional=function(){return e}}var d=a('<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+c.src+'"style="display:block;position:absolute;z-index:-1;"/>');return this.each(function(){var h=a(this);if(c.conditional(this)===false){return}var g=h.children("iframe.bgiframe");var f=g.length===0?d.clone():g;f.css({top:c.top=="auto"?((parseInt(h.css("borderTopWidth"),10)||0)*-1)+"px":b(c.top),left:c.left=="auto"?((parseInt(h.css("borderLeftWidth"),10)||0)*-1)+"px":b(c.left),width:c.width=="auto"?(this.offsetWidth+"px"):b(c.width),height:c.height=="auto"?(this.offsetHeight+"px"):b(c.height),opacity:c.opacity===true?0:undefined});if(g.length===0){h.prepend(f)}})};a.fn.bgIframe=a.fn.bgiframe;function b(c){return c&&c.constructor===Number?c+"px":c}}));

View File

@ -1,197 +0,0 @@
/*
* Array prototype extensions. Doesn't depend on any
* other code. Doens't overwrite existing methods.
*
* Adds forEach, every, some, map, filter, indexOf and unique.
*
* Copyright (c) 2006 Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function() {
/**
* Adds a given method under the given name
* to the Array prototype if it doesn't
* currently exist.
*
* @private
*/
function add(name, method) {
if( !Array.prototype[name] ) {
Array.prototype[name] = method;
}
};
/**
* Executes a provided function once per array element.
*
* @example var stuff = "";
* ["foo", "bar"].forEach(function(element, index, array) {
* stuff += element;
* });
* @result "foobar";
*
* @param Function handler Function to execute for each element.
* @param Object scope (optional) Object to use as 'this' when executing handler.
* @name forEach
* @type undefined
* @cat Plugins/Methods/Array
*/
add("forEach", function(handler, scope) {
scope = scope || window;
for( var i = 0; i < this.length; i++)
handler.call(scope, this[i], i, this);
});
/**
* Tests whether all elements in the array pass the test
* implemented by the provided function.
*
* @example [12, 54, 18, 130, 44].every(function(element, index, array) {
* return element >= 10;
* });
* @result true;
*
* @example [12, 5, 8, 130, 44].every(function(element, index, array) {
* return element >= 10;
* });
* @result false;
*
* @param Function handler Function to execute for each element.
* @param Object scope (optional) Object to use as 'this' when executing handler.
* @name every
* @type Boolean
* @cat Plugins/Methods/Array
*/
add("every", function(handler, scope) {
scope = scope || window;
for( var i = 0; i < this.length; i++)
if( !handler.call(scope, this[i], i, this) )
return false;
return true;
});
/**
* Tests whether at least one element in the array passes the test
* implemented by the provided function.
*
* @example [12, 5, 8, 1, 44].some(function(element, index, array) {
* return element >= 10;
* });
* @result true;
*
* @example [2, 5, 8, 1, 4].some(function(element, index, array) {
* return element >= 10;
* });
* @result false;
*
* @param Function handler Function to execute for each element.
* @param Object scope (optional) Object to use as 'this' when executing handler.
* @name some
* @type Boolean
* @cat Plugins/Methods/Array
*/
add("some", function(handler, scope) {
scope = scope || window;
for( var i = 0; i < this.length; i++)
if( handler.call(scope, this[i], i, this) )
return true;
return false;
});
/**
* Creates a new array with the results of
* calling a provided function on every element in this array.
*
* @example ["hello", "Array", "WORLD"].map(function(element, index, array) {
* return element.toUpperCase();
* });
* @result ["HELLO", "ARRAY", "WORLD"];
*
* @example [1, 4, 9].map(Math.sqrt);
* @result [1, 2, 3];
*
* @param Function handler Function to execute for each element.
* @param Object scope (optional) Object to use as 'this' when executing handler.
* @name map
* @type Array
* @cat Plugins/Methods/Array
*/
add("map", function(handler, scope) {
scope = scope || window;
var r = [];
for( var i = 0; i < this.length; i++)
r[r.length] = handler.call(scope, this[i], i, this);
return r;
});
/**
* Creates a new array with all elements that pass
* the test implemented by the provided function.
*
* @example [12, 5, 8, 1, 44].filter(function(element, index, array) {
* return element >= 10;
* });
* @result [12, 44];
*
* @param Function handler Function to execute for each element.
* @param Object scope (optional) Object to use as 'this' when executing handler.
* @name filter
* @type Array
* @cat Plugins/Methods/Array
*/
add("filter", function(handler, scope) {
scope = scope || window;
var r = [];
for( var i = 0; i < this.length; i++)
if( handler.call(scope, this[i], i, this) )
r[r.length] = this[i];
return r;
});
/**
* Returns the first index at which a given element can
* be found in the array, or -1 if it is not present.
*
* @example [12, 5, 8, 5, 44].indexOf(5);
* @result 1;
*
* @example [12, 5, 8, 5, 44].indexOf(5, 2);
* @result 3;
*
* @param Object subject Object to search for
* @param Number offset (optional) Index at which to start searching
* @name filter
* @type Array
* @cat Plugins/Methods/Array
*/
add("indexOf", function(subject, offset) {
for( var i = offset || 0; i < this.length; i++)
if ( this[i] === subject )
return i;
return -1;
});
/**
* Returns a new array that contains all unique elements
* of this array.
*
* @example [1, 2, 1, 4, 5, 4].unique();
* @result [1, 2, 4, 5]
*
* @name unique
* @type Array
* @cat Plugins/Methods/Array
*/
add("unique", function() {
return this.filter(function(element, index, array) {
return array.indexOf(element) >= index;
});
});
})();

View File

@ -1,467 +0,0 @@
/*
* Date prototype extensions. Doesn't depend on any
* other code. Doens't overwrite existing methods.
*
* Adds dayNames, abbrDayNames, monthNames and abbrMonthNames static properties and isLeapYear,
* isWeekend, isWeekDay, getDaysInMonth, getDayName, getMonthName, getDayOfYear, getWeekOfYear,
* setDayOfYear, addYears, addMonths, addDays, addHours, addMinutes, addSeconds methods
*
* Copyright (c) 2006 Jörn Zaefferer and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
*
* Additional methods and properties added by Kelvin Luck: firstDayOfWeek, dateFormat, zeroTime, asString, fromString -
* I've added my name to these methods so you know who to blame if they are broken!
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* An Array of day names starting with Sunday.
*
* @example dayNames[0]
* @result 'Sunday'
*
* @name dayNames
* @type Array
* @cat Plugins/Methods/Date
*/
Date.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
/**
* An Array of abbreviated day names starting with Sun.
*
* @example abbrDayNames[0]
* @result 'Sun'
*
* @name abbrDayNames
* @type Array
* @cat Plugins/Methods/Date
*/
Date.abbrDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
/**
* An Array of month names starting with Janurary.
*
* @example monthNames[0]
* @result 'January'
*
* @name monthNames
* @type Array
* @cat Plugins/Methods/Date
*/
Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
/**
* An Array of abbreviated month names starting with Jan.
*
* @example abbrMonthNames[0]
* @result 'Jan'
*
* @name monthNames
* @type Array
* @cat Plugins/Methods/Date
*/
Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
/**
* The first day of the week for this locale.
*
* @name firstDayOfWeek
* @type Number
* @cat Plugins/Methods/Date
* @author Kelvin Luck
*/
Date.firstDayOfWeek = 1;
/**
* The format that string dates should be represented as (e.g. 'dd/mm/yyyy' for UK, 'mm/dd/yyyy' for US, 'yyyy-mm-dd' for Unicode etc).
*
* @name format
* @type String
* @cat Plugins/Methods/Date
* @author Kelvin Luck
*/
Date.format = 'dd/mm/yyyy';
//Date.format = 'mm/dd/yyyy';
//Date.format = 'yyyy-mm-dd';
//Date.format = 'dd mmm yy';
/**
* The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear
* only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes.
*
* @name format
* @type String
* @cat Plugins/Methods/Date
* @author Kelvin Luck
*/
Date.fullYearStart = '20';
(function() {
/**
* Adds a given method under the given name
* to the Date prototype if it doesn't
* currently exist.
*
* @private
*/
function add(name, method) {
if( !Date.prototype[name] ) {
Date.prototype[name] = method;
}
};
/**
* Checks if the year is a leap year.
*
* @example var dtm = new Date("01/12/2008");
* dtm.isLeapYear();
* @result true
*
* @name isLeapYear
* @type Boolean
* @cat Plugins/Methods/Date
*/
add("isLeapYear", function() {
var y = this.getFullYear();
return (y%4==0 && y%100!=0) || y%400==0;
});
/**
* Checks if the day is a weekend day (Sat or Sun).
*
* @example var dtm = new Date("01/12/2008");
* dtm.isWeekend();
* @result false
*
* @name isWeekend
* @type Boolean
* @cat Plugins/Methods/Date
*/
add("isWeekend", function() {
return this.getDay()==0 || this.getDay()==6;
});
/**
* Check if the day is a day of the week (Mon-Fri)
*
* @example var dtm = new Date("01/12/2008");
* dtm.isWeekDay();
* @result false
*
* @name isWeekDay
* @type Boolean
* @cat Plugins/Methods/Date
*/
add("isWeekDay", function() {
return !this.isWeekend();
});
/**
* Gets the number of days in the month.
*
* @example var dtm = new Date("01/12/2008");
* dtm.getDaysInMonth();
* @result 31
*
* @name getDaysInMonth
* @type Number
* @cat Plugins/Methods/Date
*/
add("getDaysInMonth", function() {
return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()];
});
/**
* Gets the name of the day.
*
* @example var dtm = new Date("01/12/2008");
* dtm.getDayName();
* @result 'Saturday'
*
* @example var dtm = new Date("01/12/2008");
* dtm.getDayName(true);
* @result 'Sat'
*
* @param abbreviated Boolean When set to true the name will be abbreviated.
* @name getDayName
* @type String
* @cat Plugins/Methods/Date
*/
add("getDayName", function(abbreviated) {
return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()];
});
/**
* Gets the name of the month.
*
* @example var dtm = new Date("01/12/2008");
* dtm.getMonthName();
* @result 'Janurary'
*
* @example var dtm = new Date("01/12/2008");
* dtm.getMonthName(true);
* @result 'Jan'
*
* @param abbreviated Boolean When set to true the name will be abbreviated.
* @name getDayName
* @type String
* @cat Plugins/Methods/Date
*/
add("getMonthName", function(abbreviated) {
return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()];
});
/**
* Get the number of the day of the year.
*
* @example var dtm = new Date("01/12/2008");
* dtm.getDayOfYear();
* @result 11
*
* @name getDayOfYear
* @type Number
* @cat Plugins/Methods/Date
*/
add("getDayOfYear", function() {
var tmpdtm = new Date("1/1/" + this.getFullYear());
return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000);
});
/**
* Get the number of the week of the year.
*
* @example var dtm = new Date("01/12/2008");
* dtm.getWeekOfYear();
* @result 2
*
* @name getWeekOfYear
* @type Number
* @cat Plugins/Methods/Date
*/
add("getWeekOfYear", function() {
return Math.ceil(this.getDayOfYear() / 7);
});
/**
* Set the day of the year.
*
* @example var dtm = new Date("01/12/2008");
* dtm.setDayOfYear(1);
* dtm.toString();
* @result 'Tue Jan 01 2008 00:00:00'
*
* @name setDayOfYear
* @type Date
* @cat Plugins/Methods/Date
*/
add("setDayOfYear", function(day) {
this.setMonth(0);
this.setDate(day);
return this;
});
/**
* Add a number of years to the date object.
*
* @example var dtm = new Date("01/12/2008");
* dtm.addYears(1);
* dtm.toString();
* @result 'Mon Jan 12 2009 00:00:00'
*
* @name addYears
* @type Date
* @cat Plugins/Methods/Date
*/
add("addYears", function(num) {
this.setFullYear(this.getFullYear() + num);
return this;
});
/**
* Add a number of months to the date object.
*
* @example var dtm = new Date("01/12/2008");
* dtm.addMonths(1);
* dtm.toString();
* @result 'Tue Feb 12 2008 00:00:00'
*
* @name addMonths
* @type Date
* @cat Plugins/Methods/Date
*/
add("addMonths", function(num) {
var tmpdtm = this.getDate();
this.setMonth(this.getMonth() + num);
if (tmpdtm > this.getDate())
this.addDays(-this.getDate());
return this;
});
/**
* Add a number of days to the date object.
*
* @example var dtm = new Date("01/12/2008");
* dtm.addDays(1);
* dtm.toString();
* @result 'Sun Jan 13 2008 00:00:00'
*
* @name addDays
* @type Date
* @cat Plugins/Methods/Date
*/
add("addDays", function(num) {
this.setDate(this.getDate() + num);
return this;
});
/**
* Add a number of hours to the date object.
*
* @example var dtm = new Date("01/12/2008");
* dtm.addHours(24);
* dtm.toString();
* @result 'Sun Jan 13 2008 00:00:00'
*
* @name addHours
* @type Date
* @cat Plugins/Methods/Date
*/
add("addHours", function(num) {
this.setHours(this.getHours() + num);
return this;
});
/**
* Add a number of minutes to the date object.
*
* @example var dtm = new Date("01/12/2008");
* dtm.addMinutes(60);
* dtm.toString();
* @result 'Sat Jan 12 2008 01:00:00'
*
* @name addMinutes
* @type Date
* @cat Plugins/Methods/Date
*/
add("addMinutes", function(num) {
this.setMinutes(this.getMinutes() + num);
return this;
});
/**
* Add a number of seconds to the date object.
*
* @example var dtm = new Date("01/12/2008");
* dtm.addSeconds(60);
* dtm.toString();
* @result 'Sat Jan 12 2008 00:01:00'
*
* @name addSeconds
* @type Date
* @cat Plugins/Methods/Date
*/
add("addSeconds", function(num) {
this.setSeconds(this.getSeconds() + num);
return this;
});
/**
* Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant.
*
* @example var dtm = new Date();
* dtm.zeroTime();
* dtm.toString();
* @result 'Sat Jan 12 2008 00:01:00'
*
* @name zeroTime
* @type Date
* @cat Plugins/Methods/Date
* @author Kelvin Luck
*/
add("zeroTime", function() {
this.setMilliseconds(0);
this.setSeconds(0);
this.setMinutes(0);
this.setHours(0);
return this;
});
/**
* Returns a string representation of the date object according to Date.format.
* (Date.toString may be used in other places so I purposefully didn't overwrite it)
*
* @example var dtm = new Date("01/12/2008");
* dtm.asString();
* @result '12/01/2008' // (where Date.format == 'dd/mm/yyyy'
*
* @name asString
* @type Date
* @cat Plugins/Methods/Date
* @author Kelvin Luck
*/
add("asString", function() {
var r = Date.format;
return r
.split('yyyy').join(this.getFullYear())
.split('yy').join((this.getFullYear() + '').substring(2))
.split('mmm').join(this.getMonthName(true))
.split('mm').join(_zeroPad(this.getMonth()+1))
.split('dd').join(_zeroPad(this.getDate()));
});
/**
* Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object
* (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere)
*
* @example var dtm = Date.fromString("12/01/2008");
* dtm.toString();
* @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/yyyy'
*
* @name fromString
* @type Date
* @cat Plugins/Methods/Date
* @author Kelvin Luck
*/
Date.fromString = function(s)
{
var f = Date.format;
var d = new Date('01/01/1977');
var iY = f.indexOf('yyyy');
if (iY > -1) {
d.setFullYear(Number(s.substr(iY, 4)));
} else {
// TODO - this doesn't work very well - are there any rules for what is meant by a two digit year?
d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('yy'), 2)));
}
var iM = f.indexOf('mmm');
if (iM > -1) {
var mStr = s.substr(iM, 3);
for (var i=0; i<Date.abbrMonthNames.length; i++) {
if (Date.abbrMonthNames[i] == mStr) break;
}
d.setMonth(i);
} else {
d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1);
}
d.setDate(Number(s.substr(f.indexOf('dd'), 2)));
if (isNaN(d.getTime())) {
return false;
}
return d;
};
// utility method
var _zeroPad = function(num) {
var s = '0'+num;
return s.substring(s.length-2)
//return ('0'+num).substring(-2); // doesn't work on IE :(
};
})();

View File

@ -1,10 +0,0 @@
// date localization for locale 'be' (Belarussian), utf-8 encoding
// provided by Vladimir Prudnikov http://prudnikov.com/)
Date.dayNames = ['Нядзеля', 'Панядзелак', 'Ауторак', 'Серада', 'Чацьвер', 'Пятница', 'Суббота'];
Date.abbrDayNames = ['Нд', 'Пн', 'Аў', 'Ср', 'Чц', 'Пт', 'Сб'];
Date.monthNames = ['Студзень', 'Люты', 'Сакавік', 'Красавік', 'Травень', 'Чэрвень', 'Ліпень', 'Жнівень', 'Верасень', 'Кастрычнік', 'Лістапад', 'Снежань'];
Date.abbrMonthNames = ['Сту', 'Лют', 'Сак', 'Кра', 'Тра', 'Чэр', 'Ліп', 'Жні', 'Вер', 'Кас', 'Ліс', 'Сне'];
Date.firstDayOfWeek = 1;
Date.format = 'dd.mm.yyyy';

View File

@ -1,6 +0,0 @@
// date localization for locale 'de'
// generated by Jörn Zaefferer using Java's java.util.SimpleDateFormat
Date.dayNames = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
Date.abbrDayNames = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
Date.monthNames = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
Date.abbrMonthNames = ['Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'];

View File

@ -1,6 +0,0 @@
// date localization for locale 'es'
// generated by Jörn Zaefferer using Java's java.util.SimpleDateFormat
Date.dayNames = ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'];
Date.abbrDayNames = ['dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb'];
Date.monthNames = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'];
Date.abbrMonthNames = ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'];

View File

@ -1,6 +0,0 @@
// date localization for locale 'fr'
// generated by Jörn Zaefferer using Java's java.util.SimpleDateFormat
Date.dayNames = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'];
Date.abbrDayNames = ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'];
Date.monthNames = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'];
Date.abbrMonthNames = ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'];

View File

@ -1,6 +0,0 @@
// date localization for locale 'it'
// generated by Jörn Zaefferer using Java's java.util.SimpleDateFormat
Date.dayNames = ['domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato'];
Date.abbrDayNames = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
Date.monthNames = ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'];
Date.abbrMonthNames = ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'];

View File

@ -1,11 +0,0 @@
// date localization for locale 'po'
// provided by eRIZ (http://eriz.pcinside.pl/)
Date.dayNames = ['Niedziela', 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota'];
Date.abbrDayNames = ['Ni', 'Po', 'Wt', 'Śr', 'Cz', 'Pt', 'So'];
Date.monthNames = ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'];
Date.abbrMonthNames = ['Sty', 'Lut', 'Mar', 'Kwi', 'Maj', 'Cze', 'Lip', 'Sie', 'Wrz', 'Paź', 'Lis', 'Gru'];
Date.firstDayOfWeek = 1;
Date.format = 'dd.mmm.yyyy';

View File

@ -1,10 +0,0 @@
// date localization for locale 'ru-RU', utf-8 encoding
// provided by Sergey Nechaev http://nechaev.org/)
Date.dayNames = ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'];
Date.abbrDayNames = ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'];
Date.monthNames = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
Date.abbrMonthNames = ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'];
Date.firstDayOfWeek = 1;
Date.format = 'dd.mm.yyyy';

View File

@ -1,10 +0,0 @@
// date localization for locale 'ru-RU', win-1251 encoding
// provided by Sergey Nechaev http://nechaev.org/)
Date.dayNames = ['Âîñêðåñåíüå', 'Ïîíåäåëüíèê', 'Âòîðíèê', 'Ñðåäà', '×åòâåðã', 'Ïÿòíèöà', 'Ñóááîòà'];
Date.abbrDayNames = ['Âñ', 'Ïí', 'Âò', 'Ñð', '×ò', 'Ïò', 'Ñá'];
Date.monthNames = ['ßíâàðü', 'Ôåâðàëü', 'Ìàðò', 'Àïðåëü', 'Ìàé', 'Èþíü', 'Èþëü', 'Àâãóñò', 'Ñåíòÿáðü', 'Îêòÿáðü', 'Íîÿáðü', 'Äåêàáðü'];
Date.abbrMonthNames = ['ßíâ', 'Ôåâ', 'Ìàð', 'Àïð', 'Ìàé', 'Èþí', 'Èþë', 'Àâã', 'Ñåí', 'Îêò', 'Íîÿ', 'Äåê'];
Date.firstDayOfWeek = 1;
Date.format = 'dd.mm.yyyy';

View File

@ -1,11 +0,0 @@
// date localization for locale 'ru-UA' (Ukrainian), utf-8 encoding
// just put it after "date.js" declaration
// provided by Frankovskyi Bogdan, bfrankovskyi@gmail.com
Date.dayNames = ['Неділя', 'Понеділок', 'Вівторок', 'Середа', 'Четвер', 'Пятниця', 'Субота'];
Date.abbrDayNames = ['Нд', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'];
Date.monthNames = ['Січень', 'Лютий', 'Березень', 'Квітень', 'Травень', 'Червень', 'Липень', 'Серпень', 'Вересень', 'Жовтень', 'Листопад', 'Грудень'];
Date.abbrMonthNames = ['Січ', 'Лют', 'Бер', 'Квіт', 'Трав', 'Чер', 'Лип', 'Сер', 'Вер', 'Жов', 'Лис', 'Груд'];
Date.firstDayOfWeek = 1;
Date.format = 'dd.mm.yyyy';

View File

@ -1,412 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="Stylesheet" media="screen" href="../../../qunit/testsuite.css" />
<script type="text/javascript" src="../../jquery/dist/jquery.js"></script>
<script type="text/javascript" src="../../../qunit/testrunner.js"></script>
<script type="text/javascript" src="string.js"></script>
<script type="text/javascript" src="array.js"></script>
<script type="text/javascript" src="date.js"></script>
<script type="text/javascript">
test("String.trim()", function() {
ok( "" == "".trim(), "Expected no modification" );
ok( "" == " ".trim(), "Expected removal of single whitespace" );
ok( "" == " ".trim(), "Expected removal of multiple whitespace" );
ok( "peter" == "peter".trim(), "Expected no modification" );
ok( "peter" == " peter".trim(), "Expected trim at start" );
ok( "peter" == "peter ".trim(), "Expected trim at end" );
ok( "peter" == " peter ".trim(), "Expected trim at start and end" );
ok( "peter" == " peter ".trim(), "Expected lots of trim at start and end" );
ok( "pet er" == "pet er".trim(), "Expected no modification" );
ok( "pet er" == " pet er".trim(), "Expected trim at start" );
ok( "pet er" == "pet er ".trim(), "Expected trim at end" );
ok( "pet er" == " pet er ".trim(), "Expected trim at start and end" );
ok( "pet er" == " pet er ".trim(), "Expected lots of trim at start and end" );
ok( "p et er" == "p et er".trim(), "Expected no modification" );
ok( "p et er" == " p et er".trim(), "Expected trim at start" );
ok( "p et er" == "p et er ".trim(), "Expected trim at end" );
ok( "p et er" == " p et er ".trim(), "Expected trim at start and end" );
ok( "p et er" == " p et er ".trim(), "Expected lots of trim at start and end" );
ok( "Hello Boys and Girls!" == " Hello Boys and Girls! ".trim(), "Check example" );
} );
test("String.startsWith(prefix)", function() {
ok( "peter".startsWith("p") );
ok( "peter".startsWith("pet") );
ok( "peter".startsWith("pete") );
ok( "peter".startsWith("peter") );
ok( !"peter".startsWith("xst") );
ok( !"peter".startsWith("petr") );
ok( "/%$/".startsWith("/") );
ok( "/%$/".startsWith("/%") );
ok( !"/%$/".startsWith("/$") );
ok( "/%$/".startsWith("") );
ok( "".startsWith("") );
});
test("String.startsWith(prefix, offset)", function() {
ok( "peter".startsWith("e", 1) );
ok( "peter".startsWith("et", 1) );
ok( "peter".startsWith("ete", 1) );
ok( "peter".startsWith("eter", 1) );
ok( "peter".startsWith("t", 2) );
ok( "peter".startsWith("te", 2) );
ok( "peter".startsWith("ter", 2) );
ok( !"peter".startsWith("p", 1) );
ok( !"peter".startsWith("pe", 1) );
ok( !"peter".startsWith("e", 2) );
ok( !"peter".startsWith("et", 2) );
ok( !"peter".startsWith("pe", -1) );
ok( "peter".startsWith("r", 4) );
ok( !"peter".startsWith("r", 5) );
ok( "/%$/".startsWith("%", 1) );
ok( "/%$/".startsWith("%$", 1) );
ok( "/%$/".startsWith("$/", 2) );
ok( !"/%$/".startsWith("%$\"", 1) );
ok( "/%$/".startsWith("", 0) );
ok( "".startsWith("", 0) );
});
test("String.endsWith(suffix)", function() {
ok( "peter".endsWith("r") );
ok( "peter".endsWith("er") );
ok( "peter".endsWith("ter") );
ok( "peter".endsWith("eter") );
ok( "peter".endsWith("peter") );
ok( !"peter".endsWith("x") );
ok( !"peter".endsWith("xer") );
ok( !"peter".endsWith("pter") );
ok( "/%$/".endsWith("/") );
ok( "/%$/".endsWith("$/") );
ok( !"/%$/".endsWith("%/") );
ok( "/%$/".endsWith("") );
ok( "".endsWith("") );
});
test("String.truncate()", function() {
ok( "thisistenc thisistenc thisistenc ".truncate() == "thisistenc thisistenc thisi..." );
ok( "thisistenc thisistenc ".truncate() == "thisistenc thisistenc " );
});
test("String.truncate(length)", function() {
ok( "thisistenc ".truncate(5) == "th..." );
ok( "thisi".truncate() == "thisi" );
});
test("String.truncate(length, truncation)", function() {
ok( "thisistenc thisistenc thisistenc ".truncate(30, "x") == "thisistenc thisistenc thisistx" );
ok( "thisistenc thisistenc ".truncate(30, "x") == "thisistenc thisistenc " );
ok( "thisistenc ".truncate(5, "x") == "thisx" );
ok( "thisi".truncate(5, "x") == "thisi" );
});
test("String.stripTags()", function() {
ok( "<div id='hi'>Bla</div>".stripTags() == "Bla" );
var testString = [
'<html>',
'<head>',
'<link rel="stylesheet" href="../../jquery/build/test/data/testsuite.css" />',
'<script type="text/javascript" src="../../jquery/dist/jquery.js"><\/script>',
'<script type="text/javascript" src="../../jquery/build/test/data/testrunner.js"><\/script>',
'<script type="text/javascript" src="jquery.string.js"><\/script>',
'<script type="text/javascript" src="jquery.array.js"><\/script>',
'<script type="text/javascript">'
].join('');
ok( !testString.stripTags() );
});
test("Array.forEach()", function() {
var stuff = "";
["foo", "bar"].forEach(function(element, index, array) {
stuff += element;
});
ok( stuff == "foobar" );
});
test("Array.every()", function() {
ok( [12, 54, 18, 130, 44].every(function(element, index, array) {
return element >= 10;
}) === true );
ok( [12, 5, 8, 130, 44].every(function(element, index, array) {
return element >= 10;
}) === false );
});
test("Array.some()", function() {
ok( [12, 5, 8, 1, 44].some(function(element, index, array) {
return element >= 10;
}) === true );
ok( [2, 5, 8, 1, 4].some(function(element, index, array) {
return element >= 10;
}) === false );
});
test("Array.map()", function() {
var s = ["hello", "Array", "WORLD"];
var r = s.map(function(element, index, array) {
return element.toUpperCase();
});
isSet( s, ["hello", "Array", "WORLD"] );
isSet( r, ["HELLO", "ARRAY", "WORLD"] );
s = [1, 4, 9];
r = s.map(Math.sqrt);
isSet( s, [1, 4, 9] );
isSet( r, [1, 2, 3] );
});
test("Array.filter()", function() {
var s = [12, 5, 8, 1, 44];
var r = s.filter(function(element, index, array) {
return element >= 10;
});
isSet( s, [12, 5, 8, 1, 44] );
isSet( r, [12, 44] );
});
test("Array.indexOf()", function() {
ok( [12, 5, 8, 5, 44].indexOf(5) == 1 );
ok( [12, 5, 8, 5, 44].indexOf(5, 2) == 3 );
ok( [12, 5, 8, 5, 44].indexOf(5, 4) == -1 );
});
test("Array.unique()", function() {
var s = [1, 2, 1, 4, 5, 4];
var r = s.unique();
isSet( s, [1, 2, 1, 4, 5, 4] );
isSet( r, [1, 2, 4, 5] );
});
test("Date.isLeapYear()", function() {
var dtm = new Date('01/01/2008');
ok( dtm.isLeapYear() == true, 'is a leap year' );
dtm = new Date('01/01/2007');
ok( dtm.isLeapYear() == false, 'is not a lear' );
});
test("Date.isWeekend()", function() {
var dtm = new Date('01/07/2007');
ok( dtm.isWeekend() == true, 'on a Sunday' );
dtm = new Date('01/08/2007');
ok( dtm.isWeekend() == false, 'on a Monday' );
dtm = new Date('01/09/2007');
ok( dtm.isWeekend() == false, 'on a Tuesday' );
dtm = new Date('01/10/2007');
ok( dtm.isWeekend() == false, 'on a Wednesday' );
dtm = new Date('01/11/2007');
ok( dtm.isWeekend() == false, 'on a Thursday' );
dtm = new Date('01/12/2007');
ok( dtm.isWeekend() == false, 'on a Friday' );
dtm = new Date('01/06/2007');
ok( dtm.isWeekend() == true, 'on a Saturday' );
});
test("Date.isWeekDay()", function() {
var dtm = new Date('01/07/2007');
ok( dtm.isWeekDay() == false, 'on a Sunday' );
dtm = new Date('01/08/2007');
ok( dtm.isWeekDay() == true, 'on a Monday' );
dtm = new Date('01/09/2007');
ok( dtm.isWeekDay() == true, 'on a Tuesday' );
dtm = new Date('01/10/2007');
ok( dtm.isWeekDay() == true, 'on a Wednesday' );
dtm = new Date('01/11/2007');
ok( dtm.isWeekDay() == true, 'on a Thursday' );
dtm = new Date('01/12/2007');
ok( dtm.isWeekDay() == true, 'on a Friday' );
dtm = new Date('01/06/2007');
ok( dtm.isWeekDay() == false, 'on a Saturday' );
});
test("Date.getDaysInMonth()", function() {
var dtm = new Date('01/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in January');
dtm = new Date('02/01/2007');
ok( dtm.getDaysInMonth() == 28, 'in February');
dtm = new Date('02/01/2008');
ok( dtm.getDaysInMonth() == 29, 'in February on a leap year');
dtm = new Date('03/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in March');
dtm = new Date('04/01/2007');
ok( dtm.getDaysInMonth() == 30, 'in April');
dtm = new Date('05/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in May');
dtm = new Date('06/01/2007');
ok( dtm.getDaysInMonth() == 30, 'in June');
dtm = new Date('07/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in July');
dtm = new Date('08/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in August');
dtm = new Date('09/01/2007');
ok( dtm.getDaysInMonth() == 30, 'in September');
dtm = new Date('10/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in October');
dtm = new Date('11/01/2007');
ok( dtm.getDaysInMonth() == 30, 'in November');
dtm = new Date('12/01/2007');
ok( dtm.getDaysInMonth() == 31, 'in December');
});
test("Date.getDayName()", function() {
var dtm = new Date('01/07/2007');
ok( dtm.getDayName() == 'Sunday', 'on a Sunday' );
dtm = new Date('01/08/2007');
ok( dtm.getDayName() == 'Monday', 'on a Monday' );
dtm = new Date('01/09/2007');
ok( dtm.getDayName() == 'Tuesday', 'on a Tuesday' );
dtm = new Date('01/10/2007');
ok( dtm.getDayName() == 'Wednesday', 'on a Wednesday' );
dtm = new Date('01/11/2007');
ok( dtm.getDayName() == 'Thursday', 'on a Thursday' );
dtm = new Date('01/12/2007');
ok( dtm.getDayName() == 'Friday', 'on a Friday' );
dtm = new Date('01/06/2007');
ok( dtm.getDayName() == 'Saturday', 'on a Saturday' );
dtm = new Date('01/07/2007');
ok( dtm.getDayName(true) == 'Sun', 'on a Sunday abbreviated' );
dtm = new Date('01/08/2007');
ok( dtm.getDayName(true) == 'Mon', 'on a Monday abbreviated' );
dtm = new Date('01/09/2007');
ok( dtm.getDayName(true) == 'Tue', 'on a Tuesday abbreviated' );
dtm = new Date('01/10/2007');
ok( dtm.getDayName(true) == 'Wed', 'on a Wednesday abbreviated' );
dtm = new Date('01/11/2007');
ok( dtm.getDayName(true) == 'Thu', 'on a Thursday abbreviated' );
dtm = new Date('01/12/2007');
ok( dtm.getDayName(true) == 'Fri', 'on a Friday abbreviated' );
dtm = new Date('01/06/2007');
ok( dtm.getDayName(true) == 'Sat', 'on a Saturday abbreviated' );
});
test("Date.getMonthName()", function() {
var dtm = new Date('01/01/2007');
ok( dtm.getMonthName() == 'January', 'in January');
dtm = new Date('02/01/2007');
ok( dtm.getMonthName() == 'February', 'in February');
dtm = new Date('03/01/2007');
ok( dtm.getMonthName() == 'March', 'in March');
dtm = new Date('04/01/2007');
ok( dtm.getMonthName() == 'April', 'in April');
dtm = new Date('05/01/2007');
ok( dtm.getMonthName() == 'May', 'in May');
dtm = new Date('06/01/2007');
ok( dtm.getMonthName() == 'June', 'in June');
dtm = new Date('07/01/2007');
ok( dtm.getMonthName() == 'July', 'in July');
dtm = new Date('08/01/2007');
ok( dtm.getMonthName() == 'August', 'in August');
dtm = new Date('09/01/2007');
ok( dtm.getMonthName() == 'September', 'in September');
dtm = new Date('10/01/2007');
ok( dtm.getMonthName() == 'October', 'in October');
dtm = new Date('11/01/2007');
ok( dtm.getMonthName() == 'November', 'in November');
dtm = new Date('12/01/2007');
ok( dtm.getMonthName() == 'December', 'in December');
dtm = new Date('01/01/2007');
ok( dtm.getMonthName(true) == 'Jan', 'in January');
dtm = new Date('02/01/2007');
ok( dtm.getMonthName(true) == 'Feb', 'in February');
dtm = new Date('03/01/2007');
ok( dtm.getMonthName(true) == 'Mar', 'in March');
dtm = new Date('04/01/2007');
ok( dtm.getMonthName(true) == 'Apr', 'in April');
dtm = new Date('05/01/2007');
ok( dtm.getMonthName(true) == 'May', 'in May');
dtm = new Date('06/01/2007');
ok( dtm.getMonthName(true) == 'Jun', 'in June');
dtm = new Date('07/01/2007');
ok( dtm.getMonthName(true) == 'Jul', 'in July');
dtm = new Date('08/01/2007');
ok( dtm.getMonthName(true) == 'Aug', 'in August');
dtm = new Date('09/01/2007');
ok( dtm.getMonthName(true) == 'Sep', 'in September');
dtm = new Date('10/01/2007');
ok( dtm.getMonthName(true) == 'Oct', 'in October');
dtm = new Date('11/01/2007');
ok( dtm.getMonthName(true) == 'Nov', 'in November');
dtm = new Date('12/01/2007');
ok( dtm.getMonthName(true) == 'Dec', 'in December');
});
test("Date.getDayOfYear()", function() {
var dtm = new Date('01/01/2007');
ok( dtm.getDayOfYear() == 0, 'First day of the year' );
dtm = new Date('12/31/2007');
ok( dtm.getDayOfYear() == 364, 'Last day of the year' );
});
test("Date.getWeekOfYear()", function() {
var dtm = new Date('01/01/2007');
ok( dtm.getWeekOfYear() == 0, 'First week of the year' );
dtm = new Date('12/31/2007');
ok( dtm.getWeekOfYear() == 52, 'Last week of the year' );
});
test("Date.setDayOfYear()", function() {
var dtm = new Date('01/01/2007');
ok( dtm.setDayOfYear(365).getDayOfYear() == 364, 'Last day of the year' );
dtm = new Date('12/31/2007');
ok( dtm.setDayOfYear(1).getDayOfYear() == 0, 'First day of the year' );
});
test("Date.addYears()", function() {
var dtm = new Date('01/01/2007');
dtm.addYears(1);
ok( dtm.getFullYear() == 2008, 'Add one year' );
dtm.addYears(-1);
ok( dtm.getFullYear() == 2007, 'Subtract one year' );
});
test("Date.addMonths()", function() {
var dtm = new Date('01/01/2007');
dtm.addMonths(1);
ok( dtm.getMonthName() == 'February', 'Add one month' );
dtm.addMonths(-1);
ok( dtm.getMonthName() == 'January', 'Subtract one month' );
});
test("Date.addDays()", function() {
var dtm = new Date('01/01/2007');
dtm.addDays(1);
ok( dtm.getDayName() == 'Tuesday', 'Add one day' );
dtm.addDays(-1);
ok( dtm.getDayName() == 'Monday', 'Subtract one day' );
});
test("Date.addHours()", function() {
var dtm = new Date('01/01/2007');
dtm.addHours(24);
ok( dtm.getDayName() == 'Tuesday', 'Add 24 hours' );
dtm.addHours(-24);
ok( dtm.getDayName() == 'Monday', 'Subtract 24 hours' );
});
test("Date.addMinutes()", function() {
var dtm = new Date('01/01/2007');
dtm.addMinutes(1440);
ok( dtm.getDayName() == 'Tuesday', 'Add 1440 minutes' );
dtm.addMinutes(-1440);
ok( dtm.getDayName() == 'Monday', 'Subtract 1440 minutes' );
});
test("Date.addSeconds()", function() {
var dtm = new Date('01/01/2007');
dtm.addSeconds(86400);
ok( dtm.getDayName() == 'Tuesday', 'Add 86400 seconds' );
dtm.addSeconds(-86400);
ok( dtm.getDayName() == 'Monday', 'Subtract 86400 seconds' );
});
</script>
</head>
<body>
<h1>jQuery - Methods Test Suite</h1>
<div id="main"></div>
<ol id="tests"></ol>
</body>
</html>

View File

@ -1,153 +0,0 @@
/*
* String prototype extensions. Doesn't depend on any
* other code. Doens't overwrite existing methods.
*
* Adds trim, camelize, startsWith, endsWith, truncate and stripTags.
*
* Copyright (c) 2006 Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
(function() {
/**
* Adds a given method under the given name
* to the String prototype if it doesn't
* currently exist.
*
* @private
*/
function add(name, method) {
if( !String.prototype[name] ) {
String.prototype[name] = method;
}
}
/**
* Returns a string with with leading and trailing whitespace removed.
*
* @example " Hello Boys and Girls! ".trim()
* @result "Hello Boys and Girls!"
*
* @name trim
* @type String
* @cat Plugins/Methods/String
*/
add("trim", function(){
return this.replace(/(^\s+|\s+$)/g, "");
});
/**
* Return a camelized String, removing all underscores and dashes
* and replacing the next character with it's uppercase representation.
*
* @example "font-weight".camelize()
* @result "fontWeight"
*
* @example "border_width_bottom".camelize()
* @result "borderWidthBottom"
*
* @example "border_width-bottom".camelize()
* @result "borderWidthBottom"
*
* @name camelize
* @type String
* @cat Plugins/Methods/String
*/
add("camelize", function() {
return this.replace( /[-_]([a-z])/ig, function(z,b){ return b.toUpperCase();} );
});
/**
* Tests if this string starts with a prefix.
*
* An optional offset specifies where to start searching,
* default is 0 (start of the string).
*
* Returns false if the offset is negative or greater than the length
* of this string.
*
* @example "goldvein".startsWith("go")
* @result true
*
* @example "goldvein".startsWith("god")
* @result false
*
* @example "goldvein".startsWith("ld", 2)
* @result true
*
* @example "goldvein".startsWith("old", 2)
* @result false
*
* @name startsWith
* @type Boolean
* @param prefix The prefix to test
* @param offset (optional) From where to start testing
* @cat Plugins/Methods/String
*/
add("startsWith", function(prefix, offset) {
var offset = offset || 0;
if(offset < 0 || offset > this.length) return false;
return this.substring(offset, offset + prefix.length) == prefix;
});
/**
* Tests if this string ends with the specified suffix.
*
* @example "goldvein".endsWith("ein")
* @result true
*
* @example "goldvein".endsWith("vei")
* @result false
*
* @name endsWith
* @type Boolean
* @param suffix The suffix to test
* @cat Plugins/Methods/String
*/
add("endsWith", function(suffix) {
return this.substring(this.length - suffix.length) == suffix;
});
/**
* Returns a new String that is no longer than a certain length.
*
* @example "thisistenc ".truncate(5);
* @result "th..."
*
* @example "thisistenc ".truncate(5, "x")
* @result "thisx"
*
* @name truncate
* @type String
* @param Number length (optional) The maximum length of the returned string, default is 30
* @param String suffix (optional) The suffix to append to the truncated string, default is "..."
* @cat Plugins/Methods/String
*/
add("truncate", function(length, suffix) {
length = length || 30;
suffix = suffix === undefined ? "..." : suffix;
return this.length > length ?
this.slice(0, length - suffix.length) + suffix : this;
});
/**
* Returns a new String with all tags stripped.
*
* @example "<div id='hi'>Bla</div>".stripTags()
* @result "Bla"
*
* @name stripTags
* @type String
* @cat Plugins/Methods/String
*/
add("stripTags", function() {
return this.replace(/<\/?[^>]+>/gi, '');
});
})();