Commit 7960ccdf by Qiang Xue

Tab to spaces conversion.

parent 8cb144c5
(function() { (function () {
var ajax = function(url, settings) { var ajax = function (url, settings) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
settings = settings || {}; settings = settings || {};
xhr.open(settings.method || 'GET', url, true); xhr.open(settings.method || 'GET', url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = function(state) { xhr.onreadystatechange = function (state) {
if (xhr.readyState == 4) { if (xhr.readyState == 4) {
if (xhr.status == 200 && settings.success) { if (xhr.status == 200 && settings.success) {
settings.success(xhr); settings.success(xhr);
} else if (xhr.status != 200 && settings.error) { } else if (xhr.status != 200 && settings.error) {
settings.error(xhr); settings.error(xhr);
} }
} }
}; };
xhr.send(settings.data || ''); xhr.send(settings.data || '');
}; };
var e = document.getElementById('yii-debug-toolbar'); var e = document.getElementById('yii-debug-toolbar');
if (e) { if (e) {
e.style.display = 'block'; e.style.display = 'block';
var url = e.getAttribute('data-url'); var url = e.getAttribute('data-url');
ajax(url, { ajax(url, {
success: function(xhr) { success: function (xhr) {
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = xhr.responseText; div.innerHTML = xhr.responseText;
e.parentNode.replaceChild(div, e); e.parentNode.replaceChild(div, e);
if (window.localStorage) { if (window.localStorage) {
var pref = localStorage.getItem('yii-debug-toolbar'); var pref = localStorage.getItem('yii-debug-toolbar');
if (pref == 'minimized') { if (pref == 'minimized') {
document.getElementById('yii-debug-toolbar').style.display = 'none'; document.getElementById('yii-debug-toolbar').style.display = 'none';
document.getElementById('yii-debug-toolbar-min').style.display = 'block'; document.getElementById('yii-debug-toolbar-min').style.display = 'block';
} }
} }
}, },
error: function(xhr) { error: function (xhr) {
e.innerHTML = xhr.responseText; e.innerHTML = xhr.responseText;
} }
}); });
} }
})(); })();
...@@ -10,63 +10,63 @@ ...@@ -10,63 +10,63 @@
* @since 2.0 * @since 2.0
*/ */
(function ($) { (function ($) {
$.fn.yiiCaptcha = function (method) { $.fn.yiiCaptcha = function (method) {
if (methods[method]) { if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) { } else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments); return methods.init.apply(this, arguments);
} else { } else {
$.error('Method ' + method + ' does not exist on jQuery.yiiCaptcha'); $.error('Method ' + method + ' does not exist on jQuery.yiiCaptcha');
return false; return false;
} }
}; };
var defaults = { var defaults = {
refreshUrl: undefined, refreshUrl: undefined,
hashKey: undefined hashKey: undefined
}; };
var methods = { var methods = {
init: function (options) { init: function (options) {
return this.each(function () { return this.each(function () {
var $e = $(this); var $e = $(this);
var settings = $.extend({}, defaults, options || {}); var settings = $.extend({}, defaults, options || {});
$e.data('yiiCaptcha', { $e.data('yiiCaptcha', {
settings: settings settings: settings
}); });
$e.on('click.yiiCaptcha', function() { $e.on('click.yiiCaptcha', function () {
methods.refresh.apply($e); methods.refresh.apply($e);
return false; return false;
}); });
}); });
}, },
refresh: function () { refresh: function () {
var $e = this, var $e = this,
settings = this.data('yiiCaptcha').settings; settings = this.data('yiiCaptcha').settings;
$.ajax({ $.ajax({
url: $e.data('yiiCaptcha').settings.refreshUrl, url: $e.data('yiiCaptcha').settings.refreshUrl,
dataType: 'json', dataType: 'json',
cache: false, cache: false,
success: function(data) { success: function (data) {
$e.attr('src', data.url); $e.attr('src', data.url);
$('body').data(settings.hashKey, [data.hash1, data.hash2]); $('body').data(settings.hashKey, [data.hash1, data.hash2]);
} }
}); });
}, },
destroy: function () { destroy: function () {
return this.each(function () { return this.each(function () {
$(window).unbind('.yiiCaptcha'); $(window).unbind('.yiiCaptcha');
$(this).removeData('yiiCaptcha'); $(this).removeData('yiiCaptcha');
}); });
}, },
data: function() { data: function () {
return this.data('yiiCaptcha'); return this.data('yiiCaptcha');
} }
}; };
})(window.jQuery); })(window.jQuery);
...@@ -10,120 +10,120 @@ ...@@ -10,120 +10,120 @@
* @since 2.0 * @since 2.0
*/ */
(function ($) { (function ($) {
$.fn.yiiGridView = function (method) { $.fn.yiiGridView = function (method) {
if (methods[method]) { if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) { } else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments); return methods.init.apply(this, arguments);
} else { } else {
$.error('Method ' + method + ' does not exist on jQuery.yiiGridView'); $.error('Method ' + method + ' does not exist on jQuery.yiiGridView');
return false; return false;
} }
}; };
var defaults = { var defaults = {
filterUrl: undefined, filterUrl: undefined,
filterSelector: undefined filterSelector: undefined
}; };
var gridData = {}; var gridData = {};
var methods = { var methods = {
init: function (options) { init: function (options) {
return this.each(function () { return this.each(function () {
var $e = $(this); var $e = $(this);
var settings = $.extend({}, defaults, options || {}); var settings = $.extend({}, defaults, options || {});
gridData[$e.prop('id')] = {settings: settings}; gridData[$e.prop('id')] = {settings: settings};
var enterPressed = false; var enterPressed = false;
$(document).off('change.yiiGridView keydown.yiiGridView', settings.filterSelector) $(document).off('change.yiiGridView keydown.yiiGridView', settings.filterSelector)
.on('change.yiiGridView keydown.yiiGridView', settings.filterSelector, function (event) { .on('change.yiiGridView keydown.yiiGridView', settings.filterSelector, function (event) {
if (event.type === 'keydown') { if (event.type === 'keydown') {
if (event.keyCode !== 13) { if (event.keyCode !== 13) {
return; // only react to enter key return; // only react to enter key
} else { } else {
enterPressed = true; enterPressed = true;
} }
} else { } else {
// prevent processing for both keydown and change events // prevent processing for both keydown and change events
if (enterPressed) { if (enterPressed) {
enterPressed = false; enterPressed = false;
return; return;
} }
} }
methods.applyFilter.apply($e); methods.applyFilter.apply($e);
return false; return false;
}); });
}); });
}, },
applyFilter: function () { applyFilter: function () {
var $grid = $(this); var $grid = $(this);
var settings = gridData[$grid.prop('id')].settings; var settings = gridData[$grid.prop('id')].settings;
var data = {}; var data = {};
$.each($(settings.filterSelector).serializeArray(), function () { $.each($(settings.filterSelector).serializeArray(), function () {
data[this.name] = this.value; data[this.name] = this.value;
}); });
$.each(yii.getQueryParams(settings.filterUrl), function (name, value) { $.each(yii.getQueryParams(settings.filterUrl), function (name, value) {
if (data[name] === undefined) { if (data[name] === undefined) {
data[name] = value; data[name] = value;
} }
}); });
var pos = settings.filterUrl.indexOf('?'); var pos = settings.filterUrl.indexOf('?');
var url = pos < 0 ? settings.filterUrl : settings.filterUrl.substring(0, pos); var url = pos < 0 ? settings.filterUrl : settings.filterUrl.substring(0, pos);
$grid.find('form.gridview-filter-form').remove(); $grid.find('form.gridview-filter-form').remove();
var $form = $('<form action="' + url + '" method="get" class="gridview-filter-form" style="display:none" data-pjax></form>').appendTo($grid); var $form = $('<form action="' + url + '" method="get" class="gridview-filter-form" style="display:none" data-pjax></form>').appendTo($grid);
$.each(data, function (name, value) { $.each(data, function (name, value) {
$form.append($('<input type="hidden" name="t" value="" />').attr('name', name).val(value)); $form.append($('<input type="hidden" name="t" value="" />').attr('name', name).val(value));
}); });
$form.submit(); $form.submit();
}, },
setSelectionColumn: function (options) { setSelectionColumn: function (options) {
var $grid = $(this); var $grid = $(this);
var id = $(this).prop('id'); var id = $(this).prop('id');
gridData[id].selectionColumn = options.name; gridData[id].selectionColumn = options.name;
if (!options.multiple) { if (!options.multiple) {
return; return;
} }
var inputs = "#" + id + " input[name='" + options.checkAll + "']"; var inputs = "#" + id + " input[name='" + options.checkAll + "']";
$(document).off('click.yiiGridView', inputs).on('click.yiiGridView', inputs, function () { $(document).off('click.yiiGridView', inputs).on('click.yiiGridView', inputs, function () {
$grid.find("input[name='" + options.name + "']:enabled").prop('checked', this.checked); $grid.find("input[name='" + options.name + "']:enabled").prop('checked', this.checked);
}); });
$(document).off('click.yiiGridView', inputs + ":enabled").on('click.yiiGridView', inputs + ":enabled", function () { $(document).off('click.yiiGridView', inputs + ":enabled").on('click.yiiGridView', inputs + ":enabled", function () {
var all = $grid.find("input[name='" + options.name + "']").length == $grid.find("input[name='" + options.name + "']:checked").length; var all = $grid.find("input[name='" + options.name + "']").length == $grid.find("input[name='" + options.name + "']:checked").length;
$grid.find("input[name='" + options.checkAll + "']").prop('checked', all); $grid.find("input[name='" + options.checkAll + "']").prop('checked', all);
}); });
}, },
getSelectedRows: function () { getSelectedRows: function () {
var $grid = $(this); var $grid = $(this);
var data = gridData[$grid.prop('id')]; var data = gridData[$grid.prop('id')];
var keys = []; var keys = [];
if (data.selectionColumn) { if (data.selectionColumn) {
$grid.find("input[name='" + data.selectionColumn + "']:checked").each(function () { $grid.find("input[name='" + data.selectionColumn + "']:checked").each(function () {
keys.push($(this).parent().closest('tr').data('key')); keys.push($(this).parent().closest('tr').data('key'));
}); });
} }
return keys; return keys;
}, },
destroy: function () { destroy: function () {
return this.each(function () { return this.each(function () {
$(window).unbind('.yiiGridView'); $(window).unbind('.yiiGridView');
$(this).removeData('yiiGridView'); $(this).removeData('yiiGridView');
}); });
}, },
data: function () { data: function () {
var id = $(this).prop('id'); var id = $(this).prop('id');
return gridData[id]; return gridData[id];
} }
}; };
})(window.jQuery); })(window.jQuery);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment