publisher: extract services into subview
This commit is contained in:
parent
5eb5057864
commit
253ab23f5e
2 changed files with 59 additions and 48 deletions
|
|
@ -3,49 +3,58 @@
|
|||
* the COPYRIGHT file.
|
||||
*/
|
||||
|
||||
(function(){
|
||||
// mixin-object, used in conjunction with the publisher to provide the
|
||||
// functionality for selecting services for cross-posting
|
||||
app.views.PublisherServices = {
|
||||
// Services view for the publisher.
|
||||
// Provides the ability for selecting services for cross-posting
|
||||
app.views.PublisherServices = Backbone.View.extend({
|
||||
|
||||
// visually toggle the icon and kick-off all other actions for cross-posting
|
||||
toggleService: function(evt) {
|
||||
var el = $(evt.target);
|
||||
var provider = el.attr('id');
|
||||
events: {
|
||||
'click .service_icon': 'toggleService'
|
||||
},
|
||||
|
||||
el.toggleClass("dim");
|
||||
tooltipSelector: '.service_icon',
|
||||
|
||||
this._createCounter();
|
||||
this._toggleServiceField(provider);
|
||||
},
|
||||
initialize: function() {
|
||||
// init tooltip plugin
|
||||
this.$(this.tooltipSelector).tooltip();
|
||||
},
|
||||
|
||||
// keep track of character count
|
||||
_createCounter: function() {
|
||||
// remove obsolete counter
|
||||
this.$('.counter').remove();
|
||||
// visually toggle the icon and handle all other actions for cross-posting
|
||||
toggleService: function(evt) {
|
||||
var el = $(evt.target);
|
||||
var provider = el.attr('id');
|
||||
|
||||
// create new counter
|
||||
var min = 40000;
|
||||
var a = this.$('.service_icon:not(.dim)');
|
||||
if(a.length > 0){
|
||||
$.each(a, function(index, value){
|
||||
var num = parseInt($(value).attr('maxchar'));
|
||||
if (min > num) { min = num; }
|
||||
});
|
||||
this.el_input.charCount({allowed: min, warning: min/10 });
|
||||
}
|
||||
},
|
||||
el.toggleClass("dim");
|
||||
|
||||
// add or remove the input containing the selected service
|
||||
_toggleServiceField: function(provider) {
|
||||
var hidden_field = this.$('input[name="services[]"][value="'+provider+'"]');
|
||||
if(hidden_field.length > 0){
|
||||
hidden_field.remove();
|
||||
} else {
|
||||
var uid = _.uniqueId('services_');
|
||||
this.$(".content_creation form").append(
|
||||
'<input id="'+uid+'" name="services[]" type="hidden" value="'+provider+'">');
|
||||
}
|
||||
this._createCounter();
|
||||
this._toggleServiceField(provider);
|
||||
},
|
||||
|
||||
// keep track of character count
|
||||
_createCounter: function() {
|
||||
// remove any obsolete counters
|
||||
this.options.input.siblings('.counter').remove();
|
||||
|
||||
// create new counter
|
||||
var min = 40000;
|
||||
var a = this.$('.service_icon:not(.dim)');
|
||||
if(a.length > 0){
|
||||
$.each(a, function(index, value){
|
||||
var num = parseInt($(value).attr('maxchar'));
|
||||
if (min > num) { min = num; }
|
||||
});
|
||||
this.options.input.charCount({allowed: min, warning: min/10 });
|
||||
}
|
||||
};
|
||||
})();
|
||||
},
|
||||
|
||||
// add or remove the input containing the selected service
|
||||
_toggleServiceField: function(provider) {
|
||||
var hidden_field = this.options.form.find('input[name="services[]"][value="'+provider+'"]');
|
||||
if(hidden_field.length > 0){
|
||||
hidden_field.remove();
|
||||
} else {
|
||||
var uid = _.uniqueId('services_');
|
||||
this.options.form.append(
|
||||
'<input id="'+uid+'" name="services[]" type="hidden" value="'+provider+'">');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
//= require jquery.textchange
|
||||
|
||||
app.views.Publisher = Backbone.View.extend(_.extend(
|
||||
app.views.PublisherServices,
|
||||
app.views.PublisherAspectsSelector,
|
||||
app.views.PublisherGettingStarted, {
|
||||
|
||||
|
|
@ -21,7 +20,6 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
"click #hide_publisher" : "clear",
|
||||
"submit form" : "createStatusMessage",
|
||||
"click .post_preview_button" : "createPostPreview",
|
||||
"click .service_icon": "toggleService",
|
||||
"textchange #status_message_fake_text": "handleTextchange",
|
||||
"click .dropdown .dropdown_list li": "toggleAspect",
|
||||
"click #locator" : "showLocation",
|
||||
|
|
@ -29,8 +27,6 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
"keypress #location_address" : "avoidEnter"
|
||||
},
|
||||
|
||||
tooltipSelector: ".service_icon",
|
||||
|
||||
initialize : function(){
|
||||
// init shortcut references to the various elements
|
||||
this.el_input = this.$('#status_message_fake_text');
|
||||
|
|
@ -46,9 +42,6 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
// init autoresize plugin
|
||||
this.el_input.autoResize({ 'extraSpace' : 10, 'maxHeight' : Infinity });
|
||||
|
||||
// init tooltip plugin
|
||||
this.$(this.tooltipSelector).tooltip();
|
||||
|
||||
// sync textarea content
|
||||
if( this.el_hiddenInput.val() == "" ) {
|
||||
this.el_hiddenInput.val( this.el_input.val() );
|
||||
|
|
@ -73,10 +66,19 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
}
|
||||
});
|
||||
|
||||
this.initSubviews();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
initSubviews: function() {
|
||||
this.view_services = new app.views.PublisherServices({
|
||||
el: this.$('#publisher_service_icons'),
|
||||
input: this.el_input,
|
||||
form: this.$('.content_creation form')
|
||||
});
|
||||
},
|
||||
|
||||
createStatusMessage : function(evt) {
|
||||
if(evt){ evt.preventDefault(); }
|
||||
|
||||
|
|
@ -260,11 +262,11 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
},
|
||||
|
||||
tryClose : function(){
|
||||
// if it is not submittable, close it.
|
||||
// if it is not submittable, close it.
|
||||
if( !this._submittable() ){
|
||||
this.close()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
open : function() {
|
||||
// visually 'open' the publisher
|
||||
|
|
|
|||
Loading…
Reference in a new issue