<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techy Things &#187; javascript</title>
	<atom:link href="https://tech.yipp.ca/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://tech.yipp.ca</link>
	<description>Just another Yipp.ca Blogs site</description>
	<lastBuildDate>Thu, 01 May 2025 18:06:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>RangeError: Invalid array length</title>
		<link>https://tech.yipp.ca/typescript/rangeerror-invalid-array-length/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rangeerror-invalid-array-length</link>
		<comments>https://tech.yipp.ca/typescript/rangeerror-invalid-array-length/#comments</comments>
		<pubDate>Tue, 30 Apr 2024 14:21:18 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[typescript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=4438</guid>
		<description><![CDATA[<p>This can happen if the value is NaN. Solution : Check for isNaN(myvar) before trying to create an array form it with [...Array(myvar)]</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/typescript/rangeerror-invalid-array-length/">RangeError: Invalid array length</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><a href="http://tech.yipp.ca/files/2024/04/invalid-array-length.png"><img class="alignnone size-full wp-image-4439" src="http://tech.yipp.ca/files/2024/04/invalid-array-length.png" alt="invalid array length" width="990" height="480" /></a></p>
<p>This can happen if the value is NaN.</p>
<h3>Solution :</h3>
<p>Check for isNaN(myvar) before trying to create an array form it with [...Array(myvar)]</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/typescript/rangeerror-invalid-array-length/">RangeError: Invalid array length</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/typescript/rangeerror-invalid-array-length/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three ways to add dropdown options via Javascripts</title>
		<link>https://tech.yipp.ca/javascript/three-ways-add-dropdown-options-via-javascripts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=three-ways-add-dropdown-options-via-javascripts</link>
		<comments>https://tech.yipp.ca/javascript/three-ways-add-dropdown-options-via-javascripts/#comments</comments>
		<pubDate>Wed, 27 Mar 2019 16:20:18 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=3247</guid>
		<description><![CDATA[<p>Method #1 - Via jQuery + html tag var self = this; var sel = (self.selected === -1)?true:false; var option = null; option = $(""); option.val(-1).prop("selected", sel).text("(None)"); this.$el.append(option); this.collection.forEach(function(model) { sel = (self.selected ==&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/three-ways-add-dropdown-options-via-javascripts/">Three ways to add dropdown options via Javascripts</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>Method #1 - Via jQuery + html tag</h2>
<pre>     var self = this;
     var sel = (self.selected === -1)?true:false;
     var option = null;
     option = $("");
     option.val(-1).prop("selected", sel).text("(None)");
     this.$el.append(option);
     this.collection.forEach(function(model)
     {
       sel = (self.selected == model.get('id'))?true:false;
       option = $("");
       option.val(model.get("id")).prop("selected", sel).text(model.getName());
       self.$el.append(option);
     });
</pre>
<h2>Method #2 - Via native "Option" object</h2>
<pre>                option = new Option(data.text, data.id, false, false);
                this.$('#entropy').append(option).trigger('change');
</pre>
<h3>Method #3 - Just render two &lt;select&gt; and hide the unused one - think outside the box.</h3>
<p>This is my preferred method when there are only two sets of valid options</p>
<pre>html:

 &lt;div class="control-group" id="encoding_profile_row_hevc"&gt;
 &lt;label class="control-label"&gt;Encoding Profile&lt;/label&gt;
 &lt;div class="controls"&gt;
 &lt;select name="encodingProfile" class="selectpicker span3" data-style="btn-select-gray" data-size="false" id="encodingProfileHevc"&gt;
 &lt;option value="2"&gt;Main&lt;/option&gt;
 &lt;% if (systemInfo.get("yuv10bit") === true) {%&gt;&lt;option value="6"&gt;Main 10&lt;/option&gt;&lt;% } %&gt;
 &lt;% if (systemInfo.get("yuv422") === true &amp;&amp; systemInfo.get("yuv10bit") === true) {%&gt;&lt;option value="7"&gt;Main 4:2:2 10&lt;/option&gt;&lt;% } %&gt;
 &lt;/select&gt;
 &lt;/div&gt;
 &lt;/div&gt;

 &lt;div class="control-group hidden" id="encoding_profile_row_h264"&gt;
 &lt;label class="control-label"&gt;Encoding Profile&lt;/label&gt;
 &lt;div class="controls"&gt;
 &lt;select name="encodingProfile" class="selectpicker span3" data-style="btn-select-gray" data-size="false" id="encodingProfileH264"&gt;
 &lt;option value="1"&gt;Baseline&lt;/option&gt;
 &lt;option value="2"&gt;Main&lt;/option&gt;
 &lt;option value="3"&gt;High&lt;/option&gt;
 &lt;% if (systemInfo.get("yuv10bit") == true) {%&gt;&lt;option value="4"&gt;High 10&lt;/option&gt;&lt;% } %&gt;
 &lt;% if (systemInfo.get("yuv422") === true) {%&gt;&lt;option value="5"&gt;High 4:2:2&lt;/option&gt;&lt;% } %&gt;
 &lt;/select&gt;
 &lt;/div&gt;
 &lt;/div&gt;


 onChangeCodec: function() {
 var codec = this.$("#codecAlgorithm").val();
 if (codec == "0")
 { //h264
 this.$("#encoding_profile_row_h264").removeClass("hidden");
 this.$("#encoding_profile_row_hevc").addClass("hidden");
 }
 else
 {
 this.$("#encoding_profile_row_hevc").removeClass("hidden");
 this.$("#encoding_profile_row_h264").addClass("hidden");
 }
 this.onChangeEncodingProfile();
 },</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/three-ways-add-dropdown-options-via-javascripts/">Three ways to add dropdown options via Javascripts</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/javascript/three-ways-add-dropdown-options-via-javascripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backbone Collection Flexible Value Sorting Solution</title>
		<link>https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-collection-custom-sorting-solution</link>
		<comments>https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/#comments</comments>
		<pubDate>Mon, 18 Jun 2018 19:03:33 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[backbone]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=3103</guid>
		<description><![CDATA[<p>Model/Collection Declaration Inputs.Collection = Backbone.Collection.extend({ model: Inputs.Model, url: "/apis/v2/inputs", sortAttribute: "name", // supported attributes are model's element names + any custom strategies below comparator: function(model) { return Utils.genericComparator.call(this, model); }, strategies: {}, changeSort: function&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/">Backbone Collection Flexible Value Sorting Solution</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>Model/Collection Declaration</h2>
<pre> Inputs.Collection = Backbone.Collection.extend({
   model: Inputs.Model,
   url: "/apis/v2/inputs",
   sortAttribute: "name", // supported attributes are model's element names + any custom strategies below
   comparator: function(model) 
   {
     return Utils.genericComparator.call(this, model);
   },
   strategies: {},
   changeSort: function (sortAttribute) 
   {
     if (this.strategies[sortAttribute]) {
       this.comparator = this.strategies[sortAttribute];
       return;
     }
     this.comparator = Inputs.Collection.prototype.comparator;
     this.sortAttribute = sortAttribute;
   },
   parse: function (resp)
   {
     var data = ( resp &amp;&amp; resp.input_list ) ? resp.input_list : [];
     return data;
   }
 });
</pre>
<h2>Initialization of Sort Method in View</h2>
<pre> initialize: function () // View Initialize
 {
   var self = this;
   this.collection = new Inputs.Collection();
   var currentMethod = app.storageModel.load("inputs:sort");
   if (currentMethod) {
     this.collection.changeSort(currentMethod);
   } else {
     app.storageModel.save("inputs:sort", this.collection.sortAttribute);
   }
   ...
 },
 afterRender: function() 
 {
   // Indicate to user what we are sorting
   var currentMethod = this.collection.sortAttribute;
   if (currentMethod &amp;&amp; currentMethod.match(/_r$/)) {
     // reserve sorting
     this.$(".jsSort[data-sort=\""+currentMethod.replace(/_r$/,"")+"\"]").addClass("down");
   } else {
     this.$(".jsSort[data-sort=\""+currentMethod+"\"]").addClass("up");
   }
 },
</pre>
<h2>Dynamic Code to Change Sort Method</h2>
<pre> events: {
   "click .jsSort": "sortTable"
 },
 sortTable: function(e) 
 {
   var sortBy = $(e.currentTarget).data("sort");
   var currentMethod = app.storageModel.load("inputs:sort");
   if (sortBy === currentMethod) {
     sortBy += "_r"; // reserve sorting
   }
   this.collection.changeSort(sortBy);
   this.collection.sort();
   app.storageModel.save("inputs:sort", sortBy);
   this.render();
 },
</pre>
<h2>Html Code</h2>
<pre>&lt;div class="span4 sort jsSort unselectable" data-sort="name"&gt;Name&lt;/div&gt;
&lt;div class="span5 sort jsSort unselectable" data-sort="url"&gt;Connection&lt;/div&gt;
&lt;div class="span2 sort jsSort unselectable" data-sort="state"&gt;Status&lt;/div
</pre>
<h2>Generic Sort Code</h2>
<pre> // Comparator Function for Collection sort
 //
 // Usage: 
 // My.Collection = Backbone.Collection.extend({
 // sortAttribute: "name", // supported attributes are model's element names + any custom strategies below
 // comparator: function(model) { return Utils.genericComparator.call(this, model); },
 // strategies: { &lt;your own custom strategy not covered by genericComparator&gt; },
 // changeSort: function (sortAttribute) {
 // if (this.strategies[sortAttribute]) {
 // this.comparator = this.strategies[sortAttribute];
 // return;
 // }
 // this.comparator = My.Collection.prototype.comparator;
 // this.sortAttribute = sortAttribute;
 // },
 // ...
 // });
 Utils.genericComparator = function (model) 
 {
   var last = this.sortAttribute.slice(-2); // last 3 chars
   var reversed = false;
   var attribute = this.sortAttribute;
   if (last === "_r") {
     attribute = this.sortAttribute.substr(0, this.sortAttribute.length-2);
     reversed = true;
   }
 
   var value = model.get(attribute);
   var matches;
   if (matches = attribute.match(/\((.*)\)$/)) // ends with () ?
   { 
     // function call
     var fname = attribute.substring(0, attribute.length - matches[0].length);
     if (fname.indexOf(".") &gt; 0) 
     { 
       var flist = fname.split(".");
       var args = matches[1].replace(/'/g, "");
       if (flist.length == 2) 
       {
         value = model[flist[0]][flist[1]](args);
       }
     } else {
       value = model[fname](matches[1]);
     }
   } 
   var retval = Utils.genericComparatorFromValue(value, reversed);
   return retval;
 };
 
 // Takes a value as input format it for consistant compare and optionally reverse it
 // Returns value prepped for compare
 Utils.genericComparatorFromValue = function (value, reversed) { 
   if (_.isUndefined(value)) {
     return value;
   }
 
   if (typeof value.toLowerCase === "function") {
     // string type 
     var string = value.toLowerCase();
     if (reversed) {
       string = string.split(""); // string to array
       string = _.map(string, function(letter) { return String.fromCharCode(-(letter.charCodeAt(0))); });
       return string;
     }
     return string;
   } else if (value === true || value === false) {
     // boolean type
     return reversed ? !value : value;
   } else if (value === null) {
     return value;
   } else {
     // integer, float
     return reversed ? -value : value;
   }
 };

</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/">Backbone Collection Flexible Value Sorting Solution</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/backbone/backbone-collection-custom-sorting-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery prevent uploading too large file in Frontend</title>
		<link>https://tech.yipp.ca/jquery/jquery-prevent-uploading-large-file-frontend/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-prevent-uploading-large-file-frontend</link>
		<comments>https://tech.yipp.ca/jquery/jquery-prevent-uploading-large-file-frontend/#comments</comments>
		<pubDate>Tue, 09 May 2017 21:39:17 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2807</guid>
		<description><![CDATA[<p>afterRender:       // Only works on HTML5       $('#file').on('change', function() {         $("#upload-package").prop("disabled",  false);         var sizeLimit = 90;         if (this.files &#38;&#38; this.files.length &#38;&#38; this.files[0].size &#62; sizeLimit*1024*1024) {           notifier.error_x("File size exceeds limit&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/jquery/jquery-prevent-uploading-large-file-frontend/">jQuery prevent uploading too large file in Frontend</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<pre>afterRender:
      // Only works on HTML5
      $('#file').on('change', function() {
        $("#upload-package").prop("disabled",  false);
        var sizeLimit = 90;
        if (this.files &amp;&amp; this.files.length &amp;&amp; this.files[0].size &gt; sizeLimit*1024*1024) {
          notifier.error_x("File size exceeds limit of "+sizeLimit+"MB");
          $("#upload-package").prop("disabled",  true);
          return;
        }
        if (this.files &amp;&amp; this.files.length &amp;&amp; this.files[0].name &amp;&amp; this.files[0].name.match(/makitox_dec_v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}-[0-9]{1,4}\.hai$/) === null) {
          notifier.error_x(this.files[0].name + " is not a valid makitox decoder package");
          $("#upload-package").prop("disabled",  true);
          return;
        }
      });

cleanup:
      $('#file').off('change');</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/jquery/jquery-prevent-uploading-large-file-frontend/">jQuery prevent uploading too large file in Frontend</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/jquery/jquery-prevent-uploading-large-file-frontend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mousewheel prevent body scroll on modal</title>
		<link>https://tech.yipp.ca/automation/backbone-prevent-body-scroll-modal/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=backbone-prevent-body-scroll-modal</link>
		<comments>https://tech.yipp.ca/automation/backbone-prevent-body-scroll-modal/#comments</comments>
		<pubDate>Tue, 09 May 2017 13:59:19 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[automation]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2802</guid>
		<description><![CDATA[<p>Solution #1   // prevent background of modal from scrolling   // DOMMouseScroll for Firefox equivalent   $(document).on("mousewheel DOMMouseScroll", ".modal-backdrop, .modal-body", function(event) {     event.stopPropagation();     event.preventDefault();   });   // prevent background of&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/automation/backbone-prevent-body-scroll-modal/">Mousewheel prevent body scroll on modal</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Solution #1</p>
<pre>  // prevent background of modal from scrolling
  // DOMMouseScroll for Firefox equivalent
  $(document).on("mousewheel DOMMouseScroll", ".modal-backdrop, .modal-body", function(event) {
    event.stopPropagation();
    event.preventDefault();
  });

  // prevent background of modal from scrolling
  var keysThatScroll = new Array(33,34,35,36,37,38,39,40);
  var DEBUG_KEY_SCROLL_PREVENTION = false;
  $(document).on("keydown", function(event) {
    var key = event.which;
    if ($.inArray(key,keysThatScroll) === -1) {
      if (DEBUG_KEY_SCROLL_PREVENTION) console.log("no worries for this key", key);
      return true; // no worries for this key
    }

    if ($(".modal-backdrop").length === 0) {
      if (DEBUG_KEY_SCROLL_PREVENTION) console.log("no modification when modal is off");
      return true; // no worries for these keys
    }

    if (event.target == null || event.target.tagName == null) { // should not happen
      if (DEBUG_KEY_SCROLL_PREVENTION) console.log("event.target or event.target.tagName is null or undefined");
      return true;
    }

    if (event.target.tagName.toLowerCase() === "body") {
      if (DEBUG_KEY_SCROLL_PREVENTION) console.log("keydown, on body, stopping");
      event.preventDefault();
      return false;
    }

    if (event.target.type == null) {
      if (DEBUG_KEY_SCROLL_PREVENTION) console.log("keydown, no type and not body, letting go");
      return true; // ok keep going
    }

    var type = event.target.type.toLowerCase();
    if (DEBUG_KEY_SCROLL_PREVENTION) console.log("keydown, type", type);
    if (type == 'input' || type == 'text' || type == 'textarea' ||type == 'select') {
      // normal keyup and keydown allowed in modals
      return true; // ok keep going
    }
    
    // stop scrolling keys in modal of further effects, for example if focus is on a button and keydown
    event.preventDefault();
    event.stopPropagation();
    return false; // in jQuery returning false does the same as preventDefault and stopPropagation
  });</pre>
<pre>Solution #2

   // extend Bootstrap modal to remove scrollbar during modal show
   var _show = $.fn.modal.Constructor.prototype.show;
   $.fn.modal.Constructor.prototype.show = function() {
      _show.apply(this, arguments);
      $("body").addClass("modal-on");
   };
   var _hide = $.fn.modal.Constructor.prototype.hide;
   $.fn.modal.Constructor.prototype.hide = function() {
      _hide.apply(this, arguments);
      $("body").removeClass("modal-on");
   };

along with CSS

html,
body {
   width: 100%;
   height: 100%;
   padding: 0;
   margin: 0;
}
body {
   overflow-y: scroll;
}

body.modal-on {
   overflow:hidden;
}


</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/automation/backbone-prevent-body-scroll-modal/">Mousewheel prevent body scroll on modal</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/automation/backbone-prevent-body-scroll-modal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jshint options</title>
		<link>https://tech.yipp.ca/javascript/jshint-options/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jshint-options</link>
		<comments>https://tech.yipp.ca/javascript/jshint-options/#comments</comments>
		<pubDate>Thu, 29 Dec 2016 00:36:42 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2694</guid>
		<description><![CDATA[<p>Inline To fix Expected a 'break' statement before 'default'. Use /* falls through */</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/jshint-options/">jshint options</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>Inline</h2>
<p>To fix</p>
<p>Expected a 'break' statement before 'default'.</p>
<p>Use</p>
<p>/* falls through */</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/jshint-options/">jshint options</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/javascript/jshint-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Single beforeEach() in Jasmine</title>
		<link>https://tech.yipp.ca/javascript/single-beforeeach-jasmine/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=single-beforeeach-jasmine</link>
		<comments>https://tech.yipp.ca/javascript/single-beforeeach-jasmine/#comments</comments>
		<pubDate>Tue, 30 Aug 2016 16:32:06 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2575</guid>
		<description><![CDATA[<p>&#160; &#60;&#60; @philipraath @olignyf a beforeAll or beforeEach that is not inside of any describe will be applied to all suites/specs, as appropriate, during the execution of the suite. &#62;&#62; https://github.com/jasmine/jasmine/issues/811</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/single-beforeeach-jasmine/">Single beforeEach() in Jasmine</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>&lt;&lt;</p>
<p><a class="user-mention" href="https://github.com/philipraath">@philipraath</a> <a class="user-mention" href="https://github.com/olignyf">@olignyf</a> a <code>beforeAll</code> or <code>beforeEach</code> that is not inside of any <code>describe</code> will be applied to all suites/specs, as appropriate, during the execution of the suite.</p>
<p>&gt;&gt;</p>
<p>https://github.com/jasmine/jasmine/issues/811</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/single-beforeeach-jasmine/">Single beforeEach() in Jasmine</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/javascript/single-beforeeach-jasmine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrade Jasmine 1.3 to 2.4</title>
		<link>https://tech.yipp.ca/javascript/referenceerror-createspy-defined/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=referenceerror-createspy-defined</link>
		<comments>https://tech.yipp.ca/javascript/referenceerror-createspy-defined/#comments</comments>
		<pubDate>Mon, 08 Aug 2016 14:24:26 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2513</guid>
		<description><![CDATA[<p>Quick upgrade with those Regexp replaces /createSpyObj/ =&#62; " jasmine.createSpyObj" /createSpy/ =&#62; "jasmine.createSpy" /\.andCallFake/ =&#62; ".and.callFake" /\.andReturn/ =&#62; ".and.returnValue" /\.andCallThrough/ =&#62; ".and.callThrough" /toNotMatch/ =&#62; "not.toMatch" /this.addMatchers/ =&#62; "jasmine.addMatchers" /\.calls\[0\]\./ =&#62; ".calls.first()" /\.calls\[(\d)\]\./ =&#62; ".calls.all()[$1]"&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/referenceerror-createspy-defined/">Upgrade Jasmine 1.3 to 2.4</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Quick upgrade with those Regexp replaces</p>
<p>/createSpyObj/ =&gt; " jasmine.createSpyObj"</p>
<p>/createSpy/ =&gt; "jasmine.createSpy"</p>
<p>/\.andCallFake/ =&gt; ".and.callFake"</p>
<p>/\.andReturn/ =&gt; ".and.returnValue"</p>
<p>/\.andCallThrough/ =&gt; ".and.callThrough"</p>
<p>/toNotMatch/ =&gt; "not.toMatch"</p>
<p>/this.addMatchers/ =&gt; "jasmine.addMatchers"</p>
<p>/\.calls\[0\]\./ =&gt; ".calls.first()"</p>
<p>/\.calls\[(\d)\]\./ =&gt; ".calls.all()[$1]"</p>
<p>/\.callCount/ =&gt; ".calls.count()"</p>
<p>runs and waitsFor have been removed and should be replaced with <em><strong>function(done) / done()</strong></em>:</p>
<p>https://groups.google.com/forum/#!topic/jasmine-js/Q_4lyEWrZKI</p>
<p>&nbsp;</p>
<h2>Problem with Expected {XYZ} to equal Object({XYZ})</h2>
<p>An Asset object should<br />
✓ get deserialized for further tests<br />
✓ be deserialized from a serialized protobuf message<br />
✗ find tracks, resources, and chunks by id<br />
- Expected ({ id: 0, type: 'PROTOBUF', chunk: [ ({ id: 0 }), ({ id: 1 }) ] }) to equal Object({ id: 0, type: 'PROTOBUF', chunk: [ Object({ id: 0 }), Object({ id: 1 }) ] }).<br />
at Object. (js/tests/lib/assets/asset_spec.js:290:22)</p>
<p><strong>Solution</strong></p>
<pre>beforeEach(function(done) {
  jasmine.addMatchers({
    toStringifyEqual: function(util, customEqualityTesters) {
      return {
        compare: function(actual, expected) {
          var result = {};
          var actual_ = JSON.stringify(actual);
          var expected_ = JSON.stringify(expected);
          result.pass = _.isEqual(actual_, expected_);
          return result;
        }
      }
    }
  });
});
</pre>
<h2>Examples</h2>
<p><strong>Error : <span style="color: #993300;">ReferenceError: createSpy is not defined</span></strong></p>
<p><strong>Solution</strong></p>
<p>Replace with <span style="color: #ff6600;"><strong>jasmine.createSpy</strong></span></p>
<p><strong>Error : </strong>On lines with<strong> .calls[0] </strong>some errors such as<strong> TypeError: Cannot read property 'args' of undefined</strong></p>
<p><strong>Solution</strong></p>
<p>Replace <strong>.calls[0]</strong> with<span style="color: #008000;"> <strong>.calls.first()</strong></span></p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/referenceerror-createspy-defined/">Upgrade Jasmine 1.3 to 2.4</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/javascript/referenceerror-createspy-defined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String manipulations in Javascripts</title>
		<link>https://tech.yipp.ca/javascript/string-manipulations-javascripts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=string-manipulations-javascripts</link>
		<comments>https://tech.yipp.ca/javascript/string-manipulations-javascripts/#comments</comments>
		<pubDate>Mon, 13 Jun 2016 22:21:14 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2451</guid>
		<description><![CDATA[<p>String.indexOf() Return value: -1 if not found 0 or higher than 0 as the index of the position found Remove one part of a string Method 1: String.replace(//, ""); Method 2: var indexEnd =&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/string-manipulations-javascripts/">String manipulations in Javascripts</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>String.indexOf()</h2>
<p>Return value:</p>
<p>-1 if not found</p>
<p>0 or higher than 0 as the index of the position found</p>
<h2>Remove one part of a string</h2>
<p>Method 1:</p>
<p>String.replace(//, "");</p>
<p>Method 2:</p>
<pre class="default prettyprint prettyprinted">var indexEnd = myString.indexOf("CutHERE");</pre>
<p><code><span class="pln">var newString = myString</span><span class="pun">.</span><span class="pln">substring</span><span class="pun">(</span><span class="lit">0</span><span class="pun">,</span><span class="pln"> indexEnd</span><span class="pun">);</span></code></p>
<p>&nbsp;</p>
<h2>Difference between String::substring() and String.substr()</h2>
<p><a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/substring" target="_blank">substring(start, indexEnd)</a></p>
<p>With substring() the second parameter is the end index</p>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr" target="_blank">substr(start, length)</a></p>
<p>With substr() the second parameter is the length to keep</p>
<h2>Remove boundary whitespace : String.trim()</h2>
<p>Use this from time to time</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/string-manipulations-javascripts/">String manipulations in Javascripts</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/javascript/string-manipulations-javascripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Submit a form with ajax</title>
		<link>https://tech.yipp.ca/javascript/submit-form-ajax/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=submit-form-ajax</link>
		<comments>https://tech.yipp.ca/javascript/submit-form-ajax/#comments</comments>
		<pubDate>Fri, 29 Jan 2016 15:55:47 +0000</pubDate>
		<dc:creator><![CDATA[frank]]></dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.yipp.ca/?p=2190</guid>
		<description><![CDATA[<p>This is a basic operation that you might have to do when upgrading an old web app. One solution is using jQuery .serialize() function &#160; Method #1: Sent using CGI params key=value pairs: var&#46;&#46;&#46;</p>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/submit-form-ajax/">Submit a form with ajax</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>This is a basic operation that you might have to do when upgrading an old web app.</p>
<pre></pre>
<p>One solution is using jQuery .serialize() function</p>
<p>&nbsp;</p>
<p>Method #1: Sent using CGI params key=value pairs:</p>
<pre>
          var $form = this.$("form");
          var data = $form.serialize(); // becomes text with proper encoding for CGI params

          $.ajax({
            method: "POST",
            url: "/run.php",
            data: data,
            success: function (data)
            {
              var response;
              try {
                response = JSON.parse(data);
                if (response.message !== undefined &#038;& response.message.indexOf("Success") >= 0) {
                  notifier.info_x(response.message);
                }
                else {
                  if (response.message !== undefined) {
                    notifier.error_x(response.message);
                  }
                }
              }
              catch (e) {
                notifier.error_x("Could not parse response");
              }
            },
            error: function ()
            {
              notifier.error_x("Failed to send request");
            }
          });
</pre>
<p>Method #2 Sent using JSON text content (supports better multi-level objects):</p>
<pre>
          var $form = this.$("form");
          var json = JSON.stringify({ username: this.get("username"), password: this.get("password") });

      $.ajax({
        type: "POST",
        url: this.url(),
        contentType: "application/json",
        data: ,
          $.ajax({
            method: "POST",
            url: "/run.php",
            data: data,
            success: function (data)
            {
              var response;
              try {
                response = JSON.parse(data);
                if (response.message !== undefined &#038;& response.message.indexOf("Success") >= 0) {
                  notifier.info_x(response.message);
                }
                else {
                  if (response.message !== undefined) {
                    notifier.error_x(response.message);
                  }
                }
              }
              catch (e) {
                notifier.error_x("Could not parse response");
              }
            },
            error: function ()
            {
              notifier.error_x("Failed to send request");
            }
          });
</pre>
<p>If you are using PHP to read the JSON, you can use</p>
<pre>
if ($_SERVER['REQUEST_METHOD'] === "POST" // to create
 || $_SERVER['REQUEST_METHOD'] === "PUT") // to update
{
	$raw_request = file_get_contents('php://input');
	$request = json_decode($raw_request);
	$requestArray = get_object_vars($request);
}
</pre>
<p>The post <a rel="nofollow" href="https://tech.yipp.ca/javascript/submit-form-ajax/">Submit a form with ajax</a> appeared first on <a rel="nofollow" href="https://tech.yipp.ca">Techy Things</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://tech.yipp.ca/javascript/submit-form-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
