diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 31aaf4b..cc8cdf7 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mergely", - "version": "4.0.4", + "version": "4.0.5", "description": "A javascript UI for diff/merge", "directories": { "doc": "doc", diff --git a/src/mergely.js b/src/mergely.js index 2bbf274..2f93090 100644 --- a/src/mergely.js +++ b/src/mergely.js @@ -659,6 +659,13 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { bind: function(el) { this.element.hide(); this.id = jQuery(el).attr('id'); + try { + // ensure the id is valid for jQuery + jQuery(`#${this.id}`); + } catch (ex) { + console.error(`jQuery failed to find mergely: #${this.id}`); + return; + } this.changed_timeout = null; this.chfns = {}; this.chfns[this.id + '-lhs'] = []; @@ -749,32 +756,42 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, { }); } + // check initialization + var rhstx; + try { + rhstx = this.element.find(`#${this.id}-rhs`).get(0); + } catch (ex) { + } + if (!rhstx) { + console.error('rhs textarea not defined - Mergely not initialized properly'); + return; + } + var lhstx; + try { + lhstx = this.element.find(`#${this.id}-lhs`).get(0); + } catch (ex) { + } + if (!lhstx) { + console.error('lhs textarea not defined - Mergely not initialized properly'); + return; + } + // get current diff border color var color = jQuery('