diff --git a/uoj/1/js/readmore/README.md b/uoj/1/js/readmore/README.md
index f00aeb0..24649f3 100644
--- a/uoj/1/js/readmore/README.md
+++ b/uoj/1/js/readmore/README.md
@@ -55,17 +55,23 @@ $('article').readmore({
* `startOpen: false` do not immediately truncate, start in the fully opened position
* `beforeToggle: function() {}` called after a more or less link is clicked, but *before* the block is collapsed or expanded
* `afterToggle: function() {}` called *after* the block is collapsed or expanded
+* `blockProcessed: function() {}` called once per block during initilization after Readmore.js has processed the block.
If the element has a `max-height` CSS property, Readmore.js will use that value rather than the value of the `collapsedHeight` option.
### The callbacks:
-The callback functions, `beforeToggle` and `afterToggle`, both receive the same arguments: `trigger`, `element`, and `expanded`.
+The `beforeToggle` and `afterToggle` callbacks both receive the same arguments: `trigger`, `element`, and `expanded`.
* `trigger`: the "Read more" or "Close" element that was clicked
* `element`: the block that is being collapsed or expanded
* `expanded`: Boolean; `true` means the block is expanded
+The `blockProcessed` callback receives `element` and `collapsable`.
+
+* `element`: the block that has just been processed
+* `collapsable`: Boolean; `false` means the block was shorter than the specified minimum `collapsedHeight`--the block will not have a "Read more" link
+
#### Callback example:
Here's an example of how you could use the `afterToggle` callback to scroll back to the top of a block when the "Close" link is clicked.
@@ -172,6 +178,6 @@ $ npm install
Which will install the necessary development dependencies. Then, to build the minified script:
```
-$ gulp compress
+$ npm run build
```
diff --git a/uoj/1/js/readmore/bower.json b/uoj/1/js/readmore/bower.json
index 46d9e92..6455a69 100644
--- a/uoj/1/js/readmore/bower.json
+++ b/uoj/1/js/readmore/bower.json
@@ -1,6 +1,6 @@
{
- "name": "Readmore.js",
- "main": "readmore.min.js",
+ "name": "readmore-js",
+ "main": "readmore.js",
"version": "2.1.0",
"homepage": "http://jedfoster.com/Readmore.js/",
"authors": [
@@ -20,6 +20,10 @@
"node_modules",
"bower_components",
"test",
- "tests"
- ]
+ "tests",
+ "gulpfile.js"
+ ],
+ "dependencies": {
+ "jquery": ">=2.1.4"
+ }
}
diff --git a/uoj/1/js/readmore/demo.html b/uoj/1/js/readmore/demo.html
index a134521..fbb9cee 100644
--- a/uoj/1/js/readmore/demo.html
+++ b/uoj/1/js/readmore/demo.html
@@ -77,13 +77,14 @@
startOpen: false
do not immediately truncate, start in the fully opened position
beforeToggle: function() {}
called after a more or less link is clicked, but before the block is collapsed or expanded
afterToggle: function() {}
called after the block is collapsed or expanded
+ blockProcessed: function() {}
called once per block during initilization after Readmore.js has processed the block.
If the element has a max-height
CSS property, Readmore.js will use that value rather than the value of the collapsedHeight
option.
The callbacks:
- The callback functions, beforeToggle
and afterToggle
, both receive the same arguments: trigger
, element
, and expanded
.
+ The beforeToggle
and afterToggle
callbacks both receive the same arguments: trigger
, element
, and expanded
.
trigger
: the “Read more” or “Close” element that was clicked
@@ -91,6 +92,13 @@
expanded
: Boolean; true
means the block is expanded
+ The blockProcessed
callback receives element
and collapsable
.
+
+
+ element
: the block that has just been processed
+ collapsable
: Boolean; false
means the block was shorter than the specified minimum collapsedHeight
—the block will not have a "Read more" link
+
+
Callback example:
Here’s an example of how you could use the afterToggle
callback to scroll back to the top of a block when the “Close” link is clicked.
diff --git a/uoj/1/js/readmore/package.json b/uoj/1/js/readmore/package.json
index cf66fb6..5ec86d9 100644
--- a/uoj/1/js/readmore/package.json
+++ b/uoj/1/js/readmore/package.json
@@ -1,10 +1,11 @@
{
"name": "readmore-js",
- "version": "2.1.0",
+ "version": "2.2.1",
"description": "A lightweight jQuery plugin for collapsing and expanding long blocks of text with \"Read more\" and \"Close\" links.",
"main": "readmore.js",
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "test": "echo \"Error: no test specified\" && exit 1",
+ "build": "./node_modules/gulp/bin/gulp.js compress"
},
"repository": {
"type": "git",
@@ -24,7 +25,7 @@
},
"homepage": "https://github.com/jedfoster/Readmore.js",
"dependencies": {
- "jquery": "~2.1.4"
+ "jquery": ">2.1.4"
},
"devDependencies": {
"gulp": "^3.9.0",
diff --git a/uoj/1/js/readmore/readmore.js b/uoj/1/js/readmore/readmore.js
index 3ea1775..3759679 100644
--- a/uoj/1/js/readmore/readmore.js
+++ b/uoj/1/js/readmore/readmore.js
@@ -37,8 +37,9 @@
startOpen: false,
// callbacks
- beforeToggle: function(){},
- afterToggle: function(){}
+ blockProcessed: function() {},
+ beforeToggle: function() {},
+ afterToggle: function() {}
},
cssEmbedded = {},
uniqueIdCounter = 0;
@@ -68,7 +69,7 @@
function uniqueId(prefix) {
var id = ++uniqueIdCounter;
- return String(prefix == null ? 'rmjs-' : prefix) + id;
+ return String(prefix === null ? 'rmjs-' : prefix) + id;
}
function setBoxHeights(element) {
@@ -187,6 +188,9 @@
if (current.outerHeight(true) <= collapsedHeight + heightMargin) {
// The block is shorter than the limit, so there's no need to truncate it.
+ if (this.options.blockProcessed && typeof this.options.blockProcessed === 'function') {
+ this.options.blockProcessed(current, false);
+ }
return true;
}
else {
@@ -206,7 +210,7 @@
};
})(this))
.attr({
- 'data-readmore-toggle': '',
+ 'data-readmore-toggle': id,
'aria-controls': id
}));
@@ -215,6 +219,10 @@
height: collapsedHeight
});
}
+
+ if (this.options.blockProcessed && typeof this.options.blockProcessed === 'function') {
+ this.options.blockProcessed(current, true);
+ }
}
},
@@ -224,11 +232,11 @@
}
if (! trigger) {
- trigger = $('[aria-controls="' + _this.element.id + '"]')[0];
+ trigger = $('[aria-controls="' + this.element.id + '"]')[0];
}
if (! element) {
- element = _this.element;
+ element = this.element;
}
var $element = $(element),
@@ -250,19 +258,23 @@
// Fire beforeToggle callback
// Since we determined the new "expanded" state above we're now out of sync
// with our true current state, so we need to flip the value of `expanded`
- this.options.beforeToggle(trigger, $element, ! expanded);
+ if (this.options.beforeToggle && typeof this.options.beforeToggle === 'function') {
+ this.options.beforeToggle(trigger, $element, ! expanded);
+ }
$element.css({'height': newHeight});
// Fire afterToggle callback
$element.on('transitionend', (function(_this) {
return function() {
- _this.options.afterToggle(trigger, $element, expanded);
+ if (_this.options.afterToggle && typeof _this.options.afterToggle === 'function') {
+ _this.options.afterToggle(trigger, $element, expanded);
+ }
$(this).attr({
'aria-expanded': expanded
}).off('transitionend');
- }
+ };
})(this));
$(trigger).replaceWith($(this.options[newLink])
@@ -272,7 +284,7 @@
};
})(this))
.attr({
- 'data-readmore-toggle': '',
+ 'data-readmore-toggle': $element.attr('id'),
'aria-controls': $element.attr('id')
}));
},
diff --git a/uoj/1/js/readmore/readmore.min.js b/uoj/1/js/readmore/readmore.min.js
index f252aad..365d73e 100644
--- a/uoj/1/js/readmore/readmore.min.js
+++ b/uoj/1/js/readmore/readmore.min.js
@@ -8,4 +8,4 @@
*
* Debounce function from http://davidwalsh.name/javascript-debounce-function
*/
-!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){"use strict";function e(t,e,i){var a;return function(){var n=this,o=arguments,r=function(){a=null,i||t.apply(n,o)},s=i&&!a;clearTimeout(a),a=setTimeout(r,e),s&&t.apply(n,o)}}function i(t){var e=++h;return String(null==t?"rmjs-":t)+e}function a(t){var e=t.clone().css({height:"auto",width:t.width(),maxHeight:"none",overflow:"hidden"}).insertAfter(t),i=e.outerHeight(),a=parseInt(e.css({maxHeight:""}).css("max-height").replace(/[^-\d\.]/g,""),10),n=t.data("defaultHeight");e.remove();var o=a||t.data("collapsedHeight")||n;t.data({expandedHeight:i,maxHeight:a,collapsedHeight:o}).css({maxHeight:"none"})}function n(t){if(!d[t.selector]){var e=" ";t.embedCSS&&""!==t.blockCSS&&(e+=t.selector+" + [data-readmore-toggle], "+t.selector+"[data-readmore]{"+t.blockCSS+"}"),e+=t.selector+"[data-readmore]{transition: height "+t.speed+"ms;overflow: hidden;}",function(t,e){var i=t.createElement("style");i.type="text/css",i.styleSheet?i.styleSheet.cssText=e:i.appendChild(t.createTextNode(e)),t.getElementsByTagName("head")[0].appendChild(i)}(document,e),d[t.selector]=!0}}function o(e,i){this.element=e,this.options=t.extend({},s,i),n(this.options),this._defaults=s,this._name=r,this.init(),window.addEventListener?(window.addEventListener("load",l),window.addEventListener("resize",l)):(window.attachEvent("load",l),window.attachEvent("resize",l))}var r="readmore",s={speed:100,collapsedHeight:200,heightMargin:16,moreLink:'Read More',lessLink:'Close',embedCSS:!0,blockCSS:"display: block; width: 100%;",startOpen:!1,beforeToggle:function(){},afterToggle:function(){}},d={},h=0,l=e(function(){t("[data-readmore]").each(function(){var e=t(this),i="true"===e.attr("aria-expanded");a(e),e.css({height:e.data(i?"expandedHeight":"collapsedHeight")})})},100);o.prototype={init:function(){var e=t(this.element);e.data({defaultHeight:this.options.collapsedHeight,heightMargin:this.options.heightMargin}),a(e);var n=e.data("collapsedHeight"),o=e.data("heightMargin");if(e.outerHeight(!0)<=n+o)return!0;var r=e.attr("id")||i(),s=this.options.startOpen?this.options.lessLink:this.options.moreLink;e.attr({"data-readmore":"","aria-expanded":this.options.startOpen,id:r}),e.after(t(s).on("click",function(t){return function(i){t.toggle(this,e[0],i)}}(this)).attr({"data-readmore-toggle":"","aria-controls":r})),this.options.startOpen||e.css({height:n})},toggle:function(e,i,a){a&&a.preventDefault(),e||(e=t('[aria-controls="'+_this.element.id+'"]')[0]),i||(i=_this.element);var n=t(i),o="",r="",s=!1,d=n.data("collapsedHeight");n.height()<=d?(o=n.data("expandedHeight")+"px",r="lessLink",s=!0):(o=d,r="moreLink"),this.options.beforeToggle(e,n,!s),n.css({height:o}),n.on("transitionend",function(i){return function(){i.options.afterToggle(e,n,s),t(this).attr({"aria-expanded":s}).off("transitionend")}}(this)),t(e).replaceWith(t(this.options[r]).on("click",function(t){return function(e){t.toggle(this,i,e)}}(this)).attr({"data-readmore-toggle":"","aria-controls":n.attr("id")}))},destroy:function(){t(this.element).each(function(){var e=t(this);e.attr({"data-readmore":null,"aria-expanded":null}).css({maxHeight:"",height:""}).next("[data-readmore-toggle]").remove(),e.removeData()})}},t.fn.readmore=function(e){var i=arguments,a=this.selector;return e=e||{},"object"==typeof e?this.each(function(){if(t.data(this,"plugin_"+r)){var i=t.data(this,"plugin_"+r);i.destroy.apply(i)}e.selector=a,t.data(this,"plugin_"+r,new o(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e?this.each(function(){var a=t.data(this,"plugin_"+r);a instanceof o&&"function"==typeof a[e]&&a[e].apply(a,Array.prototype.slice.call(i,1))}):void 0}});
\ No newline at end of file
+!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):t(jQuery)}(function(t){"use strict";function e(t,e,i){var o;return function(){var n=this,a=arguments,s=function(){o=null,i||t.apply(n,a)},r=i&&!o;clearTimeout(o),o=setTimeout(s,e),r&&t.apply(n,a)}}function i(t){var e=++h;return String(null==t?"rmjs-":t)+e}function o(t){var e=t.clone().css({height:"auto",width:t.width(),maxHeight:"none",overflow:"hidden"}).insertAfter(t),i=e.outerHeight(),o=parseInt(e.css({maxHeight:""}).css("max-height").replace(/[^-\d\.]/g,""),10),n=t.data("defaultHeight");e.remove();var a=o||t.data("collapsedHeight")||n;t.data({expandedHeight:i,maxHeight:o,collapsedHeight:a}).css({maxHeight:"none"})}function n(t){if(!d[t.selector]){var e=" ";t.embedCSS&&""!==t.blockCSS&&(e+=t.selector+" + [data-readmore-toggle], "+t.selector+"[data-readmore]{"+t.blockCSS+"}"),e+=t.selector+"[data-readmore]{transition: height "+t.speed+"ms;overflow: hidden;}",function(t,e){var i=t.createElement("style");i.type="text/css",i.styleSheet?i.styleSheet.cssText=e:i.appendChild(t.createTextNode(e)),t.getElementsByTagName("head")[0].appendChild(i)}(document,e),d[t.selector]=!0}}function a(e,i){this.element=e,this.options=t.extend({},r,i),n(this.options),this._defaults=r,this._name=s,this.init(),window.addEventListener?(window.addEventListener("load",c),window.addEventListener("resize",c)):(window.attachEvent("load",c),window.attachEvent("resize",c))}var s="readmore",r={speed:100,collapsedHeight:200,heightMargin:16,moreLink:'Read More',lessLink:'Close',embedCSS:!0,blockCSS:"display: block; width: 100%;",startOpen:!1,blockProcessed:function(){},beforeToggle:function(){},afterToggle:function(){}},d={},h=0,c=e(function(){t("[data-readmore]").each(function(){var e=t(this),i="true"===e.attr("aria-expanded");o(e),e.css({height:e.data(i?"expandedHeight":"collapsedHeight")})})},100);a.prototype={init:function(){var e=t(this.element);e.data({defaultHeight:this.options.collapsedHeight,heightMargin:this.options.heightMargin}),o(e);var n=e.data("collapsedHeight"),a=e.data("heightMargin");if(e.outerHeight(!0)<=n+a)return this.options.blockProcessed&&"function"==typeof this.options.blockProcessed&&this.options.blockProcessed(e,!1),!0;var s=e.attr("id")||i(),r=this.options.startOpen?this.options.lessLink:this.options.moreLink;e.attr({"data-readmore":"","aria-expanded":this.options.startOpen,id:s}),e.after(t(r).on("click",function(t){return function(i){t.toggle(this,e[0],i)}}(this)).attr({"data-readmore-toggle":s,"aria-controls":s})),this.options.startOpen||e.css({height:n}),this.options.blockProcessed&&"function"==typeof this.options.blockProcessed&&this.options.blockProcessed(e,!0)},toggle:function(e,i,o){o&&o.preventDefault(),e||(e=t('[aria-controls="'+this.element.id+'"]')[0]),i||(i=this.element);var n=t(i),a="",s="",r=!1,d=n.data("collapsedHeight");n.height()<=d?(a=n.data("expandedHeight")+"px",s="lessLink",r=!0):(a=d,s="moreLink"),this.options.beforeToggle&&"function"==typeof this.options.beforeToggle&&this.options.beforeToggle(e,n,!r),n.css({height:a}),n.on("transitionend",function(i){return function(){i.options.afterToggle&&"function"==typeof i.options.afterToggle&&i.options.afterToggle(e,n,r),t(this).attr({"aria-expanded":r}).off("transitionend")}}(this)),t(e).replaceWith(t(this.options[s]).on("click",function(t){return function(e){t.toggle(this,i,e)}}(this)).attr({"data-readmore-toggle":n.attr("id"),"aria-controls":n.attr("id")}))},destroy:function(){t(this.element).each(function(){var e=t(this);e.attr({"data-readmore":null,"aria-expanded":null}).css({maxHeight:"",height:""}).next("[data-readmore-toggle]").remove(),e.removeData()})}},t.fn.readmore=function(e){var i=arguments,o=this.selector;return e=e||{},"object"==typeof e?this.each(function(){if(t.data(this,"plugin_"+s)){var i=t.data(this,"plugin_"+s);i.destroy.apply(i)}e.selector=o,t.data(this,"plugin_"+s,new a(this,e))}):"string"==typeof e&&"_"!==e[0]&&"init"!==e?this.each(function(){var o=t.data(this,"plugin_"+s);o instanceof a&&"function"==typeof o[e]&&o[e].apply(o,Array.prototype.slice.call(i,1))}):void 0}});
\ No newline at end of file