patch_file/updatefiles/javascripts/jquery_prefix.js

209 lines
5.6 KiB
JavaScript

/* dataset polyfill for IE < 11 */
(function datasetModule(global, definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
exports = 'exports'; // keeps the method names for CommonJS / AMD from being compiled to single character variable
if (typeof define === 'function' && define[amd]) {
define(function definer() {
return definition(global);
});
} else if (typeof module === 'function' && module[exports]) {
module[exports] = definition(global);
} else {
definition(global);
}
}(this, function datasetPolyfill(global) {
'use strict';
var
attribute,
attributes,
counter,
dash,
dataRegEx,
document = global.document,
hasEventListener,
length,
match,
mutationSupport,
test = document.createElement('_'),
DOMAttrModified = 'DOMAttrModified';
function clearDataset(event) {
delete event.target._datasetCache;
}
function toCamelCase(string) {
return string.replace(dash, function (m, letter) {
return letter.toUpperCase();
});
}
function getDataset() {
var
dataset = {};
attributes = this.attributes;
for (counter = 0, length = attributes.length; counter < length; counter += 1) {
attribute = attributes[counter];
match = attribute.name.match(dataRegEx);
if (match) {
dataset[toCamelCase(match[1])] = attribute.value;
}
}
return dataset;
}
function mutation() {
if (hasEventListener) {
test.removeEventListener(DOMAttrModified, mutation, false);
} else {
test.detachEvent('on' + DOMAttrModified, mutation);
}
mutationSupport = true;
}
if (test.dataset !== undefined) {
return;
}
dash = /\-([a-z])/ig;
dataRegEx = /^data\-(.+)/;
hasEventListener = !!document.addEventListener;
mutationSupport = false;
if (hasEventListener) {
test.addEventListener(DOMAttrModified, mutation, false);
} else {
test.attachEvent('on' + DOMAttrModified, mutation);
}
// trigger event (if supported)
test.setAttribute('foo', 'bar');
Object.defineProperty(global.Element.prototype, 'dataset', {
get: mutationSupport
? function get() {
if (!this._datasetCache) {
this._datasetCache = getDataset.call(this);
}
return this._datasetCache;
} : getDataset
});
if (mutationSupport && hasEventListener) { // < IE9 supports neither
document.addEventListener(DOMAttrModified, clearDataset, false);
}
}));
$.fn.size= function(){
return this.length;
}
$.fn.andSelf= function() {
return this.addBack.apply(this, arguments);
}
$.fn.find= function( selector ) {
var i, ret,
len = this.length,
self = this;
if ( typeof selector !== "string" ) {
return this.pushStack( jQuery( selector ).filter( function() {
for ( i = 0; i < len; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
return true;
}
}
} ) );
}
ret = this.pushStack( [] );
if (selector != '\#'){
for ( i = 0; i < len; i++ ) {
jQuery.find( selector, self[ i ], ret );
}
}
else{
jQuery.find( document, self[ i ], ret );
}
return len > 1 ? jQuery.uniqueSort( ret ) : ret;
}
$.event.props = ( "altKey bubbles cancelable ctrlKey currentTarget detail eventPhase " +
"metaKey relatedTarget shiftKey target timeStamp view which" ).split( " " )
$.fn.load= function( url, params, callback ){
if (typeof url != 'string'){
callback = url;
return this.on( 'load',null, this, callback);
}
else{
var selector, type, response,
self = this,
off = url.indexOf( " " );
if ( off > -1 ) {
selector = jQuery.trim( url.slice( off, url.length ) );
url = url.slice( 0, off );
}
if ( jQuery.isFunction( params ) ) {
callback = params;
params = undefined;
} else if ( params && typeof params === "object" ) {
type = "POST";
}
jQuery.ajax( {
url: url,
type: type || "GET",
dataType: "html",
data: params
} ).done( function( responseText ) {
response = arguments;
self.html( selector ? jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : responseText );
} ).always( callback && function( jqXHR, status ) {
self.each( function() {
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
} );
} );
}
}
function migrateWarnFunc( obj, prop, newFunc, msg ) {
obj[ prop ] = function() {
return newFunc.apply( this, arguments );
};
}
if ( jQuery.ajax ) {
var oldAjax = jQuery.ajax;
jQuery.ajax = function( ) {
var jQXHR = oldAjax.apply( this, arguments );
// Be sure we got a jQXHR (e.g., not sync)
if ( jQXHR.promise ) {
migrateWarnFunc( jQXHR, "success", jQXHR.done,
"jQXHR.success is deprecated and removed" );
migrateWarnFunc( jQXHR, "error", jQXHR.fail,
"jQXHR.error is deprecated and removed" );
migrateWarnFunc( jQXHR, "complete", jQXHR.always,
"jQXHR.complete is deprecated and removed" );
}
return jQXHR;
};
}
$(function(){
$('input[type!="checkbox"],textarea').not('[type="submit"],[type=radio]').on('focus', function() {
$([document.documentElement, document.body]).animate({
scrollTop: $(this).offset().top -$(window).outerHeight()/2
}, 100);
});
$.each($('input[type="text"][placeholder]'),function(i,v){
if (!$(this).attr('title')){
$(this).attr('title',$(this).attr('placeholder'))
}
})
})