fuzzy1
02-13-2010, 03:31 PM
Hey All!
Working to hook into WordPress's implementation of SWFUpload,
it quickly became apparent that my procrastination was at its bitter end.
I could no longer put off having to learn jQuery. (better late than never?:eek:)
That decided, it was also readily apparent that learning jQurey and SWFUpload
simultaneously was an absolute non-starter, so I set my sights a little lower.
I had already worked up a little JavaScript File Upload prompt/confirm dialog, and thought
that it would make a good jumping off point for my first foray into the exciting world jQurey.
Below, is an expurgated version of the dialog rendered via js, followed by my first effort at same via jQuery.
I am certain that each approach can yet be further refined and distilled to provid for a more accurate comparison,
however at this stage and with the the aim of 'writing less' and 'doing more',
while (as compared to the js version) my jQuery effort does clock in at 17 fewer lines of code,
147 fewer characters (255 fewer including spaces) in the end I'm left feeling a little disappointed.
Giving it my best shot, I'm left wanting.
Hoping someone wise in the ways will give these a whirl on their own development server, and then kindly show me the light,
I present the following for your kindly review and critique.
js-code:
<SCRIPT>
function toggleCnfm(prompt)
{ //set all divs but (the prompted.div.id AND the parent.div.id) to style.display='none'
document.getElementById(prompt).style.display='inline';
cnfmArr= new Array('have_files', 'url_cnfm', 'uploader', 'src_file_alert');
for(i=0; i<cnfmArr.length; i++)
{ var id= cnfmArr[i];
if(id != prompt)
{
setTimeout("ie_hack('"+id+"')",300);
}
}
}
function ie_hack(id)
{ //because IE6 fumbles if you rush it!
document.getElementById(id).style.display='none';
}
function showHide(id)
{
subject = document.getElementById(id);
if(subject.style.display=='none')
{
subject.style.display='inline';
}
else
{
subject.style.display='none';
}
}
function ignore()
{ // see cxl(): in jquerytest.htm
showHide('src_file_prompt');
toggleCnfm('src_file_alert');
}
</SCRIPT>
<style>
.big_red {
width:325px; height:125px; position: absolute; left:200px; top:200px; background-color:#b0c4de;
}
.srcMap #uploader, #src_file_cnfm, #have_files, #src_file_alert, #urls_prompt, #url_cnfm {
width:95%; height:90%; position: absolute; top:0px; margin:10px; background-color:#EBEBEB; overflow:visible;
}
</style>
<input type='button' value='- Try It! -' onclick= "showHide('src_file_prompt')"/>
<div class='srcMap big_red' id='src_file_prompt' style='display:none'>
<div class='srcMap' id='uploader' >
<p>UPLOADER -- Got Files?<br/>
<input type='button' value='-- Select --' onclick= "ignore(); alert('Success!')"/>
<input type='button' value='-- Cancel --' onclick= "ignore()"/>
</p>
</div>
<div class='srcMap' id='url_cnfm' >
<p>URL CONFIRM<br/>
<input type='button' value='Copy Files?' onclick= "ignore(); alert('Success!')"/>
<input type='button' value=' Cancel ' onclick= "ignore()"/>
</p>
</div>
<div class='srcMap' id='src_file_alert' >
<p> SOURCE FILE FIELD FORMAT ALERT<br/>
<input type='button' value='Filenames Only?' onclick= "toggleCnfm('uploader')"/>
<input type='button' value='URLS Only?' onclick= "toggleCnfm('url_cnfm')"/>
<input type='button' value='Cancel' onclick= "ignore()"/>
</p>
</div>
</div>
jQuery-code:<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<SCRIPT>
function cxl(){
jQuery("[class$='-prmt']").show();
jQuery("[class$='-cnfm'],.big_red").hide();
}
jQuery(document).ready(function() {
jQuery("#try_it").click(function() {
jQuery('#src_file_prompt').show();
});
jQuery(".url-prmt").click(function() {
jQuery("[class$='-prmt']").hide();
jQuery(".url-cnfm").show();
});
jQuery(".upload-prmt").click(function() {
jQuery("[class$='-prmt']").hide();
jQuery(".upload-cnfm").show();
});
jQuery(".url-cnfm").click(function() {
alert('Files Copied Successfully');cxl();
});
jQuery(".upload-cnfm").click(function() {
alert('Files Uploaded Successfully');cxl();
});
jQuery(".cancle").click(function() {cxl(); });
});
</SCRIPT>
<style>
.big_red {
width:350px; height:125px; position: absolute; left:200px; top:200px; background-color:#b0c4de;
}
.srcMap #src_file_alert {
width:95%; height:90%; position: absolute; top:0px; margin:10px; background-color:#EBEBEB; overflow:visible;
}
</style>
<input type='button' id='try_it' value='- Try It! -' />
<div class='srcMap big_red' id='src_file_prompt' style='display:none'>
<div class='srcMap' id='src_file_alert' >
<p class='alert-prmt'> SOURCE FILE FIELD FORMAT ALERT<br/></p>
<p class='url-cnfm' style='display:none' >URL CONFIRM<br/></p>
<p class='upload-cnfm' style='display:none' >UPLOADER -- Got Files?<br/></p>
<input type='button' class='upload-cnfm' id='upload-cnfm' style='display:none' value='-- Select --'/>
<input type='button' class='url-cnfm' id='url-cnfm' style='display:none' value='Copy Files?'/>
<input type='button' class='upload-prmt' value='Filenames Only?' />
<input type='button' class='url-prmt' value='URLS Only?' />
<input type='button' class='cancle' value='Cancel'/>
</div>
</div>
Working to hook into WordPress's implementation of SWFUpload,
it quickly became apparent that my procrastination was at its bitter end.
I could no longer put off having to learn jQuery. (better late than never?:eek:)
That decided, it was also readily apparent that learning jQurey and SWFUpload
simultaneously was an absolute non-starter, so I set my sights a little lower.
I had already worked up a little JavaScript File Upload prompt/confirm dialog, and thought
that it would make a good jumping off point for my first foray into the exciting world jQurey.
Below, is an expurgated version of the dialog rendered via js, followed by my first effort at same via jQuery.
I am certain that each approach can yet be further refined and distilled to provid for a more accurate comparison,
however at this stage and with the the aim of 'writing less' and 'doing more',
while (as compared to the js version) my jQuery effort does clock in at 17 fewer lines of code,
147 fewer characters (255 fewer including spaces) in the end I'm left feeling a little disappointed.
Giving it my best shot, I'm left wanting.
Hoping someone wise in the ways will give these a whirl on their own development server, and then kindly show me the light,
I present the following for your kindly review and critique.
js-code:
<SCRIPT>
function toggleCnfm(prompt)
{ //set all divs but (the prompted.div.id AND the parent.div.id) to style.display='none'
document.getElementById(prompt).style.display='inline';
cnfmArr= new Array('have_files', 'url_cnfm', 'uploader', 'src_file_alert');
for(i=0; i<cnfmArr.length; i++)
{ var id= cnfmArr[i];
if(id != prompt)
{
setTimeout("ie_hack('"+id+"')",300);
}
}
}
function ie_hack(id)
{ //because IE6 fumbles if you rush it!
document.getElementById(id).style.display='none';
}
function showHide(id)
{
subject = document.getElementById(id);
if(subject.style.display=='none')
{
subject.style.display='inline';
}
else
{
subject.style.display='none';
}
}
function ignore()
{ // see cxl(): in jquerytest.htm
showHide('src_file_prompt');
toggleCnfm('src_file_alert');
}
</SCRIPT>
<style>
.big_red {
width:325px; height:125px; position: absolute; left:200px; top:200px; background-color:#b0c4de;
}
.srcMap #uploader, #src_file_cnfm, #have_files, #src_file_alert, #urls_prompt, #url_cnfm {
width:95%; height:90%; position: absolute; top:0px; margin:10px; background-color:#EBEBEB; overflow:visible;
}
</style>
<input type='button' value='- Try It! -' onclick= "showHide('src_file_prompt')"/>
<div class='srcMap big_red' id='src_file_prompt' style='display:none'>
<div class='srcMap' id='uploader' >
<p>UPLOADER -- Got Files?<br/>
<input type='button' value='-- Select --' onclick= "ignore(); alert('Success!')"/>
<input type='button' value='-- Cancel --' onclick= "ignore()"/>
</p>
</div>
<div class='srcMap' id='url_cnfm' >
<p>URL CONFIRM<br/>
<input type='button' value='Copy Files?' onclick= "ignore(); alert('Success!')"/>
<input type='button' value=' Cancel ' onclick= "ignore()"/>
</p>
</div>
<div class='srcMap' id='src_file_alert' >
<p> SOURCE FILE FIELD FORMAT ALERT<br/>
<input type='button' value='Filenames Only?' onclick= "toggleCnfm('uploader')"/>
<input type='button' value='URLS Only?' onclick= "toggleCnfm('url_cnfm')"/>
<input type='button' value='Cancel' onclick= "ignore()"/>
</p>
</div>
</div>
jQuery-code:<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<SCRIPT>
function cxl(){
jQuery("[class$='-prmt']").show();
jQuery("[class$='-cnfm'],.big_red").hide();
}
jQuery(document).ready(function() {
jQuery("#try_it").click(function() {
jQuery('#src_file_prompt').show();
});
jQuery(".url-prmt").click(function() {
jQuery("[class$='-prmt']").hide();
jQuery(".url-cnfm").show();
});
jQuery(".upload-prmt").click(function() {
jQuery("[class$='-prmt']").hide();
jQuery(".upload-cnfm").show();
});
jQuery(".url-cnfm").click(function() {
alert('Files Copied Successfully');cxl();
});
jQuery(".upload-cnfm").click(function() {
alert('Files Uploaded Successfully');cxl();
});
jQuery(".cancle").click(function() {cxl(); });
});
</SCRIPT>
<style>
.big_red {
width:350px; height:125px; position: absolute; left:200px; top:200px; background-color:#b0c4de;
}
.srcMap #src_file_alert {
width:95%; height:90%; position: absolute; top:0px; margin:10px; background-color:#EBEBEB; overflow:visible;
}
</style>
<input type='button' id='try_it' value='- Try It! -' />
<div class='srcMap big_red' id='src_file_prompt' style='display:none'>
<div class='srcMap' id='src_file_alert' >
<p class='alert-prmt'> SOURCE FILE FIELD FORMAT ALERT<br/></p>
<p class='url-cnfm' style='display:none' >URL CONFIRM<br/></p>
<p class='upload-cnfm' style='display:none' >UPLOADER -- Got Files?<br/></p>
<input type='button' class='upload-cnfm' id='upload-cnfm' style='display:none' value='-- Select --'/>
<input type='button' class='url-cnfm' id='url-cnfm' style='display:none' value='Copy Files?'/>
<input type='button' class='upload-prmt' value='Filenames Only?' />
<input type='button' class='url-prmt' value='URLS Only?' />
<input type='button' class='cancle' value='Cancel'/>
</div>
</div>