Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5dad90e

Browse files
js code updated with new function for demo3
1 parent 00cf880 commit 5dad90e

File tree

1 file changed

+102
-5
lines changed

1 file changed

+102
-5
lines changed

‎js/uploader.js‎

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
$(function(){
22
$('body').on("change", "#my-profile-file-selector", function(){
3-
checkProfileSize({
4-
// size: 200,
5-
// width: 1280,
6-
// height: null
7-
});
3+
checkProfileSize();
84
})
95
$('#remove-profile-btn').on('click', function(event) {
106
event.preventDefault();
@@ -142,6 +138,78 @@ function checkProfileSize1(arg){
142138
}
143139
}
144140

141+
$(function(){
142+
$('body').on("change", "#my-profile-file-selector-2", function(){
143+
checkProfileSize2({
144+
width: 1280,
145+
height: 720
146+
});
147+
})
148+
$('#remove-profile-btn-2').on('click', function(event) {
149+
event.preventDefault();
150+
// make image view empty
151+
$('#upload-profile-image-2').attr('src', '');
152+
// make file name empty
153+
$('#upload-profile-file-info-2').html('');
154+
// make input file value empty
155+
$('input#my-profile-file-selector-2[type=file]').val('')
156+
// remove hide button
157+
$('#remove-profile-btn-2').hide();
158+
// show upload button again
159+
$('label.profile-2').show();
160+
});
161+
});
162+
function checkProfileSize2(arg){
163+
$('#upload-profile-image-2').attr('src', '');
164+
$('#upload-profile-file-info-2').html('');
165+
$('#upload-profile-error-2').html('');
166+
var fileInput = $('form').find("input#my-profile-file-selector-2[type=file]")[0],
167+
file = fileInput.files && fileInput.files[0];
168+
var sizeKB = file.size / 1024;
169+
var tmppath = URL.createObjectURL(fileInput.files[0]);
170+
var maxSize = arg.size || sizeKB;
171+
var imgHeight, imgWidth;
172+
console.log("maxSize "+maxSize);
173+
if( file ) {
174+
var img = new Image();
175+
img.src = window.URL.createObjectURL( file );
176+
img.onload = function() {
177+
var width = img.naturalWidth, height = img.naturalHeight;
178+
window.URL.revokeObjectURL( img.src );
179+
imgWidth = arg.width || width;
180+
console.log("imgWidth "+imgWidth);
181+
imgHeight = arg.height || height;
182+
if( sizeKB <= maxSize) {
183+
if( width == imgWidth && height == imgHeight){
184+
var fileName = $('input#my-profile-file-selector-2[type=file]').val();
185+
fileName = fileName.substr(fileName.lastIndexOf("\\")+1);
186+
$('#upload-profile-image-2').attr('src', tmppath);
187+
$('#upload-profile-file-info-2').html(fileName);
188+
$('label.profile-2').hide();
189+
$('#remove-profile-btn-2').show();
190+
}
191+
else{
192+
imgWidth = arg.width || "any";
193+
imgHeight = arg.height || "any";
194+
$('#upload-profile-error-2')
195+
.html('Uploaded Picture Width should be '+
196+
imgWidth+' and Height should be '+imgHeight);
197+
var fileName = $('input#my-profile-file-selector-2[type=file]').val();
198+
console.log(fileName);
199+
}
200+
}
201+
else {
202+
$('#upload-profile-error-2').html('Uploaded Profile picture size should be less than '+maxSize+'KB');
203+
var fileName = $('input#my-profile-file-selector-2[type=file]').val();
204+
console.log(fileName);
205+
}
206+
};
207+
}
208+
else { //No file was input or browser doesn't support client side reading
209+
console.log('No file selected');
210+
}
211+
}
212+
145213

146214
// Copy to Clipboard
147215
function copyToClipboard(element) {
@@ -189,6 +257,19 @@ $(function(){
189257
placement: 'top'
190258
});
191259

260+
$('.html-copy-2').tooltip({
261+
trigger: 'click',
262+
placement: 'top'
263+
});
264+
$('.css-copy-2').tooltip({
265+
trigger: 'click',
266+
placement: 'top'
267+
});
268+
$('.js-copy-2').tooltip({
269+
trigger: 'click',
270+
placement: 'top'
271+
});
272+
192273
$('.html-copy').on('click',function(){
193274
copyToClipboard('#html-code');
194275
setTooltip($(this),'Copied!');
@@ -221,5 +302,21 @@ $(function(){
221302
hideTooltip($(this));
222303
});
223304

305+
$('.html-copy-2').on('click',function(){
306+
copyToClipboard('#html-code-2');
307+
setTooltip($(this),'Copied!');
308+
hideTooltip($(this));
309+
});
310+
$('.css-copy-2').on('click',function(){
311+
copyToClipboard('#css-code-2');
312+
setTooltip($(this),'Copied!');
313+
hideTooltip($(this));
314+
});
315+
$('.js-copy-2').on('click',function(){
316+
copyToClipboard('#js-code-2');
317+
setTooltip($(this),'Copied!');
318+
hideTooltip($(this));
319+
});
320+
224321

225322
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /