jtsage / jtsage-datebox

A multi-mode date and time picker for Bootstrap (3&4), jQueryMobile, Foundation, Bulma, FomanticUI, and UIKit (or others)
http://datebox.jtsage.dev/
Other
474 stars 166 forks source link

Additional option calBeforeGriddateAppend is needed. #369

Closed slavap closed 9 years ago

slavap commented 9 years ago

Sometimes complex class/style adjusting is needed for griddate cells. For example additional classes returned by calFormatter may contradict with "default" griddate's classes, so manual resolution is needed. It would be nice to have an ability to preprocess griddate div just before it's added to htmlRow, i.e. in the following code:

$("<div>")
    .html( fmtRet.text )
    .addClass( uid + "griddate ui-corner-all ui-btn")
    .addClass( ( curMonth === genny[row][col][1] || checked.force ) ?
        ( "ui-btn-" + checked.theme +
            ( checked.ok ? "" : " ui-state-disabled" )
        ) :
        ( uid + "griddate-empty" )
    )
    .addClass( fmtRet["class"] )
    .css(( curMonth !== genny[row][col][1] && !o.calOnlyMonth ) ?
        { cursor: "pointer" } :
        {}
    )
    .data( "date", 
        ( ( o.calWeekMode ) ?
            weekModeSel :
            genny[row][col][0] )
    )
    .data( "enabled", checked.ok)
    .data( "month",
        genny[ row ][ ( ( o.calWeekMode ) ?
                o.calWeekModeDay :
                col
            ) ][1]
    )
    .appendTo( htmlRow );

call calBeforeGriddateAppend(constructed-div), and only then appendTo( htmlRow );

jtsage commented 9 years ago

For some reason, I had a mental block on how to do this without introducing a bunch of new variables that didn't need to be there. Turns out, it's because I'm kinda dumb sometimes.

Anyway, it's called calBeforeAppendFunc. The default is a function that simply returns what it is fed. For funsies, you could override this with a non-function and watch the whole thing puke. Other than that, so long as you return something that .appendTo can operate on, it'll work.

jtsage commented 9 years ago

http://dev.jtsage.com/jQM-DateBox/api/calBeforeAppendFunc/

slavap commented 9 years ago

Looks good, the only thing may be documentation should be tweaked a little bit to emphasize that input jquery object is actually already constructed div with all classes and styles added and data (date, enabled, month) defined.

jtsage commented 9 years ago

aye, and to clean up the grammar so it doesn't read like I was drunk (really, I only just got home - haven't even made a drink yet. heh)