当我尝试使用在线工具online minify tools缩小我的javascript文件时,它并没有完全缩小。顶部缺少的代码很少。代码中有问题吗?
这是我的javascript实际代码:
var _currentUserFormVersion = 0;
var status;
var myStatus;
var getCompanyDetails = function () {
$("body").mask("");
var id = $("#customer_id").val();
$.ajax({
url: serviceURl + "v1/web-registation-add-user?id=" + id,
type: "GET",
crossDomain: true,
contentType: 'application/json; charset=utf-8',
data: "",
success: function (response) {
clearAllInputs();
$("body").unmask("");
if (response.registration_details != null) {
var companyDetails = response.registration_details.company_details;
$("#companyname").val(companyDetails.company_name);
$("#firstname").val(companyDetails.first_name);
$("#lastname").val(companyDetails.last_name);
$("#mobile").val(companyDetails.mobile_number);
var salesPerson = companyDetails.registered_by;
if (!!salesPerson) {
var salesPersonTxt = $("li[name='" + salesPerson + "']").text();
$("#referalCode").val(salesPerson);
$("#salesPersonList").prev().html(salesPersonTxt + '<span class="caret arrow-sales"></span>');
}
var status_indicator = companyDetails.status;
// console.log("status: " + status_indicator);
if (status_indicator == "Active") {
$("[name='my-checkbox']").prop('checked', true);
}
else {
$("[name='my-checkbox']").prop('checked', false);
}
if (companyDetails.customer_type == "Transporter") {
$("#transporterType").attr('checked', 'checked');
}
else {
$("#consignorType").attr('checked', 'checked');
}
if (response.registration_details.customer_details != null) {
var users = response.registration_details.customer_details;
for (var i = 0; i < users.length; i++) {
$("#addUser").trigger("click");
$("#userFirstName" + i).val(users[i].user_first_name);
$("#userLastName" + i).val(users[i].user_last_name);
$("#userMobileNumber" + i).val(users[i].mobile_no);
$("#userMobileNumber" + i).attr('readonly', true);
$("#removeUser" + i).remove();
$("#password" + i).val(users[i].password);
if (users[i].customer_user_status == "Active") {
$("#switcher-lg" + i).prop('checked', true);
} else {
$("#switcher-lg" + i).prop('checked', false);
}
// set preference form first user
if (i == 0) {
var goodsType = $("li[name='cargo" + users[i].goods_type_id + "']").text();
var bodyType = $("li[name='body" + users[i].body_type_id + "']").text();
$("#cargoTypeId").val(users[i].goods_type_id);
$("#bodyTypeId").val(users[i].body_type_id);
$(".body-type-value").prev().html(users[i].bodyType + "<span class='caret arrow-sales'></span>");
$("#goodsTypeList").prev().html(goodsType + '<span class="caret arrow-sales"></span>');
$("#bodyTypeList").prev().html(bodyType + '<span class="caret arrow-sales"></span>');
$("#gcity").val(users[i].locations.city_name + ", " + users[i].locations.state_name + ", India");
$("#gcityName").val(users[i].locations.city_name);
$("#gcityPlaceId").val(users[i].locations.place_id);
$("#gcityState").val(users[i].locations.state_name);
}
}
}
if (response.registration_details.preferences != null) {
$("#gcity").val();
}
}
},
statusCode: {
409: function () {
$("body").unmask("");
$("#account-exists").modal("show");
},
500: function () {
$("body").unmask("");
$("#something-went-wrong").modal("show");
}
},
error: function () {
$("body").unmask("");
}
});
};
initcaption();
$(window).load(function () {
$(".loader").fadeOut("2000");
});
function initializePlugins() {
$.validate({
form: '#registration, #userDetailsForm'
});
};
jQuery(document).ready(function ($) {
$('.initCap').on("keyup", function (event) {
//console.log(String.fromCharCode(event.which));
var c = String.fromCharCode(event.which);
var textBox = event.target;
var start = textBox.selectionStart;
var end = textBox.selectionEnd;
textBox.value = textBox.value.charAt(0).toUpperCase() + textBox.value.slice(1);
textBox.setSelectionRange(start, end);
});
});
function bindEvents() {
//binding functions
$("#cancelButton").click(function () {
window.open("/companies", "_self")
});
$("#addUser").click(function () {
if (_currentUserFormVersion < 5) {
var formGroupHtml = getFormGroupHtml(_currentUserFormVersion);
var formSeperator = getFormSeperator(_currentUserFormVersion);
if (_currentUserFormVersion == 0) {
$("#userDetailSection").after(formGroupHtml);
}
else {
var lastUser = _currentUserFormVersion - 1;
$("#userDetailsForm" + lastUser).after(formSeperator + formGroupHtml);
}
$("#removeUser" + _currentUserFormVersion).click(function () {
var formId = $(this).attr("remove-form");
$("#" + formId).remove();
$("#" + formId + "Seperator").remove();
_currentUserFormVersion--;
});
$("#userFirstName" + _currentUserFormVersion).keypress(function (e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32);
});
$("#userLastName" + _currentUserFormVersion).keypress(function (e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32);
});
$("#userMobileNumber" + _currentUserFormVersion).bind("paste", function (e) {
// access the clipboard using the api
var _this = $(this);
setTimeout(function () {
var pastedData = e.originalEvent.clipboardData.getData('text');
var valobj = _this.val();
valobj = valobj.replace(/[^\d\.]/g, "");
if (valobj.length >= 10) {
var obj = valobj.slice(0, 10);
_this.val(obj);
}
e.preventDefault();
}, 50);
});
_currentUserFormVersion++;
$("[name='user-checkbox']").bootstrapSwitch();
}
checkMobileNumber();
initcaption();
});
$("#save").click(function () {
if (checkMobileDigits()) {
state = $("[name='my-checkbox']").prop('checked')
if (state == true) {
status = "Active";
}
else {
status = "Inactive";
}
$("body").mask("");
if (validateform()) {
return;
}
else {
var companyInfoJson = getCompanyInfo();
var userInfoJson = getUserInfo();
var jsonString = '{' +
'"registration_details": {' +
companyInfoJson + ',' +
userInfoJson +
'}' +
'}';
console.log(jsonString);
var edit_id = $("#customer_id").val()
//var SID = Math.floor(Math.random() * 111);
$.ajax({
url: serviceURl + "v1/web-registation-add-user?" + "&id=" + edit_id,
type: "PUT",
crossDomain: true,
contentType: 'application/json; charset=utf-8',
data: jsonString,
success: function (data) {
clearAllInputs();
window.location.replace("/companies");
$("body").unmask("");
//$("#account-alert").modal("show");
},
statusCode: {
409: function () {
$("body").unmask("");
$("#account-exists").modal("show");
},
500: function () {
$("body").unmask("");
$("#something-went-wrong").modal("show");
},
401: function (error) {
var data = JSON.parse(error.responseText)
if (!!data && data.error.code == "INVALID_MOBILE") {
$("body").unmask("");
$("#mobileExist").modal("show");
}
}
},
error: function () {
$("body").unmask("");
}
});
}
}
});
};
function getFormGroupHtml(_currentUserFormVersion) {
var formGroupHtml = '<div class="col-md-12 userDetails" id="userDetailsForm' + _currentUserFormVersion + '">' +
'<div class = "form-group">' +
'<div class="row">' +
'<div class="col-md-3 pull-right">' +
'<div class="switchContainer pull-right">' +
//'<input type="checkbox" id="userCheckbox' + _currentUserFormVersion + '" class="toggleSwitch" name="user-checkbox" data-on-color="success" data-off-color="danger" data-size="mini" data-on-text="Active" data-off-text="Inactive" checked>' +
'<div class="form-switcher form-switcher-lg">' +
'<input type="checkbox" id="switcher-lg' + _currentUserFormVersion + '" class="toggleSwitch" name="us-checkbox" data-on-color="success" data-off-color="danger" data-size="mini" data-on-text="Active" data-off-text="Inactive" checked>' +
'<label class="switcher" for="switcher-lg' + _currentUserFormVersion + '"></label>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-md-6">' +
'<div class = "form-group">' +
'<label for = "userFirstName' + _currentUserFormVersion + '" class="label-head">First Name <sup><span class="glyphicon glyphicon-asterisk red" aria-hidden="true"></span></sup></label>' +
'<input type = "text" class = "form-control initCap text-box-length input-lg" id = "userFirstName' + _currentUserFormVersion + '" placeholder = "Enter User\'s First Name" data-validation="required" maxlength="20" data-validation-error-msg-container="#userFirstNameErrorContainer' + _currentUserFormVersion + '">' +
'<div id="userFirstNameErrorContainer' + _currentUserFormVersion + '"></div>' +
'</div>' +
'</div>' +
'<div class="col-md-6">' +
'<div class = "form-group">' +
'<label for = "userLastName' + _currentUserFormVersion + '" class="label-head">Last Name</label>' +
'<input type = "text" maxlength="20" class = "form-control initCap text-box-length input-lg" id = "userLastName' + _currentUserFormVersion + '" placeholder = "Enter User\'s Last Name" data-validation-error-msg-container="#userLastNameErrorContainer' + _currentUserFormVersion + '">' +
'<div id="userLastNameErrorContainer' + _currentUserFormVersion + '"></div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-md-6">' +
'<div class = "form-group">' +
'<label for = "userMobileNumber' + _currentUserFormVersion + '" class="label-head">Mobile Number <sup><span class="glyphicon glyphicon-asterisk red" aria-hidden="true"></span></sup></label>' +
'<input autocomplete="off" type = "number" maxlength="10" pattern="[789][0-9]{9}" required class = "form-control text-box-length input-lg mobileNo" id = "userMobileNumber' + _currentUserFormVersion + '" placeholder = "Enter User\'s Mobile Number" data-validation="number" onkeydown="restrict()" data-validation-error-msg-container="#userMobileNumberErrorContainer' + _currentUserFormVersion + '">' +
'<div id="userMobileNumberErrorContainer' + _currentUserFormVersion + '" ></div>' +
'</div>' +
'</div>' +
'<div class="col-md-6">' +
'<div class = "form-group">' +
'<label for = "userPassword' + _currentUserFormVersion + '" class="label-head">Password <sup><span class="glyphicon glyphicon-asterisk red" aria-hidden="true"></span></sup></label>' +
'<input autocomplete="new-password" type = "password" class = "form-control text-box-length input-lg" id = "password' + _currentUserFormVersion + '" placeholder = "Enter Password" data-validation="required" data-validation-error-msg-container="#userPasswordErrorContainer' + _currentUserFormVersion + '">' +
'<div id="userPasswordErrorContainer' + _currentUserFormVersion + '"></div>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="col-md-12">' +
'<div style="float: right">';
if (_currentUserFormVersion > 0) {
formGroupHtml += '<button id="removeUser' + _currentUserFormVersion + '" remove-form="userDetailsForm' + _currentUserFormVersion + '" type="button" class="btn cancel-btn" id="addUser">Remove</button>';
}
formGroupHtml += '</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
return formGroupHtml;
};
function getFormSeperator(_currentUserFormVersion) {
return '<div id="userDetailsForm' + _currentUserFormVersion + 'Seperator" class="col-md-12" style="height: 2px; background-color: #334f7d; margin: 5px 0 20px 0"></div>';
};
function getUserInfo() {
var bodyTypeId = $("#bodyTypeId").val();
var goodsTypeId = $("#cargoTypeId").val();
var locations = {
"place_id": $("#gcityPlaceId").val(),
"state_name": $("#gcityState").val(),
"city_name": $("#gcityName").val()
};
var userInfoJson = '"customer_details":[';
for (var i = 0; i < _currentUserFormVersion; i++) {
var status;
var checkStatus = $("#switcher-lg" + i).prop('checked');
if (checkStatus) {
status = "Active"
} else {
status = "Inactive"
}
var mobile_no = $("#userMobileNumber" + i).val();
var firstName = $("#userFirstName" + i).val();
var lastName = $("#userLastName" + i).val();
var password = $("#password" + i).val();
var userObject = "";
if (userInfoJson != '"customer_details":[') {
userObject += ",";
}
userObject += '{' +
'"mobile_no": ' + mobile_no + ',' +
'"user_first_name": "' + firstName + '",' +
'"user_last_name": "' + lastName + '",' +
'"password": "' + password + '",' +
'"body_type_id": "' + bodyTypeId + '",' +
'"goods_type_id": "' + goodsTypeId + '",' +
'"locations": ' + JSON.stringify(locations) + ',' +
'"customer_user_status": "' + status + '"' +
'}';
userInfoJson += userObject;
}
userInfoJson += ']';
return userInfoJson;
};
function getCompanyInfo() {
var salesGuy = $.trim($('#salesPersonList').prev().text());
var registered_by = (salesGuy == "Salesperson") ? "" : $("#referalCode").val();
var companyInfoJson = '"company_details": {' +
'"company_name": "' + $("#companyname").val() + '",' +
'"customer_type": "' + $('input[name=optionsRadiosinline]:checked', '#registration').val() + '",' +
'"registered_by": "' + registered_by + '",' +
'"status": "' + status + '"' +
'}';
return companyInfoJson;
};
function checkUserDetails() {
if ($("#userFirstName").val() == "" || $("#userMobileNumber").val() == "" || $("#userLastName").val() == "" || $("#password").val() == "") {
$("body").unmask("");
$("#alerts").modal("show");
return;
}
for (var i = 0; i < _currentUserFormVersion; i++) {
if ($("#userMobileNumber" + i).val() == "") {
$("body").unmask("");
$("#alerts").modal("show");
return;
}
else {
return true
}
}
}
function clearAllInputs() {
for (var i = 0; i < _currentUserFormVersion; i++) {
$("#userFirstName" + i).val("");
$("#userMobileNumber" + i).val("");
$("#userLastName" + i).val("");
$("#password" + i).val("");
}
$("#companyname").val("");
$("#firstname").val("");
$("#lastname").val("");
$("#mobile").val("");
$("#userFirstName").val("");
$("#userMobileNumber").val("");
$("#userLastName").val("");
$("#password").val("");
}
function checkMobileNumber() {
$('.mobileNo').keypress(function (event) {
var _this = $(this).val();
if (_this.length > 9) {
event.preventDefault();
return false;
}
});
}
function initcaption() {
$(document).ready(function () {
$('input[type="text"]').on('keydown', function (event) {
if (this.selectionStart == 0 && event.keyCode >= 65 && event.keyCode <= 90 && !(event.shiftKey) && !(event.ctrlKey) && !(event.metaKey) && !(event.altKey)) {
//var $t = $(this);
event.preventDefault();
var char = String.fromCharCode(event.keyCode);
$t.val(char + $t.val().slice(this.selectionEnd));
this.setSelectionRange(1, 1);
}
});
});
}
function validateform() {
if ($("#companyname").val() == "" || $("#firstname").val() == "" || $("#mobile").val() == "" || $("#userFirstName").val() == "" || $("#userMobileNumber").val() == "" || $("#userLastName").val() == "" || $("#password").val() == "" || $("#gcity").val() == "") {
$("body").unmask("");
$("#alerts").modal("show");
return true;
}
for (var i = 0; i < _currentUserFormVersion; i++) {
if ($("#userFirstName" + i).val() == "" || $("#userMobileNumber" + i).val() == "" || $("#password" + i).val() == "") {
$("body").unmask("");
$("#alerts").modal("show");
return true;
}
}
return false;
}
function checkMobileDigits() {
var isValid = false;
for (var i = 0; i < _currentUserFormVersion; i++) {
if ((!($("#userMobileNumber" + i).val().length == 10))) {
$("body").unmask("");
$("#mobile-alert").modal("show");
isValid = false;
return false;
}
else {
isValid = true;
}
}
return isValid;
}
restrict = function () {
for (var i = 0; i < _currentUserFormVersion; i++) {
var textBox = document.getElementById("userMobileNumber" + i);
textBox.onkeypress = function (e) {
e = e || window.event;
var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
if (/[^\d]/.test(String.fromCharCode(charCode))) {
return false;
}
};
$('#userMobileNumber' + i).on('input propertychange paste', function (e) {
var reg = /^0+/gi;
if (this.value.match(reg)) {
this.value = this.value.replace(reg, '');
}
});
}
}
getSalesPersonList = function () {
$.ajax({
url: serviceURl + "v1/sales-person",
type: "GET",
crossDomain: true,
contentType: 'application/json; charset=utf-8',
data: "",
success: function (response) {
if (response.sales_person != null) {
var list = "";
$.each(response.sales_person, function (index, val) {
list += "<li name='" + val.referal_code + "'>" + val.first_name + " " + val.last_name + "</li>"
});
$("#salesPersonList").append(list);
$("#salesPersonList li").click(function () {
var referalCode = $(this).attr('name');
$("#referalCode").val(referalCode);
$(this).parents(".dropdown").find(".dropdown-toggle").html($(this).text() + '<span class="caret arrow-sales"></span>');
});
}
},
statusCode: {
409: function () {
$("body").unmask("");
$("#account-exists").modal("show");
},
500: function () {
$("body").unmask("");
$("#something-went-wrong").modal("show");
}
},
error: function () {
$("body").unmask("");
}
});
};
getGoodsType = function () {
$.ajax({
url: serviceURl + "v1/cargo-types",
type: "GET",
crossDomain: true,
contentType: 'application/json; charset=utf-8',
data: "",
success: function (response) {
if (response.cargo_types != null) {
var list = "";
$.each(response.cargo_types, function (index, val) {
list += "<li name='cargo" + val.id + "' >" + val.cargo_type_name + "</li>"
});
$("#goodsTypeList").append(list);
$("#goodsTypeList li").click(function () {
var id = $(this).attr('name');
id = id.replace("cargo", "");
$("#cargoTypeId").val(id);
console.log(id);
$(this).parents(".dropdown").find(".dropdown-toggle").text($(this).text()).html($(this).text() + '<span class="caret arrow-sales"></span>');
});
}
},
statusCode: {
409: function () {
$("body").unmask("");
$("#account-exists").modal("show");
},
500: function () {
$("body").unmask("");
$("#something-went-wrong").modal("show");
}
},
error: function () {
$("body").unmask("");
}
});
};
getBodyType = function () {
$.ajax({
url: serviceURl + "v1/body-types",
type: "GET",
crossDomain: true,
contentType: 'application/json; charset=utf-8',
data: "",
success: function (response) {
if (response.body_types != null) {
var list = "";
$.each(response.body_types, function (index, val) {
list += "<li name='body" + val.id + "'>" + val.body_type_name + "</li>"
});
$("#bodyTypeList").append(list);
$("#bodyTypeList li").click(function () {
var id = $(this).attr('name');
id = id.replace("body", "");
$("#bodyTypeId").val(id);
console.log($(this).parents(".dropdown").find(".dropdown-toggle"));
$(this).parents(".dropdown").find(".dropdown-toggle").html($(this).text() + '<span class="caret arrow-sales"></span>');
});
}
getCompanyDetails();
},
statusCode: {
409: function () {
$("body").unmask("");
$("#account-exists").modal("show");
},
500: function () {
$("body").unmask("");
$("#something-went-wrong").modal("show");
}
},
error: function () {
$("body").unmask("");
}
});
};
function initialize() {
var options = {
types: ['(cities)'],
componentRestrictions: {country: "in"}
};
var input = document.getElementById('gcity');
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place = autocomplete.getPlace();
console.log("place_id: " + place.place_id);
console.log("City: " + place.name);
console.log("State: " + place.address_components[2].long_name);
$("#gcityName").val(place.name);
$("#gcityPlaceId").val(place.place_id);
$("#gcityState").val(place.address_components[2].long_name);
});
}
getGeoLocation = function () {
// Check if the browser has support for the Geolocation API
if (!navigator.geolocation) {
findMeButton.addClass("disabled");
$('.no-browser-support').addClass("visible");
} else {
navigator.geolocation.getCurrentPosition(function (position) {
console.log(position);
// Get the coordinates of the current possition.
var lat = position.coords.latitude;
var lng = position.coords.longitude;
console.log(lat);
console.log(lng);
codeLatLng(lat, lng)
});
}
};
function codeLatLng(lat, lng) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results)
if (results[1]) {
//formatted address
alert(results[0].formatted_address)
//find country name
for (var i = 0; i < results[0].address_components.length; i++) {
for (var b = 0; b < results[0].address_components[i].types.length; b++) {
//there are different types that might hold a city admin_area_lvl_1 usually does in come cases looking for sublocality type will be more appropriate
if (results[0].address_components[i].types[b] == "administrative_area_level_1") {
//this is the object you are looking for
city = results[0].address_components[i];
break;
}
}
}
//city data
alert(city.short_name + " " + city.long_name)
} else {
alert("No results found");
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
$(document).ready(function () {
initializePlugins();
bindEvents();
checkMobileNumber();
getSalesPersonList();
getGoodsType();
getBodyType();
//getGeoLocation();
google.maps.event.addDomListener(window, 'load', initialize);
$("[name='m-checkbox']").bootstrapSwitch();
$("#userMobileNumber").bind("paste", function (e) {
// access the clipboard using the api
var _this = $(this);
setTimeout(function () {
var pastedData = e.originalEvent.clipboardData.getData('text');
var valobj = _this.val();
valobj = valobj.replace(/[^\d\.]/g, "");
if (valobj.length >= 10) {
var obj = valobj.slice(0, 10);
_this.val(obj);
}
e.preventDefault();
}, 50);
});
});
答案 0 :(得分:0)
不,这很正常。
每个缩小工具都会使用算法将长文本替换为小文本。这就是您觉得某些代码丢失的原因。要从缩小版本中识别代码,请使用生成的源地图。这会将缩小的单词映射到源。如果您的源映射位于js的同一目录中,则chrome将获取它并在源面板中显示源而不是缩小的源。
答案 1 :(得分:0)
minify工具可能试图通过删除不必要的全局变量或将它们转换为局部变量,删除函数名称和直接保留函数等来优化代码。
尝试使用html或其他支持执行一次缩小的js,并查看它是否与原始的未分类版本的行为不同。
如果它的行为不同,那么您应该尝试将原始的未分化代码拆分为独立模块,并尝试按模块缩小模块。