Note that there are some explanatory texts on larger screens.

plurals
  1. POadding variable into a jquery plugin
    primarykey
    data
    text
    <p>i dont know if it can be done but can you use a variable to use in this instance:</p> <p>This is the normal way:</p> <pre><code>jQuery(function() { jQuery('#cropbox').Jcrop({ onChange: showCoords, onSelect: showCoords, aspectRatio: 16 / 9 }); }); </code></pre> <p>wanting to do so like:</p> <pre><code>var ratioRetrieve = "16 / 9"; var run = true; if( run === true ) { jQuery(function(ratioRetrieve) { jQuery('#cropbox').Jcrop({ onChange: showCoords, onSelect: showCoords, aspectRatio: ratioRetrieve }); }); } </code></pre> <p><strong>EDIT: THIS IS THE FULL CODE</strong></p> <pre><code>&lt;script language="Javascript"&gt; $(document).ready(function(){ /**************************** ASPECT RATIO ********************************/ function getAspectRation(w, h){ var rem; var newW = w; var newH = h; while (h != 0) { rem = w % h; w = h; h = rem; } newH = newH / w; newW = newW / w; return newW / newH; } function calcRatio(){ $(".heightAndWidth").keypress(function (e) { var newW = $("#outputImageWidth").val(); var newH = $("#outputImageHeight").val(); var ratioRetrieve = getAspectRation(newW, newH); return ratioRetrieve; }); } function calcRatio2(){ var newW = $("#outputImageWidth").val(); var newH = $("#outputImageHeight").val(); var ratioRetrieve = getAspectRation(newW, newH); return ratioRetrieve; } /**************************** END ASPECT RATIO ********************************/ /**************** REPLACE TO MAKE ALL NON MOVABLE ANCHORS *********************/ function anchorChange(){ $("a").each(function(i){ var anchorElement = $(this); var newAnchorElement = $('&lt;a href="#link01' + i + '" id="' + anchorElement.attr('id') + '" class="' + anchorElement.attr('class') + '" name="#link01' + i + '"&gt;' + anchorElement.text() + '&lt;/a&gt;').insertBefore(anchorElement); anchorElement.remove(); }); } /************** REPLACE TO MAKE ALL NON MOVABLE ANCHORS END *******************/ /**************************** CLOSE PREVIEW BUTTON ****************************/ function closePreview(){ $("#closePreviewButton").bind("click", function(){ $("#cropResult").animate({ height: "0px" }, 1000, function(){ $("#cropResult").remove(); }); }); } /*********************** END CLOSE PREVIEW BUTTON ****************************/ /************************** GET HEIGHT AND WIDTH *****************************/ function getHeightOrWidth(){ $("#getHeight").bind("click", function(){ var heightOrWidthVal = $("#outputImageHeight").val(); var newImagejCrop = $("#filename").val(); var folderjCrop = $("#hiddenFolder").val(); var imageDir = folderjCrop + newImagejCrop; $("#heightWidthLoad").html('&lt;p&gt;Retrieving height... &lt;img src="../../loader.gif" /&gt;&lt;/p&gt;'); $.ajax({ type: "POST", data: 'dir=' + imageDir + '&amp;heightOrWidth=height', url: 'https://web111.secure-secure.co.uk/snowyswebsolutions.co.uk/ACTfileUploader/imageCrop/func.getSize.php', cache: false, timeout: 12000, error: function(XMLHttpRequest, textStatus, errorThrow){ $("#heightWidthLoad").html( "&lt;span class=\"red\"&gt;Error: Network connection low, please try again later.&lt;/span&gt;" );}, success: function(html){ $("#outputImageHeight").val(html); ratioRetrieve = calcRatio2(); $("#heightWidthLoad").html(''); } }); }); $("#getWidth").bind("click", function(){ var heightOrWidthVal = $("#outputImageWidth").val(); var newImagejCrop = $("#filename").val(); var folderjCrop = $("#hiddenFolder").val(); var imageDir = folderjCrop + newImagejCrop; $("#heightWidthLoad").html('&lt;p&gt;Retrieving width... &lt;img src="../../loader.gif" /&gt;&lt;/p&gt;'); $.ajax({ type: "POST", data: 'dir=' + imageDir + '&amp;heightOrWidth=width', url: 'https://web111.secure-secure.co.uk/snowyswebsolutions.co.uk/ACTfileUploader/imageCrop/func.getSize.php', cache: false, timeout: 12000, error: function(XMLHttpRequest, textStatus, errorThrow){ $("#heightWidthLoad").html( "&lt;span class=\"red\"&gt;Error: Network connection low, please try again later.&lt;/span&gt;" );}, success: function(html){ $("#outputImageWidth").val(html); ratioRetrieve = calcRatio2(); $("#heightWidthLoad").html(''); } }); }); } /************************** GET HEIGHT AND WIDTH EMD **************************/ /**************** REMOVE AND INSERT JCROP WITH IMAGE CHANGE *******************/ function imageChangejCrop(ratioRetrieve){ run = false; $("#imageList").change(function(ratioRetrieve){ var newImagejCrop = $("#imageList :selected").text(); var folderjCrop = $("#hiddenFolder").val(); $(".jcrop-holder").remove(); $("#cropbox").remove(); $("#imageWrapper").html("&lt;img src=\"" + folderjCrop + newImagejCrop + "\" id=\"cropbox\" /&gt;"); $("#filename").val(newImagejCrop); run = true; jQuery('#cropbox').Jcrop({ onChange: showCoords, onSelect: showCoords, aspectRatio: parseInt(ratioRetrieve) }); function showCoords(c){ jQuery('#x').val(c.x); jQuery('#y').val(c.y); jQuery('#x2').val(c.x2); jQuery('#y2').val(c.y2); jQuery('#w').val(c.w); jQuery('#h').val(c.h); }; function checkCoords(){ if (parseInt(jQuery('#w').val())) return true; alert('Please select a crop region then press submit.'); return false; }; }); } /************** REMOVE AND INSERT JCROP WITH IMAGE CHANGE END ***************/ imageChangejCrop(); closePreview(); anchorChange(); getHeightOrWidth(); ratioRetrieve = calcRatio(); }); /***************************************************************************/ jQuery(window).load(function() { var run = true; if( run === true ) { jQuery(function(ratioRetrieve) { jQuery('#cropbox').Jcrop({ onChange: showCoords, onSelect: showCoords, aspectRatio: parseInt(ratioRetrieve) }); }); } function showCoords(c){ jQuery('#x').val(c.x); jQuery('#y').val(c.y); jQuery('#x2').val(c.x2); jQuery('#y2').val(c.y2); jQuery('#w').val(c.w); jQuery('#h').val(c.h); }; function checkCoords(){ if (parseInt(jQuery('#w').val())) return true; alert('Please select a crop region then press submit.'); return false; }; }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload