Merge pull request #6261 from svbergerem/remove-mbp-helper
Remove mbp helper and refactor mobile publisher js
This commit is contained in:
commit
99f7e2fc52
5 changed files with 49 additions and 211 deletions
|
|
@ -42,6 +42,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure.
|
||||||
* Use upstream CSS mappings for Entypo [#6158](https://github.com/diaspora/diaspora/pull/6158)
|
* Use upstream CSS mappings for Entypo [#6158](https://github.com/diaspora/diaspora/pull/6158)
|
||||||
* Replace some mobile icons with Entypo [#6218](https://github.com/diaspora/diaspora/pull/6218)
|
* Replace some mobile icons with Entypo [#6218](https://github.com/diaspora/diaspora/pull/6218)
|
||||||
* Refactor publisher backbone view [#6228](https://github.com/diaspora/diaspora/pull/6228)
|
* Refactor publisher backbone view [#6228](https://github.com/diaspora/diaspora/pull/6228)
|
||||||
|
* Replace MBP.autogrow with autosize on mobile [#6261](https://github.com/diaspora/diaspora/pull/6261)
|
||||||
|
|
||||||
## Bug fixes
|
## Bug fixes
|
||||||
* Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852)
|
* Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852)
|
||||||
|
|
@ -56,6 +57,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure.
|
||||||
* Display poll & location on mobile [#6238](https://github.com/diaspora/diaspora/pull/6238)
|
* Display poll & location on mobile [#6238](https://github.com/diaspora/diaspora/pull/6238)
|
||||||
* Update counts on contacts page dynamically [#6240](https://github.com/diaspora/diaspora/pull/6240)
|
* Update counts on contacts page dynamically [#6240](https://github.com/diaspora/diaspora/pull/6240)
|
||||||
* Add support for relay based public post federation [#6207](https://github.com/diaspora/diaspora/pull/6207)
|
* Add support for relay based public post federation [#6207](https://github.com/diaspora/diaspora/pull/6207)
|
||||||
|
* Bigger mobile publisher [#6261](https://github.com/diaspora/diaspora/pull/6261)
|
||||||
|
|
||||||
# 0.5.3.0
|
# 0.5.3.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
//= require jquery.charcount
|
//= require jquery.charcount
|
||||||
//= require js-routes
|
//= require js-routes
|
||||||
//= require mbp-helper
|
//= require autosize
|
||||||
//= require jquery.autoSuggest.custom
|
//= require jquery.autoSuggest.custom
|
||||||
//= require fileuploader-custom
|
//= require fileuploader-custom
|
||||||
//= require rails-timeago
|
//= require rails-timeago
|
||||||
|
|
@ -18,7 +18,8 @@
|
||||||
//= require mobile/mobile_file_uploader
|
//= require mobile/mobile_file_uploader
|
||||||
//= require mobile/profile_aspects
|
//= require mobile/profile_aspects
|
||||||
//= require mobile/tag_following
|
//= require mobile/tag_following
|
||||||
//= require mobile/mobile_comments.js
|
//= require mobile/publisher
|
||||||
|
//= require mobile/mobile_comments
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
|
|
@ -125,42 +126,5 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".service_icon").bind("tap click", function() {
|
|
||||||
var service = $(this).toggleClass("dim"),
|
|
||||||
selectedServices = $("#new_status_message .service_icon:not(.dim)"),
|
|
||||||
provider = service.attr("id"),
|
|
||||||
hiddenField = $("#new_status_message input[name='services[]'][value='" + provider + "']"),
|
|
||||||
publisherMaxChars = 40000,
|
|
||||||
serviceMaxChars;
|
|
||||||
|
|
||||||
|
|
||||||
$("#new_status_message .counter").remove();
|
|
||||||
|
|
||||||
$.each(selectedServices, function() {
|
|
||||||
serviceMaxChars = parseInt($(this).attr("maxchar"));
|
|
||||||
if(publisherMaxChars > serviceMaxChars) {
|
|
||||||
publisherMaxChars = serviceMaxChars;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#status_message_text').charCount({allowed: publisherMaxChars, warning: publisherMaxChars/10 });
|
|
||||||
|
|
||||||
if(hiddenField.length > 0) { hiddenField.remove(); }
|
|
||||||
else {
|
|
||||||
$("#new_status_message").append(
|
|
||||||
$("<input/>", {
|
|
||||||
name: "services[]",
|
|
||||||
type: "hidden",
|
|
||||||
value: provider
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#submit_new_message").bind("tap click", function(evt){
|
|
||||||
evt.preventDefault();
|
|
||||||
$("#new_status_message").submit();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ $(document).ready(function() {
|
||||||
var bottomBar = link.closest(".bottom_bar").first();
|
var bottomBar = link.closest(".bottom_bar").first();
|
||||||
bottomBar.append(data);
|
bottomBar.append(data);
|
||||||
var textArea = bottomBar.find("textarea.comment_box").first()[0];
|
var textArea = bottomBar.find("textarea.comment_box").first()[0];
|
||||||
MBP.autogrow(textArea);
|
autosize(textArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".stream").on("submit", ".new_comment", function(evt) {
|
$(".stream").on("submit", ".new_comment", function(evt) {
|
||||||
|
|
|
||||||
43
app/assets/javascripts/mobile/publisher.js
Normal file
43
app/assets/javascripts/mobile/publisher.js
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
$(document).ready(function(){
|
||||||
|
// no publisher available
|
||||||
|
if($("#new_status_message").length === 0) { return; }
|
||||||
|
|
||||||
|
$(".service_icon").bind("tap click", function() {
|
||||||
|
var service = $(this).toggleClass("dim"),
|
||||||
|
selectedServices = $("#new_status_message .service_icon:not(.dim)"),
|
||||||
|
provider = service.attr("id"),
|
||||||
|
hiddenField = $("#new_status_message input[name='services[]'][value='" + provider + "']"),
|
||||||
|
publisherMaxChars = 40000,
|
||||||
|
serviceMaxChars;
|
||||||
|
|
||||||
|
|
||||||
|
$("#new_status_message .counter").remove();
|
||||||
|
|
||||||
|
$.each(selectedServices, function() {
|
||||||
|
serviceMaxChars = parseInt($(this).attr("maxchar"));
|
||||||
|
if(publisherMaxChars > serviceMaxChars) {
|
||||||
|
publisherMaxChars = serviceMaxChars;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#status_message_text").charCount({allowed: publisherMaxChars, warning: publisherMaxChars/10 });
|
||||||
|
|
||||||
|
if(hiddenField.length > 0) { hiddenField.remove(); }
|
||||||
|
else {
|
||||||
|
$("#new_status_message").append(
|
||||||
|
$("<input/>", {
|
||||||
|
name: "services[]",
|
||||||
|
type: "hidden",
|
||||||
|
value: provider
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#submit_new_message").bind("tap click", function(evt){
|
||||||
|
evt.preventDefault();
|
||||||
|
$("#new_status_message").submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
autosize($("#status_message_text"));
|
||||||
|
});
|
||||||
171
vendor/assets/javascripts/mbp-helper.js
vendored
171
vendor/assets/javascripts/mbp-helper.js
vendored
|
|
@ -1,171 +0,0 @@
|
||||||
/*
|
|
||||||
* MBP - Mobile boilerplate helper functions
|
|
||||||
*/
|
|
||||||
(function(document){
|
|
||||||
|
|
||||||
window.MBP = window.MBP || {};
|
|
||||||
|
|
||||||
// Fix for iPhone viewport scale bug
|
|
||||||
// http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
|
|
||||||
|
|
||||||
MBP.viewportmeta = document.querySelector && document.querySelector('meta[name="viewport"]');
|
|
||||||
MBP.ua = navigator.userAgent;
|
|
||||||
|
|
||||||
MBP.scaleFix = function () {
|
|
||||||
if (MBP.viewportmeta && /iPhone|iPad/.test(MBP.ua) && !/Opera Mini/.test(MBP.ua)) {
|
|
||||||
MBP.viewportmeta.content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
|
|
||||||
document.addEventListener("gesturestart", MBP.gestureStart, false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
MBP.gestureStart = function () {
|
|
||||||
MBP.viewportmeta.content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Hide URL Bar for iOS and Android by Scott Jehl
|
|
||||||
// https://gist.github.com/1183357
|
|
||||||
|
|
||||||
MBP.hideUrlBar = function () {
|
|
||||||
var win = window,
|
|
||||||
doc = win.document;
|
|
||||||
|
|
||||||
// If there's a hash, or addEventListener is undefined, stop here
|
|
||||||
if( !location.hash || !win.addEventListener ){
|
|
||||||
|
|
||||||
//scroll to 1
|
|
||||||
window.scrollTo( 0, 1 );
|
|
||||||
var scrollTop = 1,
|
|
||||||
|
|
||||||
//reset to 0 on bodyready, if needed
|
|
||||||
bodycheck = setInterval(function(){
|
|
||||||
if( doc.body ){
|
|
||||||
clearInterval( bodycheck );
|
|
||||||
scrollTop = "scrollTop" in doc.body ? doc.body.scrollTop : 1;
|
|
||||||
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
|
|
||||||
}
|
|
||||||
}, 15 );
|
|
||||||
|
|
||||||
win.addEventListener( "load", function(){
|
|
||||||
setTimeout(function(){
|
|
||||||
//reset to hide addr bar at onload
|
|
||||||
win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
|
|
||||||
}, 0);
|
|
||||||
}, false );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Fast Buttons - read wiki below before using
|
|
||||||
// https://github.com/shichuan/mobile-html5-boilerplate/wiki/JavaScript-Helper
|
|
||||||
|
|
||||||
MBP.fastButton = function (element, handler) {
|
|
||||||
this.element = element;
|
|
||||||
this.handler = handler;
|
|
||||||
if (element.addEventListener) {
|
|
||||||
element.addEventListener('touchstart', this, false);
|
|
||||||
element.addEventListener('click', this, false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.fastButton.prototype.handleEvent = function(event) {
|
|
||||||
switch (event.type) {
|
|
||||||
case 'touchstart': this.onTouchStart(event); break;
|
|
||||||
case 'touchmove': this.onTouchMove(event); break;
|
|
||||||
case 'touchend': this.onClick(event); break;
|
|
||||||
case 'click': this.onClick(event); break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.fastButton.prototype.onTouchStart = function(event) {
|
|
||||||
event.stopPropagation();
|
|
||||||
this.element.addEventListener('touchend', this, false);
|
|
||||||
document.body.addEventListener('touchmove', this, false);
|
|
||||||
this.startX = event.touches[0].clientX;
|
|
||||||
this.startY = event.touches[0].clientY;
|
|
||||||
this.element.style.backgroundColor = "rgba(0,0,0,.7)";
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.fastButton.prototype.onTouchMove = function(event) {
|
|
||||||
if(Math.abs(event.touches[0].clientX - this.startX) > 10 ||
|
|
||||||
Math.abs(event.touches[0].clientY - this.startY) > 10 ) {
|
|
||||||
this.reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.fastButton.prototype.onClick = function(event) {
|
|
||||||
event.stopPropagation();
|
|
||||||
this.reset();
|
|
||||||
this.handler(event);
|
|
||||||
if(event.type == 'touchend') {
|
|
||||||
MBP.preventGhostClick(this.startX, this.startY);
|
|
||||||
}
|
|
||||||
this.element.style.backgroundColor = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.fastButton.prototype.reset = function() {
|
|
||||||
this.element.removeEventListener('touchend', this, false);
|
|
||||||
document.body.removeEventListener('touchmove', this, false);
|
|
||||||
this.element.style.backgroundColor = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.preventGhostClick = function (x, y) {
|
|
||||||
MBP.coords.push(x, y);
|
|
||||||
window.setTimeout(function (){
|
|
||||||
MBP.coords.splice(0, 2);
|
|
||||||
}, 2500);
|
|
||||||
};
|
|
||||||
|
|
||||||
MBP.ghostClickHandler = function (event) {
|
|
||||||
for(var i = 0, len = MBP.coords.length; i < len; i += 2) {
|
|
||||||
var x = MBP.coords[i];
|
|
||||||
var y = MBP.coords[i + 1];
|
|
||||||
if(Math.abs(event.clientX - x) < 25 && Math.abs(event.clientY - y) < 25) {
|
|
||||||
event.stopPropagation();
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (document.addEventListener) {
|
|
||||||
document.addEventListener('click', MBP.ghostClickHandler, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
MBP.coords = [];
|
|
||||||
|
|
||||||
|
|
||||||
// iOS Startup Image
|
|
||||||
// https://github.com/shichuan/mobile-html5-boilerplate/issues#issue/2
|
|
||||||
|
|
||||||
MBP.splash = function () {
|
|
||||||
var filename = navigator.platform === 'iPad' ? 'h/' : 'l/';
|
|
||||||
document.write('<link rel="apple-touch-startup-image" href="/img/' + filename + 'splash.png" />' );
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Autogrow
|
|
||||||
// http://googlecode.blogspot.com/2009/07/gmail-for-mobile-html5-series.html
|
|
||||||
|
|
||||||
MBP.autogrow = function (element, lh) {
|
|
||||||
|
|
||||||
function handler(e){
|
|
||||||
var newHeight = this.scrollHeight,
|
|
||||||
currentHeight = this.clientHeight;
|
|
||||||
if (newHeight > currentHeight) {
|
|
||||||
this.style.height = newHeight + 3 * textLineHeight + "px";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var setLineHeight = (lh) ? lh : 12,
|
|
||||||
textLineHeight = element.currentStyle ? element.currentStyle.lineHeight :
|
|
||||||
getComputedStyle(element, null).lineHeight;
|
|
||||||
|
|
||||||
textLineHeight = (textLineHeight.indexOf("px") == -1) ? setLineHeight :
|
|
||||||
parseInt(textLineHeight, 10);
|
|
||||||
|
|
||||||
element.style.overflow = "hidden";
|
|
||||||
element.addEventListener ? element.addEventListener('keyup', handler, false) :
|
|
||||||
element.attachEvent('onkeyup', handler);
|
|
||||||
};
|
|
||||||
|
|
||||||
})(document);
|
|
||||||
|
|
||||||
Loading…
Reference in a new issue