Skip to content

Commit

Permalink
Recover $(...).code() with $(...).summernote('code').
Browse files Browse the repository at this point in the history
 - $(...).code and $(...).destroy is deprecated after v0.7.
  • Loading branch information
hackerwins committed Sep 22, 2015
1 parent 17310c5 commit 27eb67f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
18 changes: 12 additions & 6 deletions dist/summernote.js
Expand Up @@ -6,7 +6,7 @@
* Copyright 2013-2015 Alan Hong. and other contributors
* summernote may be freely distributed under the MIT license./
*
* Date: 2015-09-22T14:02Z
* Date: 2015-09-22T14:32Z
*/
(function (factory) {
/* global define */
Expand All @@ -17,8 +17,6 @@
// Browser globals: jQuery
factory(window.jQuery);
}


}(function ($) {


Expand Down Expand Up @@ -377,6 +375,16 @@
ui.removeLayout($note, this.layoutInfo);
};

this.code = function (html) {
if (html === undefined) {
var isActivated = this.invoke('codeview.isActivated');
this.invoke('codeview.sync');
return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html();
}

this.layoutInfo.editable.html(html);
};

this.triggerEvent = function () {
var namespace = list.head(arguments);
var args = list.tail(list.from(arguments));
Expand Down Expand Up @@ -458,10 +466,8 @@

var $note = this.first();
if (isExternalAPICalled && $note.length) {
var namespace = list.head(arguments);
var params = list.tail(list.from(arguments));
var summernote = $note.data('summernote');
summernote.invoke(namespace, params);
return summernote.invoke.apply(summernote, list.from(arguments));
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions dist/summernote.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/textarea.html
Expand Up @@ -24,20 +24,20 @@

$('form').on('submit', function (e) {
e.preventDefault();
alert($('.summernote').code());
alert($('.summernote').summernote('code'));
});
});
</script>
</head>
<body>
<form action="#">
<form action="#" novalidate>
<div class="form-group">
<label for="input">Text</label>
<input type="text" class="form-input" id="input" required="required" value="Title">
<input type="text" class="form-input" id="input" value="Title">
</div>
<div class="form-group">
<label for="contents">Contents</label>
<textarea name="text" class="summernote" id="contents" required="required" title="Contents"></textarea>
<textarea name="text" class="summernote" id="contents" title="Contents"></textarea>
</div>
<button type="submit" class="btn btn-default">submit</button>
</form>
Expand Down
14 changes: 11 additions & 3 deletions src/js/summernote.js
Expand Up @@ -42,6 +42,16 @@ define([
ui.removeLayout($note, this.layoutInfo);
};

this.code = function (html) {
if (html === undefined) {
var isActivated = this.invoke('codeview.isActivated');
this.invoke('codeview.sync');
return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html();
}

this.layoutInfo.editable.html(html);
};

this.triggerEvent = function () {
var namespace = list.head(arguments);
var args = list.tail(list.from(arguments));
Expand Down Expand Up @@ -123,10 +133,8 @@ define([

var $note = this.first();
if (isExternalAPICalled && $note.length) {
var namespace = list.head(arguments);
var params = list.tail(list.from(arguments));
var summernote = $note.data('summernote');
summernote.invoke(namespace, params);
return summernote.invoke.apply(summernote, list.from(arguments));
}
}
});
Expand Down

0 comments on commit 27eb67f

Please sign in to comment.